mail page imap connection mime 5 bis rest 16 login page 25
This commit is contained in:
parent
8876054496
commit
bdf2743bc7
@ -198,12 +198,14 @@ export async function GET() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
f.once('end', () => {
|
f.once('end', () => {
|
||||||
console.log('Fetch completed, found emails:', emails.length);
|
console.log('Emails before sending:', emails);
|
||||||
imap.end();
|
const response = {
|
||||||
resolve(NextResponse.json({
|
emails: emails,
|
||||||
emails: emails.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()),
|
|
||||||
mailUrl: process.env.NEXTCLOUD_URL ? `${process.env.NEXTCLOUD_URL}/apps/mail/` : null
|
mailUrl: process.env.NEXTCLOUD_URL ? `${process.env.NEXTCLOUD_URL}/apps/mail/` : null
|
||||||
}));
|
};
|
||||||
|
console.log('Final response:', response);
|
||||||
|
imap.end();
|
||||||
|
resolve(NextResponse.json(response));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -41,6 +41,11 @@ export function Email() {
|
|||||||
const response = await fetch('/api/mail');
|
const response = await fetch('/api/mail');
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
// Add debug logs
|
||||||
|
console.log('Raw API response:', data);
|
||||||
|
console.log('Type of data:', typeof data);
|
||||||
|
console.log('Type of data.emails:', data.emails ? typeof data.emails : 'undefined');
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
signIn();
|
signIn();
|
||||||
@ -49,17 +54,26 @@ export function Email() {
|
|||||||
throw new Error(data.error || 'Failed to fetch emails');
|
throw new Error(data.error || 'Failed to fetch emails');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure data.emails is an array
|
||||||
|
const emailsArray = Array.isArray(data.emails) ? data.emails : [];
|
||||||
|
console.log('Emails array:', emailsArray);
|
||||||
|
|
||||||
// Transform the email data to match the expected format
|
// Transform the email data to match the expected format
|
||||||
const transformedEmails = (data.emails || []).map((email: any) => ({
|
const transformedEmails = emailsArray.map((email: any) => {
|
||||||
id: email.id,
|
console.log('Processing email:', email);
|
||||||
subject: email.subject,
|
return {
|
||||||
|
id: email.id || String(Math.random()), // Fallback ID if none exists
|
||||||
|
subject: email.subject || '(No subject)',
|
||||||
sender: {
|
sender: {
|
||||||
name: email.from.split('<')[0].trim().replace(/"/g, '') || email.from,
|
name: email.from ? (email.from.split('<')[0].trim().replace(/"/g, '') || email.from) : 'Unknown',
|
||||||
email: (email.from.match(/<(.+)>/) || [])[1] || email.from
|
email: email.from ? ((email.from.match(/<(.+)>/) || [])[1] || email.from) : 'unknown@example.com'
|
||||||
},
|
},
|
||||||
date: email.date,
|
date: email.date || new Date().toISOString(),
|
||||||
isUnread: !email.read
|
isUnread: !email.read
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Transformed emails:', transformedEmails);
|
||||||
|
|
||||||
setEmails(transformedEmails);
|
setEmails(transformedEmails);
|
||||||
setMailUrl(data.mailUrl);
|
setMailUrl(data.mailUrl);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user