From d3f4ccd7bf347196ea4852a2e7e634abee144dd0 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 17 Apr 2025 14:40:56 +0200 Subject: [PATCH] solve mail backend 14 --- app/api/mail/route.ts | 11 +++++-- components/mail/mail-list.tsx | 55 ++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/api/mail/route.ts b/app/api/mail/route.ts index ed816f44..277981ef 100644 --- a/app/api/mail/route.ts +++ b/app/api/mail/route.ts @@ -51,11 +51,17 @@ export async function GET() { // Fetch only essential message data const messages = await client.fetch('1:20', { envelope: true, - flags: true + flags: true, + bodyStructure: true, + bodyParts: ['TEXT'] }); const result = []; for await (const message of messages) { + // Get the message content + const content = await client.download(message.uid.toString(), 'TEXT'); + const body = content?.content?.toString() || ''; + result.push({ id: message.uid.toString(), from: message.envelope.from[0].address, @@ -63,7 +69,8 @@ export async function GET() { date: message.envelope.date.toISOString(), read: message.flags.has('\\Seen'), starred: message.flags.has('\\Flagged'), - folder: mailbox.path + folder: mailbox.path, + body: body }); } diff --git a/components/mail/mail-list.tsx b/components/mail/mail-list.tsx index 7b63a854..21eca8b6 100644 --- a/components/mail/mail-list.tsx +++ b/components/mail/mail-list.tsx @@ -17,41 +17,42 @@ export function MailList({ mails, onMailClick }: MailListProps) { } return ( -
+
{mails.map((mail) => (
onMailClick(mail)} > -
-
- {mail.starred ? ( - - ) : ( - +
+
+
+
+ {mail.from} +
+ {mail.starred && ( + + )} +
+
+ {mail.subject} +
+
+ {mail.body} +
+ {mail.attachments && mail.attachments.length > 0 && ( +
+ + {mail.attachments.length} attachment{mail.attachments.length !== 1 ? 's' : ''} +
)} - {mail.from}
- - {format(new Date(mail.date), "MMM d, yyyy")} - -
-
-

{mail.subject}

-

- {mail.body} -

-
- {mail.attachments && mail.attachments.length > 0 && ( -
- - {mail.attachments.length} attachment - {mail.attachments.length > 1 ? "s" : ""} +
+ {format(new Date(mail.date), 'MMM d, yyyy')}
- )} +
))}