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) => {
|
return new Promise((resolve) => {
|
||||||
const allEmails: Email[] = [];
|
// Create a map to store emails by folder
|
||||||
|
const emailsByFolder: { [key: string]: any[] } = {};
|
||||||
|
|
||||||
imap.once('ready', () => {
|
imap.once('ready', () => {
|
||||||
// Get all mailboxes first
|
|
||||||
imap.getBoxes((err, boxes) => {
|
imap.getBoxes((err, boxes) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error getting mailboxes:', err);
|
console.error('Error getting mailboxes:', err);
|
||||||
@ -125,17 +125,19 @@ export async function GET() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the list of available mailboxes
|
|
||||||
const availableMailboxes = Object.keys(boxes);
|
const availableMailboxes = Object.keys(boxes);
|
||||||
console.log('Available mailboxes:', availableMailboxes);
|
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'];
|
const foldersToCheck = ['INBOX', 'Sent', 'Trash', 'Spam', 'Drafts', 'Archives', 'Archive'];
|
||||||
let foldersProcessed = 0;
|
let foldersProcessed = 0;
|
||||||
|
|
||||||
const processFolder = (folderName: string) => {
|
const processFolder = (folderName: string) => {
|
||||||
console.log(`Processing folder: ${folderName}`);
|
console.log(`Processing folder: ${folderName}`);
|
||||||
|
|
||||||
|
// Initialize array for this folder
|
||||||
|
emailsByFolder[folderName] = [];
|
||||||
|
|
||||||
imap.openBox(folderName, false, (err, box) => {
|
imap.openBox(folderName, false, (err, box) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(`Error opening ${folderName}:`, err);
|
console.error(`Error opening ${folderName}:`, err);
|
||||||
@ -156,8 +158,10 @@ export async function GET() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for all messages in the folder
|
// Search for messages in this folder
|
||||||
imap.search(['ALL'], (err, results) => {
|
const searchCriteria = ['ALL'];
|
||||||
|
|
||||||
|
imap.search(searchCriteria, (err, results) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(`Search error in ${folderName}:`, err);
|
console.error(`Search error in ${folderName}:`, err);
|
||||||
foldersProcessed++;
|
foldersProcessed++;
|
||||||
@ -167,7 +171,6 @@ export async function GET() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the most recent messages (up to 20)
|
|
||||||
const messageNumbers = results
|
const messageNumbers = results
|
||||||
.sort((a, b) => b - a)
|
.sort((a, b) => b - a)
|
||||||
.slice(0, 20);
|
.slice(0, 20);
|
||||||
@ -195,7 +198,7 @@ export async function GET() {
|
|||||||
starred: false,
|
starred: false,
|
||||||
body: '',
|
body: '',
|
||||||
to: '',
|
to: '',
|
||||||
folder: folderName // Keep exact folder name
|
folder: folderName
|
||||||
};
|
};
|
||||||
|
|
||||||
msg.on('body', (stream, info) => {
|
msg.on('body', (stream, info) => {
|
||||||
@ -223,7 +226,8 @@ export async function GET() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
msg.once('end', () => {
|
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', () => {
|
f.once('end', () => {
|
||||||
console.log(`Finished processing ${folderName}, emails found: ${allEmails.length}`);
|
console.log(`Finished processing ${folderName}, emails found: ${emailsByFolder[folderName].length}`);
|
||||||
foldersProcessed++;
|
foldersProcessed++;
|
||||||
if (foldersProcessed === foldersToCheck.length) {
|
if (foldersProcessed === foldersToCheck.length) {
|
||||||
finishProcessing();
|
finishProcessing();
|
||||||
@ -248,7 +252,14 @@ export async function GET() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function finishProcessing() {
|
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);
|
console.log('All folders processed, total emails:', allEmails.length);
|
||||||
|
|
||||||
const response = {
|
const response = {
|
||||||
emails: allEmails,
|
emails: allEmails,
|
||||||
mailUrl: process.env.NEXTCLOUD_URL ? `${process.env.NEXTCLOUD_URL}/apps/mail/` : null
|
mailUrl: process.env.NEXTCLOUD_URL ? `${process.env.NEXTCLOUD_URL}/apps/mail/` : null
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user