blob: 3cb56a42b6d5e4bb4af98a1597bc72030dc73402 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/python2
# This starts offlineimap, but first it requests passwords from pass
import os
import sys
import subprocess
import daemon
import lockfile
import syslog
from offlineimap import OfflineImap
pidfile = '/tmp/syncemail-%d.pid' % os.getuid()
# Check if not already running
def check_running():
if os.access(pidfile, os.F_OK):
with open(pidfile, "r") as f:
pid = f.readline()
if os.path.exists('/proc/%s' % pid):
sys.exit(0)
check_running()
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)
# Define out logger and redirect stdout and stderr to it
class logstd:
def write(self, data):
syslog.syslog(data)
with daemon.DaemonContext():
check_running()
with open(pidfile, "w") as f:
f.write("%s" % os.getpid())
syslog.openlog('syncemail')
sys.stderr = sys.stdout = logstd()
OfflineImap().run()
|