@@ -2837,12 +2837,6 @@ def _steal_trailing_WSP_if_exists(lines):
28372837 return wsp
28382838
28392839
2840- def _last_word_is_sill_ew (_last_word_is_ew , added_str ):
2841- # If the last word is an encoded word, and the added string is all WSP,
2842- # then (and only then) is the last word is still an encoded word.
2843- return _last_word_is_ew and not bool (added_str .strip (_WSP ))
2844-
2845-
28462840def _refold_parse_tree (parse_tree , * , policy ):
28472841 """Return string of contents of parse_tree folded according to RFC rules.
28482842
@@ -2946,7 +2940,7 @@ def _refold_parse_tree(parse_tree, *, policy):
29462940
29472941 if len (tstr ) <= maxlen - len (lines [- 1 ]):
29482942 lines [- 1 ] += tstr
2949- last_word_is_ew = _last_word_is_sill_ew ( last_word_is_ew , tstr )
2943+ last_word_is_ew = last_word_is_ew and not bool ( tstr . strip ( _WSP ) )
29502944 continue
29512945
29522946 # This part is too long to fit. The RFC wants us to break at
@@ -2957,9 +2951,8 @@ def _refold_parse_tree(parse_tree, *, policy):
29572951 newline = _steal_trailing_WSP_if_exists (lines )
29582952 if newline or part .startswith_fws ():
29592953 lines .append (newline + tstr )
2960- last_word_is_ew = _last_word_is_sill_ew (
2961- last_word_is_ew , lines [- 1 ]
2962- )
2954+ last_word_is_ew = (last_word_is_ew
2955+ and not bool (lines [- 1 ].strip (_WSP )))
29632956 last_ew = None
29642957 continue
29652958 if not hasattr (part , 'encode' ):
@@ -2999,7 +2992,7 @@ def _refold_parse_tree(parse_tree, *, policy):
29992992 else :
30002993 # We can't fold it onto the next line either...
30012994 lines [- 1 ] += tstr
3002- last_word_is_ew = _last_word_is_sill_ew ( last_word_is_ew , tstr )
2995+ last_word_is_ew = last_word_is_ew and not bool ( tstr . strip ( _WSP ) )
30032996
30042997 return policy .linesep .join (lines ) + policy .linesep
30052998
0 commit comments