Fast Convenient Mail for Travel: OfflineIMAP

Linux laptop users, try the mail solution that combines the advantages of fast local mail folders and a server-based IMAP repository.
Selecting Folders

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)

This input causes the folder named Trash and all folders containing the text Del to be excluded.

Changing Folder Names

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.

Synchronizing Two IMAP Servers

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.

Conclusion

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 jgoerzen@complete.org.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Booming

Gurkha Encounters's picture

I guess there is booming the Performance and method for travel and tourism

Thank you

Travel

Suba Sagar Malla's picture

I guess there would be such fast methods for Travel as well.

subscribed folders

Anonymous's picture

I am curious if OfflineIMAP can be set to only synchronize IMAP folders which are marked as subscribed. While reading the section marked "Selecting Folders" it seemed natural to have an option regarding IMAP subscriptions, which could, in most cases, circumvent the need for writing a special callback function in python.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix