diff options
Diffstat (limited to 'local/sbin')
-rwxr-xr-x | local/sbin/syncemail | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/local/sbin/syncemail b/local/sbin/syncemail index 95deb7e..d0ea682 100755 --- a/local/sbin/syncemail +++ b/local/sbin/syncemail @@ -1,36 +1,32 @@ #!/usr/bin/python2 -# This starts offlineimap, but first it requests passwords from pass by user -# notification launching script at front. +# This starts offlineimap, but first it requests passwords from pass import os import sys import subprocess +import daemon +import lockfile from offlineimap import OfflineImap -frontscript = """ -echo "Asking for gpg password to access pass" 1>&2 -pass mail/cynerd@email.cz -echo "All done" 1>&2 -""" -annoyme = [ - os.path.expanduser("~/.local/sbin/annoyme-request"), - "syncemail", - "Imap email synchronization service password request." - ] +if os.path.isfile('/home/cynerd/.run/syncemail.pid.lock'): + sys.exit(0) -anproc = subprocess.Popen(annoyme, stdin=subprocess.PIPE, - stdout=subprocess.PIPE) -anproc.stdin.write(frontscript) -anproc.stdin.close() -output = anproc.stdout.read().splitlines() -excode = anproc.wait() +accounts = [ + ["email", "mail/cynerd@email.cz"], + ] -if excode != 0: - print("Authentication failed. Please start emailsync again") - sys.exit(1) -print(output) +for acc in accounts: + pproc = subprocess.Popen("pass " + acc[1], + stdout=subprocess.PIPE, shell=True) + output = pproc.stdout.read().rstrip() + if pproc.wait() != 0: + print("Password receive failed.") + sys.exit(1) + sys.argv.append('-k') + sys.argv.append('Repository_' + acc[0] + '-remote:remotepass=' + output) -sys.argv.append('-k') -sys.argv.append('Repository_email-remote:remotepass=' + output[0]) +sys.argv.append('-s') # output to syslog - -OfflineImap().run() +with daemon.DaemonContext( + pidfile=lockfile.FileLock('/home/cynerd/.run/syncemail.pid') + ): + OfflineImap().run() |