diff options
author | jannschu <jannik.schuerg@posteo.de> | 2018-10-22 12:21:33 -0700 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-10-22 15:21:33 -0400 |
commit | efc0f77f02de86a94e21cafd3c8409eb7dd99ef6 (patch) | |
tree | b5e5e8c7c35148be61bcfc9acdc8b15a1aabae40 /tests/mail | |
parent | 043407ec7e6e659a69c2432319140b4a813928d2 (diff) | |
download | django-efc0f77f02de86a94e21cafd3c8409eb7dd99ef6.tar.gz |
Fixed #29830 -- Fixed loss of custom utf-8 body encoding in mails.
Diffstat (limited to 'tests/mail')
-rw-r--r-- | tests/mail/tests.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py index b2de5e4c10..ac44996ff9 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -8,7 +8,7 @@ import socket import sys import tempfile import threading -from email import message_from_binary_file, message_from_bytes +from email import charset, message_from_binary_file, message_from_bytes from email.header import Header from email.mime.text import MIMEText from email.utils import parseaddr @@ -686,6 +686,21 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): # The child message header is not base64 encoded self.assertIn('Child Subject', parent_s) + def test_custom_utf8_encoding(self): + """A UTF-8 charset with a custom body encoding is respected.""" + body = 'Body with latin characters: àáä.' + msg = EmailMessage('Subject', body, 'bounce@example.com', ['to@example.com']) + encoding = charset.Charset('utf-8') + encoding.body_encoding = charset.QP + msg.encoding = encoding + message = msg.message() + self.assertMessageHasHeaders(message, { + ('MIME-Version', '1.0'), + ('Content-Type', 'text/plain; charset="utf-8"'), + ('Content-Transfer-Encoding', 'quoted-printable'), + }) + self.assertEqual(message.get_payload(), encoding.body_encode(body)) + def test_sanitize_address(self): """ Email addresses are properly sanitized. |