diff --git a/lib/mail-parser-wrapper.ts b/lib/mail-parser-wrapper.ts index c400a011..fc4caf9b 100644 --- a/lib/mail-parser-wrapper.ts +++ b/lib/mail-parser-wrapper.ts @@ -22,9 +22,20 @@ export interface ParsedEmail { export async function decodeEmail(emailContent: string): Promise { try { // Ensure the email content is properly formatted - const formattedContent = emailContent.trim(); + const formattedContent = emailContent?.trim(); if (!formattedContent) { - throw new Error('Email content is empty'); + return { + subject: null, + from: null, + to: null, + cc: null, + bcc: null, + date: null, + html: null, + text: 'No content available', + attachments: [], + headers: {} + }; } const response = await fetch('/api/parse-email', { @@ -32,7 +43,7 @@ export async function decodeEmail(emailContent: string): Promise { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ emailContent: formattedContent }), + body: JSON.stringify({ email: formattedContent }), }); if (!response.ok) { @@ -43,11 +54,24 @@ export async function decodeEmail(emailContent: string): Promise { const data = await response.json(); return { ...data, - date: data.date ? new Date(data.date) : null + date: data.date ? new Date(data.date) : null, + text: data.text || null, + html: data.html || null }; } catch (error) { console.error('Error parsing email:', error); - throw error; + return { + subject: null, + from: null, + to: null, + cc: null, + bcc: null, + date: null, + html: null, + text: 'Error parsing email content', + attachments: [], + headers: {} + }; } }