fixup! Stop incorrectly RFC 2047 encoding non-ASCII email addresses

- Incorporate PR feedback
- Tailor blurbs to individual issues
This commit is contained in:
Mike Edmunds 2025-05-26 16:19:02 -07:00
parent 61ac0d75f0
commit 43eaea1fb8
No known key found for this signature in database
4 changed files with 18 additions and 13 deletions

View file

@ -2846,8 +2846,8 @@ def _refold_parse_tree(parse_tree, *, policy):
want_encoding = False
else:
raise errors.InvalidMailboxError(
"Non-ASCII address requires policy with utf8=True:"
" '{}'".format(part)
f"Non-ASCII mailbox '{part}' is invalid"
" under current policy setting (utf8=False)"
)
if want_encoding and not wrap_as_ew_blocked:

View file

@ -306,7 +306,7 @@ class TestGeneratorBase:
msg['To'] = address
addr_spec = msg['To'].addresses[0].addr_spec
expected_error = (
fr"(?i)(?=.*non-ascii)(?=.*utf8.*True)(?=.*{re.escape(addr_spec)})"
fr"(?i)(?=.*non-ascii)(?=.*{re.escape(addr_spec)})(?=.*policy.*utf8)"
)
with self.assertRaisesRegex(
email.errors.InvalidMailboxError, expected_error

View file

@ -1,5 +1,8 @@
The :mod:`email` module no longer incorrectly encodes non-ASCII characters
in email addresses using :rfc:`2047` encoding. Under a policy with ``utf8=True``
this means the addresses will be correctly passed through. Under a policy with
``utf8=False``, attempting to serialize a message with non-ASCII email addresses
will now result in an :exc:`~email.errors.InvalidMailboxError`.
The :mod:`email` module no longer incorrectly uses :rfc:`2047` encoding for
a mailbox with non-ASCII characters in its domain. Under a policy with
:attr:`~email.policy.EmailPolicy.utf8` set ``False``, attempting to serialize
such a message will now raise an :exc:`~email.errors.InvalidMailboxError`.
Either apply an appropriate IDNA encoding to convert the domain to ASCII before
serialization, or use :data:`email.policy.SMTPUTF8` (or another policy with
``utf8=True``) to correctly pass through the internationalized domain name
as Unicode characters.

View file

@ -1,5 +1,7 @@
The :mod:`email` module no longer incorrectly encodes non-ASCII characters
in email addresses using :rfc:`2047` encoding. Under a policy with ``utf8=True``
this means the addresses will be correctly passed through. Under a policy with
``utf8=False``, attempting to serialize a message with non-ASCII email addresses
will now result in an :exc:`~email.errors.InvalidMailboxError`.
The :mod:`email` module no longer incorrectly uses :rfc:`2047` encoding for
a mailbox with non-ASCII characters in its local-part. Under a policy with
:attr:`~email.policy.EmailPolicy.utf8` set ``False``, attempting to serialize
such a message will now raise an :exc:`~email.errors.InvalidMailboxError`.
There is no valid 7-bit encoding for an internationalized local-part. Use
:data:`email.policy.SMTPUTF8` (or another policy with ``utf8=True``) to
correctly pass through the local-part as Unicode characters.