Skip to content

Commit 9a332f2

Browse files
[3.13] gh-120930: Remove extra blank occuring in wrapped encoded words in email headers (GH-121747) (GH-121963)
gh-120930: Remove extra blank occuring in wrapped encoded words in email headers (GH-121747) (cherry picked from commit cecacee) Co-authored-by: Matthieu Caneill <[email protected]>
1 parent e881145 commit 9a332f2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,7 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset,
29882988
excess = len(encoded_word) - remaining_space
29892989
lines[-1] += encoded_word
29902990
to_encode = to_encode[len(to_encode_word):]
2991+
leading_whitespace = ''
29912992

29922993
if to_encode:
29932994
lines.append(' ')

Lib/test/test_email/test_generator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ def test_defaults_handle_spaces_between_encoded_words_when_folded(self):
294294
g.flatten(msg)
295295
self.assertEqual(s.getvalue(), expected)
296296

297+
def test_defaults_handle_spaces_when_encoded_words_is_folded_in_middle(self):
298+
source = ('A very long long long long long long long long long long long long '
299+
'long long long long long long long long long long long súmmäry')
300+
expected = ('Subject: A very long long long long long long long long long long long long\n'
301+
' long long long long long long long long long long long =?utf-8?q?s=C3=BAmm?=\n'
302+
' =?utf-8?q?=C3=A4ry?=\n\n').encode('ascii')
303+
msg = EmailMessage()
304+
msg['Subject'] = source
305+
s = io.BytesIO()
306+
g = BytesGenerator(s)
307+
g.flatten(msg)
308+
self.assertEqual(s.getvalue(), expected)
309+
297310
def test_defaults_handle_spaces_at_start_of_subject(self):
298311
source = " Уведомление"
299312
expected = b"Subject: =?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtQ==?=\n\n"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a bug introduced by gh-92081 that added an incorrect extra
2+
blank to encoded words occurring in wrapped headers.

0 commit comments

Comments
 (0)