Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
fixup! Fix email header wrapping omitting white space
  • Loading branch information
robsdedude committed Feb 11, 2026
commit 050491c170b5a165fee4808b39b896718fbb9411
9 changes: 3 additions & 6 deletions Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2840,9 +2840,7 @@ def _steal_all_trailing_WSP_if_exists(lines):
wsp_lines = []
while lines and lines[-1]:
for i in range(len(lines[-1]), -1, -1):
if i <= 0:
break
if lines[-1][i - 1] not in WSP:
if i <= 0 or lines[-1][i - 1] not in WSP:
break
wsp_line = lines[-1][i:]
if not wsp_line:
Expand All @@ -2854,9 +2852,8 @@ def _steal_all_trailing_WSP_if_exists(lines):
lines.pop()
else:
break

if lines_popped:
lines.append(' ')
lines.append(' ' if lines else '')
return ''.join(wsp_lines)
Comment thread
robsdedude marked this conversation as resolved.
Outdated

def _refold_parse_tree(parse_tree, *, policy):
Expand Down Expand Up @@ -2967,7 +2964,7 @@ def _refold_parse_tree(parse_tree, *, policy):
newline = _steal_trailing_WSP_if_exists(lines)
if newline or part.startswith_fws():
lines.append(newline + tstr)
if not all(char in WSP for char in lines[-1]):
if any(char not in WSP for char in lines[-1]):
last_word_is_ew = False
Comment thread
robsdedude marked this conversation as resolved.
Outdated
last_ew = None
continue
Expand Down
Loading