diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 91243378dc0441..90b7f82efd2093 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -3011,7 +3011,10 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset, to_encode_word = to_encode_word[:-1] encoded_word = _ew.encode(to_encode_word, charset=encode_as) excess = len(encoded_word) - remaining_space - lines[-1] += encoded_word + # If encoding a single character pushes this line over the limit, + # give up on it and go to the next line. + if to_encode_word != "": + lines[-1] += encoded_word to_encode = to_encode[len(to_encode_word):] leading_whitespace = '' diff --git a/Misc/NEWS.d/next/Library/2025-06-29-15-25-56.gh-issue-136052.P1HgAD.rst b/Misc/NEWS.d/next/Library/2025-06-29-15-25-56.gh-issue-136052.P1HgAD.rst new file mode 100644 index 00000000000000..5b4a46143e3d94 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-06-29-15-25-56.gh-issue-136052.P1HgAD.rst @@ -0,0 +1 @@ +Do not create empty MIME encoded-words when preparing e-mail headers.