From 96d6d50e503bb0f6269907ff320e2dd64beaa1eb Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 25 Apr 2025 09:38:06 +0200 Subject: [PATCH] compose mime --- app/courrier/page.tsx | 117 +++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 54 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 7f3cb15b..d27ee22b 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -42,21 +42,16 @@ export interface Account { } export interface Email { - id: number; - accountId: number; + id: string; from: string; - fromName: string; + fromName?: string; to: string; subject: string; - body: string; + content: string; date: string; read: boolean; starred: boolean; - folder: string; - cc?: string; - bcc?: string; - flags?: string[]; - raw: string; + attachments?: { name: string; url: string }[]; } interface Attachment { @@ -113,7 +108,7 @@ function EmailContent({ email }: { email: Email }) { setIsLoading(true); try { - if (!email.body) { + if (!email.content) { if (mounted) { setContent(
No content available
); setIsLoading(false); @@ -121,7 +116,7 @@ function EmailContent({ email }: { email: Email }) { return; } - const formattedEmail = email.body.trim(); + const formattedEmail = email.content.trim(); if (!formattedEmail) { if (mounted) { setContent(
No content available
); @@ -167,7 +162,7 @@ function EmailContent({ email }: { email: Email }) { return () => { mounted = false; }; - }, [email?.body]); + }, [email?.content]); if (isLoading) { return ( @@ -263,12 +258,12 @@ function ReplyContent({ email, type }: { email: Email; type: 'reply' | 'reply-al async function loadReplyContent() { try { - if (!email.body) { + if (!email.content) { if (mounted) setContent(''); return; } - const decoded = await decodeEmail(email.body); + const decoded = await decodeEmail(email.content); if (mounted) { let formattedContent = ''; @@ -278,7 +273,7 @@ function ReplyContent({ email, type }: { email: Email; type: 'reply' | 'reply-al

---------- Forwarded message ---------

From: ${decoded.from || ''}

-

Date: ${formatDate(decoded.date)}

+

Date: ${formatDate(decoded.date ? new Date(decoded.date) : null)}

Subject: ${decoded.subject || ''}

To: ${decoded.to || ''}


@@ -288,7 +283,7 @@ function ReplyContent({ email, type }: { email: Email; type: 'reply' | 'reply-al } else { formattedContent = `
-

On ${formatDate(decoded.date)}, ${decoded.from || ''} wrote:

+

On ${formatDate(decoded.date ? new Date(decoded.date) : null)}, ${decoded.from || ''} wrote:

${decoded.html || `
${decoded.text || ''}
`}
@@ -313,7 +308,7 @@ function ReplyContent({ email, type }: { email: Email; type: 'reply' | 'reply-al return () => { mounted = false; }; - }, [email.body, type]); + }, [email.content, type]); if (error) { return
{error}
; @@ -336,14 +331,14 @@ function EmailPreview({ email }: { email: Email }) { let mounted = true; async function loadPreview() { - if (!email?.body) { + if (!email?.content) { if (mounted) setPreview('No content available'); return; } setIsLoading(true); try { - const decoded = await decodeEmail(email.body); + const decoded = await decodeEmail(email.content); if (mounted) { if (decoded.text) { setPreview(decoded.text.substring(0, 150) + '...'); @@ -371,7 +366,7 @@ function EmailPreview({ email }: { email: Email }) { return () => { mounted = false; }; - }, [email?.body]); + }, [email?.content]); if (isLoading) { return Loading preview...; @@ -1078,45 +1073,51 @@ export default function CourrierPage() { }, [availableFolders]); // Update the email list item to match header checkbox alignment - const renderEmailListItem = (email: Email) => { - return ( -
handleEmailSelect(email.id)} - > + const renderEmailListItem = (email: Email) => ( +
handleEmailSelect(email.id)} + > +
{ - const e = { target: { checked }, stopPropagation: () => {} } as React.ChangeEvent; - handleEmailCheckbox(e, email.id); - }} + checked={selectedEmails.includes(email.id)} + onCheckedChange={(checked) => toggleEmailSelection(email.id)} onClick={(e) => e.stopPropagation()} className="mt-0.5" /> -
-
-
- - {email.fromName || email.from} - -
- - {formatDate(new Date(email.date))} - -
-

- {email.subject || '(No subject)'} -

-
- {generateEmailPreview(email)} -
-
- ); - }; +
+
+
+ + {email.fromName || email.from} + + {!email.read && ( + + )} +
+ + {formatDate(new Date(email.date))} + +
+

+ {email.subject || '(No subject)'} +

+ +
+
+ {email.starred && ( + + )} + {email.attachments && email.attachments.length > 0 && ( + + )} +
+
+ ); const handleMailboxChange = async (newMailbox: string) => { setCurrentView(newMailbox); @@ -1355,6 +1356,14 @@ export default function CourrierPage() { ); + const toggleEmailSelection = (emailId: string) => { + setSelectedEmails((prev) => + prev.includes(emailId) + ? prev.filter((id) => id !== emailId) + : [...prev, emailId] + ); + }; + if (error) { return (