Repository navigation
feat(platform): store email attachments on ingest - #2914
Merged
Merged
Conversation
Mail arriving over IMAP lost its attachments. The connector returned body text and headers only, so a message with a CV or an invoice landed in the Inbox as prose with no trace of the file. Pull attachment parts out of the parsed MIME in `imap-smtp.get_message` and carry them on the email object: metadata always, plus base64 bytes when the part fits under the inline cap. Sync then drains those bytes into the org's blob storage, records the file in `fileMetadata`, and rewrites the attachment to a `storageId` + download URL before ingest — so what reaches a conversation is a reference the Inbox can open, not a payload it has to carry. Bytes are drained per message rather than per page: holding a whole page of base64 in one action would scale resident memory with `limit`. The cap is 5 MiB raw (~6.7 MiB encoded), well inside the Convex function-payload ceiling; a larger part is listed as metadata only rather than risking the pass. `contentBase64` is wire-only. `attachmentsForMetadata` strips it at every ingest sink, because the message validator is a strict object that would reject the row and the metadata records — untyped JSON — would otherwise swell by the whole attachment.
This was referenced Aug 4, 2026
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.
Mail arriving over IMAP lost its attachments.
imap-smtp.get_messagereturned body text and headers only, so a message carrying a CV or an invoice landed in the Inbox as prose with no trace of the file.The path
mailAttachmentsFromParsedpulls attachment parts out of the parsed MIME and returns metadata always, pluscontentBase64when the part fits under the inline cap.materializeEmailAttachmentsdecodes those bytes into the org's blob storage, records the file infileMetadata, and rewrites the attachment tostorageId+ a download URL.Gmail and Outlook are unchanged here: connector
ctx.filesis deliberately unwired, so theirdownloadAttachmentsflag cannot store duringget_message. This wires the IMAP path, and the helper is shaped to take the others when that seam opens.Two things worth reviewing
Bytes drain per message, not per page.
fetchBodiesmaterializes each body before fetching the next. Fetching the whole page first would make resident memory scale withlimit(25 by default) × the per-attachment cap — hundreds of MiB of base64 string live in one action. A test pins the interleaving (get:1 → store → get:2 → store), so a future "batch the stores" refactor fails loudly.The cap is 5 MiB raw, ≈6.7 MiB base64, well inside the Convex function-payload ceiling — that string crosses the connector-action boundary before it reaches storage. A larger part is listed as metadata only rather than risking the pass. The number is asserted against the figure
connector.ymladvertises, so the manifest and the constant cannot drift apart.contentBase64is wire-only.attachmentsForMetadatastrips it at all four ingest sinks —emailAttachmentMetaValidatoris a strict object that would reject the message row, and the metadata records are untyped JSON that would otherwise swell by the whole attachment.Tests
New unit coverage for
mailAttachmentsFromParsed(small parts encoded, oversized kept metadata-only,cidnormalised),materializeEmailAttachments, andattachmentsForMetadata; plus two sync-level cases for the drain ordering and the stored-reference hand-off. Full server suite green: 610 files, 74,366 tests.