2017-05-26 13:07:27 +02:00
|
|
|
#!/usr/bin/python3
|
2016-03-07 17:31:28 +01:00
|
|
|
import subprocess
|
2017-05-26 13:07:27 +02:00
|
|
|
import sys
|
2016-03-07 17:31:28 +01:00
|
|
|
|
|
|
|
def mailpasswd(account):
|
|
|
|
path = "/home/sanchayan/.%s.gpg" % account
|
2017-05-26 13:07:27 +02:00
|
|
|
args = ["gpg2", "--use-agent", "--quiet", "--batch", "-d", path]
|
2016-03-13 10:23:53 +01:00
|
|
|
try:
|
2017-05-26 13:07:27 +02:00
|
|
|
return subprocess.check_output(["gpg2", "--batch", "-d", path]).strip()
|
2016-03-13 10:23:53 +01:00
|
|
|
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()
|