mail page ui correction maj compose 20 bis 18 1
This commit is contained in:
parent
119180c214
commit
acd562b310
@ -113,7 +113,6 @@ export async function GET() {
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// Create a map to store emails by folder
|
||||
const emailsByFolder: { [key: string]: any[] } = {};
|
||||
|
||||
imap.once('ready', () => {
|
||||
@ -121,21 +120,19 @@ export async function GET() {
|
||||
if (err) {
|
||||
console.error('Error getting mailboxes:', err);
|
||||
imap.end();
|
||||
resolve(NextResponse.json({ emails: [], error: 'Failed to get mailboxes' }));
|
||||
resolve(NextResponse.json({ emails: {}, error: 'Failed to get mailboxes' }));
|
||||
return;
|
||||
}
|
||||
|
||||
const availableMailboxes = Object.keys(boxes);
|
||||
console.log('Available mailboxes:', availableMailboxes);
|
||||
|
||||
// Process only the mailboxes we want to use
|
||||
// Only process these specific folders
|
||||
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) => {
|
||||
@ -158,10 +155,7 @@ export async function GET() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Search for messages in this folder
|
||||
const searchCriteria = ['ALL'];
|
||||
|
||||
imap.search(searchCriteria, (err, results) => {
|
||||
imap.search(['ALL'], (err, results) => {
|
||||
if (err) {
|
||||
console.error(`Search error in ${folderName}:`, err);
|
||||
foldersProcessed++;
|
||||
@ -226,7 +220,6 @@ export async function GET() {
|
||||
});
|
||||
|
||||
msg.once('end', () => {
|
||||
// Add email to its folder's array
|
||||
emailsByFolder[folderName].push(email);
|
||||
});
|
||||
});
|
||||
@ -246,22 +239,17 @@ export async function GET() {
|
||||
});
|
||||
};
|
||||
|
||||
// Process each folder sequentially
|
||||
foldersToCheck.forEach(folder => processFolder(folder));
|
||||
});
|
||||
});
|
||||
|
||||
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,
|
||||
emailsByFolder: emailsByFolder,
|
||||
mailUrl: process.env.NEXTCLOUD_URL ? `${process.env.NEXTCLOUD_URL}/apps/mail/` : null
|
||||
};
|
||||
imap.end();
|
||||
@ -271,7 +259,7 @@ export async function GET() {
|
||||
imap.once('error', (err) => {
|
||||
console.error('IMAP error:', err);
|
||||
resolve(NextResponse.json({
|
||||
emails: [],
|
||||
emailsByFolder: {},
|
||||
error: 'IMAP connection error'
|
||||
}));
|
||||
});
|
||||
@ -281,7 +269,7 @@ export async function GET() {
|
||||
} catch (error) {
|
||||
console.error('Error in mail API:', error);
|
||||
return NextResponse.json({
|
||||
emails: [],
|
||||
emailsByFolder: {},
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
});
|
||||
}
|
||||
|
||||
1091
app/mail/page.tsx
1091
app/mail/page.tsx
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user