From aba98083e081411dac595976468ff90b7a31ec32 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Sun, 29 Jun 2025 14:30:02 +0200 Subject: [PATCH 1/2] Do not generate empty encoded-words Fixes #136052. --- Lib/email/_header_value_parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 = '' From 65f60fdd1cd7eb45ca8058c95cd639e2fa315f56 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Sun, 29 Jun 2025 15:26:04 +0200 Subject: [PATCH 2/2] Add NEWS --- .../next/Library/2025-06-29-15-25-56.gh-issue-136052.P1HgAD.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-06-29-15-25-56.gh-issue-136052.P1HgAD.rst 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.