Skip to content

feat(platform): store email attachments on ingest - #2914

Merged
Israeltheminer merged 1 commit into
mainfrom
feat/email-attachment-storage
Aug 5, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
feat/email-attachment-storage

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Mail arriving over IMAP lost its attachments. imap-smtp.get_message returned 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

  1. Connector — mailAttachmentsFromParsed pulls attachment parts out of the parsed MIME and returns metadata always, plus contentBase64 when the part fits under the inline cap.
  2. Sync — materializeEmailAttachments decodes those bytes into the org's blob storage, records the file in fileMetadata, and rewrites the attachment to storageId + a download URL.
  3. Ingest — conversations receive a reference the Inbox can open, never a payload they have to carry.

Gmail and Outlook are unchanged here: connector ctx.files is deliberately unwired, so their downloadAttachments flag cannot store during get_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. fetchBodies materializes each body before fetching the next. Fetching the whole page first would make resident memory scale with limit (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.yml advertises, so the manifest and the constant cannot drift apart.

contentBase64 is wire-only. attachmentsForMetadata strips it at all four ingest sinks — emailAttachmentMetaValidator is 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, cid normalised), materializeEmailAttachments, and attachmentsForMetadata; plus two sync-level cases for the drain ordering and the stored-reference hand-off. Full server suite green: 610 files, 74,366 tests.

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.
@Israeltheminer
Israeltheminer merged commit dbc6bd1 into main Aug 5, 2026
84 of 88 checks passed
@Israeltheminer
Israeltheminer deleted the feat/email-attachment-storage branch August 5, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant