panel 2 courier api restore

This commit is contained in:
alma 2025-04-26 10:23:17 +02:00
parent dab82e212b
commit 42615957ec

View File

@ -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 = '<div style="color: #666; font-style: italic;">Error processing original content</div>';
@ -175,7 +186,7 @@ export default function ComposeEmail({
processedContent = '<div style="color: #666; font-style: italic;">No content available</div>';
}
// Create a clean, well-formatted forwarded message
// Create a clean, well-formatted forwarded message with the original styles preserved
const forwardedContent = `
<div style="border-top: 1px solid #e5e7eb; padding-top: 20px; margin-top: 20px; color: #6b7280; font-size: 0.875rem;">
---------- Forwarded message ---------<br/>
@ -185,7 +196,7 @@ export default function ComposeEmail({
To: ${formatRecipients(initialEmail.to)}<br/>
${initialEmail.cc && initialEmail.cc.length ? `Cc: ${formatRecipients(initialEmail.cc)}<br/>` : ''}
</div>
<div style="margin-top: 10px; color: #374151;">
<div style="margin-top: 10px;">
${processedContent}
</div>
`;