diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx
index f05d85d7..07349d7f 100644
--- a/app/courrier/page.tsx
+++ b/app/courrier/page.tsx
@@ -410,7 +410,7 @@ function getReplyBody(email: Email, type: 'reply' | 'reply-all' | 'forward' = 'r
Subject: ${email.subject}
To: ${email.to}
${email.cc ? `Cc: ${email.cc}
` : ''}
- ${content}
+ ${content}
`;
@@ -419,7 +419,7 @@ function getReplyBody(email: Email, type: 'reply' | 'reply-all' | 'forward' = 'r
On ${new Date(email.date).toLocaleString()}, ${email.from} wrote:
-
${content}
+
${content}
`;
@@ -514,6 +514,10 @@ export default function CourrierPage() {
const [isMarkingUnread, setIsMarkingUnread] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);
const composeBodyRef = useRef(null);
+ const [originalEmail, setOriginalEmail] = useState<{
+ content: string;
+ type: 'reply' | 'reply-all' | 'forward';
+ } | null>(null);
// Debug logging for email distribution
useEffect(() => {
@@ -1389,9 +1393,13 @@ export default function CourrierPage() {
const handleReply = (type: 'reply' | 'reply-all' | 'forward') => {
if (!selectedEmail) return;
+ // Phase 1: Format the original email content
+ const originalContent = getReplyBody(selectedEmail, type);
+
+ // Phase 2: Set up the composition interface
const getReplyTo = () => {
if (type === 'forward') return '';
- return selectedEmail.from;
+ return selectedEmail.from;
};
const getReplyCc = () => {
@@ -1401,25 +1409,17 @@ export default function CourrierPage() {
const getReplySubject = () => {
const subject = selectedEmail.subject || '';
- if (type === 'forward') {
+ if (type === 'forward') {
return subject.startsWith('Fwd:') ? subject : `Fwd: ${subject}`;
}
return subject.startsWith('Re:') ? subject : `Re: ${subject}`;
};
- // Prepare the reply email
- const replyEmail = {
- to: getReplyTo(),
- cc: getReplyCc(),
- subject: getReplySubject(),
- body: getReplyBody(selectedEmail, type)
- };
-
// Update the compose form with the reply content
- setComposeTo(replyEmail.to);
- setComposeCc(replyEmail.cc);
- setComposeSubject(replyEmail.subject);
- setComposeBody(replyEmail.body);
+ setComposeTo(getReplyTo());
+ setComposeCc(getReplyCc());
+ setComposeSubject(getReplySubject());
+ setComposeBody(''); // Start with empty body for new content
setComposeBcc('');
// Show the compose form and CC field for Reply All
@@ -1427,6 +1427,12 @@ export default function CourrierPage() {
setShowCc(type === 'reply-all');
setShowBcc(false);
setAttachments([]);
+
+ // Pass the formatted original email content to the compose modal
+ setOriginalEmail({
+ content: originalContent,
+ type
+ });
};
// Add the confirmation dialog component
diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx
index 418dfc0c..dc0863c0 100644
--- a/components/ComposeEmail.tsx
+++ b/components/ComposeEmail.tsx
@@ -1,6 +1,6 @@
'use client';
-import { useRef, useEffect } from 'react';
+import { useRef, useEffect, useState } from 'react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
@@ -28,6 +28,10 @@ interface ComposeEmailProps {
attachments: any[];
setAttachments: (attachments: any[]) => void;
handleSend: () => Promise;
+ originalEmail?: {
+ content: string;
+ type: 'reply' | 'reply-all' | 'forward';
+ };
}
export default function ComposeEmail({
@@ -49,9 +53,11 @@ export default function ComposeEmail({
setShowBcc,
attachments,
setAttachments,
- handleSend
+ handleSend,
+ originalEmail
}: ComposeEmailProps) {
const composeBodyRef = useRef(null);
+ const [showOriginalContent, setShowOriginalContent] = useState(true);
useEffect(() => {
if (composeBodyRef.current) {
@@ -62,7 +68,21 @@ export default function ComposeEmail({
const handleInput = (e: React.FormEvent) => {
if (composeBodyRef.current) {
- const encodedContent = encodeComposeContent(composeBodyRef.current.innerHTML);
+ // Get the current content
+ const content = composeBodyRef.current.innerHTML;
+
+ // Create a temporary div to parse the content
+ const tempDiv = document.createElement('div');
+ tempDiv.innerHTML = content;
+
+ // Check if the content contains RTL text
+ const hasRTL = /[\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC]/.test(content);
+
+ // Set the appropriate direction
+ composeBodyRef.current.dir = hasRTL ? 'rtl' : 'ltr';
+
+ // Encode the content
+ const encodedContent = encodeComposeContent(content);
setComposeBody(encodedContent);
}
};
@@ -214,14 +234,37 @@ export default function ComposeEmail({
/>
+ {/* Original Email Content Preview */}
+ {originalEmail && showOriginalContent && (
+
+
+
+ {originalEmail.type === 'forward' ? 'Forwarded Message' : 'Original Message'}
+
+
+
+
+
+ )}
+
{/* Message Body */}
-