mirror of
https://github.com/spartanz51/tutabridge.git
synced 2026-06-24 10:54:32 +02:00
cmd_search only ever special-cased UNSEEN — every other query (SUBJECT, FROM, SINCE, …) fell through to "return all message ids", so a search in Thunderbird silently matched the entire mailbox. Now that the full mailbox is listed, that made search actively misleading. New imap/search.rs parses the RFC 3501 SEARCH grammar into a SearchKey tree (AND/OR/NOT, parens, CHARSET prefix, quoted strings, sequence/UID sets) and matches each message via a lightweight MsgView the session projects from its cached mail. Coverage is metadata-first: SUBJECT, FROM, TO, CC, BCC, HEADER, flags, dates (BEFORE/ON/SINCE + SENT*), LARGER/ SMALLER, UID and sequence sets. Flag predicates resolve consistently with what we report over FETCH (only \Seen and \Deleted exist). BODY/TEXT match the body only when it's already decoded — whole-mailbox full-text body search is the next increment, backed by an on-disk index. Unknown criteria degrade to a non-restrictive match so search never hides a message. Validated live on a 19,322-message INBOX: SEEN+UNSEEN partition the mailbox exactly, NOT SEEN == UNSEEN, AND/OR compose, and a nonexistent subject now returns 0 hits instead of everything. 223 unit tests.