I use the following method, which works fairly well:
1) Store your passwords in separate gpg encrypted files. For example ~/.passwd/<accountname>.gpg
2) Create a python extension file with a name of your choosing (e.g., ~/.offlineimap.py
), with the following contents:
def mailpasswd(acct):
acct = os.path.basename(acct)
path = "/home/<username>/.passwd/%s.gpg" % acct
args = ["gpg", "--use-agent", "--quiet", "--batch", "-d", path]
try:
return subprocess.check_output(args).strip()
except subprocess.CalledProcessError:
return ""
3) Modify your .offlineimaprc file to tell it about the python file, and to tell it how to read your passwords
[general]
pythonfile = ~/.offlineimap.py
# ...
[Repository <reponame>]
# add this line for each remote repository
remotepasseval = mailpasswd("<accountname>")
If you have several accounts that get checked simultaneously (separate threads), and you use gpg-agent, then it will ask for you passphrase for each account. I prime the agent by creating a file (echo "prime" | gpg -e -r [email protected] > ~/.passwd/prime.gpg
), and priming the gpg agent by decrypting this file on launch of offlineimap. To do this, add the following to the end of ~/.offlineimap.py
:
def prime_gpg_agent():
ret = False
i = 1
while not ret:
ret = (mailpasswd("prime") == "prime")
if i > 2:
from offlineimap.ui import getglobalui
sys.stderr.write("Error reading in passwords. Terminating.\n")
getglobalui().terminate()
i += 1
return ret
prime_gpg_agent()
root
user could do to get around the encryption. Remember that even X11 forwarding from untrusted machines (e.g. viassh -X
) is not safe.