diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index baebae1f..8e862a12 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -182,18 +182,56 @@ export default function ComposeEmail({ cleanContent = '
No displayable content available
'; } + // Helper function to safely extract email information + const getSafeEmailInfo = (email: any) => { + const fromValue = email && email.from ? + (typeof email.from === 'object' && email.from.text) ? email.from.text : + (Array.isArray(email.from) && email.from[0]) ? + (email.from[0].name || email.from[0].address) : 'Unknown Sender' + : 'Unknown Sender'; + + const dateValue = email && email.date ? + new Date(email.date).toLocaleString() : new Date().toLocaleString(); + + const subjectValue = email && email.subject ? email.subject : 'No Subject'; + + const toValue = email && email.to ? + (typeof email.to === 'object' && email.to.text) ? email.to.text : + (Array.isArray(email.to)) ? email.to.map((t: any) => t.address || t.name || '').filter(Boolean).join(', ') : '' + : ''; + + const ccValue = email && email.cc ? + (typeof email.cc === 'object' && email.cc.text) ? email.cc.text : + (Array.isArray(email.cc) && email.cc.length > 0) ? + email.cc.map((c: any) => c.address || c.name || '').filter(Boolean).join(', ') : '' + : ''; + + return { from: fromValue, date: dateValue, subject: subjectValue, to: toValue, cc: ccValue }; + }; + + // Get info from both sources and combine + const decodedInfo = getSafeEmailInfo(decoded); + const emailInfo = getSafeEmailInfo(emailToProcess); + + // Use the most complete information available + const from = decodedInfo.from !== 'Unknown Sender' ? decodedInfo.from : emailInfo.from; + const date = decodedInfo.date; + const subject = decodedInfo.subject !== 'No Subject' ? decodedInfo.subject : emailInfo.subject; + const to = decodedInfo.to || emailInfo.to; + const cc = decodedInfo.cc || emailInfo.cc; + // Format the content based on reply type const quotedContent = type === 'forward' ? `
---------- Forwarded message ---------
- From: ${decoded.from || 'Unknown Sender'}
- Date: ${decoded.date ? decoded.date.toLocaleString() : new Date().toLocaleString()}
- Subject: ${decoded.subject || 'No Subject'}
- To: ${decoded.to || ''}
- ${decoded.cc ? `Cc: ${decoded.cc}
` : ''} + From: ${from}
+ Date: ${date}
+ Subject: ${subject}
+ To: ${to}
+ ${cc ? `Cc: ${cc}
` : ''}
- ${cleanContent} + ${cleanContent || '
No content available
'}
` : `