cpython/Lib/email
Miss Islington (bot) ad3bbb6b0d
[3.13] gh-98188: Fix EmailMessage.get_payload to decode data when CTE value has extra text (GH-127547) (#128528)
gh-98188: Fix EmailMessage.get_payload to decode data when CTE value has extra text (GH-127547)

Up to this point message handling has been very strict with regards to content encoding values: mixed case was accepted, but trailing blanks or other text would cause decoding failure, even if the first token was a valid encoding.  By Postel's Rule we should go ahead and decode as long as we can recognize that first token.  We have not thought of any security or backward compatibility concerns with this fix.

This fix does introduce a new technique/pattern to the Message code: we look to see if the header has a 'cte' attribute, and if so we use that.  This effectively promotes the header API exposed by HeaderRegistry to an API that any header parser "should" support.  This seems like a reasonable thing to do.  It is not, however, a requirement, as the string value of the header is still used if there is no cte attribute.

The full fix (ignore any trailing blanks or blank-separated trailing text) applies only to the non-compat32 API.  compat32 is only fixed to the extent that it now ignores trailing spaces.  Note that the HeaderRegistry parsing still records a HeaderDefect if there is extra text.

(cherry picked from commit a62ba52f14)

Co-authored-by: RanKKI <hliu86.me@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-01-07 12:43:04 -05:00
..
mime gh-102542 Remove unused bytes object and bytes slicing (#106433) 2023-07-05 09:17:37 -07:00
__init__.py
_encoded_words.py
_header_value_parser.py [3.13] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122484) 2024-08-06 19:06:41 +02:00
_parseaddr.py gh-109653: Improve import time of importlib.metadata / email.utils (#114664) 2024-01-29 01:30:22 -08:00
_policybase.py [3.13] gh-124452: Fix header mismatches when folding/unfolding with email message (GH-125919) (#126917) 2024-11-17 15:06:18 -05:00
architecture.rst
base64mime.py
charset.py
contentmanager.py
encoders.py
errors.py [3.13] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122484) 2024-08-06 19:06:41 +02:00
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 [3.13] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122484) 2024-08-06 19:06:41 +02:00
header.py
headerregistry.py
iterators.py
message.py [3.13] gh-98188: Fix EmailMessage.get_payload to decode data when CTE value has extra text (GH-127547) (#128528) 2025-01-07 12:43:04 -05:00
parser.py
policy.py [3.13] gh-124452: Fix header mismatches when folding/unfolding with email message (GH-125919) (#126917) 2024-11-17 15:06:18 -05:00
quoprimime.py
utils.py [3.13] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122012) 2024-07-19 09:13:08 +00:00