diff --git a/app/api/mail/route.ts b/app/api/mail/route.ts index 4de2604..807606f 100644 --- a/app/api/mail/route.ts +++ b/app/api/mail/route.ts @@ -19,6 +19,7 @@ interface Email { read: boolean; starred: boolean; body: string; + to?: string; } interface ImapBox { @@ -180,13 +181,18 @@ export async function GET() { }; const messages: any[] = []; - for (let seqno = 1; seqno <= 10; seqno++) { + // Fetch the most recent 20 emails + const start = Math.max(1, box.messages.total - 19); // last 20 emails + const end = box.messages.total; + for (let seqno = start; seqno <= end; seqno++) { const msg = await fetchPromise(imap, seqno); const processedMsg = await processMessage(msg); messages.push(processedMsg); } imap.end(); + console.log('Raw messages:', messages); + const emails: Email[] = messages.map((msg) => { return { id: msg.uid.toString(), @@ -195,7 +201,8 @@ export async function GET() { date: msg.date, read: !msg.flags?.includes('\\Unseen'), starred: msg.flags?.includes('\\Flagged') || false, - body: msg.body + body: msg.body, + to: msg.to // add this if available }; }); diff --git a/app/mail/page.tsx b/app/mail/page.tsx index a068977..b1f3d43 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -484,26 +484,8 @@ export default function MailPage() { ...accounts ]; - // Filter emails based on selected account and current view - const filteredEmails = emails.filter(email => { - if (selectedAccount) { - return email.to === selectedAccount.email; - } - return true; - }).filter(email => { - switch (currentView) { - case 'inbox': - return true; - case 'starred': - return email.starred; - case 'sent': - return email.category === 'sent'; - case 'trash': - return email.category === 'trash'; - default: - return true; - } - }); + // TEMP: Show all emails for debugging + const filteredEmails = emails; // Format date for display const formatDate = (dateString: string) => {