From 3c81473239144c59fc349ff7bd4244ae77241b20 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 24 Apr 2025 17:03:03 +0200 Subject: [PATCH] mime change --- components/ComposeEmail.tsx | 271 +++++++++++++++++++----------------- 1 file changed, 145 insertions(+), 126 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 6cdeaf2a..f3280bd7 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -83,26 +83,45 @@ export default function ComposeEmail({ useEffect(() => { if (composeBodyRef.current && !isInitialized) { - // Initialize the content structure with both new reply area and original content in a single contentEditable div - const content = replyTo || forwardFrom ? ` -
-
- ${forwardFrom ? ` - ---------- Forwarded message ---------
- From: ${forwardFrom.from}
- Date: ${new Date(forwardFrom.date).toLocaleString()}
- Subject: ${forwardFrom.subject}
- To: ${forwardFrom.to}
- ${forwardFrom.cc ? `Cc: ${forwardFrom.cc}
` : ''} -
- ` : ` - On ${new Date(replyTo?.date || '').toLocaleString()}, ${replyTo?.from} wrote:
- `} -
- ${composeBody} -
-
- ` : ''; + let content = ''; + + if (replyTo) { + // For replies + content = ` +
+
+
+ On ${new Date(replyTo.date).toLocaleString()}, ${replyTo.from} wrote: +
+
+ ${composeBody} +
+
+ `; + } else if (forwardFrom) { + // For forwards + content = ` +
+
+
+ ---------- Forwarded message ---------
+ From: ${forwardFrom.from}
+ Date: ${new Date(forwardFrom.date).toLocaleString()}
+ Subject: ${forwardFrom.subject}
+ To: ${forwardFrom.to}
+ ${forwardFrom.cc ? `Cc: ${forwardFrom.cc}
` : ''} +
+
+ ${composeBody} +
+
+ `; + } else { + // For new messages + content = ` +
+ `; + } composeBodyRef.current.innerHTML = content; setIsInitialized(true); @@ -116,16 +135,20 @@ export default function ComposeEmail({ range.collapse(true); sel?.removeAllRanges(); sel?.addRange(range); + (composeArea as HTMLElement).focus(); } } }, [composeBody, replyTo, forwardFrom, isInitialized]); - // Modified input handler to work with the single contentEditable area const handleInput = (e: React.FormEvent) => { if (!composeBodyRef.current) return; const composeArea = composeBodyRef.current.querySelector('.compose-area'); if (composeArea) { - setComposeBody(composeArea.innerHTML); + const newContent = composeArea.innerHTML; + setComposeBody(newContent); + if (onBodyChange) { + onBodyChange(newContent); + } } }; @@ -143,12 +166,11 @@ export default function ComposeEmail({ } try { - // Read file as base64 const base64Content = await new Promise((resolve) => { const reader = new FileReader(); reader.onloadend = () => { const base64 = reader.result as string; - resolve(base64.split(',')[1]); // Remove data URL prefix + resolve(base64.split(',')[1]); }; reader.readAsDataURL(file); }); @@ -198,150 +220,147 @@ export default function ComposeEmail({
{/* To Field */}
- + setComposeTo(e.target.value)} - placeholder="recipient@example.com" - className="w-full mt-1 bg-white border-gray-300 text-gray-900" + placeholder="Recipients" + className="mt-1" />
- {/* CC/BCC Toggle Buttons */} -
- - -
- - {/* CC Field */} + {/* Cc Field */} {showCc && (
- + setComposeCc(e.target.value)} - placeholder="cc@example.com" - className="w-full mt-1 bg-white border-gray-300 text-gray-900" + placeholder="Carbon copy" + className="mt-1" />
)} - {/* BCC Field */} + {/* Bcc Field */} {showBcc && (
- + setComposeBcc(e.target.value)} - placeholder="bcc@example.com" - className="w-full mt-1 bg-white border-gray-300 text-gray-900" + placeholder="Blind carbon copy" + className="mt-1" />
)} {/* Subject Field */}
- + setComposeSubject(e.target.value)} - placeholder="Enter subject" - className="w-full mt-1 bg-white border-gray-300 text-gray-900" + placeholder="Subject" + className="mt-1" />
- {/* Message Body - Single contentEditable area with separated regions */} -
- + {/* Message Body */} +
- + onInput={handleInput} + className="h-full" + style={{ overflowY: 'auto' }} + /> +
+ + {/* Attachments */} + {attachments.length > 0 && ( +
+
+ {attachments.map((attachment, index) => ( +
+ + {attachment.name} + +
+ ))} +
+
+ )} + + {/* Action Buttons */} +
+
+ + {!showCc && ( + + )} + {!showBcc && ( + + )} +
+
+ +
- - {/* Modal Footer */} -
-
- {/* File Input for Attachments */} - - -
-
- - -
-
);