mail page ui correction maj compose 20 bis 10

This commit is contained in:
alma 2025-04-16 14:18:34 +02:00
parent f1befb1515
commit de4dfd0a7d

View File

@ -116,7 +116,6 @@ export async function GET() {
const allEmails: Email[] = [];
imap.once('ready', () => {
// First, get all mailboxes to find the correct folder names
imap.getBoxes((err, boxes) => {
if (err) {
console.error('Error getting mailboxes:', err);
@ -125,10 +124,7 @@ export async function GET() {
return;
}
// Log available mailboxes to see their structure
console.log('Available mailboxes:', Object.keys(boxes));
// For Infomaniak, common folder names are:
const foldersToCheck = ['INBOX', 'Sent', 'Trash', 'Drafts'];
let foldersProcessed = 0;
@ -154,13 +150,40 @@ export async function GET() {
return;
}
// Calculate the range for the last 20 messages
const start = Math.max(1, box.messages.total - 19);
const f = imap.seq.fetch(`${start}:${box.messages.total}`, {
const range = `${start}:${box.messages.total}`;
// Search for all messages in the range
imap.search(['ALL'], (err, results) => {
if (err) {
console.error(`Search error in ${folderName}:`, err);
foldersProcessed++;
if (foldersProcessed === foldersToCheck.length) {
finishProcessing();
}
return;
}
// Filter results to get only the last 20 messages
const messageNumbers = results
.sort((a, b) => b - a) // Sort in descending order
.slice(0, 20); // Take only the last 20
if (messageNumbers.length === 0) {
foldersProcessed++;
if (foldersProcessed === foldersToCheck.length) {
finishProcessing();
}
return;
}
const f = imap.fetch(messageNumbers, {
bodies: ['HEADER.FIELDS (FROM TO SUBJECT DATE)', 'TEXT'],
struct: true
});
f.on('message', (msg) => {
f.on('message', (msg, seqno) => {
const email: any = {
id: '',
from: '',
@ -214,9 +237,10 @@ export async function GET() {
}
});
});
});
};
// Process each folder sequentially to avoid IMAP connection issues
// Process folders sequentially
foldersToCheck.forEach(folder => processFolder(folder));
});
});