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


Python MimeHeaders.from_stream方法代碼示例

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


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

示例1: headers_roundtrip_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def headers_roundtrip_test():
    headers = MimeHeaders.from_stream(StringIO(BILINGUAL))
    out = StringIO()
    headers.to_stream(out)

    headers2 = MimeHeaders.from_stream(StringIO(out.getvalue()))
    eq_(21, len(headers2))
    eq_(u"Simple text. How are you? Как ты поживаешь?", headers["Subject"])
    received_headers = headers.getall("Received")
    eq_(5, len(received_headers))
    ok_("c2cs24435ybk" in received_headers[0])
    eq_(headers["Content-Transfer-Encoding"], headers2["Content-Transfer-Encoding"])
    eq_(headers["DKIM-Signature"], headers2["DKIM-Signature"])
開發者ID:nickcatal,項目名稱:flanker,代碼行數:15,代碼來源:headers_test.py

示例2: headers_roundtrip_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def headers_roundtrip_test():
    headers = MimeHeaders.from_stream(six.StringIO(BILINGUAL.decode('utf-8')))
    out = six.StringIO()
    headers.to_stream(out)

    headers2 = MimeHeaders.from_stream(six.StringIO(out.getvalue()))
    eq_(21, len(headers2))
    eq_(u"Simple text. How are you? Как ты поживаешь?", headers['Subject'])
    received_headers = headers.getall('Received')
    eq_(5, len(received_headers))
    ok_('c2cs24435ybk' in received_headers[0])
    eq_(headers['Content-Transfer-Encoding'],
        headers2['Content-Transfer-Encoding'])
    eq_(headers['DKIM-Signature'],
        headers2['DKIM-Signature'])
開發者ID:plq,項目名稱:flanker,代碼行數:17,代碼來源:headers_test.py

示例3: bilingual_message_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def bilingual_message_test():
    headers = MimeHeaders.from_stream(StringIO(BILINGUAL))
    eq_(21, len(headers))
    eq_(u"Simple text. How are you? Как ты поживаешь?", headers['Subject'])
    received_headers = headers.getall('Received')
    eq_(5, len(received_headers))
    ok_('c2cs24435ybk' in received_headers[0])
開發者ID:Appono,項目名稱:flanker,代碼行數:9,代碼來源:headers_test.py

示例4: test_folding_combinations

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def test_folding_combinations():
    message = """From [email protected] Mon Feb  8 02:53:47 PST 1993\nTo: sasha\r\n  continued\n      line\nFrom: single line  \r\nSubject: hello, how are you\r\n today?"""
    headers = MimeHeaders.from_stream(StringIO(message))
    eq_('sasha  continued      line', headers['To'])
    eq_('single line  ', headers['From'])
    eq_("hello, how are you today?", headers['Subject'])
開發者ID:Appono,項目名稱:flanker,代碼行數:8,代碼來源:headers_test.py

示例5: broken_sequences_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def broken_sequences_test():
    headers = StringIO("  hello this is a bad header\nGood: this one is ok")
    headers = MimeHeaders.from_stream(headers)
    eq_(1, len(headers))
    eq_("this one is ok", headers["Good"])
開發者ID:Appono,項目名稱:flanker,代碼行數:7,代碼來源:headers_test.py

示例6: headers_parsing_empty_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def headers_parsing_empty_test():
    h = MimeHeaders.from_stream(StringIO(""))
    eq_(0, len(h))
開發者ID:Appono,項目名稱:flanker,代碼行數:5,代碼來源:headers_test.py

示例7: slurp_imap_namespace_gmail

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]

#.........這裏部分代碼省略.........
                    len(imap_uids), examine_response[u'EXISTS']))

            # Create folder_messages entries
            db.executemany("""
                INSERT INTO folder_messages (folder_name, imap_uid)
                VALUES (?, ?)
                """, ((folder_name, imap_uid) for imap_uid in imap_uids))

            ## Get the folder flags
            #folder_flags = set(row[0] for row in db.execute(
            #    "SELECT flag FROM folder_flags WHERE folder_name = ?",
            #    [folder_name]))
            #
            ## This is Gmail, so only actually fetch messages from the 'All
            ## Mail' and 'Trash' folders.  This *should* give us all of the
            ## messages.
            #if not folder_flags & {u'\\All', u'\\Trash', u'\\Sent'}:
            #    continue

            # Get folder messages
            batch_size = 1000
            fetch_data = ['RFC822.SIZE', 'ENVELOPE', 'FLAGS',
                          'X-GM-MSGID', 'X-GM-THRID', 'X-GM-LABELS',
                          'INTERNALDATE', 'RFC822.HEADER']
            for i in range(0, len(imap_uids), batch_size):
                imap_uids_batch = imap_uids[i:i+batch_size]

                # Fetch message info from the IMAP server
                fetch_response = imap.fetch(imap_uids_batch, fetch_data)

                # Fetch message info and insert it into the messages table.
                # Don't bother deduplicating at this point.
                for uid, data in fetch_response.items():
                    headers = MimeHeaders.from_stream(StringIO(data['RFC822.HEADER']))
                    msg_data = dict(
                        date=data['INTERNALDATE'],
                        subject=data['ENVELOPE'].subject,
                        in_reply_to=data['ENVELOPE'].in_reply_to,
                        size=data['RFC822.SIZE'],
                        message_id_header=data['ENVELOPE'].message_id,
                        x_gm_thrid=unicode(data['X-GM-THRID']),
                        x_gm_msgid=unicode(data['X-GM-MSGID']),
                        sender_addr=json.dumps(parse_email_address_list(headers.get('Sender'))),
                        from_addr=json.dumps(parse_email_address_list(headers.get('From'))),
                        reply_to_addr=json.dumps(parse_email_address_list(headers.get('Reply-To'))),
                        to_addr=json.dumps(parse_email_address_list(headers.get('To'))),
                        cc_addr=json.dumps(parse_email_address_list(headers.get('Cc'))),
                        bcc_addr=json.dumps(parse_email_address_list(headers.get('Bcc'))),
                    )
                    msg_data['clean_subject'] = \
                        cleanup_subject(parse_header_value('Subject', msg_data['subject']))

                    # Check if we've already stored the message
                    cur = db.execute("""
                        SELECT id, x_gm_msgid FROM messages
                        WHERE x_gm_msgid = :x_gm_msgid
                        """, msg_data)
                    row = next(iter(cur.fetchall()), None)    # returns 0 or 1 rows
                    message_id = row['id'] if row is not None else None

                    # If we've never stored the message, store it now.
                    if message_id is None:
                        cur = db.execute("""
                            INSERT INTO messages (
                                date, subject, clean_subject,
                                in_reply_to, size, message_id_header,
開發者ID:Analect,項目名稱:sync-engine,代碼行數:70,代碼來源:imap_gm.py

示例8: headers_parsing_binary_stuff_survives_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def headers_parsing_binary_stuff_survives_test():
    value = zlib.compress(b"abcdefg")
    header = "Hello: {0}\r\n".format(value)
    ok_(MimeHeaders.from_stream(StringIO(header)))
開發者ID:mailgun,項目名稱:flanker,代碼行數:6,代碼來源:headers_test.py

示例9: headers_parsing_ridiculously_long_line_test

# 需要導入模塊: from flanker.mime.message.headers import MimeHeaders [as 別名]
# 或者: from flanker.mime.message.headers.MimeHeaders import from_stream [as 別名]
def headers_parsing_ridiculously_long_line_test():
    val = "abcdefg"*100000
    header = "Hello: {0}\r\n".format(val)
    MimeHeaders.from_stream(StringIO(header))
開發者ID:mailgun,項目名稱:flanker,代碼行數:6,代碼來源:headers_test.py


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