From c501784bbe962fddcb1ed99fd587f01727c1030f Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 30 Apr 2025 22:05:17 +0200 Subject: [PATCH] courrier preview --- components/email/EmailPanel.tsx | 47 +++++++++++++++++++++++++++++++-- hooks/use-email-fetch.ts | 7 +++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/components/email/EmailPanel.tsx b/components/email/EmailPanel.tsx index cc8dce6b..aa7e9789 100644 --- a/components/email/EmailPanel.tsx +++ b/components/email/EmailPanel.tsx @@ -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]); diff --git a/hooks/use-email-fetch.ts b/hooks/use-email-fetch.ts index bfe45ea7..995dc6e8 100644 --- a/hooks/use-email-fetch.ts +++ b/hooks/use-email-fetch.ts @@ -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;