diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 205c680561..5e799d3fe1 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -108,13 +108,15 @@ def sanitize_address(addr, encoding): # Avoid UTF-8 encode, if it's possible. try: nm.encode("ascii") - nm = Header(nm).encode() + nm = Header(nm, None, RFC5322_EMAIL_LINE_LENGTH_LIMIT).encode() except UnicodeEncodeError: - nm = Header(nm, encoding).encode() + nm = Header(nm, encoding, RFC5322_EMAIL_LINE_LENGTH_LIMIT).encode() try: localpart.encode("ascii") except UnicodeEncodeError: - localpart = Header(localpart, encoding).encode() + localpart = Header( + localpart, encoding, RFC5322_EMAIL_LINE_LENGTH_LIMIT + ).encode() domain = punycode(domain) parsed_address = Address(username=localpart, domain=domain) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 9e55398d60..133f80d2e3 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1079,25 +1079,28 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): "Tó Example very long" * 4 + " ", "utf-8", "=?utf-8?q?T=C3=B3_Example_very_longT=C3=B3_Example_very_longT" - "=C3=B3_Example_?=\n" - " =?utf-8?q?very_longT=C3=B3_Example_very_long?= " + "=C3=B3_Example_very_longT=C3=B3_Example_very_long?= " "", ), ( ("Tó Example very long" * 4, "to@example.com"), "utf-8", "=?utf-8?q?T=C3=B3_Example_very_longT=C3=B3_Example_very_longT" - "=C3=B3_Example_?=\n" - " =?utf-8?q?very_longT=C3=B3_Example_very_long?= " + "=C3=B3_Example_very_longT=C3=B3_Example_very_long?= " "", ), + ( + "ţēśţ." * 6 + "@example.com", + "utf-8", + "=?utf-8?b?xaPEk8WbxaMuxaPEk8WbxaMuxaPEk8WbxaMuxaPEk8WbxaMuxa" + "PEk8WbxaMuxaPEk8WbxaMu?=@example.com", + ), # Address with long display name and unicode domain. ( ("To Example very long" * 4, "to@exampl€.com"), "utf-8", "To Example very longTo Example very longTo Example very longT" - "o Example very\n" - " long ", + "o Example very long ", ), ): with self.subTest(email_address=email_address, encoding=encoding):