Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.mailbox.close()
sys.exit()
else:
while True:
try:
unseen_msgs = self.mailbox.get_unseen_uids()
if len(unseen_msgs) > 0:
self._process_uids(unseen_msgs)
self.mailbox.expunge()
try:
self.mailbox.server.idle(TIMEOUT)
except:
log("IDLE caused exception. Sleeping for %s seconds" \
% TIMEOUT)
time.sleep(TIMEOUT)
except imaplib.IMAP4.abort, data:
log("In run(): caught exception: %s" % str(data))
self.mailbox.reconnect()
log("Reconnected mailbox")
# TODO: check if this could end in an infinite try-except
if not is_ok((search_status,)):
raise ReaderError(search_result)
#print "UID searched with: "+ command + ", got result "+repr(search_status)+" and found "+repr(search_result)
email_ids = search_result[0].split()
if len(email_ids):
print "Processing messages from IMAP: %d "% (len(email_ids))
for email_id in email_ids:
self.import_email(email_id)
if self.status != ReaderStatus.READING:
break
else:
print "No IMAP messages to process"
self.successful_read()
self.set_status(ReaderStatus.PAUSED)
except IMAP4.abort as e:
raise IrrecoverableError(e)
except IMAP4.error as e:
raise ClientError(e)