feat(messages): add searchAttachments with bounded MIME-parse concurrency (stacked on #145)#149
Open
JordanRO2 wants to merge 2 commits into
Open
feat(messages): add searchAttachments with bounded MIME-parse concurrency (stacked on #145)#149JordanRO2 wants to merge 2 commits into
JordanRO2 wants to merge 2 commits into
Conversation
Header-only reads for agent workflows that need to triage/enrich a result
set without decoding bodies or paying N round-trips.
- getMessageHeaders(messageId, folderPath): returns a flat header object
(id, subject, author, recipients, ccList, date, tags, isRead, isFlagged,
threadId, references, inReplyTo, size) via a shared msgHdrToHeaderObject
extractor; reuses the existing findMessage -> openFolder -> getAccessibleFolder
access gate (same as getMessage).
- batchGetMessageHeaders(messageIds, folderPath): one folder open + a single
linear enumeration fallback (O(M), SCAN_CAP 50000) instead of N findMessage
calls; returns { headers: { id -> header | { error } }, total, failed }.
Hard cap of 200 enforced in the handler (clear { error }), schema left
unbounded so the empty-input fast path stays reachable.
- Tests: validation fixtures + ALL_TOOLS entries; full suite 386 pass, lint
0 errors.
…ncurrency Find messages whose attachments match a filename substring (nameContains) and/or a Content-Type prefix (contentType), scanning a folder (or the inbox of each accessible account when folderPath is omitted). Returns header objects annotated with the matching attachment metadata. Reuses the shared msgHdrToHeaderObject extractor and the folder/account access gate. Caps: maxResults default 50 / max 200; scanCap default 5000 / max 50000 per folder; candidate prefilter on the Attachment flag with a cap*4 buffer; results sliced to cap, newest-first. Hardened over a naive fan-out: the MIME parse step (MsgHdrToMimeMessage) runs through a bounded worker pool (max 8 concurrent) instead of firing one parse per candidate at once (up to 800 simultaneous, and network fetches on IMAP). Each parse is bounded by a one-shot nsITimer timeout, and an aggregate deadline stops pulling new work so the call can never exceed the client/bridge request timeout; truncation is signalled via the truncated flag. The 3-arg MsgHdrToMimeMessage form is used so it never downloads bodies over the network. Tests + ALL_TOOLS updated; full suite green, lint 0 errors.
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
searchAttachments(nameContains, contentType, folderPath, maxResults, scanCap)— find messages whose attachments match a filename substring and/or a Content-Type prefix, scanning a folder (or the inbox of each accessible account whenfolderPathis omitted). Returns header objects (via the sharedmsgHdrToHeaderObjectfrom #145) annotated with the matching attachment metadata, newest-first.Caps:
maxResultsdefault 50 / max 200;scanCapdefault 5000 / max 50000 per folder; candidates pre-filtered on the Attachment flag with acap*4buffer; results sliced tocap.Bounded MIME-parse concurrency (the interesting part)
Resolving attachment metadata requires a
MsgHdrToMimeMessageparse per candidate. A naive implementation fires one parse per candidate at once — up tocap*4(≈800) simultaneous parses, which on IMAP means a burst of network fetches. This PR bounds that:MAX_MIME_CONCURRENCY = 8pulls candidates from a shared index, so at most 8 parses are ever in flight;nsITimertimeout so a stuck parse frees its slot instead of wedging the batch;truncatedis set when it trips);MsgHdrToMimeMessageform is used (noallowDownload), so it reads cached MIME without forcing network body downloads.Tests
test/validation.test.cjscovers the schema;ALL_TOOLSupdated (structural test passes). Full suite green,eslint .0 errors.