Problem
The IMAP SEARCH command parser in `packages/imap/src/protocol/parser.ts` does not recognize flag-based search criteria. Any client sending `SEARCH UNSEEN`, `SEARCH SEEN`, `SEARCH ANSWERED`, `SEARCH DELETED`, `SEARCH DRAFT`, or `SEARCH FLAGGED` receives:
```
a001 BAD Unknown search criterion: UNSEEN
```
These are all RFC 3501 Section 6.4.4 criteria and are used heavily by mainstream clients:
- Apple Mail: `SEARCH UNSEEN` on folder select to build the unread badge
- Thunderbird: `SEARCH FLAGGED` for the "Starred" smart folder
- K-9 Mail: `SEARCH UNSEEN SINCE ` for "new mail since last check"
- Outlook: `SEARCH ANSWERED` for the "Replied" view
Without support, these UI elements either fail to populate or hit the error path.
Current state
Verified by reading `packages/imap/src/protocol/parser.ts` directly. The switch statement in `parseCriterion` has cases for: ALL, NEW, FROM, TO, CC, BCC, SUBJECT, BEFORE, ON, SINCE, LARGER, SMALLER, TEXT, BODY, UID, NOT, OR, plus bare sequence sets. No flag-based cases.
The `MessageAdapter.searchMessages` interface signature already accepts a criterion shape that could carry flag comparisons -- the gap is in the parser, not the adapter.
Fix scope
- Extend `SearchCriterion` type in parser.ts to include flag variants
- Add case statements in `parseCriterion` for ANSWERED, DELETED, DRAFT, FLAGGED, SEEN, UNSEEN
- Update `searchMessages` implementations to evaluate flag criteria against the message's `isRead`, `isStarred`, `deletedAt`, and thread-reply / folder-slug derivations
- Add tests referencing RFC 3501 Section 6.4.4 for each criterion
- Also consider: KEYWORD, UNKEYWORD, HEADER, SENTBEFORE / SENTON / SENTSINCE -- all RFC 3501 criteria that are similarly unimplemented. Could be a follow-up issue if this one gets too large.
Related
Problem
The IMAP SEARCH command parser in `packages/imap/src/protocol/parser.ts` does not recognize flag-based search criteria. Any client sending `SEARCH UNSEEN`, `SEARCH SEEN`, `SEARCH ANSWERED`, `SEARCH DELETED`, `SEARCH DRAFT`, or `SEARCH FLAGGED` receives:
```
a001 BAD Unknown search criterion: UNSEEN
```
These are all RFC 3501 Section 6.4.4 criteria and are used heavily by mainstream clients:
Without support, these UI elements either fail to populate or hit the error path.
Current state
Verified by reading `packages/imap/src/protocol/parser.ts` directly. The switch statement in `parseCriterion` has cases for: ALL, NEW, FROM, TO, CC, BCC, SUBJECT, BEFORE, ON, SINCE, LARGER, SMALLER, TEXT, BODY, UID, NOT, OR, plus bare sequence sets. No flag-based cases.
The `MessageAdapter.searchMessages` interface signature already accepts a criterion shape that could carry flag comparisons -- the gap is in the parser, not the adapter.
Fix scope
Related