Offlineimap for Mutt


03-28-2016


Filed under: mail

I use mutt, the lesser sucky email client according to its author, on osx. I use offlineimap to periodically sync with fastmail (preferred to free gmail service) server.

My basic offlineimap setup in .offlineimaprc is:

[general]
accounts = zlu
pythonfile = ~/.mutt/offlineimap.py

[Account zlu]
localrepository = zlu-local
remoterepository = zlu-remote
status_backend = sqlite

[Repository zlu-local]
type = Maildir
localfolders = ~/Maildir

[Repository zlu-remote]
type = IMAP
remotehost = mail.messagingengine.com
remoteuser = youremail@fastmail.com
remotepasseval = get_keychain_pass()
remoteport = 992
ssl = yes
cert_fingerprint = BDDC89DAE48629898AF13421D7844F806CA33943 

There are a couple of things worth mentioning in this config file.

#!/usr/bin/python

import subprocess

def get_keychain_pass():
command = "security find-generic-password -g -a youremail@fastmail.com 2>&1 | awk '/^password: \"(.*)\"/{print $2}'"
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
return output[1:(len(output)-2)]

The weird thing I’m doing with output character array is because check_output from stdout returns a quote in the beginning of the password and a quote with newline at the end. I’m sure this can be avoided somehow.

It is a good idea to test out offlineimap utility ‘manually’ first. brew info offlineimap (assuming you installed offlineimap with brew) tells you where the plist is stored. cat plist to find out where the binary executable is. On my system, it is /usr/local/opt/offlineimap/bin/offlineimap. Run this directly and observe the verbose output without manually turning on debug mode, thanks to the implementer. If mail syncs ok, then you are good to go.