def run(self):
"""
Infinite loop fetching email , lauching < 10 threads pushing email
to storage service and worker
"""
try:
self._imap_conn = get_imap_connection(host=HOST, port=PORT, user=USER, passwd=PASS)
except (IMAP4.error, IMAP4.abort, IMAP4.readonly) as ex:
Logger.error(unicode('Error in IMAP connection - %s' % (str(ex))))
return
except (socket.error, socket.gaierror, socket.herror, socket.timeout) as ex:
Logger.error(unicode('Error in IMAP connection - %s' % (str(ex))))
return
pool = ThreadPool(5)
while True:
try:
messages = self.get_messages()
except (socket.error, socket.gaierror, socket.herror,
socket.timeout, ssl.SSLError) as ex:
Logger.debug(unicode('Error in IMAP connection - %s' % (str(ex))))
return
if not messages:
sleep(1)
continue
uids = messages.keys()
args = [(uid, messages) for uid in uids]
pool.map(push_email, args)
pool.wait_completion()
for uid in uids:
if uid not in messages:
self._imap_conn.uid('store', uid, '+FLAGS', r'(\Deleted)')
self._imap_conn.expunge()
sleep(1)
评论列表
文章目录