コード例 #1
0
ファイル: controller.py プロジェクト: gitter-badger/Pipe
    def getEmails(self):
        """
         Retrieves emails from IMAP connection
         @return: List of email bodies
        """
        list = []

        host = conf.get("imap", "host")
        port = conf.get("imap", "port")
        username = conf.get("imap", "username")
        password = conf.get("imap", "password")
        filter = conf.get("imap", "filter")

        if not host:
            log.error('IMAP / No host specified! Exiting')
            return list

        log.info('IMAP / Connecting to %s:%s', host, port)
        M = imaplib.IMAP4_SSL(host, port)
        M.login(username, password)
        log.debug("IMAP / Logged in as %s", username)

        try:
            M.select('INBOX', readonly=False) # select INBOX mailbox
            res, data = M.uid('search', filter or '(unseen)')
            nums = data[0].split()

            if len(nums) > 0:
                log.info('IMAP / There are %s new message(s)', len(nums))
            else:
                log.info('IMAP / There are no new messages')

            for num in nums:
                res, data = M.uid('fetch', num, '(RFC822)')
                raw_email = data[0][1]

                msg = email.message_from_bytes(raw_email)
                list.append(msg)
        finally:
            try:
                M.close()
            except:
                pass
            M.logout()

        return list
コード例 #2
0
ファイル: list.py プロジェクト: gitter-badger/Pipe
# -*- coding: utf8 -*-
"""
@project   Maprox <http://www.maprox.net>
@info      Protocol handlers list
@copyright 2009-2013, Maprox LLC
"""

from kernel.logger import log
from kernel.config import conf

# Load modules
HandlerClass = None
handlerName = conf.get("settings", "handler")
handlerClassPath = "lib.handlers." + handlerName
try:
    pkg = __import__(handlerClassPath, globals(), locals(), ["Handler"])
    if hasattr(pkg, "Handler"):
        HandlerClass = getattr(pkg, "Handler")
        HandlerClass.initAmqpThread(handlerName)
        log.info("Protocol is loaded: " + HandlerClass.__doc__)
    else:
        log.error("Class 'Handler' in not found in module %s", handlerClassPath)
except Exception as E:
    log.error("Protocol '%s' loading error: %s", handlerClassPath, E)