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.
This commit is contained in:
Tobias Brunner 2018-02-06 17:46:16 +01:00
parent 13a15ec397
commit fa2932d98a

View file

@ -33,13 +33,17 @@ class EmailHandling:
""" searches for emails matching the configured subject """ """ searches for emails matching the configured subject """
self.logger.info('Searching for messages matching the subject') self.logger.info('Searching for messages matching the subject')
typ, msg_ids = self.imap.search( try:
None, typ, msg_ids = self.imap.search(
_EMAIL_SUBJECTS, None,
) _EMAIL_SUBJECTS,
if typ != 'OK': )
self.logger.error('Error searching for matching messages') if typ != 'OK':
return False 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()) num_messages = len(msg_ids[0].split())
self.logger.info('Found %s matching messages', str(num_messages)) self.logger.info('Found %s matching messages', str(num_messages))