mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-37482: Fix email address name with encoded words and special chars (GH-14561)
Special characters in email address header display names are normally put within double quotes. However, encoded words (=?charset?x?...?=) are not allowed withing double quotes. When the header contains a word with special characters and another word that must be encoded, the first one must also be encoded. In the next example, the display name in the From header is quoted and therefore the comma is allowed; in the To header, the comma is not within quotes and not encoded, which is not allowed and therefore rejected by some mail servers. From: "Foo Bar, France" <foo@example.com> To: Foo Bar, =?utf-8?q?Espa=C3=B1a?= <foo@example.com> https://bugs.python.org/issue37482
This commit is contained in:
parent
48ede6b8f6
commit
df0c21ff46
3 changed files with 28 additions and 0 deletions
|
@ -2743,6 +2743,9 @@ def _refold_parse_tree(parse_tree, *, policy):
|
|||
wrap_as_ew_blocked -= 1
|
||||
continue
|
||||
tstr = str(part)
|
||||
if part.token_type == 'ptext' and set(tstr) & SPECIALS:
|
||||
# Encode if tstr contains special characters.
|
||||
want_encoding = True
|
||||
try:
|
||||
tstr.encode(encoding)
|
||||
charset = encoding
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue