dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 9e6433bf1223e497aec8375a29555fbb32d2f6f7
parent 09a6763576e4e3cdecb98fc29508a95afbe35ffd
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 20 Dec 2018 20:22:20 +0100

Invoke gpg with agent for reading encrypted imap passwords

Diffstat:
Mlinks/.mutt/offlineimap-password-store.py | 20+++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/links/.mutt/offlineimap-password-store.py b/links/.mutt/offlineimap-password-store.py @@ -1,12 +1,14 @@ #!/usr/bin/env python -from subprocess import check_output +import os.path +import subprocess -def get_pass(account): - return check_output("pass Email/" + account, shell=True).splitlines()[0] +home = os.path.expanduser("~") -if __name__ == "__main__": - import sys - if sys.version_info[0] < 3: - print(get_pass(sys.argv[1])) - else: - print(get_pass(sys.argv[1]).decode("utf-8")) +def get_pass(acct): + acct = os.path.basename(acct) + path = "%s/.password-store/Email/%s.gpg" % (home,acct) + args = ["gpg2", "--use-agent", "--quiet", "--batch", "-d", path] + try: + return subprocess.check_output(args).strip() + except subprocess.CalledProcessError: + return ""