aboutsummaryrefslogtreecommitdiffstats
path: root/climl_imap_bridge.py
blob: fc48e9aace09a10045605f431e5a6a01e7db5258 (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
#!/usr/bin/python3

import os
import subprocess
import confparser
import imapclient

def connect_to_imap(conf, password):
    connection = imapclient.IMAPClient(conf.get('imap.server'),
            conf.get('imap.username'),
            password,
            ssl=conf.get('imap.ssl', 'true').lower() == 'true')
    if conf.get('imap.start_tls', 'false').lower() == 'true':
        connection.start_tls()
    print('connection succeed')
    return connection

def main():
    confpath = os.path.expanduser('~') + '/temp/conf.cfg'
    conf = confparser.read_conf(confpath)
    print('Read conf:', conf)
    password_command = conf.get('imap.password_command', None)
    if password_command:
        password = subprocess.check_output(password_command, shell=True)
        password = password.rstrip().decode('utf8')
        print('got pasword:', password)
    connection = connect_to_imap(conf, password)



main() # dev mode for now