cpython/Lib/test/test_email
Petr Viktorin 4766d1200f
[3.12] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122599)
* gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233)

- Encode header parts that contain newlines

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.

- Verify that email headers are well-formed

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

Co-authored-by: Bas Bloemsaat <bas@bloemsaat.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 0976339818)

* Document changes as made in 3.12.5
2024-08-06 19:07:19 +02:00
..
data [3.12] gh-106186: Don't report MultipartInvariantViolationDefect for valid multipart emails when parsing header only (GH-107016) (#107111) 2023-07-23 14:28:28 +02:00
__init__.py bpo-43651: PEP 597: Fix test_email (GH-25158) 2021-04-05 12:30:12 +09:00
__main__.py
test__encoded_words.py bpo-43323: Fix UnicodeEncodeError in the email module (GH-32137) 2022-04-30 13:17:23 +03:00
test__header_value_parser.py [3.12] gh-118643: Fix AttributeError in the email module (GH-119099) (GH-119390) 2024-05-22 14:08:05 +03:00
test_asian_codecs.py
test_contentmanager.py bpo-41402: Fix email ContentManager calling .encode() on bytes (GH-21631) 2021-08-09 18:45:41 +02:00
test_defect_handling.py bpo-27397: Make email module properly handle invalid-length base64 strings (#7583) 2018-06-12 15:46:22 +03:00
test_email.py [3.12] gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994) (GH-117998) 2024-04-17 16:59:35 +00:00
test_generator.py [3.12] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122599) 2024-08-06 19:07:19 +02:00
test_headerregistry.py [3.12] gh-92081: Fix for email.generator.Generator with whitespace between encoded words. (GH-92281) (#119246) 2024-05-20 20:10:49 +00:00
test_inversion.py bpo-30681: Support invalid date format or value in email Date header (GH-22090) 2020-10-26 17:31:06 -07:00
test_message.py [3.12] gh-94606: Fix error when message with Unicode surrogate not surrogateescaped string (GH-94641) (GH-112971) 2023-12-11 16:48:06 +00:00
test_parser.py #20476: add a message_factory policy attribute to email. 2016-09-09 18:39:18 -04:00
test_pickleable.py
test_policy.py [3.12] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122599) 2024-08-06 19:07:19 +02:00
test_utils.py [3.12] gh-113027: Fix test_variable_tzname in test_email (GH-113821) (GH-113831) 2024-01-12 12:00:17 +00:00
torture_test.py bpo-5846: Do not use obsolete unittest functions. (GH-28303) 2021-09-13 10:49:53 +03:00