mail page imap connection mime 5 bis rest 4
This commit is contained in:
parent
6e14e85ed1
commit
8c42df9d6f
@ -427,23 +427,37 @@ export default function MailPage() {
|
||||
throw new Error('Failed to fetch emails');
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log('API Response:', data); // Debug log
|
||||
// Ensure data is an array and has the expected structure
|
||||
console.log('Raw API Response:', data); // Debug raw response
|
||||
|
||||
// Handle different possible response formats
|
||||
let emailData = [];
|
||||
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([]);
|
||||
emailData = data;
|
||||
} else if (data && typeof data === 'object') {
|
||||
// If data is an object, try to extract emails from it
|
||||
if (data.emails) {
|
||||
emailData = data.emails;
|
||||
} else if (data.messages) {
|
||||
emailData = data.messages;
|
||||
} else {
|
||||
// Try to convert object values to array
|
||||
emailData = Object.values(data);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Processed email data:', emailData); // Debug processed data
|
||||
|
||||
// Ensure all dates are Date objects
|
||||
const processedEmails = emailData.map(email => ({
|
||||
...email,
|
||||
date: email.date ? new Date(email.date) : new Date(),
|
||||
read: email.read || false,
|
||||
starred: email.starred || false,
|
||||
category: email.category || 'inbox'
|
||||
}));
|
||||
|
||||
console.log('Final processed emails:', processedEmails); // Debug final data
|
||||
setEmails(processedEmails);
|
||||
} catch (err) {
|
||||
console.error('Error fetching emails:', err);
|
||||
setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user