aboutsummaryrefslogtreecommitdiff
path: root/local/sbin/syncemail
blob: d0ea682efa4756acff7a9a2e68c2a02e70b71a00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python2
# This starts offlineimap, but first it requests passwords from pass
import os
import sys
import subprocess
import daemon
import lockfile
from offlineimap import OfflineImap

if os.path.isfile('/home/cynerd/.run/syncemail.pid.lock'):
    sys.exit(0)

accounts = [
        ["email", "mail/cynerd@email.cz"],
        ]

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('-s') # output to syslog

with daemon.DaemonContext(
        pidfile=lockfile.FileLock('/home/cynerd/.run/syncemail.pid')
        ):
    OfflineImap().run()