-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-135307: Fix email error when policy max_line_length is set to 0 or None #135367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
a210d49
e9de710
0a5f379
d0dc3c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1004,6 +1004,34 @@ 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_with_zero_max_line_length(self): | ||
pol = policy.default.clone(max_line_length=0) | ||
subj = "S" * 100 | ||
msg = EmailMessage(policy=pol) | ||
msg["From"] = "a@ex.com" | ||
msg["To"] = "b@ex.com" | ||
msg["Subject"] = subj | ||
|
||
raw = msg.as_bytes() | ||
self.assertNotIn(b"\r\n ", raw, "Found fold indicator; wrapping not disabled") | ||
|
||
parsed = message_from_bytes(raw, policy=policy.default) | ||
self.assertEqual(parsed["Subject"], subj) | ||
|
||
def test_no_wrapping_with_none_max_line_length(self): | ||
pol = policy.default.clone(max_line_length=None) | ||
subj = "S" * 100 | ||
body = "B" * 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should use some bigger number? Because word "unlimited" is present. Something like 10**7, for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary, here we just want to test if it will wrap the context to the default 78 characters. 0 / None is set it to no wrap mode. This is a similar fix logic as |
||
msg = EmailMessage(policy=pol) | ||
msg["From"] = "a@ex.com" | ||
msg["To"] = "b@ex.com" | ||
zangjiucheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
msg["Subject"] = subj | ||
msg.set_content(body) | ||
|
||
parsed = message_from_bytes(msg.as_bytes(), policy=policy.default) | ||
self.assertEqual(parsed["Subject"], subj) | ||
self.assertEqual(parsed.get_body().get_content().rstrip('\n'), body) | ||
|
||
def test_invalid_header_names(self): | ||
invalid_headers = [ | ||
('Invalid Header', 'contains space'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:mod:`email`: Ensure policy accepts unlimited line lengths by | ||
treating 0 or :const:`None` as :data:`sys.maxsize` | ||
zangjiucheng marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.