I will now describe the parts and their configuration. Again, I’m no expert with these programs so it may contain mistakes. Nonetheless, I always find it useful when someone shares its own setup: it’s more practical than just documentation examples. Here it is.

OfflineImap

OfflineImap is a python program for syncing a remote IMAP account with a local Maildir folder. It accepts multiple accounts and works both ways: a mail added or deleted locally will also be added or deleted on the IMAP server.

~/.offlineimaprc # Sample minimal config file. Copy this to ~/.offlineimaprc and edit to # get started fast. [general] accounts = lertsenem pythonfile = ~/.config/offlineimap/gnome-keyring_helper.py [Account lertsenem] localrepository = lertsenem-local remoterepository = lertsenem-remote postsynchook = ~/.config/offlineimap/hooks/postsync_lertsenem [Repository lertsenem-local] type = Maildir localfolders = ~/Mail/lertsenem [Repository lertsenem-remote] type = IMAP ssl = yes sslcacertfile = ~/.config/offlineimap/certs/mail.gandi.net.chain.crt remotehost = mail.gandi.net remoteport = 993 remoteusereval = get_username("lertsenem") remotepasseval = get_password("lertsenem")

The most important part of the offlineimap configuration is the .offlineimaprc dotfile. The important parts are:

you can use multiple account (but I left only one for privacy reasons) ;

you can use hooks ;

you can store your credentials any way you like.

So, here I connect to my IMAP server provider, which is Gandi, using the credentials returned by the functions get_username() and get_password(). These functions are not defined by offlineimap, but by the python file I specified in the pythonfile configuration directive. You can read it here:

~/.config/offlineimap/gnome-keyring_helper.py #!/usr/bin/env python import gnomekeyring as gkey def set_credentials(repo, user, pw): KEYRING_NAME = "mails" attrs = { "repo": repo, "user": user } keyring = gkey.get_default_keyring_sync() gkey.item_create_sync(keyring, gkey.ITEM_NETWORK_PASSWORD, KEYRING_NAME, attrs, pw, True) def get_credentials(repo): keyring = gkey.get_default_keyring_sync() attrs = {"repo": repo} items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs) return (items[0].attributes["user"], items[0].secret) def get_username(repo): return get_credentials(repo)[0] def get_password(repo): return get_credentials(repo)[1] if __name__ == "__main__": import sys import os import getpass if len(sys.argv) < 2: print "Usage: %s (get|set)" \ % (os.path.basename(sys.argv[0])) sys.exit(0) method = sys.argv[1] if method == "set": if len(sys.argv) != 4: print "Usage: %s set <repository> <username>" \ % (os.path.basename(sys.argv[0])) sys.exit(0) repo, username = sys.argv[2:] password = getpass.getpass("Enter password for user '%s': " % username) password_confirmation = getpass.getpass("Confirm password: ") if password != password_confirmation: print "Error: password confirmation does not match" sys.exit(1) set_credentials(repo, username, password) elif method == "get": if len(sys.argv) != 4: print "Usage: %s get <repository> (username|password)" \ % (os.path.basename(sys.argv[0])) sys.exit(0) repo, toget = sys.argv[2:] if toget == "username": print(get_username(repo)) elif toget == "password": print(get_password(repo))

As you can see, this script uses the gnome-keyring to fetch a username and a password, in the default keyring (which name is Login most of the time) with the name mails. If you don’t know how to use credentials in your gnome-keyring do not frown: the script also allows you to store the credentials by running it.

The hooks are defined on a per-account basis with the postsynchook directive. They can be any script you like. Mine is written in shell and goes like this:

~/.config/offlineimap/hooks/postsync_lertsenem #!/bin/sh # Initial import notmuch new # Tagging notmuch tag -inbox +archive folder:Archive notmuch tag -inbox +draft folder:Brouillons notmuch tag -inbox +trash folder:Corbeille