mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.13] gh-135307: Fix email error when policy max_line_length is set to 0 or None (GH-135367) (#140917)
[3.13] gh-135307: Fix email error when policy max_line_length is set to 0 or None (GH-135367)
(cherry picked from commit 6d45cd8dbb)
Co-authored-by: Jiucheng(Oliver) <git.jiucheng@gmail.com>
RDM: Like the change made in a earlier PR to the folder, we can/must use 'maxlen' as a stand in for 'unlimited' when computing line lengths when max_line_length is 0 or None; otherwise the computation results in a traceback.
This commit is contained in:
parent
b8910fc444
commit
10af8404b4
3 changed files with 35 additions and 5 deletions
|
|
@ -1004,6 +1004,32 @@ def test_folding_with_long_nospace_http_policy_1(self):
|
|||
parsed_msg = message_from_bytes(m.as_bytes(), policy=policy.default)
|
||||
self.assertEqual(parsed_msg['Message-ID'], m['Message-ID'])
|
||||
|
||||
def test_no_wrapping_max_line_length(self):
|
||||
# Test that falsey 'max_line_length' are converted to sys.maxsize.
|
||||
for n in [0, None]:
|
||||
with self.subTest(max_line_length=n):
|
||||
self.do_test_no_wrapping_max_line_length(n)
|
||||
|
||||
def do_test_no_wrapping_max_line_length(self, falsey):
|
||||
self.assertFalse(falsey)
|
||||
pol = policy.default.clone(max_line_length=falsey)
|
||||
subj = "S" * 100
|
||||
body = "B" * 100
|
||||
msg = EmailMessage(policy=pol)
|
||||
msg["From"] = "a@ex.com"
|
||||
msg["To"] = "b@ex.com"
|
||||
msg["Subject"] = subj
|
||||
msg.set_content(body)
|
||||
|
||||
raw = msg.as_bytes()
|
||||
self.assertNotIn(b"=\n", raw,
|
||||
"Found fold indicator; wrapping not disabled")
|
||||
|
||||
parsed = message_from_bytes(raw, policy=policy.default)
|
||||
self.assertEqual(parsed["Subject"], subj)
|
||||
parsed_body = parsed.get_body().get_content().rstrip('\n')
|
||||
self.assertEqual(parsed_body, body)
|
||||
|
||||
def test_get_body_malformed(self):
|
||||
"""test for bpo-42892"""
|
||||
msg = textwrap.dedent("""\
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue