Fix email header folding exceeding max_line_length on continuation lines#3
Fix email header folding exceeding max_line_length on continuation lines#3JavaZeroo wants to merge 1 commit into
Conversation
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
There was a problem hiding this comment.
💡 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".
| remaining_space = maxlen - len(lines[-1]) | ||
| text_space = remaining_space - chrome_len | ||
| if text_space <= 0: | ||
| lines.append(' ') |
There was a problem hiding this comment.
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 👍 / 👎.
Summary:
_fold_as_ew()exceedingmax_line_lengthwhen an encoded word starts a continuation line whose leading whitespace is itself encoded: the leading-whitespace encoded word was appended to the line butremaining_space/text_spacewere not updated, so the next encoded word was sized against a stale budget and overflowed.Tests:
./python -m unittest test.test_email.test__header_value_parser.TestFolding.test_long_ew_after_encoded_continuation_whitespace./python -m unittest test.test_emailGenerated by Claude Code