diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx
index 0be94c9a..5eb9a5cb 100644
--- a/components/email/ComposeEmail.tsx
+++ b/components/email/ComposeEmail.tsx
@@ -256,10 +256,51 @@ export default function ComposeEmail(props: ComposeEmailAllProps) {
// Initialize the form when replying to or forwarding an email
useEffect(() => {
if (initialEmail && type !== 'new') {
+ // For all types of emails, format with a consistent approach
+ let formattedContent = '';
+
if (type === 'forward') {
- initializeForwardedEmail();
+ // Format subject with Fwd: prefix if needed
+ const subjectBase = initialEmail.subject || '(No subject)';
+ const subjectRegex = /^(Fwd|FW|Forward):\s*/i;
+ const subject = subjectRegex.test(subjectBase)
+ ? subjectBase
+ : `Fwd: ${subjectBase}`;
+
+ setSubject(subject);
+
+ // Format forwarded content
+ const fromString = initialEmail.from?.map(addr =>
+ addr.name ? `${addr.name} <${addr.address}>` : addr.address
+ ).join(', ') || '';
+
+ const toString = initialEmail.to?.map(addr =>
+ addr.name ? `${addr.name} <${addr.address}>` : addr.address
+ ).join(', ') || '';
+
+ const dateString = typeof initialEmail.date === 'string'
+ ? new Date(initialEmail.date).toLocaleString()
+ : initialEmail.date.toLocaleString();
+
+ const originalContent = initialEmail.content || initialEmail.html || initialEmail.text || '';
+
+ formattedContent = `
+
+
+
+
+
---------- Forwarded message ---------
+
From: ${fromString}
+
Date: ${dateString}
+
Subject: ${initialEmail.subject || ''}
+
To: ${toString}
+
+
${originalContent}
+
+
+ `;
} else {
- // For reply/reply-all, continue using formatEmailForReplyOrForward
+ // For reply/reply-all
const formattedEmail = formatEmailForReplyOrForward(initialEmail, type as 'reply' | 'reply-all');
setTo(formattedEmail.to);
@@ -271,12 +312,14 @@ export default function ComposeEmail(props: ComposeEmailAllProps) {
setSubject(formattedEmail.subject);
- // Make the entire content editable, just like with forwarded emails
- const bodyContent = formattedEmail.body;
- setUserMessage(bodyContent);
- setBody(bodyContent);
+ // Set the reply content with proper formatting
+ formattedContent = formattedEmail.body;
}
+ // Set the entire content as one editable area
+ setBody(formattedContent);
+ setUserMessage(formattedContent);
+
// Focus editor after initializing
setTimeout(() => {
if (editorRef.current) {
@@ -460,7 +503,7 @@ export default function ComposeEmail(props: ComposeEmailAllProps) {
}
};
- // Modified send handler to combine user message with forwarded content
+ // Modified send handler to use the entire body content
const handleSend = async () => {
if (!to) {
alert('Please specify at least one recipient');
@@ -470,50 +513,13 @@ export default function ComposeEmail(props: ComposeEmailAllProps) {
try {
setSending(true);
- // Prepare the complete email body
- let finalBody = body;
-
- if (type === 'forward' && originalContent) {
- // For forwarded emails, construct the email in a standard format
- const fromString = initialEmail?.from?.map(addr =>
- addr.name ? `${addr.name} <${addr.address}>` : addr.address
- ).join(', ') || '';
-
- const toString = initialEmail?.to?.map(addr =>
- addr.name ? `${addr.name} <${addr.address}>` : addr.address
- ).join(', ') || '';
-
- const dateString = initialEmail?.date
- ? typeof initialEmail.date === 'string'
- ? new Date(initialEmail.date).toLocaleString()
- : initialEmail.date.toLocaleString()
- : '';
-
- // Combine user message with forwarded header and content
- finalBody = `
- ${userMessage}
-
-
-
-
-
---------- Forwarded message ---------
-
From: ${fromString}
-
Date: ${dateString}
-
Subject: ${initialEmail?.subject || ''}
-
To: ${toString}
-
-
${originalContent}
-
-
- `;
- }
-
+ // Use the complete edited content as is
await onSend({
to,
cc: cc || undefined,
bcc: bcc || undefined,
subject,
- body: finalBody,
+ body: userMessage, // Use the full edited message
attachments
});
@@ -526,7 +532,7 @@ export default function ComposeEmail(props: ComposeEmailAllProps) {
}
};
- // Handle editor input
+ // Handle editor input for the entire content
const handleEditorInput = (e: React.FormEvent) => {
if (editorRef.current) {
const content = editorRef.current.innerHTML;
@@ -653,53 +659,19 @@ export default function ComposeEmail(props: ComposeEmailAllProps) {
- {/* Email editor with clear separation between user message and original content */}
+ {/* Email editor with a single editable area for the entire message */}
- {/* User's editable message area */}
-
- {/* Original content display with visual separation */}
- {type !== 'new' && originalContent && (
-