本文整理汇总了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"])
示例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'])
示例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])
示例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'])
示例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"])
示例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))
示例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,
示例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)))
示例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))