Exemple #1
0
def test_dont_base64_encode():
    """Shouldn't use Base64 encoding at all.
    """
    email = EmailMessage('Subject', 'UTF-8 encoded body', '*****@*****.**',
                         '*****@*****.**',
                         headers={'From': '*****@*****.**'})
    assert 'Content-Transfer-Encoding: base64' not in email.as_string()
Exemple #2
0
def test_message_header_overrides():
    """Specifying dates or message-ids in the extra headers overrides the
    default values.
    """
    headers = {'date': 'Fri, 09 Nov 2001 01:08:47 -0000', 'Message-ID': 'foo'}
    email = EmailMessage('Subject',
                         'Content',
                         '*****@*****.**',
                         '*****@*****.**',
                         headers=headers)

    email_as_string = email.as_string()
    lines = [
        'Content-Type: text/plain; charset="utf-8"'
        '\nMIME-Version: 1.0',
        '\nContent-Transfer-Encoding: 7bit',
        '\nSubject: Subject',
        '\nFrom: [email protected]',
        '\nTo: [email protected]',
        '\ndate: Fri, 09 Nov 2001 01:08:47 -0000',
        '\nMessage-ID: foo',
        '\n\nContent',
    ]
    for line in lines:
        assert line in email_as_string
def test_message_header_overrides():
    """Specifying dates or message-ids in the extra headers overrides the
    default values.
    """
    headers = {'date': 'Fri, 09 Nov 2001 01:08:47 -0000', 'Message-ID': 'foo'}
    email = EmailMessage('Subject', 'Content', '*****@*****.**',
        '*****@*****.**', headers=headers)
    
    assert email.as_string() == 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Subject\nFrom: [email protected]\nTo: [email protected]\ndate: Fri, 09 Nov 2001 01:08:47 -0000\nMessage-ID: foo\n\nContent'
Exemple #4
0
def test_dont_base64_encode():
    """Shouldn't use Base64 encoding at all.
    """
    email = EmailMessage('Subject',
                         'UTF-8 encoded body',
                         '*****@*****.**',
                         '*****@*****.**',
                         headers={'From': '*****@*****.**'})
    assert 'Content-Transfer-Encoding: base64' not in email.as_string()
Exemple #5
0
def test_7bit_no_quoted_printable():
    """Shouldn't use quoted printable, should detect it can represent content
    with 7 bit data.
    """
    email = EmailMessage('Subject', 'Body with only ASCII characters.',
                         '*****@*****.**', '*****@*****.**',
                         headers={'From': '*****@*****.**'})
    msg = email.as_string()

    assert 'Content-Transfer-Encoding: quoted-printable' not in msg
    assert 'Content-Transfer-Encoding: 7bit' in msg
def test_8bit_no_quoted_printable():
    """Shouldn't use quoted printable, should detect it can represent content
    with 8 bit data.
    """
    email = EmailMessage('Subject', 'Body with latin characters: àáä.',
        '*****@*****.**', '*****@*****.**',
        headers={'From': '*****@*****.**'})
    msg = email.as_string()
    
    assert 'Content-Transfer-Encoding: quoted-printable' not in msg
    assert 'Content-Transfer-Encoding: 8bit' in msg

    email = EmailMessage('Subject',
        u'Body with non latin characters: А Б В Г Д Е Ж Ѕ З И І К Л М Н О П.',
        '*****@*****.**', '*****@*****.**',
        headers={'From': '*****@*****.**'})
    msg = email.as_string()

    assert 'Content-Transfer-Encoding: quoted-printable' not in msg
    assert 'Content-Transfer-Encoding: 8bit' in msg
Exemple #7
0
def test_7bit_no_quoted_printable():
    """Shouldn't use quoted printable, should detect it can represent content
    with 7 bit data.
    """
    email = EmailMessage('Subject',
                         'Body with only ASCII characters.',
                         '*****@*****.**',
                         '*****@*****.**',
                         headers={'From': '*****@*****.**'})
    msg = email.as_string()

    assert 'Content-Transfer-Encoding: quoted-printable' not in msg
    assert 'Content-Transfer-Encoding: 7bit' in msg
Exemple #8
0
def test_8bit_no_quoted_printable():
    """Shouldn't use quoted printable, should detect it can represent content
    with 8 bit data.
    """
    email = EmailMessage('Subject',
                         'Body with latin characters: àáä.',
                         '*****@*****.**',
                         '*****@*****.**',
                         headers={'From': '*****@*****.**'})
    msg = email.as_string()

    assert 'Content-Transfer-Encoding: quoted-printable' not in msg
    assert 'Content-Transfer-Encoding: 8bit' in msg

    email = EmailMessage(
        'Subject',
        u'Body with non latin characters: А Б В Г Д Е Ж Ѕ З И І К Л М Н О П.',
        '*****@*****.**',
        '*****@*****.**',
        headers={'From': '*****@*****.**'})
    msg = email.as_string()

    assert 'Content-Transfer-Encoding: quoted-printable' not in msg
    assert 'Content-Transfer-Encoding: 8bit' in msg
def test_dont_mangle_from_in_body():
    """Make sure that EmailMessage doesn't mangle 'From' in message body."""
    email = EmailMessage('Subject', 'From the future', '*****@*****.**', 
        '*****@*****.**', headers={'From': '*****@*****.**'})
    
    assert '>From the future' not in email.as_string()