Alpine, offlineimap, and Gmail (under Ubuntu)

Another round of attempts at getting my email to do what I want has left me without success on the alpine+uw-imapd+offlineimap+gmail front, but I have now managed to compile Eduardo Chappa’s infamous (due to licensing issues) maildir patch into alpine. After figuring out some configuration difficulties, I am using that enhanced alpine directly on the offlineimap repository.

To summarise, I have my beloved, efficient alpine interface with access to a local copy of all of my Gmail mail, available to me whether or not I am online. Folders (other than my inbox)  in alpine correspond to Gmail tags. The program offlineimap does a two-way synchronization of Gmail with my (or each) local copy of mail, so I can use Gmail’s web interface (or any other imap client talking to it) or alpine on my local machine to sort and label mail and it will all have the same effect everywhere once I’m back online and offlineimap has had a chance to run.

In principle, I can have such local repositories sync’ed with offlineimap on multiple computers. (I cannot see a problem with that, anyway, and I have two offlineimap’s running now).

In the mean time, by the way, I have learned that the Gmail interface itself is quite efficient when you learn all the keystrokes and have got Gmail’s offline feature working (requires 64 bit Google Gears, not supported). So I can now move back from that to alpine, but will not suffer as much as I used to when I want/need to use Gmail directly.

So, here is what I did under Ubuntu 9.10, after downloading alpine 2.00 and Chappa’s maildir patch for alpine 2.00.

# Neat apt feature to install all compilation dependencies for alpine without installing alpine:

sudo apt-get build-dep alpine

# from just above the alpine-2.00 (or whatever)  folder you downloaded, and with the maildir patch local:

patch -p0 < maildir.patch

# Compile alpine: (from just inside the alpine-2.00 (or etc)  folder):

sudo make install

My gmail username is “MyName”. I set up offlineimap to put my stuff in ~/imap/gmailMyName.  That is, within that folder are all my mail folders (gmail tags) plus  “INBOX”, each containing a “cur”, a “new”, and a “tmp”. The latter format is a feature of the “maildir” directory/file format which offlineimap uses. Thus:

apt-get install offlineimap
mkdir imap
mkdir imap/gmailMyName

Now (after running alpine once to create .pinerc) I put the following lines in my .pinerc file. (These features can be set up using alpine’s configuration menus too, of course). Thanks to Eduardo Chappa both for his instructions (see the link above), and for his kind personal help setting this up:


folder-collections=gmailMaildir #md/imap/gmailMyName/[]
default-fcc=[Gmail].Sent Mailpostponed-folder=[Gmail].Drafts

There are other sites providing example offlineimap+gmail setups, and the offlineimap site explains the following parameters. Here are some key lines (actually, sufficient as a complete set) from my .offlineimaprc file. Note that I have included “All Mail” in the do-not-sync list. It may be a good trick to start out with this setting, and then later to allow All Mail to be synced as well.  So far it seems that the offlineimap repository takes up a fair bit more space locally than it does on Gmail’s servers, so if you’ve been good about tagging messages, you may want never to have a local copy of “All Mail”.

accounts = myNameGMAIL


[Account myNameGMAIL]
localrepository = gmailLocal
remoterepository = gmailRemote

[Repository gmailLocal]
type = Maildir
localfolders = /home/cpbl/imap/gmailMyName

[Repository gmailRemote]
type = Gmail
remoteuser =
realdelete = no
folderfilter = lambda foldername: foldername not in [ ‘[Gmail]/Trash’,'[Gmail]/Spam’,'[Gmail]/All Mail’,]

So when that is done, simply run “offlineimap” and wait for it to sync up. You can start using alpine immediately, ie before the first sync is complete.  Alpine should start up showing your Gmail inbox, and pressing “l” should show you all your tags.

I have yet to see a good description of how offlineimap treats message threads or how alpine will interact with gmail.  What happens if I delete an attachment from a message in alpine, and then save it to a folder?  What happens if I save one message of a thread in one folder and another of the same thread in a different folder? If I want to have two tags on a message, do I save it to a different folder and then remove the local delete mark? Does that double the disk space usage for that message in offlineimap?

It would be nice to have some local (fake smtp?) server running so that I could send my messages from alpine instantly and they would be shuttled off to my favourite real smtp server when I was next online, or just in the background…

Update 25 Nov 2009:  offlineimap keeps dying on doing certain copies, I think when alpine is running, for various reasons. So I have set cron to run it every couple of minutes instead of using offlineimap’s own recheck feature. ie, install with

apt-get install gnome-schedule

and choose (i.e., run) “Scheduled tasks” from the system tools menu; set it to run offlineimap as often as you like.

Update 18 March 2010:  I suppose I’ve not been able to get the “quick” mode of offlineimap to run nicely, so instead of calling offlineimap every few minutes, I call the following script every few minutes (ie set it to execute regularly using gnome-schedule):

curl -u MyName:MyNamePassword --silent "" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;' > /home/cpbl/tmp/newGmail
touch /home/cpbl/tmp/newGmail
touch /home/cpbl/tmp/oldGmail
cmp -s /home/cpbl/tmp/oldGmail /home/cpbl/tmp/newGmail > /dev/null
if [ $? -eq 1 ]; then
 offlineimap -u Noninteractive.Quiet
 echo is not different
cp /home/cpbl/tmp/newGmail /home/cpbl/tmp/oldGmail

That is, this does a quick check with Gmail to see whether anything is new, and only then does it call offlineimap.

Update 2012 / January: I’ve a newer post that describes an upgraded method for a very similar outcome: How-to: Alpine and maildir (and offlineimap (and GMail)) — no more maildir patches.


This entry was posted in GNU/linux, software, Ubuntu and tagged , , , , , . Bookmark the permalink.

4 Responses to Alpine, offlineimap, and Gmail (under Ubuntu)

  1. Graham says:

    Sounds like a nice pragmatic solution. I fear that your crashes could be due to Maildir’s alleged locking issues, but then again my maildir-free offlineimap has died on me a couple of times (for obscure message metadata reasons), so perhaps not… Maybe file a bug if you think you can isolate a problem: John Goerzen has been very responsive in dealing with issues in the past.

    As regards fake SMTP: you’re actually looking for a real SMTP server with a “smart host” setup. Very low overhead, and will hang on to your messages until you’re online. A simple guide to doing this with sendmail is available at

    Note the project of the above link, which I’ve only just found: it seems to be a competing IMAP sync daemon which I’ve not yet tried..!

  2. cpbl says:

    … Oh, and just set the default mail reader (System->Preferences->Preferred Applications) to “Custom”: gnome-terminal -e /usr/bin/alpine

    That way, pressing the button on my keyboard that has an envelope icon launches Alpine! As does my mail notifier, etc.

  3. Pingback: Using Email at McGill university: Ongoing suffering of an open-source user, year 9 | The Red Pen

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s