panel 2 courier api restore

This commit is contained in:
alma 2025-04-25 18:27:59 +02:00
parent 8a4a18c1c7
commit 6d319af061

View File

@ -159,9 +159,13 @@ export async function GET(request: Request) {
}
console.log('Fetching messages with options:', fetchOptions);
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, fetchOptions);
const fetchPromises = [];
for (let i = adjustedStart; i <= adjustedEnd; i++) {
fetchPromises.push(client.fetchOne(i, fetchOptions));
}
const results = await Promise.all(fetchPromises);
for await (const message of messages) {
for await (const message of results) {
console.log('Processing message ID:', message.uid);
const emailData: any = {
id: message.uid,
@ -209,12 +213,17 @@ export async function GET(request: Request) {
};
return NextResponse.json(responseData);
} finally {
try {
await client.logout();
console.log('IMAP client logged out');
} catch (e) {
console.error('Error during logout:', e);
} catch (error) {
if (error.source === 'timeout') {
// Retry with exponential backoff
return retryOperation(operation, attempt + 1);
} else if (error.source === 'auth') {
// Prompt for credentials refresh
return NextResponse.json({ error: 'Authentication failed', code: 'AUTH_ERROR' });
} else {
// General error handling
console.error('Operation failed:', error);
return NextResponse.json({ error: 'Operation failed', details: error.message });
}
}
} catch (error) {
@ -224,4 +233,15 @@ export async function GET(request: Request) {
{ status: 500 }
);
}
}
export async function POST(request: Request, { params }: { params: { id: string } }) {
// Mark as read logic...
// Invalidate cache entries for this folder
Object.keys(emailListCache).forEach(key => {
if (key.includes(`${userId}:${folderName}`)) {
delete emailListCache[key];
}
});
}