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 gh-102542 Remove unused bytes object and bytes slicing (#106433) 2023-07-05 09:17:37 -07:00
__init__.py gh-102507 Remove invisible pagebreak characters (#102531) 2023-03-08 13:58:14 +00:00
_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 gh-102507 Remove invisible pagebreak characters (#102531) 2023-03-08 13:58:14 +00:00
charset.py gh-102498 Clean up unused variables and imports in the email module (#102482) 2023-04-24 19:19:28 +00:00
contentmanager.py
encoders.py gh-102507 Remove invisible pagebreak characters (#102531) 2023-03-08 13:58:14 +00:00
errors.py
feedparser.py gh-106186: Don't report MultipartInvariantViolationDefect for valid multipart emails when parsing header only (#107016) 2023-07-23 12:25:18 +02:00
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 gh-102507 Remove invisible pagebreak characters (#102531) 2023-03-08 13:58:14 +00:00
headerregistry.py
iterators.py gh-102507 Remove invisible pagebreak characters (#102531) 2023-03-08 13:58:14 +00:00
message.py gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994) 2024-04-17 19:31:26 +03:00
parser.py gh-102507 Remove invisible pagebreak characters (#102531) 2023-03-08 13:58:14 +00:00
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