From a373f47a7d0b329dc04698ee3345cb232c452479 Mon Sep 17 00:00:00 2001 From: VG Date: Thu, 24 Dec 2015 16:58:44 +0100 Subject: Fix imap idle checking with remote server - fix exception class - select a mailbox to check incomming emails for - make the bridge run continuously until stopped with siginterrupt --- climl_imap_bridge.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/climl_imap_bridge.py b/climl_imap_bridge.py index f1b2752..cfc527c 100644 --- a/climl_imap_bridge.py +++ b/climl_imap_bridge.py @@ -51,16 +51,18 @@ def connect_to_imap(conf, password): connection.login(username=conf.get('imap.username'), password=password) print('successfuly logged') + # TODO: replace shutdown by logouts when it will not timeout through ssl try: yield connection - connection.logout() - except (imapclient.AbortError, socket.error, socket.timeout, + #connection.logout() + except (connection.AbortError, socket.error, socket.timeout, backports.ssl.SSLError, backports.ssl.CertificateError): raise else: - connection.logout() - #finally: - # connection.shutdown() + pass + #connection.logout() + finally: + connection.shutdown() def main(): confpath = os.path.expanduser('~/temp/conf.cfg') @@ -74,12 +76,17 @@ def main(): #connection = connect_to_imap(conf, password) with connect_to_imap(conf, password) as connection: + print('selecting folder') + connection.select_folder(conf.get('imap.mailbox')) print('entering idle mode') connection.idle() print('waiting for an event') - result = connection.idle_check(timeout=10) - print('result:', result) - + while True: + try: + result = connection.idle_check(timeout=10) + except KeyboardInterrupt: + break + print('result:', result) print('end of connection') -- cgit v1.2.3