panel 2 courier

This commit is contained in:
alma 2025-04-25 11:32:17 +02:00
parent 90d9aaafd9
commit 5f17baf88e
2 changed files with 22 additions and 10 deletions

View File

@ -77,8 +77,10 @@ export async function GET(request: Request) {
envelope: true,
flags: true,
bodyStructure: true,
source: true, // Get the full email source
bodyParts: ['text/plain', 'text/html'] // Get both text and HTML content
bodyParts: [
'text/plain',
'text/html'
]
});
for await (const message of messages) {
@ -86,7 +88,8 @@ export async function GET(request: Request) {
let content = '';
if (message.bodyParts) {
// Prefer HTML content if available
content = message.bodyParts.get('text/html')?.toString() || message.bodyParts.get('text/plain')?.toString() || '';
content = message.bodyParts.get('text/html')?.toString() ||
message.bodyParts.get('text/plain')?.toString() || '';
}
result.push({
@ -101,8 +104,7 @@ export async function GET(request: Request) {
folder: mailbox.path,
hasAttachments: message.bodyStructure?.type === 'multipart',
flags: Array.from(message.flags),
content: content,
source: message.source?.toString() || '' // Include full email source for parsing
content: content
});
}

View File

@ -500,22 +500,32 @@ export default function CourrierPage() {
try {
console.log('Checking for stored credentials...');
const response = await fetch('/api/courrier');
const data = await response.json();
if (!response.ok) {
const errorData = await response.json();
console.log('API response error:', errorData);
if (errorData.error === 'No stored credentials found') {
console.log('API response error:', data);
if (data.error === 'No mail credentials found. Please configure your email account.') {
console.log('No credentials found, redirecting to login...');
router.push('/courrier/login');
return;
}
throw new Error(errorData.error || 'Failed to check credentials');
if (data.error === 'Unauthorized') {
console.log('User not authenticated, redirecting to auth...');
router.push('/api/auth/signin');
return;
}
setError(data.error || 'Failed to check credentials');
setLoading(false);
return;
}
// If we get here, credentials are valid and we have emails
console.log('Credentials verified, loading emails...');
setLoading(false);
loadEmails();
} catch (err) {
console.error('Error checking credentials:', err);
setError(err instanceof Error ? err.message : 'Failed to check credentials');
setError('Failed to connect to mail server. Please try again later.');
setLoading(false);
}
};