https://github.com/python/cpython/commit/9a332f260d188fa3fa0502940098e326c1e8aa5e
commit: 9a332f260d188fa3fa0502940098e326c1e8aa5e
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2024-07-19T19:21:53+02:00
summary:

[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 cecaceea31f32f01b5617989e3dc8b2077f53f89)

Co-authored-by: Matthieu Caneill <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst
M Lib/email/_header_value_parser.py
M Lib/test/test_email/test_generator.py

diff --git a/Lib/email/_header_value_parser.py 
b/Lib/email/_header_value_parser.py
index ab3c3031ef590c..7da1bbaf8a80d7 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -2988,6 +2988,7 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, 
ew_combine_allowed, charset,
             excess = len(encoded_word) - remaining_space
         lines[-1] += encoded_word
         to_encode = to_encode[len(to_encode_word):]
+        leading_whitespace = ''
 
         if to_encode:
             lines.append(' ')
diff --git a/Lib/test/test_email/test_generator.py 
b/Lib/test/test_email/test_generator.py
index bfff1051262079..bc6f734d4fd0a9 100644
--- a/Lib/test/test_email/test_generator.py
+++ b/Lib/test/test_email/test_generator.py
@@ -294,6 +294,19 @@ def 
test_defaults_handle_spaces_between_encoded_words_when_folded(self):
         g.flatten(msg)
         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):
         source = " Уведомление"
         expected = b"Subject:  
=?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtQ==?=\n\n"
diff --git 
a/Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst 
b/Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst
new file mode 100644
index 00000000000000..9e11595cdb50b8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst
@@ -0,0 +1,2 @@
+Fixed a bug introduced by gh-92081 that added an incorrect extra
+blank to encoded words occurring in wrapped headers.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to