It doesn’t make sense to look at the Mutt config first, even though that is at the heart of everything. So first of all I’ll cover offlineimap.
This package will replicate the IMAP folders from your email provider (Google Apps in this case), which makes them available to Mutt at any time (instant download of message bodies, offline access). A few choices need to be made about name substitutions, but I’m happy with the approach used in the config I cribbed from which is to convert all mailboxes to lowercase, and to substitute ‘bak’ in place of ‘[GMail]’.
This should be named .offlineimaprc and should be placed in your home directory.
[general] # Substitute something that makes sense for 'account_name' accounts = account_name # Only one account used here. Multiple accounts are supported, but need some changes maxsyncaccounts = 1 # No output ui = quiet [mbnames] # Creates a list of all imap mailboxes to be used by mutt to avoid having to retrieve # mailboxes from the IMAP server for every move or copy command enabled = yes # Just create .mutt, and the mailboxes file will be written by offlineimap filename = ~/.mutt/mailboxes # Standard stuff header = "mailboxes " peritem = "+%(foldername)s" sep = " " footer = "\n" # Substitute something that makes sense for 'account_name' [Account account_name] # Substitute something that makes sense for 'account_name_local' # and 'account_name_remote' localrepository = account_name_local remoterepository = account_name_remote # A file-based backend gets slower as it gets bigger, apparently. # SQLite may be a dependency you need to install status_backend = sqlite # Substitute something that makes sense for 'account_name_local' [Repository account_name_local] type = Maildir # Create the directory you want to use to store the mirrored IMAP folders localfolders = ~/.imap # Substitute something that makes sense for 'account_name_remote' [Repository account_name_remote] type = Gmail remotehost = imap.gmail.com remoteport = 993 # This can be 'email@example.com' or any domain registered with Google Apps with # active Mail settings remoteuser = firstname.lastname@example.org remotepass = xxxxxxxx # Standard stuff ssl = yes keepalive = 60 # Maxconnections can be increased, but 1-3 are recommended values maxconnections = 2 # In Mutt we will move deleted items to Trash, so no need to set this to yes realdelete = no # Renames some folders, and convert them all to lowercase nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak', re.sub ('sent_mail', 'sent', re.sub ('starred', 'flagged', re.sub (' ', '_', foldername.lower())))) # Don't mirror the All Mail folder folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail' # Allows SSL connections. This is probably an install dependency sslcacertfile = /etc/ssl/certs/ca-certificates.crt
Make the required changes to the remoteuser and remotepass keys, and change the account_name* values to something more applicable (though that’s not strictly required) and you should be good to go. Run ‘offlineimap’ and wait. Wait for a long time if you have a big mailbox. And maybe change .offlineimaprc to set ‘ui = ttyui’ for the first run, so you get some helpful feedback.
There are ways to run this as a daemon, but I’ve found a simple cronjob is working fine. With this, I do a quick check every couple of minutes, which takes about 40 seconds for me. Then every hour I do a full check, which takes a little longer.
These entries in the crontab achieve this:
4-59/2 * * * * /usr/bin/offlineimap -q > /dev/null 2>&1 0 * * * * /usr/bin/offlineimap > /dev/null 2>&1
Next I’ll look at setting up msmtp for seamless sending of emails.