diff --git a/imapfilter/config.lua b/imapfilter/config.lua index 976a822..4cca196 100644 --- a/imapfilter/config.lua +++ b/imapfilter/config.lua @@ -168,7 +168,7 @@ function get_imap_password(file) end function get_pwd_victor() - local cmd = "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.victor.gpg" + local cmd = "gpg --use-agent --quiet --batch --decrypt ~/.victor.gpg" local fd = io.popen(cmd, 'r') pass = fd:read("*a") fd:close() @@ -176,7 +176,7 @@ function get_pwd_victor() end function get_pwd_sanchayan() - local cmd = "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.sanchayan.gpg" + local cmd = "gpg --use-agent --quiet --batch --decrypt ~/.sanchayan.gpg" local fd = io.popen(cmd, 'r') pass = fd:read("*a") fd:close() diff --git a/msmtprc b/msmtprc index 587be35..4e88500 100644 --- a/msmtprc +++ b/msmtprc @@ -11,19 +11,19 @@ account Sanchayan host smtp.gmail.com from maitysanchayan@gmail.com user maitysanchayan@gmail.com -passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.sanchayan.gpg" +passwordeval "gpg --use-agent --batch --quiet --no-greeting --no-tty --for-your-eyes-only --homedir /home/sanchayan/.gnupg --decrypt ~/.sanchayan.gpg" account Victor host smtp.gmail.com from victorascroft@gmail.com user victorascroft@gmail.com -passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.victor.gpg" +passwordeval "gpg --use-agent --batch --quiet --no-greeting --no-tty --for-your-eyes-only --homedir /home/sanchayan/.gnupg --decrypt ~/.victor.gpg" account Toradex host smtp.office365.com from sanchayan.maity@toradex.com user sanchayan.maity@toradex.com -passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.toradex.gpg" +passwordeval "gpg --use-agent --batch --quiet --no-greeting --no-tty --for-your-eyes-only --homedir /home/sanchayan/.gnupg --decrypt ~/.toradex.gpg" # Set a default account account default : Sanchayan diff --git a/offlineimap.py b/offlineimap.py index 51b7e83..7aaa4dc 100644 --- a/offlineimap.py +++ b/offlineimap.py @@ -2,4 +2,23 @@ import subprocess def mailpasswd(account): path = "/home/sanchayan/.%s.gpg" % account - return subprocess.check_output(["gpg", "--quiet", "--batch", "-d", path]).strip() + 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()