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

Skip to content
Merged
Prev Previous commit
Next Next commit
Inline helper function
  • Loading branch information
robsdedude committed Feb 14, 2026
commit 0d694d6624a41a0c6b414028b08cc9f352f3a1fd
15 changes: 4 additions & 11 deletions Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2837,12 +2837,6 @@ def _steal_trailing_WSP_if_exists(lines):
return wsp


def _last_word_is_sill_ew(_last_word_is_ew, added_str):
# If the last word is an encoded word, and the added string is all WSP,
# then (and only then) is the last word is still an encoded word.
return _last_word_is_ew and not bool(added_str.strip(_WSP))


def _refold_parse_tree(parse_tree, *, policy):
"""Return string of contents of parse_tree folded according to RFC rules.

Expand Down Expand Up @@ -2946,7 +2940,7 @@ def _refold_parse_tree(parse_tree, *, policy):

if len(tstr) <= maxlen - len(lines[-1]):
lines[-1] += tstr
last_word_is_ew = _last_word_is_sill_ew(last_word_is_ew, tstr)
last_word_is_ew = last_word_is_ew and not bool(tstr.strip(_WSP))
continue

# This part is too long to fit. The RFC wants us to break at
Expand All @@ -2957,9 +2951,8 @@ def _refold_parse_tree(parse_tree, *, policy):
newline = _steal_trailing_WSP_if_exists(lines)
if newline or part.startswith_fws():
lines.append(newline + tstr)
last_word_is_ew = _last_word_is_sill_ew(
last_word_is_ew, lines[-1]
)
last_word_is_ew = (last_word_is_ew
and not bool(lines[-1].strip(_WSP)))
last_ew = None
continue
if not hasattr(part, 'encode'):
Expand Down Expand Up @@ -2999,7 +2992,7 @@ def _refold_parse_tree(parse_tree, *, policy):
else:
# We can't fold it onto the next line either...
lines[-1] += tstr
last_word_is_ew = _last_word_is_sill_ew(last_word_is_ew, tstr)
last_word_is_ew = last_word_is_ew and not bool(tstr.strip(_WSP))

return policy.linesep.join(lines) + policy.linesep

Expand Down
Loading