Repository navigation
fix(platform): decode Gmail bodies and render synced mail content - #3987
Merged
Merged
Conversation
Gmail's format=full returns every text part's body.data transcoded to UTF-8 while keeping the part's original charset label. The normalizer decoded it with atob alone, which yields one character per byte, so any non-ASCII body landed in the Inbox as mojibake (你好 → ä½ å¥½). Decode the bytes as UTF-8 instead, and log an invalid base64url body rather than dropping it silently. Already-ingested messages keep their stored text; this fixes new mail.
The mailbox sync fetched Gmail and Outlook messages without includeAttachments and kept only the message, so every attachment landed as a metadata-only chip: no stored file, no download, no inline cid image. Outlook messages showed no attachments at all, since Graph lists them only through the connector. When a fetched message has attachments and is not already ingested with them settled, fetch it once more with includeAttachments and put each stored fileId on the matching part of that same response (Gmail mints attachment ids per fetch). The message on the sync cursor is re-fetched every poll, so a settled one keeps its stored references instead of storing another copy. A failed download keeps the metadata-only chips and still ingests the mail. Gmail sends attachment bytes base64url inside JSON, and ctx.http carries at most 5 MiB, so a larger part failed the whole action after storing the parts before it. get_message and get_attachments now list a part over 3.5 MB as truncated instead of fetching it.
EmailPreview resolved cid: references to the caller's signed storage links first and then routed every remote-looking image through /api/image-proxy, so an inline image became a proxied fetch of the platform's own blob store. That route has answered 404 since the Convex HTTP router was retired, so every inline image rendered broken. Rewrite remote images to the proxy first and resolve cid: parts after, so an inline part loads straight from its signed link.
EmailPreview routes every remote image an email draws through /api/image-proxy, but the route went with the Convex HTTP router in #2857 and was never registered on the new backend, so it answered 404 and no remote image in any email has rendered since. GET /api/image-proxy is back as a session-gated door, charged per person on a new security:image-proxy lane. It fetches through the SSRF-safe client with a new credentialless option: with no credential to leak, plaintext http and redirects onto another public host are admitted, while every hop is still resolved, checked and pinned and private and metadata addresses stay refused. It caps an image at 10 MB, runs at most 16 fetches at once per process, and serves only a raster type detected from the bytes; SVG and anything else are refused whatever the host claims. Responses carry a sandboxing CSP and private caching.
rewriteExternalImageSrcs passed the raw src to btoa, which throws on any character outside Latin-1, so one image URL with a Chinese file name or an internationalized host took the whole email preview down. Encode the parsed URL's href instead: punycode host, percent-encoded path, always ASCII.
yannickmonney
added a commit
that referenced
this pull request
Oct 1, 2026
CHAT-F52 now follows the header's Create task and the one-step start. CHAT-F53 to CHAT-F55, CHAT-B20 and CHAT-A8 cover the task's live row and its states, the reply's hand-over steps, a hand-over with no agent anywhere, and the keyboard and screen reader; TASK-F59 covers Create and start agent on the board. The automation reference names the specs that own the rest, and the readme counts are current, including the conversations suite's two boxes from #3987.
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.
Problem
Two Inbox defects on mail synced from Gmail (the second also affects Outlook):
你今天怎么样readsä½ ä»å¤©æä¹æ ·,GrüßereadsGrüÃe. Subjects are fine, because Gmail decodes RFC 2047 headers itself.cid:image. Outlook messages show no attachments at all.EmailPreviewresolvedcid:parts to their signed storage link first, then routed every non-same-origin image through/api/image-proxy. That route has answered 404 since feat(platform): rewrite the AI backend on a minimal YAML-config core #2857 dropped it along with the Convex HTTP router ("re-registers with the chat rebuild"; it never did).Causes
decodeBase64Urlinbackend/core/conversations/ingest/normalize_email.tsreturnedatob(...)directly. That yields one character per byte (Latin-1), so the UTF-8 bytes Gmail sends were never decoded. Gmail'sformat=fulltranscodes every text part'sbody.datato UTF-8 but keeps the originalcharsetlabel, so the fix decodes UTF-8 and ignores the label. The bug dates from feat: workflow automation templates and integration-linked automations #805 (v0.2.7).sync_mailbox.fetchOneBodycalledget_messagewith{ messageId }only, andunwrapFetchedMessagekept onlyoutput.message. The Gmail and Outlook connectors download and store attachments only withincludeAttachments: true, and no caller ever passed it. Graph lists no attachments on the message itself, so Outlook ingested none. IMAP is unaffected, since it carries bytes inline.Change
TextDecoderas UTF-8. An invalid body is logged instead of dropped silently.hasAttachments) and is not already ingested with them settled, the sync fetches it once more withincludeAttachments: true.fileIdbecomes the matching part'sstorageIdby id, because Gmail mints attachment ids per fetch. Outlook's attachments come from the connector's list.settledAttachmentsOfIngested(inreuse_stored_attachments.ts) hands back the stored references of a message whose parts are all settled (stored, ortruncated), so nothing is downloaded or stored twice.reuseStoredAttachmentsskips its lookup when every part is already settled.ctx.httpcarries at most 5 MiB, and Gmail sends attachment bytes base64url inside JSON. A larger part used to fail the whole action, after the parts before it were already stored.get_messageandget_attachmentsnow list a part over 3.5 MB astruncated(IMAP's term) instead of fetching it.@tale/uiemail-preview.tsx): remote images are rewritten to the proxy first andcid:parts resolved after, so an inline part loads straight from its signed link. The stale "Convex storage" line in the rewrite's comment is gone.backend/domains/image_proxy/):GET /api/image-proxyagain.security:image-proxylane (token bucket: 300 a minute, burst 600).safeFetchBinarywith a newcredentiallessoption. With no credential to leak, plaintexthttp:and redirects onto another public host are admitted. Every hop is still resolved, checked and pinned; private and metadata addresses stay refused; a credential header on such a request throws.file-type). SVG and anything else answer 415 whatever the host claims.Content-Security-Policy: default-src 'none'; sandbox,privatecaching,no-referrerand CORPsame-origin.INVALID_IMAGE_URL,IMAGE_HOST_REFUSED,IMAGE_TOO_LARGE,NOT_AN_IMAGE,IMAGE_FETCH_FAILED,IMAGE_FETCH_TIMEOUT(registered inerror-codes.md). The path has its own metrics route class.rewriteExternalImageSrcspassed the raw src tobtoa, which throws outside Latin-1, so one image URL with a Chinese file name took the whole preview down. It now encodes the parsedhref.CONV-F35andCONV-F36plus their rows inreference/automation.md.Not in this PR
includeSent: false.Verification
normalize_email.test.ts: the old decoder produces the exact string from the report.sync_mailbox.test.ts: six cases (Gmail new, already settled, legacy chip, truncated, failed download; Outlook).reuse_stored_attachments.test.ts: five cases.shipped-connectors.test.ts: runs the real Gmailget_message/get_attachmentsbodies on the in-process runner.@tale/platform test: 960 files, 80306 tests pass.@tale/docs test: 200 pass. Platform typecheck and lint green;lint:manualandcheck-guidegreen on the suite.@tale/ui test: 274 files, 2676 tests pass; the updatedemail-preview.test.tsxcase fails on the old ordering. Platform conversation UI tests: 248 pass.safe-fetchsuites (25 + 53 cases) green, every new case red on the old code. SAST on the new files: 0 findings. Full@tale/platform test: 962 files, 80334 tests pass.fetchProxiedImage(the route's own fetch path, run from a scratch script) for every remote image URL in the dev inbox:.png), JPEG, and LinkedIn's GIF tracking pixels.http://github.com/fluidicon.png(plaintext plus a cross-host redirect) loads. An SVG answers 415.169.254.169.254and127.0.0.1answer 403.CONV-F36can be judged in the browser.你好啊. The inline part was stored with astorageIdby the gated second fetch. The fixedEmailPreview, given that message's real HTML and its presigned link in Chromium, rendered the image (2244×943) straight from the store, not through the proxy. The in-page render used a fresh module import, because this session'sgit stashhad cost Vite its watch on the file. A PDF attachment's Download has not yet been clicked through live (CONV-F35).