Skip to content

Fix email header folding exceeding max_line_length on continuation lines#3

Open
JavaZeroo wants to merge 1 commit into
mainfrom
fix/email-fold-line-length
Open

Fix email header folding exceeding max_line_length on continuation lines#3
JavaZeroo wants to merge 1 commit into
mainfrom
fix/email-fold-line-length

Conversation

@JavaZeroo

Copy link
Copy Markdown
Owner

Summary:

  • Fix _fold_as_ew() exceeding max_line_length when an encoded word starts a continuation line whose leading whitespace is itself encoded: the leading-whitespace encoded word was appended to the line but remaining_space/text_space were not updated, so the next encoded word was sized against a stale budget and overflowed.
  • Add a regression test for the leading-whitespace continuation overflow case.

Tests:

  • ./python -m unittest test.test_email.test__header_value_parser.TestFolding.test_long_ew_after_encoded_continuation_whitespace
  • ./python -m unittest test.test_email

Generated by Claude Code

When an encoded word starts a continuation line, _fold_as_ew() emits the
line's leading whitespace as its own encoded word but kept using the
remaining_space/text_space computed before that word was added.  The
following encoded word was therefore sized against a stale budget, so the
folded line could exceed max_line_length.  Recompute the available space
after appending the whitespace encoded word, and start a new line when
nothing else fits.

https://claude.ai/code/session_019aJ7pxZ6gNWzXmYT5obbvN

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c87341f64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3006 to +3009
remaining_space = maxlen - len(lines[-1])
text_space = remaining_space - chrome_len
if text_space <= 0:
lines.append(' ')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Start a new line when no character fits after the whitespace word

When the recomputed text_space is positive but too small for the encoded representation of the first character, the shrinking loop below reduces to_encode_word to '' and emits an invalid empty encoded-word. For example, folding the new regression input with max_line_length=28 now produces =?utf-8?q?_?==?utf-8?q??=. RFC 2047 requires nonempty encoded text; detect the empty candidate and move the actual word to a new continuation line instead.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants