From fa2932d98a7a0d8643f81600aad4aab4ebba9619 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 6 Feb 2018 17:46:16 +0100 Subject: [PATCH] catch imap abortions and exit exiting will allow f.e. OpenShift to restart the failed pod. reason: got "imaplib.abort: Server shutting down." some day. --- library/emailhandling.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/library/emailhandling.py b/library/emailhandling.py index 95b88da..9f102c8 100644 --- a/library/emailhandling.py +++ b/library/emailhandling.py @@ -33,13 +33,17 @@ class EmailHandling: """ searches for emails matching the configured subject """ self.logger.info('Searching for messages matching the subject') - typ, msg_ids = self.imap.search( - None, - _EMAIL_SUBJECTS, - ) - if typ != 'OK': - self.logger.error('Error searching for matching messages') - return False + try: + typ, msg_ids = self.imap.search( + None, + _EMAIL_SUBJECTS, + ) + if typ != 'OK': + self.logger.error('Error searching for matching messages') + return False + except imaplib.IMAP4.abort as err: + self.logger.error('IMAP search aborted - exiting: %s', str(err)) + raise SystemExit(1) num_messages = len(msg_ids[0].split()) self.logger.info('Found %s matching messages', str(num_messages))