From e013913f4d1f2bc61944a7a2dc796a7b57044693 Mon Sep 17 00:00:00 2001 From: alma Date: Tue, 15 Apr 2025 22:59:15 +0200 Subject: [PATCH] mail page imap connection mime 5 bis rest 6 --- app/mail/page.tsx | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/mail/page.tsx b/app/mail/page.tsx index e6ae50a..9b35b10 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -388,7 +388,7 @@ function decodeMimeContent(content: string): string { export default function MailPage() { // Single IMAP account for now const [accounts, setAccounts] = useState([ - { id: 1, name: 'Mail', email: 'contact@governance-labs.org', color: 'bg-blue-500' }, + { id: 1, name: 'Mail', email: 'alma@governance-labs.org', color: 'bg-blue-500' }, { id: 2, name: 'Work', email: 'work@governance-labs.org', color: 'bg-green-500' } ]); @@ -427,7 +427,7 @@ export default function MailPage() { throw new Error('Failed to fetch emails'); } const data = await response.json(); - console.log('Raw API Response:', data); // Debug raw response + console.log('API Response:', data); // Debug log // Handle different possible response formats let emailData = []; @@ -445,18 +445,25 @@ export default function MailPage() { } } - console.log('Processed email data:', emailData); // Debug processed data + console.log('Processed email data:', emailData); // Debug log - // Ensure all dates are Date objects - const processedEmails = emailData.map((email: Email) => ({ - ...email, + // Ensure all dates are Date objects and add required properties + const processedEmails = emailData.map((email: any) => ({ + id: email.id || email.uid || email.messageId || Math.random().toString(), + accountId: email.accountId || '1', + from: email.from || '', + fromName: email.fromName || email.from?.split('@')[0] || '', + to: email.to || '', + subject: email.subject || '(No Subject)', + body: email.body || email.text || email.html || '', + preview: email.preview || email.body?.substring(0, 100) || '', + category: email.category || 'inbox', date: email.date ? new Date(email.date) : new Date(), read: email.read || false, - starred: email.starred || false, - category: email.category || 'inbox' + starred: email.starred || false })); - console.log('Final processed emails:', processedEmails); // Debug final data + console.log('Final processed emails:', processedEmails); // Debug log setEmails(processedEmails); } catch (err) { console.error('Error fetching emails:', err); @@ -482,7 +489,7 @@ export default function MailPage() { ]; // Filter emails based on current view - const filteredEmails = Array.isArray(emails) ? emails.filter(email => { + const filteredEmails = emails.filter(email => { if (selectedAccount === 0) return true; return email.accountId === selectedAccount.toString(); }).filter(email => { @@ -498,7 +505,7 @@ export default function MailPage() { default: return true; } - }) : []; + }); // Format date for display const formatDate = (dateString: string) => {