def test_encoding(): """Encode body correctly with other encodings than utf-8 """ email = EmailMessage('Subject', 'Firstname Sürname is a great guy.', '*****@*****.**', '*****@*****.**') email.encoding = 'iso-8859-1' message = email.message() assert message.as_string().startswith('Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: [email protected]\nTo: [email protected]') assert message.get_payload() == 'Firstname S=FCrname is a great guy.' # Make sure MIME attachments also works correctly with other encodings than utf-8 text_content = 'Firstname Sürname is a great guy.' html_content = '<p>Firstname Sürname is a <strong>great</strong> guy.</p>' email = EmailMessage('Subject', text_content, '*****@*****.**', '*****@*****.**', html_content=html_content) email.encoding = 'iso-8859-1' message = email.message() assert message.get_payload(0).as_string() == \ 'Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\nFirstname S=FCrname is a great guy.' assert message.get_payload(1).as_string() == \ 'Content-Type: text/html; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\n<p>Firstname S=FCrname is a <strong>great</strong> guy.</p>'
def test_encoding(): """Encode body correctly with other encodings than utf-8 """ email = EmailMessage('Subject', 'Firstname Sürname is a great guy.', '*****@*****.**', '*****@*****.**') email.encoding = 'iso-8859-1' message = email.render() assert message.as_string().startswith( 'Content-Type: text/plain; charset="iso-8859-1"' '\nMIME-Version: 1.0' '\nContent-Transfer-Encoding: quoted-printable' '\nSubject: Subject' '\nFrom: [email protected]' '\nTo: [email protected]') assert message.get_payload() == 'Firstname S=FCrname is a great guy.' # Make sure MIME attachments also works correctly with other encodings than utf-8 text_content = 'Firstname Sürname is a great guy.' html_content = '<p>Firstname Sürname is a <strong>great</strong> guy.</p>' email = EmailMessage('Subject', text_content, '*****@*****.**', '*****@*****.**', html_content=html_content) email.encoding = 'iso-8859-1' message = email.render() assert message.get_payload(0).as_string() == ( 'Content-Type: text/plain; charset="iso-8859-1"' '\nMIME-Version: 1.0' '\nContent-Transfer-Encoding: quoted-printable' '\n\nFirstname S=FCrname is a great guy.') assert message.get_payload(1).as_string() == ( 'Content-Type: text/html; charset="iso-8859-1"' '\nMIME-Version: 1.0' '\nContent-Transfer-Encoding: quoted-printable' '\n\n<p>Firstname S=FCrname is a <strong>great</strong> guy.</p>')
def test_safe_mime_multipart(): """Make sure headers can be set with a different encoding than utf-8 in SafeMIMEMultipart as well """ subject = 'Message from Firstname Sürname' from_email = '*****@*****.**' to = '"Sürname, Firstname" <*****@*****.**>' text_content = 'This is an important message.' html_content = '<p>This is an <strong>important</strong> message.</p>' headers = {"Date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"} email = EmailMessage(subject, text_content, from_email, to, html_content=html_content, headers=headers) email.encoding = 'iso-8859-1' email.render()