Repository navigation
fix(gmail): keep attachments whose bytes arrive inline in the message body - #50765
Conversation
Gmail can return attachment bytes inline in MessagePartBody.data with no attachmentId. attachmentsOf only listed parts with an attachmentId, so those files were dropped from `orca gmail read`, attachment downloads, forwards and draft revisions. List named parts that carry either, and serve inline bytes without calling the attachments endpoint. Fixes #50620 Co-authored-by: Neil <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
Some Gmail messages carry a file's contents right inside the message instead of as a separate download link. Orca only looked for the download link, so those files quietly disappeared when you read, downloaded or forwarded the message. Now Orca keeps them.
What Changed
attachmentsOfonly listed named parts that had abody.attachmentId. Parts whose bytes Gmail returned inline inMessagePartBody.data(noattachmentId) were dropped fromorca gmail read, attachment downloads, forwards and draft revisions.attachmentIdor inlinebody.data(including empty files).downloadGmailAttachmentfetches from the attachments endpoint only when there is anattachmentId; otherwise it serves the inline bytes that are already in the full message response. Parts with neither are still excluded, and the existing size limit still applies.Why
Gmail's API documents that
MessagePartBody.datamay hold the attachment bytes directly, withattachmentIdpresent only when the data is stored separately. Treating both shapes as attachments fixes every caller (read, download, forward, revision) at the single place where attachments are discovered, rather than patching each caller.Linked Issue
Fixes #50620
Visual Proof
N/A. This changes which attachments Gmail CLI/RPC operations return and forward in the main process; there is no UI layout or interaction change.
Testing
Added
forwards attachments whose bytes Gmail returns in the part bodyinsrc/main/google/google-gmail-draft-compose.test.ts. It runs the realcomposeForwardwith only Gmail API responses stubbed: one binary inline part, one remoteattachmentIdpart, and one part with neither. Against main's source the test fails (the inline file is missing); with this change both files are forwarded with exact bytes in order and the unavailable part stays excluded. Allsrc/main/google/google-gmail*.test.tspass (3 files, 13 tests). oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on the touched files. Tested on macOS (unit level; no live Google account).Performance
None, because this only runs when an agent or user reads, downloads or forwards a Gmail message (on-demand main-process work, not a hot path). Measured
attachmentsOf: 5 parts 0.18/0.12 us old vs 0.19/0.20 us new; 1000 parts 44 us vs 47 us (all remote) and 22 us vs 53 us (mixed, where the new code now lists twice as many attachments); 10000 mixed parts 0.23 ms vs 0.44 ms. Inline downloads skip a network request they never needed.Risk
Level: Low
Previously dropped inline files now appear in reads and forwarded drafts, so the existing forward size check counts them and may reject a forward that was previously silently incomplete. Remote attachment retrieval is unchanged. A plain revert restores the old detection.
Review
Agent skill upstream boundary
Notes
Original fix by @Afloat16 in #50621 (authorship preserved on the commit).
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)