[3.12] gh-120930: Remove extra blank occuring in wrapped encoded words in email headers (GH-121747) (GH-121964)

gh-120930: Remove extra blank occuring in wrapped encoded words in email headers (GH-121747)
(cherry picked from commit cecaceea31)

Co-authored-by: Matthieu Caneill <matthieucan@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-07-19 19:22:07 +02:00 committed by GitHub
parent 3f72821f80
commit 8bd47132d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View file

@ -2988,6 +2988,7 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset,
excess = len(encoded_word) - remaining_space excess = len(encoded_word) - remaining_space
lines[-1] += encoded_word lines[-1] += encoded_word
to_encode = to_encode[len(to_encode_word):] to_encode = to_encode[len(to_encode_word):]
leading_whitespace = ''
if to_encode: if to_encode:
lines.append(' ') lines.append(' ')

View file

@ -294,6 +294,19 @@ class TestBytesGenerator(TestGeneratorBase, TestEmailBase):
g.flatten(msg) g.flatten(msg)
self.assertEqual(s.getvalue(), expected) self.assertEqual(s.getvalue(), expected)
def test_defaults_handle_spaces_when_encoded_words_is_folded_in_middle(self):
source = ('A very long long long long long long long long long long long long '
'long long long long long long long long long long long súmmäry')
expected = ('Subject: A very long long long long long long long long long long long long\n'
' long long long long long long long long long long long =?utf-8?q?s=C3=BAmm?=\n'
' =?utf-8?q?=C3=A4ry?=\n\n').encode('ascii')
msg = EmailMessage()
msg['Subject'] = source
s = io.BytesIO()
g = BytesGenerator(s)
g.flatten(msg)
self.assertEqual(s.getvalue(), expected)
def test_defaults_handle_spaces_at_start_of_subject(self): def test_defaults_handle_spaces_at_start_of_subject(self):
source = " Уведомление" source = " Уведомление"
expected = b"Subject: =?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtQ==?=\n\n" expected = b"Subject: =?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtQ==?=\n\n"

View file

@ -0,0 +1,2 @@
Fixed a bug introduced by gh-92081 that added an incorrect extra
blank to encoded words occurring in wrapped headers.