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');
|
||||
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.status === 401) {
|
||||
signIn();
|
||||
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
|
||||
let emailsToProcess = [];
|
||||
if (Array.isArray(data)) {
|
||||
emailsToProcess = data;
|
||||
} else if (data && Array.isArray(data.emails)) {
|
||||
emailsToProcess = data.emails;
|
||||
} else {
|
||||
console.error('Unexpected data structure:', data);
|
||||
// Get the response data
|
||||
const data = await response.json();
|
||||
console.log('Received data:', data);
|
||||
|
||||
// Check if data has the expected structure
|
||||
if (!data || !Array.isArray(data.emails)) {
|
||||
console.error('Invalid response format:', data);
|
||||
throw new Error('Invalid response format: no emails array found');
|
||||
}
|
||||
|
||||
console.log('Emails to process:', emailsToProcess);
|
||||
|
||||
// Transform the emails
|
||||
const transformedEmails = emailsToProcess.map((email) => {
|
||||
console.log('Processing email:', email);
|
||||
return {
|
||||
id: String(email.id || ''),
|
||||
subject: email.subject || '(No subject)',
|
||||
sender: {
|
||||
name: extractSenderName(email.from || ''),
|
||||
email: extractEmailAddress(email.from || '')
|
||||
},
|
||||
date: email.date || new Date().toISOString(),
|
||||
isUnread: !email.read
|
||||
};
|
||||
});
|
||||
const transformedEmails = data.emails.map((email) => ({
|
||||
id: String(email.id || ''),
|
||||
subject: email.subject || '(No subject)',
|
||||
sender: {
|
||||
name: extractSenderName(email.from || ''),
|
||||
email: extractEmailAddress(email.from || '')
|
||||
},
|
||||
date: email.date || new Date().toISOString(),
|
||||
isUnread: !email.read
|
||||
}));
|
||||
|
||||
console.log('Final transformed emails:', transformedEmails);
|
||||
console.log('Transformed emails:', transformedEmails);
|
||||
|
||||
setEmails(transformedEmails);
|
||||
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/mail/');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user