コード例 #1
0
ファイル: part_test.py プロジェクト: fpx406/flanker
def message_size_test():
    # message part as a stream
    stream_part = scan(IPHONE)
    eq_(len(IPHONE), stream_part.size)

    # assemble a message part
    text1 = 'Hey there'
    text2 = 'I am a part number two!!!'
    message = multipart('alternative')
    message.append(
        text('plain', text1),
        text('plain', text2))

    eq_(len(message.to_string()), message.size)
コード例 #2
0
ファイル: threading_test.py プロジェクト: knoguchi/flanker
def test_wrapper_references():
    message = create.text("plain", "hey")
    message.headers["References"] = "<1> <2> <3>"
    message.headers["Message-Id"] = "<4>"
    w = Wrapper(message)
    eq_("4", w.message_id)
    eq_(["1", "2", "3"], w.references)
コード例 #3
0
ファイル: threading_test.py プロジェクト: knoguchi/flanker
def make_message(message_id, references=None, subject=""):
    message = create.text("plain", "hey")
    if message_id:
        message.headers["Message-Id"] = "<{0}>".format(message_id)
    if references:
        message.headers["References"] = " ".join("<{0}>".format(rid) for rid in references)
    return message
コード例 #4
0
ファイル: threading_test.py プロジェクト: AnSavvides/flanker
def test_wrapper_references():
    message = create.text('plain','hey')
    message.headers['References'] = '<1> <2> <3>'
    message.headers['Message-Id'] = '<4>'
    w = Wrapper(message)
    eq_('4', w.message_id)
    eq_(['1', '2', '3'], w.references)
コード例 #5
0
ファイル: threading_test.py プロジェクト: AnSavvides/flanker
def test_wrapper_in_reply_to():
    message = create.text('plain','hey')
    message.headers['In-Reply-To'] = '<3>'
    message.headers['Message-Id'] = '<4>'
    w = Wrapper(message)
    eq_('4', w.message_id)
    eq_(['3'], w.references)
コード例 #6
0
def create_long_lines_test():
    val = "hello" * 1024
    text = create.text("plain", val, "utf-8")
    eq_('ascii', text.charset)

    create.from_string(text.to_string())
    eq_(val, text.body)
コード例 #7
0
ファイル: threading_test.py プロジェクト: knoguchi/flanker
def test_wrapper_in_reply_to():
    message = create.text("plain", "hey")
    message.headers["In-Reply-To"] = "<3>"
    message.headers["Message-Id"] = "<4>"
    w = Wrapper(message)
    eq_("4", w.message_id)
    eq_(["3"], w.references)
コード例 #8
0
ファイル: threading_test.py プロジェクト: AnSavvides/flanker
def make_message(message_id, references=None, subject=""):
    message = create.text('plain','hey')
    if message_id:
        message.headers['Message-Id'] = '<{}>'.format(message_id)
    if references:
        message.headers['References'] = ' '.join(
            '<{}>'.format(rid) for rid in references)
    return message
コード例 #9
0
def create_newlines_in_headers_test():
    text = create.text("plain", 'yo', "utf-8")
    text.headers['Subject'] = 'Hello,\nnewline\r\n\r\n'
    text.headers.add('To', u'\n\nПревед, медвед\n!\r\n')

    text = create.from_string(text.to_string())
    eq_('Hello,newline', text.headers['Subject'])
    eq_(u'Превед, медвед!', text.headers['To'])
コード例 #10
0
def create_multipart_nested_test():
    message = create.multipart("mixed")
    nested = create.multipart("alternative")
    nested.append(
        create.text("plain", u"Саша с уралмаша"),
        create.text("html", u"<html>Саша с уралмаша</html>"))
    message.append(
        create.text("plain", "Hello"),
        nested)

    message2 = create.from_string(message.to_string())
    eq_(2, len(message2.parts))
    eq_('text/plain', message2.parts[0].content_type)
    eq_('Hello', message2.parts[0].body)

    eq_(u"Саша с уралмаша", message2.parts[1].parts[0].body)
    eq_(u"<html>Саша с уралмаша</html>", message2.parts[1].parts[1].body)
コード例 #11
0
def create_multipart_with_text_non_unicode_attachment_test():
    """Make sure we encode text attachment in base64
    """
    message = create.multipart("mixed")
    filename = "text-attachment.txt"
    message.append(
        create.text("plain", "Hello"),
        create.text("html", "<html>Hello</html>"),
        create.binary(
            "text", "plain", u"Саша с уралмаша".encode("koi8-r"),
            filename, "attachment"))

    message2 = create.from_string(message.to_string())

    eq_(3, len(message2.parts))
    attachment = message2.parts[2]
    ok_(attachment.is_attachment())
    eq_("base64", attachment.content_encoding.value)
    eq_(u"Саша с уралмаша", attachment.body)
コード例 #12
0
ファイル: create_test.py プロジェクト: ubi-mirrors/flanker
def create_enclosed_nested_test():
    nested = create.multipart("alternative")
    nested.append(
        create.text("plain", u"Саша с уралмаша"),
        create.text("html", u"<html>Саша с уралмаша</html>"))

    message = create.multipart("mailgun-recipient-variables")
    variables = {"a": u"<b>Саша</b>" * 1024}
    message.append(
        create.binary("application", "json", json.dumps(variables)),
        create.message_container(nested))

    message2 = create.from_string(message.to_string())
    eq_(variables, json.loads(message2.parts[0].body))

    nested = message2.parts[1].enclosed
    eq_(2, len(nested.parts))
    eq_(u"Саша с уралмаша", nested.parts[0].body)
    eq_(u"<html>Саша с уралмаша</html>", nested.parts[1].body)
コード例 #13
0
def create_singlepart_ascii_long_lines_test():
    very_long = "very long line  " * 1000 + "preserve my newlines \r\n\r\n"
    message = create.text("plain", very_long)

    message2 = create.from_string(message.to_string())
    eq_("quoted-printable", message2.content_encoding.value)
    eq_(very_long, message2.body)

    message2 = email.message_from_string(message.to_string())
    eq_(very_long, message2.get_payload(decode=True))
コード例 #14
0
def create_enclosed_nested_test():
    nested = create.multipart("alternative")
    nested.append(
        create.text("plain", u"Саша с уралмаша"),
        create.text("html", u"<html>Саша с уралмаша</html>"))

    message = create.multipart("mailgun-recipient-variables")
    variables = {"a": u"<b>Саша</b>" * 1024}
    message.append(
        create.binary("application", "json", json.dumps(variables)),
        create.message_container(nested))

    message2 = create.from_string(message.to_string())
    eq_(variables, json.loads(message2.parts[0].body))

    nested = message2.parts[1].enclosed
    eq_(2, len(nested.parts))
    eq_(u"Саша с уралмаша", nested.parts[0].body)
    eq_(u"<html>Саша с уралмаша</html>", nested.parts[1].body)
コード例 #15
0
ファイル: create_test.py プロジェクト: ubi-mirrors/flanker
def create_singlepart_ascii_long_lines_test():
    very_long = "very long line  " * 1000 + "preserve my newlines \r\n\r\n"
    message = create.text("plain", very_long)

    message2 = create.from_string(message.to_string())
    eq_("quoted-printable", message2.content_encoding.value)
    eq_(very_long, message2.body)

    message2 = email.message_from_string(message.to_string())
    eq_(very_long, message2.get_payload(decode=True))
コード例 #16
0
ファイル: create_test.py プロジェクト: rcharp/airform
def create_multipart_with_text_non_unicode_attachment_test():
    """
    Make sure we encode text attachment in base64
    """
    message = create.multipart("mixed")
    filename = "text-attachment.txt"
    message.append(
        create.text("plain", "Hello"), create.text("html",
                                                   "<html>Hello</html>"),
        create.binary("text", "plain", u"Саша с уралмаша".encode("koi8-r"),
                      filename, "attachment"))

    message2 = create.from_string(message.to_string())

    eq_(3, len(message2.parts))
    attachment = message2.parts[2]
    ok_(attachment.is_attachment())
    eq_("base64", attachment.content_encoding.value)
    eq_(u"Саша с уралмаша", attachment.body)
コード例 #17
0
def create_multipart_simple_test():
    message = create.multipart("mixed")
    message.append(create.text("plain", "Hello"),
                   create.text("html", "<html>Hello</html>"))
    ok_(message.is_root())
    assert_false(message.parts[0].is_root())
    assert_false(message.parts[1].is_root())

    message2 = create.from_string(message.to_string())
    eq_(2, len(message2.parts))
    eq_("multipart/mixed", message2.content_type)
    eq_(2, len(message.parts))
    eq_("Hello", message.parts[0].body)
    eq_("<html>Hello</html>", message.parts[1].body)

    message2 = email.message_from_string(message.to_string())
    eq_("multipart/mixed", message2.get_content_type())
    eq_("Hello", message2.get_payload()[0].get_payload(decode=False))
    eq_("<html>Hello</html>",
        message2.get_payload()[1].get_payload(decode=False))
コード例 #18
0
def create_multipart_with_attachment_test():
    message = create.multipart("mixed")
    filename = u"Мейлган картиночка картиночечка с длинным  именем и пробельчиками"
    message.append(
        create.text("plain", "Hello"), create.text("html",
                                                   "<html>Hello</html>"),
        create.binary("image", "png", MAILGUN_PNG, filename, "attachment"))
    eq_(3, len(message.parts))

    message2 = create.from_string(message.to_string())
    eq_(3, len(message2.parts))
    eq_("base64", message2.parts[2].content_encoding.value)
    eq_(MAILGUN_PNG, message2.parts[2].body)
    eq_(filename, message2.parts[2].content_disposition.params['filename'])
    eq_(filename, message2.parts[2].content_type.params['name'])
    ok_(message2.parts[2].is_attachment())

    message2 = email.message_from_string(message.to_string())
    eq_(3, len(message2.get_payload()))
    eq_(MAILGUN_PNG, message2.get_payload()[2].get_payload(decode=True))
コード例 #19
0
ファイル: create_test.py プロジェクト: plq/flanker
def test_bug_line_is_too_long():
    # It was possible to create a message with a very long header value, but
    # it was impossible to parse such message.

    msg = create.text('plain', 'foo', 'utf-8')
    msg.headers.add('bar', 'y' * 10000)
    encoded_msg = msg.to_string()
    decoded_msg = create.from_string(encoded_msg)

    # When/Then
    decoded_msg.headers
コード例 #20
0
ファイル: create_test.py プロジェクト: rcharp/airform
def test_bug_line_is_too_long():
    # It was possible to create a message with a very long header value, but
    # it was impossible to parse such message.

    msg = create.text('plain', 'foo', 'utf-8')
    msg.headers.add('bar', 'y' * 10000)
    encoded_msg = msg.to_string()
    decoded_msg = create.from_string(encoded_msg)

    # When/Then
    decoded_msg.headers
コード例 #21
0
def create_enclosed_test():
    message = create.text("plain", u"Превед")
    message.headers['From'] = u' Саша <*****@*****.**>'
    message.headers['To'] = u'Женя <*****@*****.**>'
    message.headers['Subject'] = u"Все ли ок? Нормальненько??"

    message = create.message_container(message)

    message2 = create.from_string(message.to_string())
    eq_('message/rfc822', message2.content_type)
    eq_(u"Превед", message2.enclosed.body)
    eq_(u'Саша <*****@*****.**>', message2.enclosed.headers['From'])
コード例 #22
0
def create_enclosed_test():
    message = create.text("plain", u"Превед")
    message.headers['From'] = u' Саша <*****@*****.**>'
    message.headers['To'] = u'Женя <*****@*****.**>'
    message.headers['Subject'] = u"Все ли ок? Нормальненько??"

    message = create.message_container(message)

    message2 = create.from_string(message.to_string())
    eq_('message/rfc822', message2.content_type)
    eq_(u"Превед", message2.enclosed.body)
    eq_(u'Саша <*****@*****.**>', message2.enclosed.headers['From'])
コード例 #23
0
def create_multipart_simple_test():
    message = create.multipart("mixed")
    message.append(
        create.text("plain", "Hello"),
        create.text("html", "<html>Hello</html>"))
    ok_(message.is_root())
    assert_false(message.parts[0].is_root())
    assert_false(message.parts[1].is_root())

    message2 = create.from_string(message.to_string())
    eq_(2, len(message2.parts))
    eq_("multipart/mixed", message2.content_type)
    eq_(2, len(message.parts))
    eq_("Hello", message.parts[0].body)
    eq_("<html>Hello</html>", message.parts[1].body)

    message2 = email.message_from_string(message.to_string())
    eq_("multipart/mixed", message2.get_content_type())
    eq_("Hello", message2.get_payload()[0].get_payload(decode=False))
    eq_("<html>Hello</html>",
        message2.get_payload()[1].get_payload(decode=False))
コード例 #24
0
def create_multipart_with_attachment_test():
    message = create.multipart("mixed")
    filename = u"Мейлган картиночка картиночечка с длинным  именем и пробельчиками"
    message.append(
        create.text("plain", "Hello"),
        create.text("html", "<html>Hello</html>"),
        create.binary(
            "image", "png", MAILGUN_PNG,
            filename, "attachment"))
    eq_(3, len(message.parts))

    message2 = create.from_string(message.to_string())
    eq_(3, len(message2.parts))
    eq_("base64", message2.parts[2].content_encoding.value)
    eq_(MAILGUN_PNG, message2.parts[2].body)
    eq_(filename, message2.parts[2].content_disposition.params['filename'])
    eq_(filename, message2.parts[2].content_type.params['name'])
    ok_(message2.parts[2].is_attachment())

    message2 = email.message_from_string(message.to_string())
    eq_(3, len(message2.get_payload()))
    eq_(MAILGUN_PNG, message2.get_payload()[2].get_payload(decode=True))
コード例 #25
0
ファイル: threading_test.py プロジェクト: knoguchi/flanker
def test_wrapper_creates_message_id():
    message = create.text("plain", "hey")
    w = Wrapper(message)
    ok_(w.message_id)
    eq_([], w.references)
コード例 #26
0
def guessing_text_encoding_test():
    text = create.text("plain", "hello", "utf-8")
    eq_('ascii', text.charset)

    text = create.text("plain", u"hola, привет", "utf-8")
    eq_('utf-8', text.charset)
コード例 #27
0
ファイル: main.py プロジェクト: rheehot/learning-code
print(sa)

msg = '''MIME-Version: 1.0
Content-Type: text/plain
From: Example1 <*****@*****.**>
To: Example2 <*****@*****.**>
Subject: hello, message
Date: Mon, 10 Sep 2019 12:43:03 -0700

this is a single part message.'''

from flanker import mime

fs = mime.from_string(msg)
print(fs.body)
print(fs.headers.items())

print(fs.content_type)
print(fs.subject)

print(fs.content_type.is_singlepart())
print(fs.content_type.is_multipart())

from flanker.mime import create

message = create.text("plain", "hello, world!")
message.headers['From'] = u'Example1 <*****@*****.**>'
message.headers['To'] = u'Example2 <*****@*****.**>'
message.headers['Subject'] = u"hello"
message = create.from_string(message.to_string())
print(message.to_string())
コード例 #28
0
def create_singlepart_ascii_test():
    message = create.text("plain", u"Hello")
    message = create.from_string(message.to_string())
    eq_("7bit", message.content_encoding.value)
    eq_("Hello", message.body)
コード例 #29
0
def create_singlepart_unicode_qp_test():
    message = create.text("plain", u"Привет, курилка")
    message = create.from_string(message.to_string())
    eq_("quoted-printable", message.content_encoding.value)
    eq_(u"Привет, курилка", message.body)
コード例 #30
0
ファイル: threading_test.py プロジェクト: yuebo2015/flanker
def test_wrapper_creates_message_id():
    message = create.text('plain', 'hey')
    w = Wrapper(message)
    ok_(w.message_id)
    eq_([], w.references)
コード例 #31
0
def create_singlepart_unicode_test():
    message = create.text("plain", u"Привет, курилка")
    message = create.from_string(message.to_string())
    eq_("base64", message.content_encoding.value)
    eq_(u"Привет, курилка", message.body)
コード例 #32
0
def guessing_text_encoding_test():
    text = create.text("plain", "hello", "utf-8")
    eq_('ascii', text.charset)

    text = create.text("plain", u"hola, привет", "utf-8")
    eq_('utf-8', text.charset)
コード例 #33
0
def create_singlepart_ascii_test():
    message = create.text("plain", u"Hello")
    message = create.from_string(message.to_string())
    eq_("7bit", message.content_encoding.value)
    eq_("Hello", message.body)
コード例 #34
0
ファイル: threading_test.py プロジェクト: AnSavvides/flanker
def test_wrapper_creates_message_id():
    message = create.text('plain','hey')
    w = Wrapper(message)
    ok_(w.message_id)
    eq_([], w.references)