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
6 changes: 5 additions & 1 deletion Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3081,13 +3081,17 @@ def _fold_mime_parameters(part, lines, maxlen, encoding):
# the RFC standard width.
maxlen = 78
splitpoint = maxchars = maxlen - chrome_len - 2
while True:
splitpoint = max(1, splitpoint) # Ensure splitpoint is always at least 1
while splitpoint > 1:
partial = value[:splitpoint]
encoded_value = urllib.parse.quote(
partial, safe='', errors=error_handler)
if len(encoded_value) <= maxchars:
break
splitpoint -= 1
# If we still can't fit, force a minimal split
if splitpoint <= 1:
splitpoint = 1
lines.append(" {}*{}*={}{}".format(
name, section, extra_chrome, encoded_value))
extra_chrome = ''
Expand Down
2 changes: 2 additions & 0 deletions Lib/email/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ def _append_chunk(self, fws, string):
continue
break
else:
# No suitable split point found. Handle the case where we have
# an extremely long string that can't be split.
fws, part = self._current_line.pop()
if self._current_line._initial_size > 0:
# There will be a header, so leave it on a line by itself.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix infinite loop in email.message.EmailMessage.as_string() when add_attachment() is called with very long parameter keys.
Loading