From ab57966a9439a576d0ee53e0e6a9b0ac7c49f57a Mon Sep 17 00:00:00 2001 From: Linus Rath Date: Sat, 11 Apr 2026 23:21:12 +0200 Subject: [PATCH] fix: search all folders when filtering emails by tag #175 --- stores/email-store.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stores/email-store.ts b/stores/email-store.ts index 42630eac..ca3173b1 100644 --- a/stores/email-store.ts +++ b/stores/email-store.ts @@ -312,7 +312,9 @@ export const useEmailStore = create((set, get) => ({ const { selectedKeyword } = get(); const keywordFilter = selectedKeyword ? `$label:${selectedKeyword}` : undefined; - const result = await client.getEmails(jmapMailboxId, accountId, emailsPerPage, 0, keywordFilter); + // When filtering by tag, omit the mailbox constraint so emails across + // all folders that carry the tag are returned. + const result = await client.getEmails(selectedKeyword ? undefined : jmapMailboxId, accountId, emailsPerPage, 0, keywordFilter); set({ emails: result.emails, hasMoreEmails: result.hasMore, @@ -372,7 +374,8 @@ export const useEmailStore = create((set, get) => ({ // Use originalId for JMAP queries (shared mailboxes use namespaced IDs in the store) const jmapMailboxId = mailbox?.originalId || selectedMailbox; - result = await client.getEmails(jmapMailboxId, accountId, emailsPerPage, position, selectedKeyword ? `$label:${selectedKeyword}` : undefined); + // When filtering by tag, omit the mailbox constraint (same rationale as fetchEmails). + result = await client.getEmails(selectedKeyword ? undefined : jmapMailboxId, accountId, emailsPerPage, position, selectedKeyword ? `$label:${selectedKeyword}` : undefined); } // Use fresh state when merging to avoid overwriting concurrent updates