fix: harden Gmail message parsing - #97
Open
nvtoan0201-swe wants to merge 1 commit into
Open
nvtoan0201-swe wants to merge 1 commit into
nvtoan0201-swe wants to merge 1 commit into
Conversation
A single message could break or distort a mailbox read: an unknown charset label threw from TextDecoder, RFC 2231 language tags blocked header decoding, a quoted display name containing an address was preferred over the real sender, a bare angle-addr From produced an empty sender, and an attached message/rfc822 had its nested text merged into the parent body. Decode bodies with a UTF-8 fallback, strip language tags, ignore addresses inside quoted display names, fall back to the bare address, and stop recursing into attachment parts. Large remote bodies stored behind attachment IDs are still hydrated and read as message text.
This branch has not been deployed
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.
What changed
Five Gmail message-parsing gaps in
packages/integrations/src/google.ts:charsetlabel (unknown-8bit,default, …) threw fromTextDecoder, failing the whole mailbox/thread read. Body decoding now falls back to UTF-8.=?UTF-8*en?B?…?=) never decoded because the language tag was passed toTextDecoder. The tag is now stripped.addresses()matched an e-mail-looking string inside a quoted display name ("billing@other.example" <real@example.com>) before the real address. Quoted display names that precede an angle-addr are ignored.From: <bare@example.com>produced an emptysender(and therefore a blank sender in the UI). It now falls back to the address.message/rfc822attachment had its nested parts treated as message text, so a forwarded message body was merged into the parent body (and could trip the 1 MiB limit). Text collection no longer recurses into attachment parts.Large message bodies that Gmail stores behind an attachment ID (no filename) are still hydrated by the existing
hydrate()path and read as message text.Verification
pnpm test— 278 pass, 0 fail (2 new tests: unknown charset + RFC 2231 + display-name address + bare sender; forwarded-message body stays out of the parent)pnpm lintpnpm typecheckIntegration limits
Fixtures only; no live Gmail account was exercised. Existing attachment references and imports are unchanged.
AI assistance was used to prepare this change; I reviewed the code, tests and checks above.