branch14log

GMail, OfflineIMAP & Mutt

20 Jun 2012

OfflineIMAP makes accessing your GMail account with Mutt a breeze. In this example the offline Maildir directories are put under a pangmail directory, so you can easily at multiple account each into their own directory. This is what goes into you ~/.offlineimaprc. Please replace your@gmail.login with your entire email address.
[general]
accounts = PanGMail
maxsyncaccounts = 3

[Account PanGMail]
localrepository = PanGMailLocal
remoterepository = PanGMailRemote
autorefresh = 10
quick = 5

[Repository PanGMailLocal]
type = Maildir
localfolders = ~/Maildir/pangmail
sep = "/"

[Repository PanGMailRemote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = your@gmail.login
ssl = yes
nametrans = lambda folder: re.sub('.*Spam$', 'spam',
    re.sub('.*Drafts$', 'drafts',
    re.sub('.*Sent Mail$', 'sent',
    re.sub('.*Starred$', 'flagged',
    re.sub('.*Trash$', 'trash',
    re.sub('.*All Mail$', 'archive', folder))))))
folderfilter = lambda folder: folder not in ['[Gmail]/All Mail',
    '[Gmail]/Trash','[Gmail]/Spam','[Gmail]/Starred']

[mbnames]
enabled = yes
filename = ~/.offlineimap.mailboxes
header = "mailboxes "
peritem = "~/Maildir/pangmail/%(foldername)s"
sep = " "
footer = "\n"
Depending on your GMail filter you might want to add additional substitutions in the nametrans. Now fire up OfflineIMAP and watch the mail be pulled in.
% offlineimap
The last section automatically creates file to be included in your ~/.muttrc, in order to make mutt learn about the Maildir directories created by OfflineIMAP. So you have to put this line into your ~/.muttrc
source ~/.offlineimap.mailboxes
As Michael R. Elkins, author of Mutt, might put it: "GMail sucks. With Mutt, it just sucks less."