8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 414346e commit 6892b40Copy full SHA for 6892b40
Lib/email/_header_value_parser.py
@@ -956,6 +956,7 @@ class _InvalidEwError(errors.HeaderParseError):
956
DOT = ValueTerminal('.', 'dot')
957
ListSeparator = ValueTerminal(',', 'list-separator')
958
ListSeparator.as_ew_allowed = False
959
+ListSeparator.syntactic_break = False
960
RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
961
962
#
@@ -2844,7 +2845,9 @@ def _refold_parse_tree(parse_tree, *, policy):
2844
2845
if not hasattr(part, 'encode'):
2846
# It's not a Terminal, do each piece individually.
2847
parts = list(part) + parts
- else:
2848
+ want_encoding = False
2849
+ continue
2850
+ elif part.as_ew_allowed:
2851
# It's a terminal, wrap it as an encoded word, possibly
2852
# combining it with previously encoded words if allowed.
2853
if (last_ew is not None and
@@ -2858,8 +2861,14 @@ def _refold_parse_tree(parse_tree, *, policy):
2858
2861
# so clear it now.
2859
2862
leading_whitespace = ''
2860
2863
last_charset = charset
- want_encoding = False
- continue
2864
2865
2866
+ else:
2867
+ # It's a terminal which should be kept non-encoded
2868
+ # (e.g. a ListSeparator).
2869
+ last_ew = None
2870
2871
+ # fall through
2872
2873
if len(tstr) <= maxlen - len(lines[-1]):
2874
lines[-1] += tstr
Lib/test/test_email/test__header_value_parser.py
@@ -3077,9 +3077,17 @@ def test_address_list_with_unicode_names_in_quotes(self):
3077
' =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>\n')
3078
3079
def test_address_list_with_list_separator_after_fold(self):
3080
- to = '0123456789' * 8 + '@foo, ä <foo@bar>'
+ a = 'x' * 66 + '@example.com'
3081
+ to = f'{a}, "Hübsch Kaktus" <beautiful@example.com>'
3082
self._test(parser.get_address_list(to)[0],
- '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')
3091
3092
# XXX Need tests with comments on various sides of a unicode token,
3093
# and with unicode tokens in the comments. Spaces inside the quotes
Misc/NEWS.d/next/Library/2024-05-16-17-31-46.gh-issue-118643.hAWH4C.rst
@@ -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.