GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-143935: Email preserve parens when folding comments by sethmlarson · Pull Request #143936 · python/cpython

Conversation

@sethmlarson

@sethmlarson sethmlarson commented Jan 16, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

cc @beledouxdenis

  • Issue: Fix folding of long comments of unfoldable characters in email headers #143935

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@beledouxdenis @sethmlarson
email: correctly indent with a least one space folded comments
0b64fd5
@sethmlarson
sethmlarson requested a review from bitdancer January 16, 2026 20:41
@sethmlarson
sethmlarson requested a review from a team as a code owner January 16, 2026 20:41
@bedevere-app bedevere-app Bot added the awaiting review label Jan 16, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jan 16, 2026
Fix folding of long comments of unfoldable characters in email headers #143935
Closed
beledouxdenis added 4 commits January 16, 2026 14:45
@beledouxdenis @sethmlarson
email: use same strategy as quoted-string to fold comments
6142a37
- No forced space to indent,
- use almost the same code as the `bare-quoted-string`
block above, handle nested comments and escaped parenthesis
in addition
@beledouxdenis @sethmlarson
email: do not fold WhiteSpaceTerminal not starting with a WSP
7f05244
e.g. with a 40 characters length policy, the below
`((loremipsum)(loremipsum)(loremipsum)(loremipsum))<[email protected]>`

should not be folded to
`((loremipsum)(loremipsum)(loremipsum)\n(loremipsum))<[email protected]>`

but should rather stay
`((loremipsum)(loremipsum)(loremipsum)(loremipsum))<[email protected]>`

to prevent to add a new line not starting with a space / with no
indentation
@beledouxdenis @sethmlarson
email: test case for blank between nested comment
db74b26
To test a whitespace between two nested comments leads to a
new line with one space indentation on folding
@beledouxdenis @sethmlarson
email: add a blurb
8ad0fdb
@sethmlarson
sethmlarson force-pushed the email-preserve-parens-when-folding-comments branch from 3a9b2c7 to 8ad0fdb Compare January 16, 2026 20:45
@sethmlarson sethmlarson added type-security A security issue stdlib Standard Library Python modules in the Lib/ directory topic-email labels Jan 16, 2026
bitdancer
bitdancer approved these changes Jan 17, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jan 17, 2026
@Yhg1s Yhg1s added needs backport to 3.10 needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
@Yhg1s
Merge branch 'main' into email-preserve-parens-when-folding-comments
3d06334
@Yhg1s
Yhg1s enabled auto-merge (squash) January 19, 2026 12:15
@Yhg1s
Yhg1s merged commit 17d1490 into python:main Jan 19, 2026
50 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 19, 2026
@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11, 3.12, 3.13, 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
@sethmlarson @beledouxdenis @miss-islington
pythongh-143935: Email preserve parens when folding comments (pythonG…
cc68a68
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
@sethmlarson @beledouxdenis @miss-islington
pythongh-143935: Email preserve parens when folding comments (pythonG…
59cf569
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
@bedevere-app

bedevere-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

GH-144034 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jan 19, 2026
@sethmlarson sethmlarson added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Thanks @sethmlarson for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
@sethmlarson @beledouxdenis @miss-islington
pythongh-143935: Email preserve parens when folding comments (pythonG…
3900a2c
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
@sethmlarson sethmlarson removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jan 19, 2026
@sethmlarson
sethmlarson deleted the email-preserve-parens-when-folding-comments branch January 19, 2026 16:55
@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.12" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.12
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
@sethmlarson @beledouxdenis @miss-islington
pythongh-143935: Email preserve parens when folding comments (pythonG…
df45bd1
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.14" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
@sethmlarson @beledouxdenis @miss-islington
pythongh-143935: Email preserve parens when folding comments (pythonG…
636f0b6
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.13" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2026
@sethmlarson @beledouxdenis @miss-islington
pythongh-143935: Email preserve parens when folding comments (pythonG…
dfaeb01
…H-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Jan 19, 2026

Copy link
Copy Markdown

Sorry @sethmlarson and @Yhg1s, I had trouble completing the backport.
Please retry by removing and re-adding the "needs backport to 3.11" label.
Please backport backport using cherry_picker on the command line.

cherry_picker 17d1490aa97bd6b98a42b1a9b324ead84e7fd8a2 3.11
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal pushed a commit that referenced this pull request Jan 25, 2026
@miss-islington @sethmlarson @beledouxdenis
[3.13] gh-143935: Email preserve parens when folding comments (GH-143936
f738386
) (#144035)

gh-143935: Email preserve parens when folding comments (GH-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
pablogsal pushed a commit that referenced this pull request Jan 25, 2026
@miss-islington @sethmlarson @beledouxdenis
[3.11] gh-143935: Email preserve parens when folding comments (GH-143936
e9970f0
) (#144037)

gh-143935: Email preserve parens when folding comments (GH-143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
pablogsal pushed a commit that referenced this pull request Jan 25, 2026
@miss-islington @sethmlarson @beledouxdenis
[3.14] gh-143935: Email preserve parens when folding comments (GH-143936
61614a5
) (#144034)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
pablogsal pushed a commit that referenced this pull request Jan 26, 2026
@miss-islington @sethmlarson @beledouxdenis
[3.12] gh-143935: Email preserve parens when folding comments (GH-143936
a76e4cd
) (#144036)

Co-authored-by: Seth Michael Larson <[email protected]>
Co-authored-by: Denis Ledoux <[email protected]>
@bedevere-app

bedevere-app Bot commented Jan 30, 2026

Copy link
Copy Markdown

GH-144350 is a backport of this pull request to the 3.10 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.10 label Jan 30, 2026
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@sethmlarson @beledouxdenis @thunder-coding
pythongh-143935: Email preserve parens when folding comments (python#…
6fd6bbc
…143936)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.

Co-authored-by: Denis Ledoux <[email protected]>
pablogsal pushed a commit that referenced this pull request Mar 2, 2026
@edgarrmondragon @sethmlarson
[3.10] gh-143935: Email preserve parens when folding comments (GH-143936
003b831
) (#144350)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson [email protected]
Co-authored-by: Denis Ledoux [email protected]

- Issue: Fix folding of long comments of unfoldable characters in email headers #143935

Signed-off-by: Edgar Ramírez Mondragón <[email protected]>
Co-authored-by: Seth Michael Larson <[email protected]>
icanhasmath pushed a commit to ActiveState/cpython that referenced this pull request Oct 28, 2026
@edgarrmondragon @sethmlarson @icanhasmath
[3.10] pythongh-143935: Email preserve parens when folding comments (p…
dd0809a
…ythonGH-143936) (python#144350)

Fix a bug in the folding of comments when flattening an email message
using a modern email policy. Comments consisting of a very long sequence of
non-foldable characters could trigger a forced line wrap that omitted the
required leading space on the continuation line, causing the remainder of
the comment to be interpreted as a new header field. This enabled header
injection with carefully crafted inputs.
(cherry picked from commit 17d1490)

Co-authored-by: Seth Michael Larson [email protected]
Co-authored-by: Denis Ledoux [email protected]

- Issue: Fix folding of long comments of unfoldable characters in email headers python#143935

Signed-off-by: Edgar Ramírez Mondragón <[email protected]>
Co-authored-by: Seth Michael Larson <[email protected]>
(cherry picked from commit 003b831)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bitdancer bitdancer bitdancer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Yhg1s Yhg1s

Labels

stdlib Standard Library Python modules in the Lib/ directory topic-email type-security A security issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@sethmlarson @bitdancer @Yhg1s @beledouxdenis
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.