diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx
index bc0614dc..dac5139f 100644
--- a/components/ComposeEmail.tsx
+++ b/components/ComposeEmail.tsx
@@ -112,25 +112,62 @@ export default function ComposeEmail({
setIsLoading(true);
- // Check if we have content
- if (!emailToProcess?.content) {
- console.error('[DEBUG] No email content found to process');
+ // Check if email object exists
+ if (!emailToProcess) {
+ console.error('[DEBUG] No email to process for reply/forward');
composeBodyRef.current.innerHTML = `
-
Unable to load original message content.
+
No email selected for reply/forward.
`;
setIsLoading(false);
return;
}
- // Format the reply/forward content
+ // Check if we need to fetch full content first - same as panel 3
+ if (!emailToProcess.content || emailToProcess.content.length === 0) {
+ console.log('[DEBUG] Need to fetch content before composing reply/forward');
+
+ try {
+ const response = await fetch(`/api/courrier/${emailToProcess.id}?folder=${encodeURIComponent(emailToProcess.folder || 'INBOX')}`);
+
+ if (!response.ok) {
+ throw new Error(`Failed to fetch email content: ${response.status}`);
+ }
+
+ const fullContent = await response.json();
+
+ // Update the email content with the fetched full content
+ emailToProcess.content = fullContent.content;
+ emailToProcess.contentFetched = true;
+
+ console.log('[DEBUG] Successfully fetched content for reply/forward');
+ } catch (error) {
+ console.error('[DEBUG] Error fetching content for reply:', error);
+ composeBodyRef.current.innerHTML = `
+
+
+
Failed to load email content. Please try again.
+
+ `;
+ setIsLoading(false);
+ return; // Exit if we couldn't get the content
+ }
+ }
+
+ // Now proceed with the usual decoding
const type = replyTo ? 'reply' : 'forward';
try {
// Parse the email to get headers and content - using the same function as panel 3
const decoded = await decodeEmail(emailToProcess.content);
+ console.log('[DEBUG] Decoded email for compose:', {
+ hasHtml: !!decoded.html,
+ hasText: !!decoded.text,
+ from: decoded.from,
+ subject: decoded.subject
+ });
// This is exactly how panel 3 handles email content - simple sanitization of HTML or showing text
let cleanContent = '';