dotfiles/offlineimap.py

24 lines
692 B
Python

import subprocess
def mailpasswd(account):
path = "/home/sanchayan/.%s.gpg" % account
args = ["gpg", "--use-agent", "--quiet", "--batch", "-d", path]
try:
return subprocess.check_output(["gpg", "--batch", "-d", path]).strip()
except subprocess.CalledProcessError:
return ""
# http://unix.stackexchange.com/questions/44214/encrypt-offlineimap-password
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()