當前位置: 首頁>>代碼示例>>Python>>正文


Python imaplib.IMAP4屬性代碼示例

本文整理匯總了Python中imaplib.IMAP4屬性的典型用法代碼示例。如果您正苦於以下問題:Python imaplib.IMAP4屬性的具體用法?Python imaplib.IMAP4怎麽用?Python imaplib.IMAP4使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在imaplib的用法示例。


在下文中一共展示了imaplib.IMAP4屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fetch_email

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def fetch_email(receiver):
    global IMAP_SERVER
    global IMAP_SERVER_PORT

    server = imaplib.IMAP4(IMAP_SERVER, IMAP_SERVER_PORT)
    server.login(receiver["address"],receiver["password"])
    server.select("INBOX")
    typ, data = server.search(None, "ALL")

    index = data[0].split()
    typ, data = server.fetch(index[-1], '(RFC822)')
    try:
        message = email.message_from_string(data[0][1].decode("utf-8"))
    except UnicodeEncodeError:
        logging.warning("failed to decode the email because of UnicodeEncodeError")

    server.close()
    server.logout()

    return message 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:22,代碼來源:do_experiments.py

示例2: test_aborted_authentication

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def test_aborted_authentication(self):

        class MyServer(SimpleIMAPHandler):

            def cmd_AUTHENTICATE(self, tag, args):
                self._send_textline('+')
                self.response = yield

                if self.response == b'*\r\n':
                    self._send_tagged(tag, 'NO', '[AUTHENTICATIONFAILED] aborted')
                else:
                    self._send_tagged(tag, 'OK', 'MYAUTH successful')

        with self.reaped_pair(MyServer) as (server, client):
            with self.assertRaises(imaplib.IMAP4.error):
                code, data = client.authenticate('MYAUTH', lambda x: None) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_imaplib.py

示例3: test_aborted_authentication

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def test_aborted_authentication(self):
        class MyServer(SimpleIMAPHandler):
            def cmd_AUTHENTICATE(self, tag, args):
                self._send_textline('+')
                self.response = yield
                if self.response == b'*\r\n':
                    self._send_tagged(
                        tag,
                        'NO',
                        '[AUTHENTICATIONFAILED] aborted')
                else:
                    self._send_tagged(tag, 'OK', 'MYAUTH successful')
        client, _ = self._setup(MyServer)
        with self.assertRaisesRegex(imaplib.IMAP4.error,
                r'\[AUTHENTICATIONFAILED\] aborted'):
            client.authenticate('MYAUTH', lambda x: None) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:18,代碼來源:test_imaplib.py

示例4: get_imap_server

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def get_imap_server(cls):
        import imaplib
        conf = cls.conf()

        if not conf.get('imap_host'):
            raise ValueError("No IMAP server defined - check your configuration")

        if conf.get('imap_ssl'):
            server = imaplib.IMAP4_SSL(conf['imap_host'])
        else:
            server = imaplib.IMAP4(conf['imap_host'])

        server.login(conf['imap_user'], conf['imap_password'])
        server.select()
        return server 
開發者ID:fpsw,項目名稱:Servo,代碼行數:17,代碼來源:common.py

示例5: __init__

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def __init__(self, target):
        # Target comes as protocol://target:port
        self.target = target
        proto, host, port = target.split(':')
        host = host[2:]
        if int(port) == 993 or proto.upper() == 'IMAPS':
            self.session = imaplib.IMAP4_SSL(host,int(port))
        else:
            #assume non-ssl IMAP
            self.session = imaplib.IMAP4(host,port)
        if 'AUTH=NTLM' not in self.session.capabilities:
            logging.error('IMAP server does not support NTLM authentication!')
            return False
        self.authtag = self.session._new_tag()
        self.lastresult = None 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:17,代碼來源:imaprelayclient.py

示例6: test_issue5949

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def test_issue5949(self):

        class EOFHandler(SocketServer.StreamRequestHandler):
            def handle(self):
                # EOF without sending a complete welcome message.
                self.wfile.write('* OK')

        with self.reaped_server(EOFHandler) as server:
            self.assertRaises(imaplib.IMAP4.abort,
                              self.imap_class, *server.server_address) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_imaplib.py

示例7: test_linetoolong

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def test_linetoolong(self):
        maxline = 10

        class TooLongHandler(SimpleIMAPHandler):
            def handle(self):
                # Send a very long response line
                self.wfile.write('* OK ' + maxline * 'x' + '\r\n')

        with self.reaped_server(TooLongHandler) as server, \
                 support.swap_attr(imaplib, '_MAXLINE', maxline):
            with self.assertRaisesRegexp(imaplib.IMAP4.error,
                    'got more than 10 bytes'):
                self.imap_class(*server.server_address) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_imaplib.py

示例8: test_LOGIN

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def test_LOGIN(self):
    """Testing different login combinations using simple login auth mechanism."""

    def imap_login():
      login_sequences = [('kajoj_admin', 'thebestpassword'),
                         ('\"kajoj_admin\"', 'the best password')]

      imap_obj = imaplib.IMAP4('127.0.0.1', port=8888)
      for sequence in login_sequences:
        with self.assertRaises(imaplib.IMAP4.error) as error:
          imap_obj.login(sequence[0], sequence[1])
        imap_exception = error.exception
        self.assertEqual(imap_exception.args[0], b'Authentication failed')
      imap_obj.logout()

    options = {
        'enabled': 'True',
        'port': 143,
        'timeout': 30,
        'protocol_specific_data': {
            'max_attempts': 3,
            'banner': '* OK IMAP4rev1 Server Ready'
        }
    }
    capability = Imap(options, self.loop)
    server_coro = asyncio.start_server(
        capability.handle_session, '0.0.0.0', 8888, loop=self.loop)
    self.server = self.loop.run_until_complete(server_coro)

    imap_task = self.loop.run_in_executor(None, imap_login)
    self.loop.run_until_complete(imap_task) 
開發者ID:johnnykv,項目名稱:heralding,代碼行數:33,代碼來源:test_imap.py

示例9: test_linetoolong

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def test_linetoolong(self):
        class TooLongHandler(SimpleIMAPHandler):
            def handle(self):
                # Send a very long response line
                self.wfile.write('* OK ' + imaplib._MAXLINE*'x' + '\r\n')

        with self.reaped_server(TooLongHandler) as server:
            self.assertRaises(imaplib.IMAP4.error,
                              self.imap_class, *server.server_address) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:11,代碼來源:test_imaplib.py

示例10: __init__

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def __init__(self, host, port, timeout=None):
        self._timeout = timeout

        imaplib.IMAP4.__init__(self, host, port) 
開發者ID:abusesa,項目名稱:abusehelper,代碼行數:6,代碼來源:imapbot.py

示例11: run_mailbox

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def run_mailbox(self, min_delay=5.0, max_delay=60.0):
        mailbox = None

        try:
            while True:
                item = yield idiokit.next()

                while True:
                    delay = min(min_delay, max_delay)
                    while mailbox is None:
                        try:
                            mailbox = yield idiokit.thread(self.connect)
                        except (imaplib.IMAP4.abort, socket.error) as error:
                            self.log.error("Failed IMAP connection ({0})".format(utils.format_exception(error)))
                        else:
                            break

                        self.log.info("Retrying connection in {0:.2f} seconds".format(delay))
                        yield idiokit.sleep(delay)
                        delay = min(2 * delay, max_delay)

                    event, name, args, keys = item
                    if event.result().unsafe_is_set():
                        break

                    try:
                        method = getattr(mailbox, name)
                        result = yield idiokit.thread(method, *args, **keys)
                    except (imaplib.IMAP4.abort, socket.error) as error:
                        yield idiokit.thread(self.disconnect, mailbox)
                        self.log.error("Lost IMAP connection ({0})".format(utils.format_exception(error)))
                        mailbox = None
                    except imaplib.IMAP4.error as error:
                        event.fail(type(error), error, None)
                        break
                    else:
                        event.succeed(result)
                        break
        finally:
            if mailbox is not None:
                yield idiokit.thread(self.disconnect, mailbox) 
開發者ID:abusesa,項目名稱:abusehelper,代碼行數:43,代碼來源:imapbot.py

示例12: connect

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def connect(self):
        self.log.info("Connecting to IMAP server {0!r} port {1}".format(
            self.mail_server, self.mail_port))

        if self.mail_disable_ssl:
            mailbox = _IMAP4(
                self.mail_server,
                self.mail_port,
                timeout=self.mail_connection_timeout
            )
        else:
            mailbox = _IMAP4_SSL(
                self.mail_server,
                self.mail_port,
                timeout=self.mail_connection_timeout,
                ca_certs=self.mail_ca_certs
            )

        self.log.info("Logging in to IMAP server {0!r} port {1}".format(
            self.mail_server, self.mail_port))
        mailbox.login(self.mail_user, self.mail_password)
        try:
            status, msgs = mailbox.select(self.mail_box, readonly=False)

            if status != "OK":
                for msg in msgs:
                    raise imaplib.IMAP4.abort(msg)
        except:
            mailbox.logout()
            raise

        self.log.info("Logged in to IMAP server {0!r} port {1}".format(
            self.mail_server, self.mail_port))
        return mailbox 
開發者ID:abusesa,項目名稱:abusehelper,代碼行數:36,代碼來源:imapbot.py

示例13: disconnect

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def disconnect(self, mailbox):
        try:
            mailbox.close()
        except (imaplib.IMAP4.error, socket.error):
            pass

        try:
            mailbox.logout()
        except (imaplib.IMAP4.error, socket.error):
            pass 
開發者ID:abusesa,項目名稱:abusehelper,代碼行數:12,代碼來源:imapbot.py

示例14: get_inbox

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def get_inbox(self):
        mailbox = imaplib.IMAP4(self.host)
        mailbox.login(
            bytes(self.username, "utf8"), bytes(self.password, "utf8")
        )
        mailbox.select()
        x, data = mailbox.search(None, "ALL")
        messages = []
        for num in data[0].split():
            x, message = mailbox.fetch(num, "(RFC822)")
            messages.append(message[0][1])
        return messages 
開發者ID:PacktPublishing,項目名稱:Python-3-Object-Oriented-Programming-Third-Edition,代碼行數:14,代碼來源:email_facade.py

示例15: main

# 需要導入模塊: import imaplib [as 別名]
# 或者: from imaplib import IMAP4 [as 別名]
def main():
    source = {"name": "longz", "address": "source@foo.bar", "password": "xxxxxx"}
    imap_server = "xxx.xxx.xxx.xxx"
    imap_server_port = 143
    folder_name = "dataset"

    # create a folder to save all the emails
    if not os.path.exists(folder_name): os.system("mkdir '%s'"%(folder_name))

    server = imaplib.IMAP4(imap_server, imap_server_port)
    server.login(source["address"],source["password"])
    server.select("INBOX")
    typ, data = server.search(None, "ALL")

    index = data[0].split()

    for i in index:
        logging.info("fetching email with index %s"%i)

        typ, data = server.fetch(i, '(RFC822)')
        try:
            message = email.message_from_string(data[0][1].decode("utf-8"))
            filepath = "./%s/%s.msg"%(folder_name, i)
            save_to_file(filepath, message)

            logging.info("email saved to %s"%filepath)
        except UnicodeEncodeError:
            logging.warning("skip to save this email because of UnicodeEncodeError")
    
    server.close()
    server.logout() 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:33,代碼來源:dataset_generator.py


注:本文中的imaplib.IMAP4屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。