[3.9] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233...
authorŁukasz Langa <lukasz@langa.pl>
Wed, 4 Sep 2024 15:39:02 +0000 (17:39 +0200)
committerSean Whitton <spwhitton@spwhitton.name>
Thu, 20 Mar 2025 02:07:39 +0000 (10:07 +0800)
commitbdbe3b1e86be5960313b84504fd8e4ecb9b914d9
tree8a9247cab9133db0632ea156bd59997993e5a518
parent8bbdd31d6f196bb421313477f4d37ba012436be9
[3.9] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122610)

Per RFC 2047:

> [...] these encoding schemes allow the
> encoding of arbitrary octet values, mail readers that implement this
> decoding should also ensure that display of the decoded data on the
> recipient's terminal will not cause unwanted side-effects

It seems that the "quoted-word" scheme is a valid way to include
a newline character in a header value, just like we already allow
undecodable bytes or control characters.
They do need to be properly quoted when serialized to text, though.

This should fail for custom fold() implementations that aren't careful
about newlines.

(cherry picked from commit 097633981879b3c9de9a1dd120d3aa585ecc2384)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Bas Bloemsaat <bas@bloemsaat.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Gbp-Pq: Name 0023-3.9-gh-121650-Encode-newlines-in-headers-and-verify-.patch
Doc/library/email.errors.rst
Doc/library/email.policy.rst
Lib/email/_header_value_parser.py
Lib/email/_policybase.py
Lib/email/errors.py
Lib/email/generator.py
Lib/test/test_email/test_generator.py
Lib/test/test_email/test_policy.py