]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-83938, gh-122476: Stop incorrectly RFC 2047 encoding non-ASCII email addresses...
authorMike Edmunds <medmunds@gmail.com>
Fri, 1 May 2026 17:52:06 +0000 (10:52 -0700)
committerGitHub <noreply@github.com>
Fri, 1 May 2026 17:52:06 +0000 (13:52 -0400)
commitd96ffc18320a58d164c1809871bb3aea7f549ac6
treeba6dcbe7350590bc0590dc65859eec6a54fe51c3
parent9668d260a197207b440c8e65f09f4cc24b9cd566
gh-83938, gh-122476: Stop incorrectly RFC 2047 encoding non-ASCII email addresses (#122540)

The email generators had been incorrectly flattening non-ASCII email
addresses to RFC 2047 encoded-word format, leaving them undeliverable.
(RFC 2047 prohibits use of encoded-word in an addr-spec.)
This change raises a HeaderWriteError when attempting to flatten an
EmailMessage with a non-ASCII addr-spec and a policy with utf8=False.
(Exception: If the non-ASCII address originated from parsing a message,
it will be flattened as originally parsed, without error.)  This also applies
to other contexts in which RFC2047 words are not allowed by the RFCs.

Non-ASCII email addresses are supported when using a policy with
utf8=True (such as email.policy.SMTPUTF8) under RFCs 6531 and 6532.

Non-ASCII email address domains (but not localparts) can also be used
with non-SMTPUTF8 policies by encoding the domain as an IDNA A-label.
(The email package does not perform this encoding, because it cannot
know whether the caller wants IDNA 2003, IDNA 2008, or some other
variant such as UTS #46.)

Co-authored-by: R. David Murray <rdmurray@bitdance.com>
Doc/library/email.policy.rst
Doc/whatsnew/3.15.rst
Lib/email/_header_value_parser.py
Lib/test/test_email/test__header_value_parser.py
Lib/test/test_email/test_generator.py
Misc/NEWS.d/next/Library/2024-07-31-17-22-10.gh-issue-83938.TtUa-c.rst [new file with mode: 0644]
Misc/NEWS.d/next/Library/2024-07-31-17-23-06.gh-issue-122476.TtUa-c.rst [new file with mode: 0644]