cpython/Lib/email
Toshio Kuratomi a6fdb31b67
gh-92081: Fix for email.generator.Generator with whitespace between encoded words. (#92281)
* Fix for email.generator.Generator with whitespace between encoded words.

email.generator.Generator currently does not handle whitespace between
encoded words correctly when the encoded words span multiple lines.  The
current generator will create an encoded word for each line.  If the end
of the line happens to correspond with the end real word in the
plaintext, the generator will place an unencoded space at the start of
the subsequent lines to represent the whitespace between the plaintext
words.

A compliant decoder will strip all the whitespace from between two
encoded words which leads to missing spaces in the round-tripped
output.

The fix for this is to make sure that whitespace between two encoded
words ends up inside of one or the other of the encoded words.  This
fix places the space inside of the second encoded word.

A second problem happens with continuation lines.  A continuation line that
starts with whitespace and is followed by a non-encoded word is fine because
the newline between such continuation lines is defined as condensing to
a single space character.  When the continuation line starts with whitespace
followed by an encoded word, however, the RFCs specify that the word is run
together with the encoded word on the previous line.  This is because normal
words are filded on syntactic breaks by encoded words are not.

The solution to this is to add the whitespace to the start of the encoded word
on the continuation line.

Test cases are from #92081

* Rename a variable so it's not confused with the final variable.
2024-05-20 19:10:47 +00:00
..
mime
__init__.py
_encoded_words.py
_header_value_parser.py gh-92081: Fix for email.generator.Generator with whitespace between encoded words. (#92281) 2024-05-20 19:10:47 +00:00
_parseaddr.py gh-109653: Improve import time of importlib.metadata / email.utils (#114664) 2024-01-29 01:30:22 -08:00
_policybase.py gh-118455: Fix mangle_from_ default value in email.policy.Policy.__doc__ (#118456) 2024-05-05 09:18:04 +03:00
architecture.rst
base64mime.py
charset.py
contentmanager.py
encoders.py
errors.py
feedparser.py
generator.py gh-76511: Fix email.Message.as_string() for non-ASCII message with ASCII charset (GH-116125) 2024-03-05 17:49:01 +02:00
header.py
headerregistry.py
iterators.py
message.py gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994) 2024-04-17 19:31:26 +03:00
parser.py
policy.py gh-117313: Fix re-folding email messages containing non-standard line separators (GH-117369) 2024-04-17 13:00:25 +03:00
quoprimime.py
utils.py gh-118798: Remove deprecated isdst parameter from `email.utils.localtime` (#118799) 2024-05-09 03:17:02 -06:00