Some real use cases
- Sync from GMail to another IMAP server
- Sync from Gmail to a local Maildir with labels
- Selecting only a few folders to sync
- Another nametrans transpose example
- 2 IMAP using name translations
Sync from GMail to another IMAP server
This is an example of a setup where “TheOtherImap” requires all folders to be under INBOX:
Sync from Gmail to a local Maildir with labels
This is an example of a setup where GMail gets synced with a local Maildir. It also keeps track of GMail labels, that get embedded into the messages under the header configured in the labelsheader setting, and syncs them back and forth the same way as flags. This is particularly useful with an email client that indexes your email and recognizes the labels header, so that you can sync a single “All Mail” folder, and navigate your email via searches.
The header used to store the labels depends on the email client you plan to use. Some choices that may be recognized by email clients are X-Keywords (the default) or X-Labels. Note that if you need to change the label header after the labels have already been synced, you will have to change the header manually on all messages, otherwise offlineimap will not pick up the labels under the old header.
The first time OfflineIMAP runs with synclabels enabled on a large repository it may take some time as the labels are read / embedded on every message. Afterwards local label changes are detected using modification times, which is much faster:
There are some labels, that gmail treats in a special way. All internal gmail labels start with “\”. Those labels include:
- \Drafts
- \Important
- \Inbox
- \Sent
- \Junk
- \Flagged
- \Trash
You can add and remove those labels locally, and when synced, will have special actions on the gmail side. For instance, adding the label \Trash
to an email will move it to the trash, and be permanantly deleted after some time. This is relevant, since gmail’s IMAP prevents from removing messages from the “All Mail” folder the usual way.
Selecting only a few folders to sync
Add this to the remote gmail repository section to only sync mails which are in a certain folder:
To only get the All Mail folder from a Gmail account, you would e.g. do:
Another nametrans transpose example
Put everything in a GMX. subfolder except for the boxes INBOX, Draft, and Sent which should keep the same name:
2 IMAP using name translations
Synchronizing 2 IMAP accounts to local Maildirs that are “next to each other”, so that mutt can work on both. Full email setup described by Thomas Kahle at http://dev.gentoo.org/~tomka/mail.html.
offlineimap.conf
:
One of the coolest things about OfflineIMAP is that you can call arbitrary python code from your configuration. To do this, specify a pythonfile with:
Here is a basic content sample:
From this sample, replace the cmd line with whatever can retrieve your password. Your pythonfile needs to contain implementations for the functions that you want to use in offflineimaprc. The example uses it for two purposes: Fetching passwords from the gnome-keyring and translating folder names on the server to local foldernames.
An example implementation of get_username and get_password showing how to query gnome-keyring is contained in http://dev.gentoo.org/~tomka/mail-setup.tar.bz2.
The folderfilter is a lambda term that, well, filters which folders to get. The function oimaptransfolder_acc2
translates remote folders into local folders with a very simple logic. The INBOX
folder will have the same name as the account while any other folder will have the account name and a dot as a prefix. This is useful for hierarchichal display in mutt.
Offlineimap handles the renaming correctly in both directions: