mail page ui correction maj compose 20 bis 17
This commit is contained in:
parent
a1b39f3169
commit
119180c214
@ -113,10 +113,10 @@ export async function GET() {
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const allEmails: Email[] = [];
|
||||
// Create a map to store emails by folder
|
||||
const emailsByFolder: { [key: string]: any[] } = {};
|
||||
|
||||
imap.once('ready', () => {
|
||||
// Get all mailboxes first
|
||||
imap.getBoxes((err, boxes) => {
|
||||
if (err) {
|
||||
console.error('Error getting mailboxes:', err);
|
||||
@ -125,17 +125,19 @@ export async function GET() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list of available mailboxes
|
||||
const availableMailboxes = Object.keys(boxes);
|
||||
console.log('Available mailboxes:', availableMailboxes);
|
||||
|
||||
// These are the folders we want to process based on your IMAP structure
|
||||
// Process only the mailboxes we want to use
|
||||
const foldersToCheck = ['INBOX', 'Sent', 'Trash', 'Spam', 'Drafts', 'Archives', 'Archive'];
|
||||
let foldersProcessed = 0;
|
||||
|
||||
const processFolder = (folderName: string) => {
|
||||
console.log(`Processing folder: ${folderName}`);
|
||||
|
||||
// Initialize array for this folder
|
||||
emailsByFolder[folderName] = [];
|
||||
|
||||
imap.openBox(folderName, false, (err, box) => {
|
||||
if (err) {
|
||||
console.error(`Error opening ${folderName}:`, err);
|
||||
@ -156,8 +158,10 @@ export async function GET() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Search for all messages in the folder
|
||||
imap.search(['ALL'], (err, results) => {
|
||||
// Search for messages in this folder
|
||||
const searchCriteria = ['ALL'];
|
||||
|
||||
imap.search(searchCriteria, (err, results) => {
|
||||
if (err) {
|
||||
console.error(`Search error in ${folderName}:`, err);
|
||||
foldersProcessed++;
|
||||
@ -167,7 +171,6 @@ export async function GET() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the most recent messages (up to 20)
|
||||
const messageNumbers = results
|
||||
.sort((a, b) => b - a)
|
||||
.slice(0, 20);
|
||||
@ -195,7 +198,7 @@ export async function GET() {
|
||||
starred: false,
|
||||
body: '',
|
||||
to: '',
|
||||
folder: folderName // Keep exact folder name
|
||||
folder: folderName
|
||||
};
|
||||
|
||||
msg.on('body', (stream, info) => {
|
||||
@ -223,7 +226,8 @@ export async function GET() {
|
||||
});
|
||||
|
||||
msg.once('end', () => {
|
||||
allEmails.push(email);
|
||||
// Add email to its folder's array
|
||||
emailsByFolder[folderName].push(email);
|
||||
});
|
||||
});
|
||||
|
||||
@ -232,7 +236,7 @@ export async function GET() {
|
||||
});
|
||||
|
||||
f.once('end', () => {
|
||||
console.log(`Finished processing ${folderName}, emails found: ${allEmails.length}`);
|
||||
console.log(`Finished processing ${folderName}, emails found: ${emailsByFolder[folderName].length}`);
|
||||
foldersProcessed++;
|
||||
if (foldersProcessed === foldersToCheck.length) {
|
||||
finishProcessing();
|
||||
@ -248,7 +252,14 @@ export async function GET() {
|
||||
});
|
||||
|
||||
function finishProcessing() {
|
||||
// Combine all emails from all folders
|
||||
const allEmails = Object.entries(emailsByFolder).flatMap(([folder, emails]) => emails);
|
||||
|
||||
console.log('Emails by folder:', Object.fromEntries(
|
||||
Object.entries(emailsByFolder).map(([folder, emails]) => [folder, emails.length])
|
||||
));
|
||||
console.log('All folders processed, total emails:', allEmails.length);
|
||||
|
||||
const response = {
|
||||
emails: allEmails,
|
||||
mailUrl: process.env.NEXTCLOUD_URL ? `${process.env.NEXTCLOUD_URL}/apps/mail/` : null
|
||||
|
||||
Loading…
Reference in New Issue
Block a user