Skip to content

Commit 43eaea1

Browse files
committed
fixup! Stop incorrectly RFC 2047 encoding non-ASCII email addresses
- Incorporate PR feedback - Tailor blurbs to individual issues
1 parent 61ac0d7 commit 43eaea1

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

Lib/email/_header_value_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,8 +2846,8 @@ def _refold_parse_tree(parse_tree, *, policy):
28462846
want_encoding = False
28472847
else:
28482848
raise errors.InvalidMailboxError(
2849-
"Non-ASCII address requires policy with utf8=True:"
2850-
" '{}'".format(part)
2849+
f"Non-ASCII mailbox '{part}' is invalid"
2850+
" under current policy setting (utf8=False)"
28512851
)
28522852

28532853
if want_encoding and not wrap_as_ew_blocked:

Lib/test/test_email/test_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def test_non_ascii_addr_spec_raises(self):
306306
msg['To'] = address
307307
addr_spec = msg['To'].addresses[0].addr_spec
308308
expected_error = (
309-
fr"(?i)(?=.*non-ascii)(?=.*utf8.*True)(?=.*{re.escape(addr_spec)})"
309+
fr"(?i)(?=.*non-ascii)(?=.*{re.escape(addr_spec)})(?=.*policy.*utf8)"
310310
)
311311
with self.assertRaisesRegex(
312312
email.errors.InvalidMailboxError, expected_error
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
The :mod:`email` module no longer incorrectly encodes non-ASCII characters
2-
in email addresses using :rfc:`2047` encoding. Under a policy with ``utf8=True``
3-
this means the addresses will be correctly passed through. Under a policy with
4-
``utf8=False``, attempting to serialize a message with non-ASCII email addresses
5-
will now result in an :exc:`~email.errors.InvalidMailboxError`.
1+
The :mod:`email` module no longer incorrectly uses :rfc:`2047` encoding for
2+
a mailbox with non-ASCII characters in its domain. Under a policy with
3+
:attr:`~email.policy.EmailPolicy.utf8` set ``False``, attempting to serialize
4+
such a message will now raise an :exc:`~email.errors.InvalidMailboxError`.
5+
Either apply an appropriate IDNA encoding to convert the domain to ASCII before
6+
serialization, or use :data:`email.policy.SMTPUTF8` (or another policy with
7+
``utf8=True``) to correctly pass through the internationalized domain name
8+
as Unicode characters.
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
The :mod:`email` module no longer incorrectly encodes non-ASCII characters
2-
in email addresses using :rfc:`2047` encoding. Under a policy with ``utf8=True``
3-
this means the addresses will be correctly passed through. Under a policy with
4-
``utf8=False``, attempting to serialize a message with non-ASCII email addresses
5-
will now result in an :exc:`~email.errors.InvalidMailboxError`.
1+
The :mod:`email` module no longer incorrectly uses :rfc:`2047` encoding for
2+
a mailbox with non-ASCII characters in its local-part. Under a policy with
3+
:attr:`~email.policy.EmailPolicy.utf8` set ``False``, attempting to serialize
4+
such a message will now raise an :exc:`~email.errors.InvalidMailboxError`.
5+
There is no valid 7-bit encoding for an internationalized local-part. Use
6+
:data:`email.policy.SMTPUTF8` (or another policy with ``utf8=True``) to
7+
correctly pass through the local-part as Unicode characters.

0 commit comments

Comments
 (0)