diff --git a/components/email/EmailPanel.tsx b/components/email/EmailPanel.tsx index 2f2ef02d..3dee9037 100644 --- a/components/email/EmailPanel.tsx +++ b/components/email/EmailPanel.tsx @@ -69,35 +69,30 @@ export default function EmailPanel({ const [isComposing, setIsComposing] = useState(false); const [composeType, setComposeType] = useState<'new' | 'reply' | 'reply-all' | 'forward'>('new'); - // Create a formatted version of the email content using the same formatter as ComposeEmail + // Create a formatted version of the email content const formattedEmail = useMemo(() => { if (!email) return null; try { - // Convert to the formatter message format - this is what ComposeEmail does - const formatterEmail: FormatterEmailMessage = { - id: email.id, - messageId: email.messageId, - subject: email.subject, - from: email.from || [], - to: email.to || [], - cc: email.cc || [], - bcc: email.bcc || [], - date: email.date, - content: email.content, - html: email.html, - text: email.text, - hasAttachments: email.hasAttachments || false - }; + // Handle different content structures + let content = ''; - // Get the formatted content - const formattedContent = email.content || email.html || email.text || ''; + if (typeof email.content === 'string') { + // Direct string content + content = email.content; + } else if (email.content && typeof email.content === 'object') { + // Object with text/html properties + content = email.content.html || email.content.text || ''; + } else { + // Fallback to html or text properties + content = email.html || email.text || ''; + } // Return a new email object with the formatted content return { ...email, - content: formattedContent, - formattedContent + content, + formattedContent: content }; } catch (error) { console.error('Error formatting email content:', error); diff --git a/components/email/EmailPreview.tsx b/components/email/EmailPreview.tsx index c0c82d40..e372f4e6 100644 --- a/components/email/EmailPreview.tsx +++ b/components/email/EmailPreview.tsx @@ -105,37 +105,33 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP .slice(0, 2); }; - // Format the email content using the same formatter as ComposeEmail + // Format the email content const formattedContent = useMemo(() => { if (!email) return ''; try { - // Convert to the formatter message format - same as what ComposeEmail does - const formatterEmail: FormatterEmailMessage = { - id: email.id, - messageId: email.messageId, - subject: email.subject, - from: email.from || [], - to: email.to || [], - cc: email.cc || [], - bcc: email.bcc || [], - date: email.date instanceof Date ? email.date : new Date(email.date), - content: email.content || '', - html: email.html, - text: email.text, - hasAttachments: email.hasAttachments || false - }; + // Get the content in order of preference + let content = ''; - // Get the formatted content - if already formatted content is provided, use that instead if (email.formattedContent) { - return email.formattedContent; + content = email.formattedContent; + } else if (typeof email.content === 'string') { + content = email.content; + } else if (email.content && typeof email.content === 'object') { + content = email.content.html || email.content.text || ''; + } else { + content = email.html || email.text || ''; } - // Otherwise sanitize the content for display - return sanitizeHtml(email.content || email.html || email.text || ''); + // Sanitize the content for display + return sanitizeHtml(content, { + ADD_TAGS: ['table', 'thead', 'tbody', 'tr', 'td', 'th'], + ADD_ATTR: ['target', 'rel', 'colspan', 'rowspan', 'style', 'class', 'id', 'border'], + ALLOW_DATA_ATTR: false + }); } catch (error) { console.error('Error formatting email content:', error); - return email.content || email.html || email.text || ''; + return ''; } }, [email]); @@ -241,7 +237,7 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP )} - {/* Email content - using the preformatted content */} + {/* Email content */}