Skip to content
Closed
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
18 changes: 16 additions & 2 deletions Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def append_if_fits(self, token, stoken=None):
self.stickyspace = None
self.firstline = False
return True
if token.has_fws:
if token.has_leading_fws:
ws = token.pop_leading_fws()
if ws is not None:
self.stickyspace += str(ws)
Expand Down Expand Up @@ -267,7 +267,7 @@ def startswith_fws(self):
return self[0].startswith_fws()

def pop_leading_fws(self):
if self[0].token_type == 'fws':
if self[0].token_type == 'fws' or self[0].token_type == 'cfws':
return self.pop(0)
return self[0].pop_leading_fws()

Expand All @@ -283,6 +283,14 @@ def has_fws(self):
return True
return False

@property
def has_leading_fws(self):
for part in self:
if part.has_fws:
return True
break
return False

def has_leading_comment(self):
return self[0].has_leading_comment()

Expand Down Expand Up @@ -1292,6 +1300,8 @@ def startswith_fws(self):

has_fws = True

has_leading_fws = True


class ValueTerminal(Terminal):

Expand All @@ -1304,6 +1314,8 @@ def startswith_fws(self):

has_fws = False

has_leading_fws = False

def as_encoded_word(self, charset):
return _ew.encode(str(self), charset)

Expand All @@ -1323,6 +1335,8 @@ def __str__(self):

has_fws = True

has_leading_fws = True


# XXX these need to become classes and used as instances so
# that a program can't change them in a parse tree and screw
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2723,5 +2723,14 @@ def test_long_filename_attachment(self):
folded
)

def test_long_filename_attachment_with_space(self):
folded = self.policy.fold('Content-Disposition', 'attachment; filename="1234 67890123456789012345678901234567890123456789012345678901234567890"')
self.assertEqual(
'Content-Disposition: attachment;\n filename="1234 67890123456789012345678901234567890123456789012345678901234567890"\n',
folded
)



if __name__ == '__main__':
unittest.main()