mail page imap connection mime 5 bis rest 16 login page 30
This commit is contained in:
parent
358bedaeec
commit
11d86f9464
@ -42,59 +42,38 @@ export function Email() {
|
|||||||
const response = await fetch('/api/mail');
|
const response = await fetch('/api/mail');
|
||||||
console.log('Response status:', response.status);
|
console.log('Response status:', response.status);
|
||||||
|
|
||||||
// First, get the raw text of the response
|
|
||||||
const rawText = await response.text();
|
|
||||||
console.log('Raw response text:', rawText);
|
|
||||||
|
|
||||||
// Try to parse it as JSON
|
|
||||||
let data;
|
|
||||||
try {
|
|
||||||
data = JSON.parse(rawText);
|
|
||||||
console.log('Parsed data type:', typeof data);
|
|
||||||
console.log('Is Array?', Array.isArray(data));
|
|
||||||
console.log('Data:', data);
|
|
||||||
} catch (parseError) {
|
|
||||||
console.error('JSON parse error:', parseError);
|
|
||||||
throw new Error('Invalid JSON response from server');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
signIn();
|
signIn();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(data.error || 'Failed to fetch emails');
|
const errorData = await response.json();
|
||||||
|
throw new Error(errorData.error || 'Failed to fetch emails');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we have an array to work with
|
// Get the response data
|
||||||
let emailsToProcess = [];
|
const data = await response.json();
|
||||||
if (Array.isArray(data)) {
|
console.log('Received data:', data);
|
||||||
emailsToProcess = data;
|
|
||||||
} else if (data && Array.isArray(data.emails)) {
|
// Check if data has the expected structure
|
||||||
emailsToProcess = data.emails;
|
if (!data || !Array.isArray(data.emails)) {
|
||||||
} else {
|
console.error('Invalid response format:', data);
|
||||||
console.error('Unexpected data structure:', data);
|
|
||||||
throw new Error('Invalid response format: no emails array found');
|
throw new Error('Invalid response format: no emails array found');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Emails to process:', emailsToProcess);
|
|
||||||
|
|
||||||
// Transform the emails
|
// Transform the emails
|
||||||
const transformedEmails = emailsToProcess.map((email) => {
|
const transformedEmails = data.emails.map((email) => ({
|
||||||
console.log('Processing email:', email);
|
id: String(email.id || ''),
|
||||||
return {
|
subject: email.subject || '(No subject)',
|
||||||
id: String(email.id || ''),
|
sender: {
|
||||||
subject: email.subject || '(No subject)',
|
name: extractSenderName(email.from || ''),
|
||||||
sender: {
|
email: extractEmailAddress(email.from || '')
|
||||||
name: extractSenderName(email.from || ''),
|
},
|
||||||
email: extractEmailAddress(email.from || '')
|
date: email.date || new Date().toISOString(),
|
||||||
},
|
isUnread: !email.read
|
||||||
date: email.date || new Date().toISOString(),
|
}));
|
||||||
isUnread: !email.read
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Final transformed emails:', transformedEmails);
|
console.log('Transformed emails:', transformedEmails);
|
||||||
|
|
||||||
setEmails(transformedEmails);
|
setEmails(transformedEmails);
|
||||||
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/mail/');
|
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/mail/');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user