diff options
author | VG <vg@devys.org> | 2015-12-16 00:28:34 +0100 |
---|---|---|
committer | VG <vg@devys.org> | 2015-12-16 00:28:34 +0100 |
commit | 567ca0efca8b89371fe4d91bbe55932c94f106e8 (patch) | |
tree | a630665347a6453bc524c87962d24b3fa3f46537 | |
parent | 7f679638c4ec54fe5bdf656b07018f4e753b9439 (diff) | |
download | climl-567ca0efca8b89371fe4d91bbe55932c94f106e8.tar.gz climl-567ca0efca8b89371fe4d91bbe55932c94f106e8.tar.bz2 climl-567ca0efca8b89371fe4d91bbe55932c94f106e8.zip |
add option to specify CA certificate
-rw-r--r-- | climl_imap_bridge.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/climl_imap_bridge.py b/climl_imap_bridge.py index fc48e9a..f4d75e7 100644 --- a/climl_imap_bridge.py +++ b/climl_imap_bridge.py @@ -6,13 +6,21 @@ 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') + + ssl_context = None + + if conf.get('imap.ssl_ca', None): + ssl_context = imapclient.create_default_context( + cafile=os.path.expanduser(conf.get('imap.ssl_ca'))) + + connection = imapclient.IMAPClient(host=conf.get('imap.server'), + ssl=conf.get('imap.ssl', 'true').lower() == 'true', + ssl_context=ssl_context) if conf.get('imap.start_tls', 'false').lower() == 'true': - connection.start_tls() + connection.start_tls(ssl_context=ssl_context) print('connection succeed') + connection.login(username=conf.get('imap.username'), password=password) + print('successfuly logged') return connection def main(): |