From a35cf88c707b8dab5fc585530a5c296edee18f8f Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 28 Apr 2025 17:27:52 +0200 Subject: [PATCH] courrier multi account restore compose --- app/courrier/page.tsx | 17 ++++++++++------- lib/services/email-service.ts | 7 ++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index c8da2b8a..4b134c61 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -582,25 +582,28 @@ export default function CourrierPage() { account.folders = ['INBOX', 'SENT', 'DRAFTS', 'TRASH']; } + // Remove account prefix if present + const baseFolder = folder.includes(':') ? folder.split(':')[1] : folder; + // Use the exact folder name from the account's folders list - if (!account.folders.includes(folder)) { - console.warn(`Folder ${folder} not found in account ${accountId}, defaulting to INBOX`); + if (!account.folders.includes(baseFolder)) { + console.warn(`Folder ${baseFolder} not found in account ${accountId}, defaulting to INBOX`); toast({ title: "Folder not found", - description: `The folder ${folder} does not exist for this account. Defaulting to INBOX.`, + description: `The folder ${baseFolder} does not exist for this account. Defaulting to INBOX.`, variant: "destructive", }); folder = 'INBOX'; // Default to INBOX if folder doesn't exist } - // Update selected folders state + // Update selected folders state with the full prefixed folder name setSelectedFolders(prev => ({ ...prev, - [accountId]: folder + [accountId]: `${accountId}:${folder}` })); - // Change to the selected folder - changeFolder(folder, accountId); + // Change to the selected folder with account prefix + changeFolder(`${accountId}:${folder}`, accountId); } else { // For all accounts view, use the original folder name changeFolder(folder, accountId); diff --git a/lib/services/email-service.ts b/lib/services/email-service.ts index 861f1577..c938b169 100644 --- a/lib/services/email-service.ts +++ b/lib/services/email-service.ts @@ -608,7 +608,12 @@ export async function getMailboxes(client: ImapFlow, accountId?: string): Promis try { const mailboxes = await client.list(); - // Return the exact folder names from IMAP without any mapping + // If we have an accountId, prefix the folder names to prevent namespace collisions + if (accountId) { + return mailboxes.map(mailbox => `${accountId}:${mailbox.path}`); + } + + // For backward compatibility, return unprefixed names when no accountId return mailboxes.map(mailbox => mailbox.path); } catch (error) { console.error('Error fetching mailboxes:', error);