Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

zangjiucheng
Copy link
Contributor

@zangjiucheng zangjiucheng commented Jun 10, 2025

@zangjiucheng zangjiucheng changed the title gh-135307: Support email unlimited line lengths when policy max_line_length is 0 or None gh-135307: Fix email error when policy max_line_length is set to 0 or None Jun 10, 2025
@ZeroIntensity ZeroIntensity added topic-email needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jun 10, 2025
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triage silliness

@zangjiucheng
Copy link
Contributor Author

Haha, nice catch lol

def test_no_wrapping_with_none_max_line_length(self):
pol = policy.default.clone(max_line_length=None)
subj = "S" * 100
body = "B" * 100
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@zangjiucheng zangjiucheng Jun 11, 2025

Choose a reason for hiding this comment

The 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 _refold_parse_tree so I mentioned 'unlimited' as there, but it actually takes sys.maxsize. Thanks for comment.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments. I'll review more on my laptop.

@zangjiucheng
Copy link
Contributor Author

@picnixz Thanks for your detailed review. I addressed all the issues you mentioned in the new commit.

@zangjiucheng zangjiucheng requested a review from picnixz June 19, 2025 14:50
lines = string.encode(charset).splitlines()
linesep = policy.linesep.encode('ascii')
def embedded_body(lines): return linesep.join(lines) + linesep
def normal_body(lines): return b'\n'.join(lines) + b'\n'
if cte is None:
# Use heuristics to decide on the "best" encoding.
if max((len(x) for x in lines), default=0) <= policy.max_line_length:
if max((len(x) for x in lines), default=0) <= maxlen:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use: max(map(len, lines), default=0), though I'm not sure which is the fastest and which is the most "readable".

@bitdancer What is the style you'd recommend in general in the email package? would you rather for readability, succintness, or performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my comment: we're not required to take the fastest route here, since we may not have a heavy load on the email module. Still wish to hear more comments before we resolve this :)

@zangjiucheng
Copy link
Contributor Author

Hi everyone, sorry to bother you. Is there any update on this PR?

@@ -142,22 +143,23 @@ def _encode_base64(data, max_line_length):


def _encode_text(string, charset, cte, policy):
# max_line_length 0/None means no limit, ie: infinitely long.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# max_line_length 0/None means no limit, ie: infinitely long.
# If max_line_length is 0 or None, there is no limit.

Comment on lines +1025 to +1026
self.assertNotIn(b"\r\n ", raw,
"Found fold indicator; wrapping not disabled")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we check on b"\r\n " not to be present?
Maybe it should be soft_break from quoprimime.body_encode, i.e. b"=\n"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy