feat: implement batch archiving of emails

This commit is contained in:
Linus Rath
2026-04-22 00:05:38 +02:00
parent 3ade1c6473
commit 3c9fa5dc25
5 changed files with 187 additions and 5 deletions
+38
View File
@@ -89,6 +89,7 @@ interface EmailStore {
batchMarkAsRead: (client: IJMAPClient, read: boolean) => Promise<void>;
batchDelete: (client: IJMAPClient, permanent?: boolean) => Promise<void>;
batchMoveToMailbox: (client: IJMAPClient, mailboxId: string) => Promise<void>;
batchArchive: (client: IJMAPClient) => Promise<void>;
// Spam operations
spamUndoCache: Map<string, { emailId: string; originalMailboxId: string; accountId?: string }>;
@@ -1190,6 +1191,43 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
}
},
batchArchive: async (client) => {
const { selectedEmailIds, emails, mailboxes, fetchMailboxes, fetchEmails, selectedMailbox } = get();
if (selectedEmailIds.size === 0) return;
const archiveMailbox = mailboxes.find(m => m.role === 'archive' || m.name.toLowerCase() === 'archive');
if (!archiveMailbox) return;
const mode = useSettingsStore.getState().archiveMode;
const archiveId = archiveMailbox.originalId || archiveMailbox.id;
const selected = emails.filter(e => selectedEmailIds.has(e.id));
if (selected.length === 0) return;
set({ isLoading: true, error: null });
try {
await client.batchArchiveEmails(
selected.map(e => ({ id: e.id, receivedAt: e.receivedAt })),
archiveId,
mode,
mailboxes,
archiveMailbox.accountId,
);
const remaining = emails.filter(e => !selectedEmailIds.has(e.id));
set({ emails: remaining, selectedEmailIds: new Set(), isLoading: false });
await fetchMailboxes(client);
await fetchEmails(client, selectedMailbox);
} catch (error) {
set({
error: error instanceof Error ? error.message : 'Failed to archive emails',
isLoading: false,
});
throw error;
}
},
// Spam operations
markAsSpam: async (client, emailId) => {
const { selectedMailbox, mailboxes, emails } = get();