8000 [3.13] gh-118643: Fix AttributeError in the email module (GH-119099) … · python/cpython@6892b40 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6892b40

Browse files
[3.13] gh-118643: Fix AttributeError in the email module (GH-119099) (GH-119389)
Fix regression introduced in gh-100884: AttributeError when re-fold a long address list. Also fix more cases of incorrect encoding of the address separator in the address list missed in gh-100884. (cherry picked from commit 858b9e8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 414346e commit 6892b40

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Lib/email/_header_value_parser.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ class _InvalidEwError(errors.HeaderParseError):
956956
DOT = ValueTerminal('.', 'dot')
957957
ListSeparator = ValueTerminal(',', 'list-separator')
958958
ListSeparator.as_ew_allowed = False
959+
ListSeparator.syntactic_break = False
959960
RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
960961

961962
#
@@ -2844,7 +2845,9 @@ def _refold_parse_tree(parse_tree, *, policy):
28442845
if not hasattr(part, 'encode'):
28452846
# It's not a Terminal, do each piece individually.
28462847
parts = list(part) + parts
2847-
else:
2848+
want_encoding = False
2849+
continue
2850+
elif part.as_ew_allowed:
28482851
# It's a terminal, wrap it as an encoded word, possibly
28492852
# combining it with previously encoded words if allowed.
28502853
if (last_ew is not None and
@@ -2858,8 +2861,14 @@ def _refold_parse_tree(parse_tree, *, policy):
28582861
# so clear it now.
28592862
leading_whitespace = ''
28602863
last_charset = charset
2861-
want_encoding = False
2862-
continue
2864+
want_encoding = False
2865+
continue
2866+
else:
2867+
# It's a terminal which should be kept non-encoded
2868+
# (e.g. a ListSeparator).
2869+
last_ew = None
2870+
want_encoding = False
2871+
# fall through
28632872

28642873
if len(tstr) <= maxlen - len(lines[-1]):
28652874
lines[-1] += tstr

Lib/test/test_email/test__header_value_parser.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,9 +3077,17 @@ def test_address_list_with_unicode_names_in_quotes(self):
30773077
' =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>\n')
30783078

30793079
def test_address_list_with_list_separator_after_fold(self):
3080-
to = '0123456789' * 8 + '@foo, ä <foo@bar>'
3080+
a = 'x' * 66 + '@example.com'
3081+
to = f'{a}, "Hübsch Kaktus" <beautiful@example.com>'
30813082
self._test(parser.get_address_list(to)[0],
3082-
'0123456789' * 8 + '@foo,\n =?utf-8?q?=C3=A4?= <foo@bar>\n')
3083+
f'{a},\n =?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>\n')
3084+
3085+
a = '.' * 79
3086+
to = f'"{a}" <xyz@example.com>, "Hübsch Kaktus" <beautiful@example.com>'
3087+
self._test(parser.get_address_list(to)[0],
3088+
f'{a}\n'
3089+
' <xyz@example.com>, =?utf-8?q?H=C3=BCbsch?= Kaktus '
3090+
'<beautiful@example.com>\n')
3083309 750F 1

30843092
# XXX Need tests with comments on various sides of a unicode token,
30853093
# and with unicode tokens in the comments. Spaces inside the quotes
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an AttributeError in the :mod:`email` module when re-fold a long address
2+
list. Also fix more cases of incorrect encoding of the address separator in the address list.

0 commit comments

Comments
 (0)
0