courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 14:35:48 +02:00
parent 1506cc7390
commit 181375fe08

View File

@ -292,16 +292,19 @@ export async function getEmails(
}
try {
// Select the mailbox
await client.mailboxOpen(folder);
// Select the mailbox and wait for it to be fully opened
const mailbox = await client.mailboxOpen(folder);
if (!mailbox) {
throw new Error(`Failed to open mailbox ${folder}`);
}
// Get total count
const totalEmails = await client.mailbox.messages.total;
// Get total count from the mailbox object
const totalEmails = mailbox.exists || 0;
const totalPages = Math.ceil(totalEmails / perPage);
// Calculate range for this page
const start = (page - 1) * perPage + 1;
const end = Math.min(start + perPage - 1, totalEmails);
const start = Math.max(1, totalEmails - (page * perPage) + 1);
const end = Math.max(1, totalEmails - ((page - 1) * perPage));
// Fetch messages
const messages = await client.fetch(`${start}:${end}`, {
@ -310,9 +313,7 @@ export async function getEmails(
bodyStructure: true,
internalDate: true,
size: true,
bodyParts: [
{ part: 'TEXT', query: { headers: true } }
]
bodyParts: ['HEADER']
});
// Process messages
@ -320,8 +321,14 @@ export async function getEmails(
for await (const message of messages) {
const email: EmailMessage = {
id: message.uid.toString(),
from: message.envelope.from[0]?.address || '',
to: message.envelope.to.map(addr => addr.address).join(', '),
from: message.envelope.from.map(addr => ({
name: addr.name || '',
address: addr.address
})),
to: message.envelope.to.map(addr => ({
name: addr.name || '',
address: addr.address
})),
subject: message.envelope.subject || '',
date: message.internalDate,
flags: {