diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index 27c52690..da7006a4 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -6,6 +6,7 @@ import { X, Paperclip, ChevronDown, ChevronUp, SendHorizontal, Loader2 } from 'l import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'; +import DOMPurify from 'isomorphic-dompurify'; interface ComposeEmailProps { initialEmail?: EmailMessage | null; @@ -126,7 +127,7 @@ export default function ComposeEmail({ ).join(', '); }; - // Initialize forwarded email + // Initialize forwarded email with improved style handling const initializeForwardedEmail = async () => { if (!initialEmail) { console.error('No email available for forwarding'); @@ -145,14 +146,14 @@ export default function ComposeEmail({ setSubject(formattedSubject); - // Process the email content using the API + // Process the email content const emailContent = initialEmail.content || ''; let processedContent = ''; // Only attempt to parse if we have content if (emailContent.trim()) { try { - // Send to server API for parsing + // Parse email on the server const response = await fetch('/api/parse-email', { method: 'POST', headers: { @@ -166,7 +167,17 @@ export default function ComposeEmail({ throw new Error(data.error || 'Failed to parse email'); } - processedContent = data.html || data.text || ''; + // Use DOMPurify to sanitize the HTML but preserve style tags + const htmlContent = data.html || data.text || ''; + + // Configure DOMPurify to keep certain tags including style + const sanitizedContent = DOMPurify.sanitize(htmlContent, { + ADD_TAGS: ['style', 'meta', 'link'], + ADD_ATTR: ['id', 'class', 'style'], + WHOLE_DOCUMENT: false + }); + + processedContent = sanitizedContent; } catch (error) { console.error('Error parsing email content:', error); processedContent = '