| 1 | import os |
| 2 | import subprocess |
| 3 | |
| 4 | def mailpasswd(acct): |
| 5 | acct = os.path.basename(acct) |
| 6 | path = "/home/amin/.passwd/%s.gpg" % acct |
| 7 | args = ["gpg", "--use-agent", "--quiet", "--batch", "-d", path] |
| 8 | try: |
| 9 | return subprocess.check_output(args).strip() |
| 10 | except subprocess.CalledProcessError: |
| 11 | return "" |
| 12 | |
| 13 | def mailuser(acct): |
| 14 | acct = os.path.basename(acct) |
| 15 | path = "/home/amin/.passwd/%s" % acct |
| 16 | args = ["cat", path] |
| 17 | try: |
| 18 | return subprocess.check_output(args).strip() |
| 19 | except subprocess.CalledProcessError: |
| 20 | return "" |
| 21 | |
| 22 | def prime_gpg_agent(): |
| 23 | ret = False |
| 24 | i = 1 |
| 25 | while not ret: |
| 26 | ret = (mailpasswd("prime") == "prime") |
| 27 | if i > 2: |
| 28 | from offlineimap.ui import getglobalui |
| 29 | sys.stderr.write("Error reading in passwords. Terminating.\n") |
| 30 | getglobalui().terminate() |
| 31 | i += 1 |
| 32 | return ret |
| 33 | |
| 34 | prime_gpg_agent() |