Fix Body#extract_parts leaving boundary's CRLF at head of raw_source - #1688
Open
hikmetba-bit wants to merge 1 commit into
Open
hikmetba-bit wants to merge 1 commit into
hikmetba-bit wants to merge 1 commit into
Conversation
RFC 2046's multipart delimiter is "dash-boundary transport-padding CRLF" -- the CRLF that terminates a boundary line belongs to the delimiter, not to the part content that follows it. extract_parts's regex only looks ahead at that trailing CRLF (via `(?=\s*$)`) without consuming it, so it was left dangling at the head of the next part's raw_source instead of the part's actual content starting there. This was invisible for most users because Mail::Part#initialize lstrips whitespace/CRLF from its input, so the parsed body ends up correct either way -- but raw_source itself was wrong, e.g. starting with "\r\nContent-Type: ..." instead of "Content-Type: ...". Strip that one delimiter-owned line break from each part's content after the first (the preamble, at index 0, is unaffected since nothing precedes it). Fixes mikel#1171. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1171.
RFC 2046's multipart delimiter is "dash-boundary transport-padding CRLF" — the CRLF that terminates a boundary line belongs to the delimiter itself, not to the part content that follows it.
Body#extract_parts's regex only looks ahead at that trailing CRLF (via(?=\s*$)) without consuming it, so it gets left dangling at the head of the next part'sraw_sourceinstead of that part's actual content starting there:This was invisible for most users because
Mail::Part#initializelstrips whitespace/CRLF from its input, so the parsed body ends up correct either way. Butraw_sourceitself is wrong, which matters for anyone who readsraw_sourcedirectly (my case, and the original reporter's).Fix
Strip that one delimiter-owned line break from each part's content after the first (the preamble at index 0 is unaffected, since nothing precedes it). Kept the existing lookahead-based split and blank-part/missing-closing-boundary logic untouched — just clean up the resulting part strings afterward, rather than restructuring the regex (which the existing
final_separator == "--#{boundary}--"exact-match check depends on).Testing
spec/mail/body_spec.rbasserting each part'sraw_sourcestarts at its actual content, not a leading\r\n.\r\n), and passes with it.multipart_report_multiple_status.eml) and confirmedraw_sourceis now clean for all parts.bundle exec rspec spec/— 1837 examples, 0 failures, 4 pending (all 4 pending pre-exist on unmodifiedmastertoo, unrelated to this change — address-list/date/sender-field edge cases).🤖 Generated with Claude Code