diff --git a/app/[section]/page.tsx b/app/[section]/page.tsx index 185849b3..0736fa5b 100644 --- a/app/[section]/page.tsx +++ b/app/[section]/page.tsx @@ -11,7 +11,7 @@ const menuItems = { } export default async function SectionPage({ params }: { params: { section: string } }) { - const { section } = await Promise.resolve(params); + const { section } = params; const iframeUrl = menuItems[section as keyof typeof menuItems] if (!iframeUrl) { diff --git a/app/api/courrier/[id]/mark-read/route.ts b/app/api/courrier/[id]/mark-read/route.ts index 66022b10..7cea058d 100644 --- a/app/api/courrier/[id]/mark-read/route.ts +++ b/app/api/courrier/[id]/mark-read/route.ts @@ -39,8 +39,8 @@ export async function POST( return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } - // Properly await the params object before accessing its properties - const { id: emailId } = await Promise.resolve(params); + // No need to await Promise.resolve(), params is already an object + const { id: emailId } = params; if (!emailId) { return NextResponse.json({ error: 'Email ID is required' }, { status: 400 }); } diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index 230cd6f5..6849e377 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -93,6 +93,45 @@ export default function ComposeEmail({ } }, [initialEmail, type]); + // Helper functions for formatting the forwarded message - moved outside try block + + // Format date for the forwarded message header + const formatDate = (date: Date | null): string => { + if (!date) return ''; + try { + return date.toLocaleString('en-US', { + weekday: 'short', + year: 'numeric', + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' + }); + } catch (e) { + return date.toString(); + } + }; + + // Format sender address in a readable format + const formatSender = (from: Array<{name?: string, address: string}> | undefined): string => { + if (!from || from.length === 0) return 'Unknown'; + return from.map(sender => + sender.name && sender.name !== sender.address + ? `${sender.name} <${sender.address}>` + : sender.address + ).join(', '); + }; + + // Format recipient addresses in a readable format + const formatRecipients = (recipients: Array<{name?: string, address: string}> | undefined): string => { + if (!recipients || recipients.length === 0) return ''; + return recipients.map(recipient => + recipient.name && recipient.name !== recipient.address + ? `${recipient.name} <${recipient.address}>` + : recipient.address + ).join(', '); + }; + // New function to initialize forwarded email using same approach as Panel 3 const initializeForwardedEmail = async () => { if (!initialEmail) { @@ -112,68 +151,45 @@ export default function ComposeEmail({ setSubject(formattedSubject); - // Format date for the forwarded message header - const formatDate = (date: Date | null): string => { - if (!date) return ''; - try { - return date.toLocaleString('en-US', { - weekday: 'short', - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }); - } catch (e) { - return date.toString(); - } - }; - // Create a forwarded message header with proper formatting const headerContent = `
---------- Forwarded message ---------
-From: ${initialEmail.from || ''}
+From: ${formatSender(initialEmail.from)}
Date: ${formatDate(initialEmail.date)}
Subject: ${initialEmail.subject || ''}
-To: ${initialEmail.to || ''}
+To: ${formatRecipients(initialEmail.to)}
---------- Forwarded message ---------
-From: ${initialEmail.from || ''}
-Date: ${formatDate(initialEmail.date)}
+From: ${initialEmail.from ? formatSender(initialEmail.from) : 'Unknown'}
+Date: ${initialEmail.date ? formatDate(initialEmail.date) : ''}
Subject: ${initialEmail.subject || ''}
-To: ${initialEmail.to || ''}
+To: ${initialEmail.to ? formatRecipients(initialEmail.to) : ''}