courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 14:38:26 +02:00
parent 2f76050352
commit d6728947c6

View File

@ -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