email_fetcher.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:cerberus-core 作者: ovh 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号