courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 15:34:32 +02:00
parent 3b455d33d4
commit 427392f0d0

View File

@ -272,13 +272,15 @@ export async function getEmails(
perPage: number = 20, perPage: number = 20,
accountId?: string accountId?: string
): Promise<EmailListResult> { ): Promise<EmailListResult> {
let client: ImapFlow | undefined;
try { try {
// Extract base folder name (remove accountId suffix if present) // Extract base folder name (remove accountId suffix if present)
const baseFolder = folder.split('-')[0]; const baseFolder = folder.split('-')[0];
console.log(`Fetching emails for folder: ${folder} (base: ${baseFolder})`); console.log(`Fetching emails for folder: ${folder} (base: ${baseFolder})`);
// Get IMAP connection // Get IMAP connection
const client = await getImapConnection(userId, accountId); client = await getImapConnection(userId, accountId);
if (!client) { if (!client) {
throw new Error('Failed to establish IMAP connection'); throw new Error('Failed to establish IMAP connection');
} }
@ -379,13 +381,15 @@ export async function getEmails(
console.error('Error fetching emails:', error); console.error('Error fetching emails:', error);
throw error; throw error;
} finally { } finally {
if (client) {
try { try {
await client?.mailboxClose(); await client.mailboxClose();
} catch (error) { } catch (error) {
console.error('Error closing mailbox:', error); console.error('Error closing mailbox:', error);
} }
} }
} }
}
/** /**
* Get a single email with full content * Get a single email with full content