diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index f8e51e49..17bc562c 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -54,7 +54,6 @@ import ComposeEmail from '@/components/ComposeEmail'; import { decodeEmail, cleanHtml } from '@/lib/mail-parser-wrapper'; import { Attachment as MailParserAttachment } from 'mailparser'; import { LoadingFix } from './loading-fix'; -import { getEmailContent } from '@/lib/services/email-service'; export interface Account { id: number; @@ -1575,22 +1574,30 @@ export default function CourrierPage() { // If content hasn't been loaded yet, fetch it if (!selectedEmail.contentFetched) { console.log('[DEBUG] Fetching email content for reply:', selectedEmail.id); - const content = await getEmailContent(selectedEmail.id, selectedEmail.folder); + // Use the API route instead of directly calling getEmailContent + const response = await fetch(`/api/courrier/${selectedEmail.id}?folder=${encodeURIComponent(selectedEmail.folder || 'INBOX')}`); + + if (!response.ok) { + throw new Error(`Failed to fetch email content: ${response.status}`); + } + + const content = await response.json(); + if (content) { // Update the selected email with content const updatedEmail = { ...selectedEmail, - content: content.html || content.text || '', + content: content.content || content.html || content.text || '', html: content.html || '', text: content.text || '', contentFetched: true, // Add proper from/to/cc format for client-side formatters - from: typeof content.from === 'string' ? content.from : content.from[0]?.address || '', - fromName: typeof content.from === 'string' ? '' : content.from[0]?.name || '', - to: typeof content.to === 'string' ? content.to : content.to[0]?.address || '', + from: typeof content.from === 'string' ? content.from : content.from?.[0]?.address || '', + fromName: typeof content.from === 'string' ? '' : content.from?.[0]?.name || '', + to: typeof content.to === 'string' ? content.to : content.to?.[0]?.address || '', cc: typeof content.cc === 'string' ? content.cc : content.cc?.[0]?.address || '', bcc: typeof content.bcc === 'string' ? content.bcc : content.bcc?.[0]?.address || '', - date: typeof content.date === 'string' ? content.date : content.date.toString() + date: typeof content.date === 'string' ? content.date : (content.date ? content.date.toString() : '') }; setSelectedEmail(updatedEmail); diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 22b9fbe5..24b8ab22 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -8,7 +8,6 @@ import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; import DOMPurify from 'isomorphic-dompurify'; import { formatEmailForReply, formatEmailForForward, EmailMessageForFormatting } from '@/lib/email-formatter'; -import { getEmailContent, getUserEmailCredentials } from '@/lib/services/email-service'; interface EmailObject { id?: string;