courrier preview
This commit is contained in:
parent
41480e6666
commit
c501784bbe
@ -64,13 +64,56 @@ export default function EmailPanel({
|
||||
}
|
||||
|
||||
console.log('EmailPanel: Raw email:', email);
|
||||
console.log('EmailPanel: Raw email content type:', typeof email.content);
|
||||
|
||||
if (email.content) {
|
||||
// Log detailed content structure for debugging
|
||||
if (typeof email.content === 'object') {
|
||||
console.log('EmailPanel: Content object keys:', Object.keys(email.content));
|
||||
console.log('EmailPanel: Content has isHtml?', 'isHtml' in email.content);
|
||||
console.log('EmailPanel: Content has text?', 'text' in email.content);
|
||||
console.log('EmailPanel: Content has direction?', 'direction' in email.content);
|
||||
} else if (typeof email.content === 'string') {
|
||||
console.log('EmailPanel: Content is string, first 100 chars:', email.content.substring(0, 100));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if it's already in standardized format
|
||||
if (email.content &&
|
||||
typeof email.content === 'object' &&
|
||||
'isHtml' in email.content &&
|
||||
'text' in email.content &&
|
||||
'direction' in email.content) {
|
||||
console.log('EmailPanel: Email already in standardized format');
|
||||
return email as EmailMessage;
|
||||
}
|
||||
|
||||
// Use the adapter utility to convert to the standardized format
|
||||
return adaptLegacyEmail(email);
|
||||
console.log('EmailPanel: Adapting email to standardized format');
|
||||
const adapted = adaptLegacyEmail(email);
|
||||
|
||||
// Log adapted email for debugging
|
||||
console.log('EmailPanel: Adapted email content:', adapted.content);
|
||||
|
||||
return adapted;
|
||||
} catch (error) {
|
||||
console.error('EmailPanel: Error adapting email:', error);
|
||||
return null;
|
||||
// If adaptation fails, create a minimal valid email for display
|
||||
return {
|
||||
id: email.id || 'unknown',
|
||||
subject: email.subject || 'Error displaying email',
|
||||
from: email.from || '',
|
||||
to: email.to || '',
|
||||
date: email.date || new Date().toISOString(),
|
||||
flags: [],
|
||||
content: {
|
||||
text: `Error processing email: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
html: undefined,
|
||||
isHtml: false,
|
||||
direction: 'ltr'
|
||||
}
|
||||
} as EmailMessage;
|
||||
}
|
||||
}, [email]);
|
||||
|
||||
|
||||
@ -80,9 +80,12 @@ export function useEmailFetch({ onEmailLoaded, onError }: UseEmailFetchProps = {
|
||||
// Transform the data if needed
|
||||
const transformedEmail = {
|
||||
...data,
|
||||
// Create a proper content object that includes all required fields
|
||||
content: data.content || {
|
||||
text: data.text || '',
|
||||
html: data.html || ''
|
||||
html: data.html || '',
|
||||
isHtml: !!data.html, // Set isHtml based on whether html exists
|
||||
direction: 'ltr' // Default to left-to-right
|
||||
}
|
||||
};
|
||||
|
||||
@ -103,7 +106,7 @@ export function useEmailFetch({ onEmailLoaded, onError }: UseEmailFetchProps = {
|
||||
console.error('Error marking email as read:', err);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
// Don't set error if request was aborted
|
||||
if (err.name === 'AbortError') {
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user