From 638a2ee895632f24e626979eff9ae3cbf76cd154 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 26 Apr 2025 11:51:28 +0200 Subject: [PATCH] courrier clean 2 --- components/ComposeEmail.tsx | 325 ++++++++++++++++++++---------------- 1 file changed, 177 insertions(+), 148 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index abe0d6ed..3eb3acad 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -86,6 +86,7 @@ export default function ComposeEmail({ const [sending, setSending] = useState(false); const editorRef = useRef(null); const fileInputRef = useRef(null); + const composeBodyRef = useRef(null); useEffect(() => { if (editorRef.current) { @@ -101,7 +102,19 @@ export default function ComposeEmail({ const formattedEmail = formatEmailForReply(replyTo as any, 'reply'); setComposeTo(formattedEmail.to); setComposeSubject(formattedEmail.subject); - setComposeBody(formattedEmail.body); + + // Use the body but preserve the original UI styling + // Extract just the content portion from the client formatter output + // and apply the original styling + let bodyContent = formattedEmail.body; + + // Apply DOMPurify to the content for safety + bodyContent = DOMPurify.sanitize(bodyContent, { + ADD_TAGS: ['style'], + FORBID_TAGS: ['script', 'iframe'] + }); + + setComposeBody(bodyContent); // Show CC if needed for reply-all if (formattedEmail.cc) { @@ -116,36 +129,49 @@ export default function ComposeEmail({ // Initialize forwarded email content const initializeForwardedEmail = async (email: any) => { - console.log('Initializing forwarded email:', email); + if (!email) return; + console.log('Initializing forwarded email:', email); + // Use our client-side formatter const formattedEmail = formatEmailForForward(email); // Set the formatted subject with Fwd: prefix setComposeSubject(formattedEmail.subject); - // Get the email content and create a forward with proper formatting - let finalContent = ''; + // Create header for forwarded email - use the original styling + const headerHtml = formattedEmail.headerHtml; - // Add the email header with proper styling - finalContent += formattedEmail.headerHtml; + // Prepare content + let contentHtml = '
No content available
'; - // Add the original content if (email.content) { - finalContent += email.content; + // Sanitize the content + contentHtml = DOMPurify.sanitize(email.content, { + ADD_TAGS: ['style'], + FORBID_TAGS: ['script', 'iframe'] + }); } else if (email.html) { - finalContent += email.html; + contentHtml = DOMPurify.sanitize(email.html, { + ADD_TAGS: ['style'], + FORBID_TAGS: ['script', 'iframe'] + }); } else if (email.text) { - finalContent += `
${email.text}
`; + contentHtml = `
${email.text}
`; } else if (email.body) { - finalContent += email.body; - } else { - finalContent += `
- No content available -
`; + contentHtml = DOMPurify.sanitize(email.body, { + ADD_TAGS: ['style'], + FORBID_TAGS: ['script', 'iframe'] + }); } - setComposeBody(finalContent); + // Set body with header and content, preserving the original UI layout + setComposeBody(` + ${headerHtml} +
+ ${contentHtml} +
+ `); }; if (!showCompose) return null; @@ -162,99 +188,106 @@ export default function ComposeEmail({ } }; + // Body input area + const renderBodyInput = () => ( +
{ + const target = e.target as HTMLDivElement; + setComposeBody(target.innerHTML); + }} + ref={composeBodyRef} + style={{ direction: 'ltr' }} + /> + ); + return ( -
- - - - {replyTo ? 'Reply' : forwardFrom ? 'Forward' : 'New Message'} - - - - -
-
- To: - setComposeTo(e.target.value)} - className="border-0 focus-visible:ring-0" - placeholder="recipient@example.com" - /> -
- - {showCc && ( -
- Cc: - setComposeCc(e.target.value)} - className="border-0 focus-visible:ring-0" - placeholder="cc@example.com" - /> -
- )} - - {showBcc && ( -
- Bcc: - setComposeBcc(e.target.value)} - className="border-0 focus-visible:ring-0" - placeholder="bcc@example.com" - /> -
- )} - -
- Subject: - setComposeSubject(e.target.value)} - className="border-0 focus-visible:ring-0" - placeholder="Subject" - /> -
- -
- {!showCc && ( - - )} - {!showBcc && ( - - )} -
+
+ + +
+
+ To: + setComposeTo(e.target.value)} + />
-
setComposeBody(e.currentTarget.innerHTML)} - /> + {showCc && ( +
+ Cc: + setComposeCc(e.target.value)} + /> +
+ )} + + {showBcc && ( +
+ Bcc: + setComposeBcc(e.target.value)} + /> +
+ )} + +
+ + +
+ +
+ Subject: + setComposeSubject(e.target.value)} + /> +
+ + {renderBodyInput()} {attachments.length > 0 && ( -
-

Attachments

+
+

Attachments:

- {attachments.map((attachment, index) => ( -
- {attachment.name} - +
))}
)} - - -
- - -
+
+ + +
- - -
+ +
+ + + ); } \ No newline at end of file