Skip to content

A simple offlineimap tip with some mutt goodness

A few years back I switched away from a GUI email client for work and back to ‘mutt’.  While ‘mutt’ can handle doing an IMAP connection directly, I wanted to gain from the speed and portability of having fully local folders.  (This is more feasible, I think, since encrypting hard drives became so much easier; now I can carry around my work email safely.)  The tool my people have been using for synchronizing IMAP folders is ‘offlineimap’.

After using this combination for a while (running ‘offlineimap’ in ‘screen’, with ‘mutt’ running in one or more ‘screen’ windows), I ran in to some problems with ‘offlineimap’ when it was run continuously.  I could set the sync interval in the configuration just fine, but inevitably a few things happened.  It would be syncing, using CPU, memory, and bandwidth when I had other ideas for how to use those resources.  It would be in between a scheduled sync when I wanted to check for an email just sent, causing me to quit and restart it.  It would occasionally suck up all my memory, requiring a kill and restart (that was probably an older, buggier version?)  It also didn’t like it if I suspended the laptop or lost network during a sync, which seemed to be the main trigger for the memory-sucking-error.

Finally, Paul suggested to me that I try just running it manually when I wanted to get my email.  This was part of a larger discussion on how to not let email run your life.  If you know the email is constantly being refreshed, it’s easy to “just go see if there is something new”, thereby procrastinating on what you are really supposed to be doing.  By making mail poll/sync a manual task, I could eliminate most of the first problems, and fresh messages were always just moments away.  (If I’m anxious to get an email NOW, I’m usually interested in the main inbox, since my email is filtered server-side.)

All that leads me to this very simple ‘bash’ script that runs ‘offlineimap’ one time, and before exiting puts a nice visible timestamp on the console for me.  I find this really helpful to let me know when I last ran ‘offlineimap’.  Sometimes it shows me it’s only been twenty minutes, and my checking email is a sign to me that I am procrastinating.  Other times it shows me that I haven’t checked since last night!

/usr/bin/offlineimap -o;
echo "****************************"
echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvv"
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
echo "****************************"

That is such a simple script that I don’t think it warrants copyright, but just in case I am wrong, consider it under the GPL v3+ (yes, I trust the FSF with improvements to the GPL more than I trust that GPL v3 is so perfect that it never needs improving.)

For ‘mutt’ goodness, check out Paul’s configuration directory for his ‘mutt’ wrapper script (which I use), as well as his ‘mutt’ and ‘offlineimap’ configuration files (which I also modified to use.)  You might notice that Paul has contributed a ton more to my ‘offlineimap’/’mutt’ experience than the reverse, but I try. 🙂