diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx
index 8c70cae8..f87b48f4 100644
--- a/components/ComposeEmail.tsx
+++ b/components/ComposeEmail.tsx
@@ -86,6 +86,8 @@ export default function ComposeEmail({
useEffect(() => {
if (replyTo || forwardFrom) {
const initializeContent = async () => {
+ if (!composeBodyRef.current) return;
+
try {
const emailToProcess = replyTo || forwardFrom;
if (!emailToProcess?.body) {
@@ -93,6 +95,15 @@ export default function ComposeEmail({
return;
}
+ // Create initial content immediately
+ const initialContent = `
+
- ${originalContent}
+ const quotedContent = forwardFrom ? `
+
+ ---------- Forwarded message ---------
+ From: ${emailToProcess.from}
+ Date: ${new Date(emailToProcess.date).toLocaleString()}
+ Subject: ${emailToProcess.subject}
+ To: ${emailToProcess.to}
+ ${emailToProcess.cc ? `Cc: ${emailToProcess.cc}
` : ''}
+
+ ${parsedEmail.html || parsedEmail.text || 'No content available'}
+ ` : `
+
+ On ${new Date(emailToProcess.date).toLocaleString()}, ${emailToProcess.from} wrote:
+
+
+ ${parsedEmail.html || parsedEmail.text || 'No content available'}
+
`;
// Set the content in the compose area
if (composeBodyRef.current) {
+ const formattedContent = `
+
+
+ ${quotedContent}
+
+ `;
composeBodyRef.current.innerHTML = formattedContent;
+
// Place cursor at the beginning
const selection = window.getSelection();
const range = document.createRange();
@@ -129,12 +157,21 @@ export default function ComposeEmail({
range.collapse(true);
selection?.removeAllRanges();
selection?.addRange(range);
- }
- // Update compose state
- setComposeBody(formattedContent);
+ // Update compose state
+ setComposeBody(formattedContent);
+ }
} catch (error) {
console.error('Error initializing compose content:', error);
+ if (composeBodyRef.current) {
+ const errorContent = `
+
+
+
Error loading original message.
+
+ `;
+ composeBodyRef.current.innerHTML = errorContent;
+ }
}
};