feat(search): add from/date filters and require explicit search criteria#33
Open
realugbun wants to merge 2 commits into
Open
feat(search): add from/date filters and require explicit search criteria#33realugbun wants to merge 2 commits into
realugbun wants to merge 2 commits into
Conversation
The search_emails tool exposed `to` but no `from` filter, even though the underlying IMAP layer (ImapFlow SearchObject) supports both. Adds: - from: sender address substring (mirrors existing `to`) - since: INTERNALDATE >= date (ISO 8601) - before: INTERNALDATE < date - sent_since: Date: header >= date - sent_before: Date: header < date All new filters AND with `query` and existing filters, so combinations like "keyword X in the last 7 days with attachments" are now a single call instead of requiring list_emails plus client-side post-filtering. Adds 4 unit tests covering the new criteria-builder paths.
Previously, calling search_emails with no query and no filters silently
ran `client.search({}, { uid: true })`, returning every UID in the
mailbox. This made the tool indistinguishable from list_emails for
empty input — and concealed bugs where filter args were dropped (e.g.
unknown field names stripped by the Zod schema would silently produce
a full-mailbox response with no hint that the argument had been
ignored).
Now rejects with a clear error pointing callers to list_emails:
search_emails requires at least one of: query, from, to, since,
before, sent_since, sent_before, has_attachment, larger_than,
smaller_than, answered. Use list_emails to browse a mailbox without
filters.
Adds 1 unit test for the rejection path.
BREAKING CHANGE: search_emails with all-empty arguments now throws
instead of returning the full mailbox.
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.
Description
Two improvements to
search_emails:New filters —
from,since,before,sent_since,sent_before.The underlying ImapFlow
SearchObjectalready supported all of these;only the plumbing was missing. Mirrors the existing
tofield and theequivalent filters already exposed on
list_emails.Reject all-empty calls — previously,
search_emailswith no queryand no filters ran
client.search({}, { uid: true }), which matchesevery UID in the mailbox. This made the tool indistinguishable from
list_emailsfor empty input and silently masked bugs where unknownparameter names were stripped by the Zod schema (e.g. a caller passing
keyword:instead ofquery:would see a full-mailbox response withno hint that their argument had been dropped). Now throws a clear error
pointing callers to
list_emails.Motivating example
A common ask is "emails from sender X in the last N days." That used to
require
list_emails(which already hadfrom+since), even thoughsearch_emailswas the more semantically obvious tool for filteredlookups. After this PR a single call works:
{ "account": "work", "from": "billing@example.com", "since": "2026-05-01T00:00:00Z" }Or combined with a keyword:
{ "account": "work", "query": "invoice", "since": "2026-04-01T00:00:00Z", "has_attachment": true }Type of change
search_emailswith no filters now errorsChecklist
pnpm checkpasses)pnpm checkpassespnpm typecheckpassespnpm test) — 155/155, including 5 newsearchEmailscriteria-builder testsemails.tool.tsupdated to reflect new paramsNotes for reviewer
warning that returns the full mailbox for one release. Happy to soften
if you prefer a gentler landing.