summaryrefslogtreecommitdiffstats
path: root/Lib/email/_header_value_parser.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-05-22 10:17:46 (GMT)
committerGitHub <noreply@github.com>2024-05-22 10:17:46 (GMT)
commit858b9e85fcdd495947c9e892ce6e3734652c48f2 (patch)
tree793e1fef26ccd7d264e874ae9400a4a78a762d6b /Lib/email/_header_value_parser.py
parentaee8f03abbebfb76357f459dfb297026862e3c0b (diff)
downloadcpython-858b9e85fcdd495947c9e892ce6e3734652c48f2.zip
cpython-858b9e85fcdd495947c9e892ce6e3734652c48f2.tar.gz
cpython-858b9e85fcdd495947c9e892ce6e3734652c48f2.tar.bz2
gh-118643: Fix AttributeError in the email module (GH-119099)
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.
Diffstat (limited to 'Lib/email/_header_value_parser.py')
-rw-r--r--Lib/email/_header_value_parser.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index 6148801..ab3c303 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -956,6 +956,7 @@ class _InvalidEwError(errors.HeaderParseError):
DOT = ValueTerminal('.', 'dot')
ListSeparator = ValueTerminal(',', 'list-separator')
ListSeparator.as_ew_allowed = False
+ListSeparator.syntactic_break = False
RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
#
@@ -2844,7 +2845,9 @@ def _refold_parse_tree(parse_tree, *, policy):
if not hasattr(part, 'encode'):
# It's not a Terminal, do each piece individually.
parts = list(part) + parts
- else:
+ want_encoding = False
+ continue
+ elif part.as_ew_allowed:
# It's a terminal, wrap it as an encoded word, possibly
# combining it with previously encoded words if allowed.
if (last_ew is not None and
@@ -2858,8 +2861,14 @@ def _refold_parse_tree(parse_tree, *, policy):
# so clear it now.
leading_whitespace = ''
last_charset = charset
- want_encoding = False
- continue
+ want_encoding = False
+ continue
+ else:
+ # It's a terminal which should be kept non-encoded
+ # (e.g. a ListSeparator).
+ last_ew = None
+ want_encoding = False
+ # fall through
if len(tstr) <= maxlen - len(lines[-1]):
lines[-1] += tstr