Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def comments(self):
comments.extend(token.comments)
return comments

def has_token_type(self, *token_types):
if self.token_type in token_types:
return True
for t in self:
if t.has_token_type(*token_types):
return True
return False

def fold(self, *, policy):
return _refold_parse_tree(self, policy=policy)

Expand Down Expand Up @@ -922,6 +930,9 @@ def pop_trailing_ws(self):
def comments(self):
return []

def has_token_type(self, *token_types):
return self.token_type in token_types

def __getnewargs__(self):
return(str(self), self.token_type)

Expand Down Expand Up @@ -2813,7 +2824,7 @@ def _refold_parse_tree(parse_tree, *, policy):
continue
tstr = str(part)
if not want_encoding:
if part.token_type in ('ptext', 'vtext'):
if part.token_type == 'ptext' or part.has_token_type('vtext'):
# Encode if tstr contains special characters.
want_encoding = not SPECIALSNL.isdisjoint(tstr)
else:
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,11 @@ def test_address_list_with_specials_in_encoded_word(self):
'A =?utf-8?q?v=C3=A9ry?= long name\n'
' containing =?utf-8?q?a=2C?= comma\n'
' <[email protected]>\n'),
('=?utf-8?Q?a=2C=20123456789012345678901234567890123456?='
' <[email protected]>',
'=?utf-8?q?a=2C?=\n'
' 123456789012345678901234567890123456\n'
' <[email protected]>\n'),
]
for (to, folded) in cases:
with self.subTest(to=to):
Expand Down
Loading