Пример #1
0
def test_valueerror_on_multiple_resent_message():
    message = EmailMessage()
    message['Resent-Date'] = "Mon, 20 Nov 2016 21:04:27 -0000"
    message['Resent-Date'] = "Mon, 20 Nov 2017 21:04:27 -0000"

    with pytest.raises(ValueError):
        flatten_message(message)
Пример #2
0
def test_flatten_message_removes_bcc_from_message_text():
    message = EmailMessage()
    message["Bcc"] = Address(username="******", domain="example.com")

    flat_message = flatten_message(message)

    assert flat_message == b"\r\n"  # empty message
Пример #3
0
def test_flatten_message_utf8_options(utf8, cte_type, expected_chunk):
    message = EmailMessage()
    message["From"] = Address(username="******", domain="example.com")

    flat_message = flatten_message(message, utf8=utf8, cte_type=cte_type)

    assert expected_chunk in flat_message
Пример #4
0
def test_flatten_resent_message():
    message = EmailMessage()
    message["To"] = Address(username="******", domain="example.com")
    message["Cc"] = Address(username="******", domain="example.com")
    message["Bcc"] = Address(username="******", domain="example.com")

    message["Subject"] = "Hello, World."
    message["From"] = Address(username="******", domain="example.com")
    message.set_content("This is a test")

    message["Resent-Date"] = "Mon, 20 Nov 2017 21:04:27 -0000"
    message["Resent-To"] = Address(username="******", domain="example.com")
    message["Resent-Cc"] = Address(username="******", domain="example.com")
    message["Resent-Bcc"] = Address(username="******", domain="example.com")
    message["Resent-Subject"] = "Fwd: Hello, World."
    message["Resent-From"] = Address(username="******", domain="example.com")

    flat_message = flatten_message(message)

    expected_message = b"""To: [email protected]\r
Cc: [email protected]\r
Subject: Hello, World.\r
From: [email protected]\r
Content-Type: text/plain; charset="utf-8"\r
Content-Transfer-Encoding: 7bit\r
MIME-Version: 1.0\r
Resent-Date: Mon, 20 Nov 2017 21:04:27 -0000\r
Resent-To: [email protected]\r
Resent-Cc: [email protected]\r
Resent-Subject: Fwd: Hello, World.\r
Resent-From: [email protected]\r
\r
This is a test\r
"""
    assert flat_message == expected_message
Пример #5
0
def test_flatten_message_utf8_options(utf8, cte_type, expected_chunk):
    message = EmailMessage()
    message["From"] = "å[email protected]"

    flat_message = flatten_message(message, utf8=utf8, cte_type=cte_type)

    assert expected_chunk in flat_message
Пример #6
0
def test_flatten_message_removes_bcc_from_message_text():
    message = EmailMessage()
    message["Bcc"] = "*****@*****.**"

    flat_message = flatten_message(message)

    assert flat_message == b"\r\n"  # empty message
Пример #7
0
def test_flatten_message_removes_bcc_from_message_text():
    message = EmailMessage()
    message['Bcc'] = Address(username='******', domain='example.com')

    sender, recipients, flat_message = flatten_message(message)

    assert sender == ''
    assert recipients == [message['Bcc']]
    assert flat_message == "\r\n"  # empty message
Пример #8
0
def test_flatten_message_prefers_sender_header():
    message = EmailMessage()
    message['From'] = Address(username='******', domain='example.com')
    message['Sender'] = Address(username='******', domain='example.com')

    sender, recipients, flat_message = flatten_message(message)

    assert sender != message['From']
    assert sender == message['Sender']
    assert recipients == []
    assert flat_message == (
        "From: [email protected]\r\nSender: [email protected]\r\n\r\n"
    )
Пример #9
0
def test_flatten_resent_message():
    message = EmailMessage()
    message['To'] = Address(username='******', domain='example.com')
    message['Cc'] = Address(username='******', domain='example.com')
    message['Bcc'] = Address(username='******', domain='example.com')

    message['Subject'] = 'Hello, World.'
    message['From'] = Address(username='******', domain='example.com')
    message.set_content('This is a test')

    message['Resent-Date'] = "Mon, 20 Nov 2017 21:04:27 -0000"
    message['Resent-To'] = Address(username='******', domain='example.com')
    message['Resent-Cc'] = Address(username='******', domain='example.com')
    message['Resent-Bcc'] = Address(username='******', domain='example.com')
    message['Resent-Subject'] = 'Fwd: Hello, World.'
    message['Resent-From'] = Address(username='******', domain='example.com')

    sender, recipients, flat_message = flatten_message(message)
    expected_message = """To: [email protected]\r
Cc: [email protected]\r
Subject: Hello, World.\r
From: [email protected]\r
Content-Type: text/plain; charset="utf-8"\r
Content-Transfer-Encoding: 7bit\r
MIME-Version: 1.0\r
Resent-Date: Mon, 20 Nov 2017 21:04:27 -0000\r
Resent-To: [email protected]\r
Resent-Cc: [email protected]\r
Resent-Subject: Fwd: Hello, World.\r
Resent-From: [email protected]\r
\r
This is a test\r
"""

    assert sender == message['Resent-From']
    assert sender != message['From']
    assert message['Resent-To'] in recipients
    assert message['Resent-Cc'] in recipients
    assert message['Resent-Bcc'] in recipients
    assert message['To'] not in recipients
    assert message['Cc'] not in recipients
    assert message['Bcc'] not in recipients

    assert flat_message == expected_message
Пример #10
0
def test_flatten_message():
    message = EmailMessage()
    message["To"] = Address(username="******", domain="example.com")
    message["Subject"] = "Hello, World."
    message["From"] = Address(username="******", domain="example.com")
    message.set_content("This is a test")

    flat_message = flatten_message(message)

    expected_message = b"""To: [email protected]\r
Subject: Hello, World.\r
From: [email protected]\r
Content-Type: text/plain; charset="utf-8"\r
Content-Transfer-Encoding: 7bit\r
MIME-Version: 1.0\r
\r
This is a test\r
"""
    assert flat_message == expected_message
Пример #11
0
def test_simple_flatten_message():
    message = EmailMessage()
    message['To'] = Address(username='******', domain='example.com')
    message['Subject'] = 'Hello, World.'
    message['From'] = Address(username='******', domain='example.com')
    message.set_content('This is a test')

    sender, recipients, flat_message = flatten_message(message)
    expected_message = """To: [email protected]\r
Subject: Hello, World.\r
From: [email protected]\r
Content-Type: text/plain; charset="utf-8"\r
Content-Transfer-Encoding: 7bit\r
MIME-Version: 1.0\r
\r
This is a test\r
"""

    assert sender == message['From']
    assert recipients == [message['To']]
    assert flat_message == expected_message