Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,14 @@ def _refold_parse_tree(parse_tree, *, policy):
continue
if not hasattr(part, 'encode'):
# It's not a terminal, try folding the subparts.
newparts = list(part)
if part.token_type == 'bare-quoted-string':
newparts = [
ValueTerminal('"', 'DQUOTE'),
*list(part),
ValueTerminal('"', 'DQUOTE'),
]
else:
newparts = list(part)
if not part.as_ew_allowed:
wrap_as_ew_blocked += 1
newparts.append(end_ew_not_allowed)
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,13 @@ def test_long_rfc2047_header_with_embedded_fws(self):
=?utf-8?q?_to_see_if_line_wrapping_with_encoded_words_and_embedded?=
=?utf-8?q?_folding_white_space_works?=""")+'\n')

def test_long_quoted_string_header(self):
msg = Message(policy=email.policy.default)
msg['To'] = '"John Doe Example Inc. Houtesiplou Belgium" <john.doe@example.com>'
self.assertEqual(
msg.as_string(maxheaderlen=40),
'To: "John Doe Example Inc. Houtesiplou\n Belgium" <john.doe@example.com>\n\n',
)


# Test mangling of "From " lines in the body of a message
Expand Down