From 6e14e85ed1276e7ab9cfc30c1c3cbeafa967bdd9 Mon Sep 17 00:00:00 2001 From: alma Date: Tue, 15 Apr 2025 22:49:06 +0200 Subject: [PATCH] mail page imap connection mime 5 bis rest 3 --- app/mail/page.tsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/mail/page.tsx b/app/mail/page.tsx index f12702e..0b53882 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -427,11 +427,27 @@ export default function MailPage() { throw new Error('Failed to fetch emails'); } const data = await response.json(); - // Ensure data is an array - setEmails(Array.isArray(data) ? data : []); + console.log('API Response:', data); // Debug log + // Ensure data is an array and has the expected structure + if (Array.isArray(data)) { + const validEmails = data.filter(email => + email && + typeof email.id === 'string' && + typeof email.accountId === 'string' && + typeof email.from === 'string' && + typeof email.subject === 'string' && + email.date instanceof Date + ); + console.log('Valid emails:', validEmails); // Debug log + setEmails(validEmails); + } else { + console.warn('API returned non-array data:', data); + setEmails([]); + } } catch (err) { + console.error('Error fetching emails:', err); setError(err instanceof Error ? err.message : 'An error occurred'); - setEmails([]); // Set empty array on error + setEmails([]); } finally { setLoading(false); }