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 mixed sections without repeating equivalent bodies - #50497
Select representations within each multipart/alternative and the designated root within each multipart/related, preserving independent mixed sections in their original order.
In a multipart/mixed container, pair adjacent plain/HTML representations from direct text parts or a related container whose selected root is itself a text part. Both eligible neighboring plain bodies are checked for normalized equality first, retaining the exact plain body. When neither side is equal and HTML contains the complete plain body at word boundaries, retain the richer HTML representation, including its header, navigation and footer. Each plain body can match only one HTML body. Attachments do not count as visible sections; explicit nested groups and empty multipart boundaries remain independent.
Preserve the related root when a valid Content-Type contains folding whitespace, nested/escaped comments or quoted parameter text. Match Content-ID after removing comments without changing identifier case or literal parentheses within quoted identifiers and bracketed domains; malformed or unmatched references recover the implicit first root.
Within alternatives, skip representations whose body data is only available through an attachment ID. A readable empty body remains a valid representation.
Keep ordinary filename and attachment-disposition exclusions, including leading/nested/escaped disposition comments. If a malformed trailing comment cannot be normalized, retain an already recognizable attachment prefix. An explicitly selected related root remains the body even when it has a filename or attachment disposition.
The change is limited to the Gmail payload parser and its regression tests. It adds no package or settings.
Why
The current global plain-text preference loses independent HTML-only sections. The earlier fix preserved those sections but repeated the common Python MIMEMultipart() plain/HTML sibling form. Matching adjacent equivalent sibling representations addresses that review without globally deduplicating message text or dropping separately grouped sections.
N/A — this changes Gmail tool-result text extraction, with no UI or interaction changes. The tests assert the exact returned text before and after the parser change.
Testing
Latest exact-match priority follow-up
Validated head: 8e3909fc4e588e43803e97df0f767edeed028314, tree 041fa9fb046ddab54f0cd57c285249c1302b12a4. Both eligible neighboring plain bodies are checked for normalized equality before either can be paired by containment. This preserves an independent Status section beside HTML Status update and its exact plain representation.
The expanded production-parser regression covers both neighbor orders, direct HTML and a selected related text root, and normalized whitespace while retaining the original plain text. Existing richer-template, repeated-section, Unicode and linear-matching cases remain covered.
Restoring only the preceding published 0dcfb925 parser makes the new exact-priority assertions fail (1 failed / 13 passed). The control requires an assertion failure, then restores this head and verifies a clean diff.
Independent review confirmed one-to-one adjacent pairing and linear work remain intact. Each HTML part considers at most two neighboring plain bodies; exact matching takes priority over containment.
Earlier MIME and representation validation
Validated commit 0dcfb92508c7c499564f580a524d815a7eef66de, tree 57cb03ae5d37471381bca883fab0606f230a4880, based on main 251e9b0558be785f206aece6368a17b72e15c3b5.
Exact-source validation checked out this Orca commit and used its unchanged toolchain/configuration:
timeout 900 pnpm check:changed --base=251e9b0558be785f206aece6368a17b72e15c3b5 --maxWorkers=2: 28/28 checks passed, including selected unit tests, four TypeScript projects, formatting, oxlint, changed-code quality and the selected repository ratchets.
The focused parser suite: 14 tests passed. New assertions cover the 200 KB data-URI image, an adjacent selected related root, richer HTML templates, later and overlapping complete-body matches, Unicode joining/combining characters, long repeated word fragments and explicit nested group boundaries.
The 200 KB image example also passes on the preceding published 915b9bd implementation. The shared google-html-text.ts converter remains unchanged; this PR applies no 100,000-character cut or word-overlap percentage.
Each control runs the same 14 committed tests, replaces only the production parser, then restores the candidate and verifies git diff --exit-code:
Parser control
Passing
Failing
What the failures establish
Unchanged main 251e9b0
0
14
Original content-selection defects
Original published 154bf4f
7
7
MIME header, availability, boundary and representation regressions
Intermediate d23649c
9
5
Content-ID literals, dispositions and body pairing
Earlier published d73f16a
10
4
Disposition comments and three pairing regressions
Preceding published 915b9bd
11
3
Related root, richer template and later complete match
Intermediate pairing 1aa5a77
11
3
Later match, Unicode join controls and explicit nested groups
Execution used Linux x64, Node 24.22.3, pnpm 12.18.0 and Bun 1.4.4. The validation workflow lives on a separate branch of an already enabled fork and is not part of this PR. No live Gmail account, native desktop session, macOS/Windows run or full application build is claimed.
I manually tested these changes locally
Automated tests added/updated
Every added test fails without this change and avoids the test anti-patterns
Performance
Text decoding and HTML conversion are cached per selected part within one extraction. Each eligible HTML representation compares at most two neighboring plain bodies. Exact normalized equality retains the plain text; complete-body containment uses a prefix-fallback scan with linear matching time and a temporary table proportional to the plain body length. This preserves overlapping matches without repeatedly rescanning long word fragments. The boundary checks inspect at most two UTF-16 code units on either side, retaining astral letters and Unicode join controls.
The regression suite includes 64,000-character plain text beside 128,000 characters of repeated HTML text. Independent review also checked the repeated-fragment case and legitimate overlapping matches. This change leaves the shared HTML-to-text conversion algorithm untouched and adds no disk, network or subprocess work.
Risk
Level: Medium. MIME representation selection can omit or duplicate body text if equivalence or container boundaries are wrong. Exact output checks cover independent HTML, repeated sections, nested alternatives, related CID resources, quoted/folded/commented headers, empty group boundaries, unavailable alternative bodies and attachment exclusion. Pairing is limited to adjacent text representations, including a directly selected related text root; it does not cross an explicit nested group or another visible section. Unicode joining/combining characters keep word fragments independent, and HTML template text is retained with its matched body. A malformed message that separates equivalent representations with another body can still show both; preserving independent ordered content takes priority in that ambiguous case. A plain revert restores the previous extraction; no stored data or schema is changed.
AI Disclosure
Primary contributor and contribution owner: @Afloat16. ChatGPT (GPT-6 Astra Pro) was used for implementation, regression analysis and automated validation.
Review
The parser and tests were reviewed for content preservation, related-root selection, attachment boundaries and per-call work. Cross-platform impact is limited to existing Node text-processing APIs; the actual platform qualification above is Linux. There are no SSH transport, mobile protocol, path, shortcut or agent-skill changes.
Agent skill upstream boundary
Not applicable; this change copies or mechanically translates no upstream skill-installer material.
Checklist
This PR is small and focused
Explained the user-facing before/after, mechanism and alternatives
Stated the risk and how to back it out
Visual proof is N/A with a reason
Self-reviewed for correctness, security and performance
Cross-platform, SSH/remote and path/shortcut impact considered
Full pnpm lint, pnpm typecheck, pnpm test and pnpm build pass (the required changed-file gate passed; full upstream CI remains separate)
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
The Gmail body parser now selects text according to MIME structure. It resolves multipart/related roots, selects readable multipart/alternative parts, and preserves the order of multipart/mixed sections. It excludes detected attachments and suppresses adjacent equivalent plain-text and HTML representations. New tests cover root matching, attachment filtering, alternative selection, repeated sections, and output ordering.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to 8e390
Gmail body extraction now follows the MIME structure and excludes attachments, including ones whose disposition header starts with a comment. No unresolved defects remain in the reviewed changes, and the parser suite covers the edge cases.
Pre-merge checks: 3 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Description check
The description follows the repository template in most sections. It explains the change, the rationale, the testing, the performance impact, the risk level, and the AI disclosure. The template requir…
Confirm the platform coverage clearly in the Testing section. State whether the change was tested manually, and check or explain the manual testing box. Remove or explain the AI Disclosure wording so it follows the template for outside cont…
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title names the fix and its scope: mixed-section preservation in the Gmail parser without repeating equivalent bodies. This matches the main change in the summary and objectives. The title is 71 c…
Linked Issues check
Directly linked issue #50412 has only coding requirements. The reviewed head (8e3909f) implements each requirement in src/main/google/google-gmail-message.ts, read in full at head.
(1) Independent mi…
Out of Scope Changes check
The head file contains only Gmail payload parsing logic. Each changed function maps to a #50412 requirement or supports one. normalizeMimeHeader supports Content-ID matching and disposition detection.…
Full details: Title check
Explanation
The title names the fix and its scope: mixed-section preservation in the Gmail parser without repeating equivalent bodies. This matches the main change in the summary and objectives. The title is 71 characters, within a typical length, and follows the conventional-commit style.
Full details: Linked Issues check
Explanation
Directly linked issue #50412 has only coding requirements. The reviewed head (8e3909f) implements each requirement in src/main/google/google-gmail-message.ts, read in full at head.
(1) Independent mixed sections in order: bodyText() calls select() on multipart/mixed, which calls mixedBodyParts(). That function returns children in original order. It omits an HTML leaf only when an adjacent text/plain leaf is equal after normalization (exact) or is fully contained at word boundaries (containsCompleteBody). An HTML-only section has no plain neighbor to match, so it is kept.
(2) Plain text preferred within an alternative: the multipart/alternative branch returns the last readable child containing text/plain, otherwise the last readable child. Readability requires body data or no attachmentId.
(3) Explicit related root: multipart/related reads the start parameter from normalizeMimeHeader(Content-Type) through MIMEType, matches the child Content-ID after normalizeMimeHeader(..., true), and selects only that root. A missing or malformed reference falls back to the first part. CID resources are not selected as body leaves.
(4) Attachments excluded: isAttachment() excludes parts with a filename or an attachment Content-Disposition. Only an explicitly selected related root bypasses this check.
Limits: I did not run the tests and could not read the test file diff. The whole-PR text diff was unavailable because changed blobs are missing from the checkout, so the verdict rests on the head file and the PR summary. The PR author reports 14 focused tests passing; I did not verify them.
Full details: Out of Scope Changes check
Explanation
The head file contains only Gmail payload parsing logic. Each changed function maps to a #50412 requirement or supports one. normalizeMimeHeader supports Content-ID matching and disposition detection. isAttachment supports attachment exclusion. mixedBodyParts and containsCompleteBody support ordered mixed sections and adjacent duplicate handling. The alternative readability check supports alternative selection. textOf caches decoding per call. The shared google-html-text.ts converter is not changed by this head file, and the PR summary states that it is unchanged. The PR summary also excludes the separate htmlToText rewrite suggested by a reviewer. containsCompleteBody goes beyond exact equivalence, which the PR description should state. This is related duplicate-handling behavior, not unrelated work.
Limits: the whole-PR text diff was unavailable, so the file list and test-file scope were not verified against a diff. Scope was judged from the head file and the PR summary.
Full details: Description check
Explanation
The description follows the repository template in most sections. It explains the change, the rationale, the testing, the performance impact, the risk level, and the AI disclosure. The template requires a linked issue, and this PR links #50412 with a follow-up reference to #50413. The Visual Proof section is N/A with a reason. The Performance section is filled in. However, the Testing section has unchecked boxes for manual testing, and the author states that no live Gmail, native desktop, macOS, Windows, or full application-build validation was done. The template asks for the platforms actually tested. The PR states Linux x64 only. The description is long and detailed, but several template items are only partly satisfied.
Resolution
Confirm the platform coverage clearly in the Testing section. State whether the change was tested manually, and check or explain the manual testing box. Remove or explain the AI Disclosure wording so it follows the template for outside contributors. Complete the Checklist items marked as unchecked, or state why the full pnpm lint, typecheck, test, and build commands were not run locally. Fill the Notes and Review sections so that they address the required security, cross-platform, SSH, mobile, and backwards compatibility checks in the template. Keep the Linked Issue entry as Fixes #50412.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f375159a-8722-4644-8292-b6a5dc27f1a2
Commits
Reviewing files that changed from the base of the PR and between 0dcfb92 and 8e3909f.
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.
Actionable comments posted: 3
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: 3e0a18a3-12ec-41d6-be99-98526de11294
Commits
Reviewing files that changed from the base of the PR and between 81ea994 and 154bf4f.
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; 9 remain after this review.
Addressed all three review findings in d73f16a051a073691adb6971328ebbf3401dcd86:
Content-ID matching ignores surrounding comments while retaining identifier case, quoted parentheses and bracketed domain literals. Malformed comments do not throw; an unmatched reference uses the implicit first root.
Empty nonattachment multipart groups keep their boundary, so mixed plain/HTML pairing cannot cross them. Attached groups remain excluded.
Alternative selection requires available body data, preserving an earlier readable body when a later representation only has an attachment ID. An explicitly available empty body remains valid.
Exact-source validation: 28/28 required changed-file checks passed; all 8 focused tests passed. The unchanged main parser fails all 8 tests. Restoring the previously published parser reproduces the three review failures (3 failed, 5 passed); a separate control catches the Content-ID literal regression (1 failed, 7 passed). Each control restores the candidate and verifies a clean source tree.
The PR description now records this final commit and its evidence. The four upstream workflows are still awaiting maintainer approval; please approve those runs when reviewing the follow-up.
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: dfa3b242-0222-4394-bfe2-0c383c0f022d
Commits
Reviewing files that changed from the base of the PR and between 154bf4f and d73f16a.
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.
Thanks for reworking this along the lines we suggested. Our review still found cases where a body that main shows once now shows twice. Bodies also feed reply quotes and forwards, so the duplicate can end up in drafts users send:
Cut inside a tag. When the 100,000-character cut lands inside a tag, for example a large data: URI <img>, htmlToText keeps the unfinished tag as text. The word-overlap check then fails. Repro: mixed(text/plain "Nightly report\nAll checks passed. See the chart below.", text/html with the same <p> text plus a 200 KB data-URI <img>). Possible fix: drop a trailing unclosed tag (/<[^>]*$/) before converting, and add a regression test.
Plain next to a related group.mixed(text/plain, multipart/related(text/html, image)) is never paired. Main showed only the plain part.
HTML wrapped in a template. Plain Build 42 passed. next to HTML that adds a header or nav and an unsubscribe or legal footer fails the 50% overlap check. This is the Python MIMEMultipart() shape this PR targets.
The linear-time htmlToText rewrites are a real improvement: unclosed <script, runs of <, long whitespace. They deserve tests that lock in old and new output on ordinary HTML. Consider landing them as a separate small PR so they don't wait on the pairing logic.
The disposition-comment finding is fixed in 915b9bd4cee7628675ea06c08654f22e9681b43a. Attachment detection now removes leading, nested and escaped comments; an already recognizable attachment prefix is retained if a malformed trailing comment cannot be normalized. The selected-related-root bypass and inline disposition behavior are unchanged.
Exact-source validation passed 28/28 changed-file checks and all 9 focused tests. Restoring the preceding d73f16a parser fails the new regression while the other eight pass; unchanged main fails all nine. The PR description contains the updated commit, commands and controls.
Thanks for the concrete examples. The pairing follow-up is now in 0dcfb92508c7c499564f580a524d815a7eef66de.
200 KB data-URI image: I added the exact report-plus-image shape as a regression and checked it against both the preceding published 915b9bd and this head; both return the report once. This branch has no 100,000-character cut or percentage-overlap heuristic, and google-html-text.ts is unchanged.
Plain beside related HTML: an adjacent multipart/related now contributes its selected direct text root to pairing; its image/CID resources stay excluded. A related root that is itself an explicit mixed/alternative group keeps that group boundary.
HTML template: when the normalized HTML contains the complete plain body at word boundaries, the richer HTML representation is retained once. The header/navigation/footer text stays present, while the duplicate plain body is omitted. Equal representations still retain the original plain text.
Additional regressions protect repeated sections, both part orders, later and overlapping complete matches, Unicode join/combining characters, and long repeated word fragments. Complete-body matching uses linear prefix fallback; the shared HTML converter has no changes to split out of this PR.
Validation of this exact head: 28/28 required changed-file checks and all 14 focused tests passed. Restoring 915b9bd reproduces the related-root, template and later-match failures (3 failed / 11 passed); unchanged main fails all 14. All six controls restore the candidate and verify a clean diff. The PR description now records the current source, scope and evidence.
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: f9bc8d08-78df-496a-ba2f-4bfdfb085af3
Commits
Reviewing files that changed from the base of the PR and between 915b9bd and 0dcfb92.
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.
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
Keep independent Gmail sections in order and show adjacent plain/HTML representations once, retaining additional text in an HTML template.
What Changed
This follows the requested direction in #50413's closing review.
multipart/alternativeand the designated root within eachmultipart/related, preserving independent mixed sections in their original order.multipart/mixedcontainer, pair adjacent plain/HTML representations from direct text parts or a related container whose selected root is itself a text part. Both eligible neighboring plain bodies are checked for normalized equality first, retaining the exact plain body. When neither side is equal and HTML contains the complete plain body at word boundaries, retain the richer HTML representation, including its header, navigation and footer. Each plain body can match only one HTML body. Attachments do not count as visible sections; explicit nested groups and empty multipart boundaries remain independent.The change is limited to the Gmail payload parser and its regression tests. It adds no package or settings.
Why
The current global plain-text preference loses independent HTML-only sections. The earlier fix preserved those sections but repeated the common Python
MIMEMultipart()plain/HTML sibling form. Matching adjacent equivalent sibling representations addresses that review without globally deduplicating message text or dropping separately grouped sections.Linked Issue
Fixes #50412
Follow-up to #50413.
Visual Proof
N/A — this changes Gmail tool-result text extraction, with no UI or interaction changes. The tests assert the exact returned text before and after the parser change.
Testing
Latest exact-match priority follow-up
Validated head:
8e3909fc4e588e43803e97df0f767edeed028314, tree041fa9fb046ddab54f0cd57c285249c1302b12a4. Both eligible neighboring plain bodies are checked for normalized equality before either can be paired by containment. This preserves an independentStatussection beside HTMLStatus updateand its exact plain representation.0dcfb925parser makes the new exact-priority assertions fail (1 failed / 13 passed). The control requires an assertion failure, then restores this head and verifies a clean diff.Earlier MIME and representation validation
Validated commit
0dcfb92508c7c499564f580a524d815a7eef66de, tree57cb03ae5d37471381bca883fab0606f230a4880, based on main251e9b0558be785f206aece6368a17b72e15c3b5.Exact-source validation checked out this Orca commit and used its unchanged toolchain/configuration:
timeout 900 pnpm check:changed --base=251e9b0558be785f206aece6368a17b72e15c3b5 --maxWorkers=2: 28/28 checks passed, including selected unit tests, four TypeScript projects, formatting, oxlint, changed-code quality and the selected repository ratchets.915b9bdimplementation. The sharedgoogle-html-text.tsconverter remains unchanged; this PR applies no 100,000-character cut or word-overlap percentage.Each control runs the same 14 committed tests, replaces only the production parser, then restores the candidate and verifies
git diff --exit-code:251e9b0154bf4fd23649cd73f16a915b9bd1aa5a77Execution used Linux x64, Node 24.22.3, pnpm 12.18.0 and Bun 1.4.4. The validation workflow lives on a separate branch of an already enabled fork and is not part of this PR. No live Gmail account, native desktop session, macOS/Windows run or full application build is claimed.
Performance
Text decoding and HTML conversion are cached per selected part within one extraction. Each eligible HTML representation compares at most two neighboring plain bodies. Exact normalized equality retains the plain text; complete-body containment uses a prefix-fallback scan with linear matching time and a temporary table proportional to the plain body length. This preserves overlapping matches without repeatedly rescanning long word fragments. The boundary checks inspect at most two UTF-16 code units on either side, retaining astral letters and Unicode join controls.
The regression suite includes 64,000-character plain text beside 128,000 characters of repeated HTML text. Independent review also checked the repeated-fragment case and legitimate overlapping matches. This change leaves the shared HTML-to-text conversion algorithm untouched and adds no disk, network or subprocess work.
Risk
Level: Medium. MIME representation selection can omit or duplicate body text if equivalence or container boundaries are wrong. Exact output checks cover independent HTML, repeated sections, nested alternatives, related CID resources, quoted/folded/commented headers, empty group boundaries, unavailable alternative bodies and attachment exclusion. Pairing is limited to adjacent text representations, including a directly selected related text root; it does not cross an explicit nested group or another visible section. Unicode joining/combining characters keep word fragments independent, and HTML template text is retained with its matched body. A malformed message that separates equivalent representations with another body can still show both; preserving independent ordered content takes priority in that ambiguous case. A plain revert restores the previous extraction; no stored data or schema is changed.
AI Disclosure
Primary contributor and contribution owner: @Afloat16. ChatGPT (GPT-6 Astra Pro) was used for implementation, regression analysis and automated validation.
Review
The parser and tests were reviewed for content preservation, related-root selection, attachment boundaries and per-call work. Cross-platform impact is limited to existing Node text-processing APIs; the actual platform qualification above is Linux. There are no SSH transport, mobile protocol, path, shortcut or agent-skill changes.
Agent skill upstream boundary
Checklist
N/Awith a reasonpnpm lint,pnpm typecheck,pnpm testandpnpm buildpass (the required changed-file gate passed; full upstream CI remains separate)