Fast Convenient Mail for Travel: OfflineIMAP
By default, OfflineIMAP asks your remote IMAP server which folders are available to you and synchronizes all of them. A folderfilter option can be added to your remote repository section to restrict what is brought over. The folderfilter option is a tremendously powerful option. Unlike the other options you've seen so far, folderfilter actually expects to be handed a Python function. The function takes one argument and should return true if that folder is to be included.
Python provides a feature called lambda that lets you create simple functions on the fly. You thus can construct some complex rules. Here are a few examples. You can specify a set of folders you want to synchronize. You can use the Python in operator to test whether the folder in question is in the list, like this:
folderfilter = lambda foldername: foldername in ['INBOX', 'Sent Mail', 'Received']
This code synchronizes only the three named folders. Notice the indentation on the second and third lines—if you indent them, the configuration parser treats them as part of a single statement.
You also can specify folders to exclude:
folderfilter = lambda foldername: foldername not in ['Spam', 'Junk']
In this example, all folders except Spam and Junk are synchronized.
You also can use regular expressions, such as:
folderfilter = lambda foldername: not re.search('(^Trash$|Del)', foldername)
Sometimes, you may want to alter the folder names before storing the folders on the local side. OfflineIMAP provides an option called nametrans, also specified in the remote repository section, to do exactly that. Some IMAP servers, such as Courier, add “INBOX.” to the start of all folders, which can be annoying. The nametrans feature lets you get rid of that. Here's an example:
nametrans = lambda foldername: re.sub('^INBOX\.', '', foldername)
Like folderfilter, nametrans takes a Python expression. This expression receives a folder name as an argument and should return the new and improved folder name. In this example, any folder whose name starts with INBOX. gets the leading INBOX. removed. It's important to remove not only the leading INBOX; the folder INBOX itself does exist, so you'd wind up with an empty folder name (and that's a bad thing).
It's also important to be careful with your nametrans rules. You must make sure that nametrans returns a different value for each folder. If it returns the same thing for two different folders, bad things can happen.
In case you're wondering, nametrans does not change folderfilter. That is, your folderfilter rules operate on the folder names before nametrans takes effect.
Some mail readers don't support Maildir hierarchies well. For them, OfflineIMAP introduced a new feature: the ability to synchronize two IMAP servers directly. The idea is this: you install an IMAP server on your local machines. Your mail reader, which already may have slow IMAP support, is fairly speedy in accessing an IMAP server located on your own machine. The mail reader never needs to know that OfflineIMAP is sticking the messages in the folders.
To make this happen, you need to make a few simple changes to your local repository section. First, change the type from Maildir to IMAP. Secondly, remove the localfolders and other Maildir information and instead specify IMAP configurations, such as remotehost and remoteuser. Finally, delete your ~/.offlineimap directory to make sure that none of the old status information lingers around.
Certain options still are supported only in the remote section—nametrans and folderfilter are two examples—but the options relating to the connection itself are supported in both places. You can, in fact, have your local IMAP server on a machine that is remote to you.
OfflineIMAP is a powerful mail solution. I've introduced you to the basics of OfflineIMAP in this article, but there still is more you can do with it. To learn more, check out the OfflineIMAP home page and the example configuration files. If you're a Python programmer, you'll find some nice hooks for Python code as well.
John Goerzen has been programming for Linux since 1996 and currently is vice president of Software in the Public Interest, Inc. He welcomes your comments at firstname.lastname@example.org.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Firefox 46.0 Released
- Ubuntu Online Summit
- Devuan Beta Release
- The Qt Company's Qt Start-Up
- May 2016 Issue of Linux Journal
- The US Government and Open-Source Software
- The Death of RoboVM
- Open-Source Project Secretly Funded by CIA
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- New Container Image Standard Promises More Portable Apps
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide