diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx
index 5f23b293..14a2ba3c 100644
--- a/app/courrier/page.tsx
+++ b/app/courrier/page.tsx
@@ -101,8 +101,9 @@ function splitEmailHeadersAndBody(emailBody: string): { headers: string; body: s
}
function EmailContent({ email }: { email: Email }) {
- // Add debugging logs
- console.log("EmailContent rendering with:", {
+ // Improved debugging with more details
+ console.log("EmailContent rendering with EMAIL OBJECT:", email);
+ console.log("Content details:", {
hasContent: Boolean(email.content),
contentLength: email.content?.length || 0,
hasTextContent: Boolean(email.textContent),
@@ -164,8 +165,19 @@ function EmailContent({ email }: { email: Email }) {
);
}
- // Last resort
- return
No content available
;
+ // Last resort - show a better error message with debugging info
+ return (
+
+
No content available
+
+
Content flags:
+
- Has content: {hasContent ? 'Yes' : 'No'}
+
- Has text content: {hasTextContent ? 'Yes' : 'No'}
+
- Has raw content: {hasRawContent ? 'Yes' : 'No'}
+
- Has body: {hasBody ? 'Yes' : 'No'}
+
+
+ );
}
function renderEmailContent(email: Email) {
@@ -629,17 +641,27 @@ export default function CourrierPage() {
const fullEmail = await response.json();
console.log("API RESPONSE for email:", JSON.stringify(fullEmail, null, 2));
- // Create a safe version of the email with guaranteed fields
- const safeEmail = {
+ // Create a clean, processed version of the email ensuring all necessary fields exist
+ const processedEmail = {
...fullEmail,
- content: fullEmail.content || "",
- textContent: fullEmail.textContent || "",
- rawContent: fullEmail.rawContent || "",
- body: fullEmail.body || ""
+ id: fullEmail.id || emailId,
+ content: typeof fullEmail.content === 'string' ? fullEmail.content : '',
+ textContent: typeof fullEmail.textContent === 'string' ? fullEmail.textContent : '',
+ rawContent: typeof fullEmail.rawContent === 'string' ? fullEmail.rawContent : '',
+ body: typeof fullEmail.body === 'string' ? fullEmail.body : '',
+ from: fullEmail.from || initialEmail?.from || '',
+ fromName: fullEmail.fromName || initialEmail?.fromName || '',
+ to: fullEmail.to || initialEmail?.to || '',
+ subject: fullEmail.subject || initialEmail?.subject || '(No subject)',
+ date: fullEmail.date || initialEmail?.date || new Date().toISOString(),
+ read: fullEmail.read !== undefined ? fullEmail.read : true,
+ folder: fullEmail.folder || currentView
};
+ console.log("Processed email for UI:", processedEmail);
+
// Set the selected email with complete information
- setSelectedEmail(safeEmail);
+ setSelectedEmail(processedEmail);
// Update the email in the list to mark it as read
setEmails((prevEmails) =>
@@ -1036,9 +1058,16 @@ export default function CourrierPage() {
Direct Content Preview
-
-
Content: {selectedEmail.content ? selectedEmail.content.substring(0, 200) : 'Empty'}
-
Text Content: {selectedEmail.textContent ? selectedEmail.textContent.substring(0, 200) : 'Empty'}
+
+
Content: {selectedEmail.content
+ ?
{selectedEmail.content.substring(0, 500)}...
+ : 'Empty'}
+
Text Content: {selectedEmail.textContent
+ ?
{selectedEmail.textContent.substring(0, 500)}...
+ : 'Empty'}
+
Raw Content: {selectedEmail.rawContent
+ ?
{selectedEmail.rawContent.substring(0, 500)}...
+ : 'Empty'}