feat: switch folder-view search from IMAP to local SQLite FTS5 #503

Merged
guettlibot merged 0 commits from issue-501-folder-search-local-sqlite into main 2026-06-06 19:34:59 +00:00
guettlibot commented 2026-06-06 18:46:31 +00:00 (Migrated from codeberg.org)

Summary

  • Replaces the IMAP live search in searchEmails with a local SQLite FTS5 query filtered by mailbox_path, reusing the same email_fts virtual table and _toFtsQuery helper that backs searchEmailsGlobal.
  • Removes the IMAP-specific _toAddressList helper (was only used by the old IMAP search path).
  • Updates two stale comments in email_list_screen.dart that referenced IMAP.

How it works

The new SQL mirrors searchEmailsGlobal with one extra condition:

SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid
WHERE email_fts MATCH ? AND e.account_id = ? AND e.mailbox_path = ?
ORDER BY rank LIMIT 50

Folder-view search now works fully offline, and tapping a result always opens the correct email since IDs come from the same local DB as getEmail.

Verification

  • Added a unit test (searchEmails filters by mailboxPath using local FTS5) that inserts emails in two mailboxes, searches INBOX, and confirms only the INBOX email is returned.
  • Added a widget test (folder search returns results from local cache without any network call) that verifies results are returned without a network round-trip.
  • All 498 existing tests continue to pass.

Closes #501

## Summary - Replaces the IMAP live search in `searchEmails` with a local SQLite FTS5 query filtered by `mailbox_path`, reusing the same `email_fts` virtual table and `_toFtsQuery` helper that backs `searchEmailsGlobal`. - Removes the IMAP-specific `_toAddressList` helper (was only used by the old IMAP search path). - Updates two stale comments in `email_list_screen.dart` that referenced IMAP. ## How it works The new SQL mirrors `searchEmailsGlobal` with one extra condition: ```sql SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid WHERE email_fts MATCH ? AND e.account_id = ? AND e.mailbox_path = ? ORDER BY rank LIMIT 50 ``` Folder-view search now works fully offline, and tapping a result always opens the correct email since IDs come from the same local DB as `getEmail`. ## Verification - Added a unit test (`searchEmails filters by mailboxPath using local FTS5`) that inserts emails in two mailboxes, searches INBOX, and confirms only the INBOX email is returned. - Added a widget test (`folder search returns results from local cache without any network call`) that verifies results are returned without a network round-trip. - All 498 existing tests continue to pass. Closes #501
Sign in to join this conversation.