You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(gmail): preserve every mixed MIME body section - #50413
Gmail text extraction globally prefers any plain part, dropping independent HTML-only sections from multipart/mixed messages.
What Changed
Choose one representation per alternative, preserve mixed sections in order, and select only the designated multipart/related root so CID resources cannot displace a preferred plain body.
Before: The second mixed body section is lost. Related resources can incorrectly participate in body text selection.
After: Both base-failing MIME regressions pass: exact First section / Second section order, preferred plain alternative preserved, related root respected and attachments excluded.
Why
The fix belongs at the existing production boundary: Gmail read/search message conversion uses bodyText from the actual Gmail message payload parser.
It corrects the reproduced failure without adding a parallel implementation.
N/A — internal parsing/protocol/lifecycle change with no layout or interaction implementation changes. The production-input before/after is recorded above.
Testing
Follow-up verification
Follow-up commit 721ed8a builds on f95c675 and retains both of its regression additions. It handles spaced and folded start parameters, preserves quoted content, excludes ordinary unnamed attachments, and keeps the selected multipart/related root visible even when its disposition says attachment. Related-root selection takes precedence over that disposition, as specified in RFC 2387 section 4.
The identical final regression suite gives 1 pass / 1 failure on f95c675, then 2 passes on this follow-up. Separate production probes confirm that the earlier head loses both the folded-header body and the attachment-labelled related root. Existing plain/HTML alternatives, quoted parameter decoys, inline content and ordinary attachments remain covered.
Header normalization consumes quoted spans and whitespace runs once and collapses only unquoted whitespace. Both 200 KB malformed-header probes complete normally; quoted values remain unchanged. Targeted formatting and lint pass. The combined working tree passed 29 test files / 44 tests, the Node project typecheck (16,956 files), and the changed-code quality component across 71 files. The final combined Gmail regression and Node check also pass after integrating the concurrent branch update. The required full changed gate was attempted after the final edits and still stops at the package-bootstrap IPC restriction described below.
Production-code reproduction exercised locally.
Focused regression added for the reproduced invariant.
Every added regression fails against the unchanged source and passes with this change.
Reproduction: Read a mixed body with First section in a plain alternative and Second section in a separate HTML part. Also test a related HTML representation containing a plain-text CID resource and an explicit start root.
Linux x64, Node 24.22.3, pinned repository Vitest 5.1.0. Targeted oxfmt and oxlint passed. The actual repository runner was used after building process-host with Node's supported tsx loader:
Use a writable TMPDIR. Required pnpm check:changed --base=d9348ff5290fb7dd3f92f16d09b62119c24953be was attempted after final edits; package bootstrap is blocked by the environment's tsx IPC listener restriction (listen EPERM). Full lint/typecheck/build and native macOS/Windows/real SSH application runs are not claimed.
Performance
Select leaves before decoding so unused representations are not converted. Traversal follows the existing MIME tree; no extra API requests.
Risk
Level: Low. MIME alternatives and related resources are handled within their own containers. Standard Node MIMEType parses quoted start parameters. Attachment extraction and Gmail API access remain unchanged. A plain revert restores the previous behavior; no data migration is introduced.
AI Disclosure
Contribution owner: @Afloat16. GPT-6 Astra Pro was used for implementation and regression analysis.
Review
Reviewed the live caller, failure boundary, compatibility and performance. Existing local/remote transport and provider contracts are retained. Cross-platform behavior is reasoned from the shared code; only the Linux reproduction above was executed. No credentials, new network destinations or permission changes are introduced.
Agent skill upstream boundary
Not applicable; no upstream skill-installer content is copied.
Notes
Security, saved-data behavior, cross-platform support, SSH/remote, mobile compatibility and performance were considered within this change's scope. Validation limits are listed above.
Checklist
This PR is small and focused.
User-facing before/after, mechanism and motivation are explained.
Risk and revert behavior are stated.
Visual proof is N/A with its reason above.
Self-reviewed for correctness, security and performance.
Cross-platform and SSH/remote impact considered.
Full lint/typecheck/test/build gate; targeted checks passed, full hosted CI remains to run.
bodyText now selects Gmail message body parts according to MIME structure. It excludes parts with filenames or attachment dispositions, selects the root of multipart/related using the start parameter when possible, and prefers the last plain-text child in multipart/alternative. It joins selected body sections in order, converts selected HTML to text, and trims the result. Tests cover mixed sections, alternatives, related roots, and attachments.
Severity of issue fixed: Medium
Merge Risk: Low · up to 721ed
Gmail messages whose Content-Type header contains a MIME comment and whose first related part is an image could show an empty body. This is rare, and the rest of the MIME body selection fix looks sound. It can be merged with awareness of this edge case or fixed in a follow-up.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(gmail): preserve every mixed MIME body section" is specific and matches the main change: the Gmail bodyText extraction now keeps every independent section of a multipart/mixed message. …
Linked Issues check
Issue #50412 requires three coding behaviors in Gmail bodyText: (1) keep independent multipart/mixed sections in order, (2) prefer the plain alternative within each multipart/alternative, and (3…
Out of Scope Changes check
All changed code sits on the Gmail message conversion path named in #50412. The attachment-disposition exclusion in select supports the issue requirement that attachments are excluded. The Content-T…
Description check
The description follows the repository template and covers ELI5, What Changed, Why, Linked Issue (Fixes #50412), Visual Proof (N/A with reason), Testing, Performance, Risk (Level: Low, with revert pat…
Full details: Title check
Explanation
The title "fix(gmail): preserve every mixed MIME body section" is specific and matches the main change: the Gmail bodyText extraction now keeps every independent section of a multipart/mixed message. It also names the affected area (gmail) and uses conventional commit form. The title does not mention the related-root or attachment handling, but it does not need to cover every detail.
Full details: Linked Issues check
Explanation
Issue #50412 requires three coding behaviors in Gmail bodyText: (1) keep independent multipart/mixed sections in order, (2) prefer the plain alternative within each multipart/alternative, and (3) use only the designated multipart/related root so CID resources do not affect body selection, with attachments excluded. At head 721ed8a, src/main/google/google-gmail-message.ts implements these. select returns text leaves, skips nodes with filename or a Content-Disposition: attachment header (case-insensitive, with the root of multipart/related exempt from the disposition check), and joins mixed children in order via children.flat(). For multipart/alternative, it picks the last child containing text/plain, otherwise the last nonempty child. For multipart/related, it selects the root by the start Content-ID, or parts[0] when no start is given. The head code normalizes whitespace around = in Content-Type while preserving quoted values, then parses start with MIMEType. src/main/google/google-gmail-message.test.ts at head covers: nested alternatives with exact 'First section\nSecond section' output and attachment exclusion (including filename: '' parts marked ATTACHMENT); a plain alternative beating a related HTML root; start="<body>" selecting the HTML root over a plain CID resource; spaced and folded start parameters with quoted decoys; and a related root with attachment disposition. Limits: the incremental diff from f95c675 or ce76d32 to 721ed8a could not be read (changed blobs unavailable), so changes since the previous review were verified from the head blobs only. The tests were not executed in this review; their pass status rests on the source and the PR description.
Full details: Out of Scope Changes check
Explanation
All changed code sits on the Gmail message conversion path named in #50412. The attachment-disposition exclusion in select supports the issue requirement that attachments are excluded. The Content-Type start normalization and related-root selection support the requirement that only the designated related root is used. attachmentsOf, findPart, header, and the schemas keep their purpose and do not change Gmail API access. The test file contains only the helper and regressions for the reported behavior. No unrelated change was found. Limits: the incremental diff since the previous reviewed heads could not be read, so this verdict rests on the head blobs and the PR description.
Full details: Description check
Explanation
The description follows the repository template and covers ELI5, What Changed, Why, Linked Issue (Fixes #50412), Visual Proof (N/A with reason), Testing, Performance, Risk (Level: Low, with revert path), AI Disclosure, Review, the upstream boundary checkbox, and Checklist. The Testing section gives concrete reproduction steps, commands, and environment (Linux x64, Node 24.22.3, Vitest 5.1.0), and states which validations were not run. Gaps: the ELI5 contains jargon (multipart/mixed, CID) and the 'Before/After' lines reference 'base-failing' regressions without explaining them. The 'Why' section does not compare alternatives considered, as the template asks. The Visual Proof section states that the production-input before/after is 'recorded above', but no before/after output is shown in a switchable form. The Performance section is one line, which is acceptable. The unchecked final checklist item is explained in the body. Overall the description is mostly complete, so it passes, with minor improvements suggested.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: bf07ca58-dc92-4a67-9924-67ccd451abed
Commits
Reviewing files that changed from the base of the PR and between 032bf8b and ce76d32.
Files selected for processing: 2
src/main/google/google-gmail-message.test.ts
src/main/google/google-gmail-message.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Normalize unquoted whitespace around parameter = before MIMEType parsing, preserving quoted values. The related-root regression includes start = with tabs/spaces, an image first, and another quoted value containing =.
Exclude explicit Content-Disposition: attachment parts case-insensitively even when their filename is empty. The mixed-body regression now exercises that case.
Validation: the two Gmail tests passed with Vitest 5.1.0 against the actual source files and fail against the previous PR head with these expanded assertions. Full repository validation still needs CI; this was a targeted source-snapshot run.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: e60464c4-7c57-4837-90ff-8054d52cf723
Commits
Reviewing files that changed from the base of the PR and between f95c675 and 721ed8a.
Files selected for processing: 2
src/main/google/google-gmail-message.test.ts
src/main/google/google-gmail-message.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Handle MIME comments before parsing the related root.
For Content-Type: multipart/related (body); type="text/html"; start="<body>", the normalization retains (body). This is valid mail header syntax, but Node 24's MIMEType rejects the commented subtype. The catch then selects the first child. If that child is an image, the HTML root disappears from the returned body. (rfc-editor.org)
Parse or remove MIME comments outside quoted values before extracting start. Preserve quoted values. Add an image-first regression for this header form.
Thanks for the PR. After two review rounds we're closing it because of a regression in a common shape. Many senders, including Python's default MIMEMultipart() used by lots of cron and notification mail, put text/plain and text/html side by side directly under multipart/mixed. With this change their text shows twice. A fix for #50412 that treats plain and HTML siblings with the same content as alternatives, and only adds HTML-only sections that have no plain counterpart, would be welcome.
Thanks for the concrete example. The follow-up is #50497: equivalent adjacent plain/HTML siblings now produce one body, while independent HTML, explicit multipart groups and nonadjacent A/B/A sections remain in order. It also addresses the remaining MIME-comment review and retains named related roots.
The exact final commit 154bf4f passed all 28 required changed-file checks, with five parser regressions passing and all five failing against the unchanged main implementation. The PR includes the validation run and the narrower pairing rule for review.
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
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.
ELI5
Gmail text extraction globally prefers any plain part, dropping independent HTML-only sections from multipart/mixed messages.
What Changed
Choose one representation per alternative, preserve mixed sections in order, and select only the designated multipart/related root so CID resources cannot displace a preferred plain body.
Before: The second mixed body section is lost. Related resources can incorrectly participate in body text selection.
After: Both base-failing MIME regressions pass: exact First section / Second section order, preferred plain alternative preserved, related root respected and attachments excluded.
Why
The fix belongs at the existing production boundary: Gmail read/search message conversion uses bodyText from the actual Gmail message payload parser.
It corrects the reproduced failure without adding a parallel implementation.
Linked Issue
Fixes #50412
Visual Proof
N/A — internal parsing/protocol/lifecycle change with no layout or interaction implementation changes. The production-input before/after is recorded above.
Testing
Follow-up verification
Follow-up commit
721ed8abuilds onf95c675and retains both of its regression additions. It handles spaced and foldedstartparameters, preserves quoted content, excludes ordinary unnamed attachments, and keeps the selectedmultipart/relatedroot visible even when its disposition says attachment. Related-root selection takes precedence over that disposition, as specified in RFC 2387 section 4.The identical final regression suite gives 1 pass / 1 failure on
f95c675, then 2 passes on this follow-up. Separate production probes confirm that the earlier head loses both the folded-header body and the attachment-labelled related root. Existing plain/HTML alternatives, quoted parameter decoys, inline content and ordinary attachments remain covered.Header normalization consumes quoted spans and whitespace runs once and collapses only unquoted whitespace. Both 200 KB malformed-header probes complete normally; quoted values remain unchanged. Targeted formatting and lint pass. The combined working tree passed 29 test files / 44 tests, the Node project typecheck (16,956 files), and the changed-code quality component across 71 files. The final combined Gmail regression and Node check also pass after integrating the concurrent branch update. The required full changed gate was attempted after the final edits and still stops at the package-bootstrap IPC restriction described below.
Reproduction: Read a mixed body with First section in a plain alternative and Second section in a separate HTML part. Also test a related HTML representation containing a plain-text CID resource and an explicit start root.
Linux x64, Node 24.22.3, pinned repository Vitest 5.1.0. Targeted oxfmt and oxlint passed. The actual repository runner was used after building process-host with Node's supported tsx loader:
Use a writable TMPDIR. Required
pnpm check:changed --base=d9348ff5290fb7dd3f92f16d09b62119c24953bewas attempted after final edits; package bootstrap is blocked by the environment's tsx IPC listener restriction (listen EPERM). Full lint/typecheck/build and native macOS/Windows/real SSH application runs are not claimed.Performance
Select leaves before decoding so unused representations are not converted. Traversal follows the existing MIME tree; no extra API requests.
Risk
Level: Low. MIME alternatives and related resources are handled within their own containers. Standard Node MIMEType parses quoted start parameters. Attachment extraction and Gmail API access remain unchanged. A plain revert restores the previous behavior; no data migration is introduced.
AI Disclosure
Contribution owner: @Afloat16. GPT-6 Astra Pro was used for implementation and regression analysis.
Review
Reviewed the live caller, failure boundary, compatibility and performance. Existing local/remote transport and provider contracts are retained. Cross-platform behavior is reasoned from the shared code; only the Linux reproduction above was executed. No credentials, new network destinations or permission changes are introduced.
Agent skill upstream boundary
Notes
Security, saved-data behavior, cross-platform support, SSH/remote, mobile compatibility and performance were considered within this change's scope. Validation limits are listed above.
Checklist