[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)
committerAdrian Bunk <bunk@debian.org>
Sun, 1 Dec 2024 12:12:57 +0000 (14:12 +0200)
commit25fd22489e1f7b33aed8d55c012f8191edaa6dee
tree064fa6c4c89393e6f134c332c24c9db7eb01da7a
parentce9b40a1525c6f963962888adba21f6e390d079a
[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