From d6728947c64febaeba932f7c88c765c2c295546d Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 28 Apr 2025 14:38:26 +0200 Subject: [PATCH] courrier multi account restore compose --- lib/services/email-service.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/services/email-service.ts b/lib/services/email-service.ts index 7c69ec35..0f76b18a 100644 --- a/lib/services/email-service.ts +++ b/lib/services/email-service.ts @@ -279,7 +279,7 @@ export async function getEmails( ? `email:list:${userId}:${accountId}:${folder}:${page}:${perPage}:${searchQuery}` : `email:list:${userId}:${folder}:${page}:${perPage}:${searchQuery}`; - const cached = await getCachedEmailList(cacheKey); + const cached = await getCachedEmailList(userId, accountId || 'default', folder, page, perPage); if (cached) { console.log(`Using cached email list for ${cacheKey}`); return cached; @@ -339,7 +339,9 @@ export async function getEmails( deleted: message.flags.has('\\Deleted') }, size: message.size || 0, - hasAttachments: message.bodyStructure?.childNodes?.some(node => node.disposition === 'attachment') || false + hasAttachments: message.bodyStructure?.childNodes?.some(node => node.disposition === 'attachment') || false, + folder: folder, + contentFetched: false }; emails.push(email); } @@ -355,7 +357,7 @@ export async function getEmails( }; // Cache the result - await cacheEmailList(cacheKey, result); + await cacheEmailList(userId, accountId || 'default', folder, page, perPage, result); return result; } catch (error) { @@ -391,14 +393,15 @@ export async function getEmailContent( const message = await client.fetchOne(emailId, { source: true, envelope: true, - flags: true + flags: true, + size: true }); if (!message) { throw new Error('Email not found'); } - const { source, envelope, flags } = message; + const { source, envelope, flags, size } = message; // Parse the email content, ensuring all styles and structure are preserved const parsedEmail = await simpleParser(source.toString(), { @@ -412,7 +415,7 @@ export async function getEmailContent( // Preserve the raw HTML exactly as it was in the original email const rawHtml = parsedEmail.html || ''; - const email = { + const email: EmailMessage = { id: emailId, messageId: envelope.messageId, subject: envelope.subject || "(No Subject)", @@ -446,13 +449,12 @@ export async function getEmailContent( contentType: att.contentType, size: att.size || 0 })), - // Preserve the exact raw HTML to maintain all styling html: rawHtml, text: parsedEmail.text || undefined, - // For content field, prioritize using the raw HTML to preserve all styling content: rawHtml || parsedEmail.text || '', folder, - contentFetched: true + contentFetched: true, + size: size || 0 }; // Cache the email content