From 8feec7bfd1499193332ee22b2fe7a92fcfd9f278 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 24 Apr 2025 20:23:26 +0200 Subject: [PATCH] compose mime --- lib/mail-parser-wrapper.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/mail-parser-wrapper.ts b/lib/mail-parser-wrapper.ts index fc4caf9b..ea78b01b 100644 --- a/lib/mail-parser-wrapper.ts +++ b/lib/mail-parser-wrapper.ts @@ -46,17 +46,43 @@ export async function decodeEmail(emailContent: string): Promise { body: JSON.stringify({ email: formattedContent }), }); + const data = await response.json(); + if (!response.ok) { - const errorData = await response.json(); - throw new Error(errorData.error || 'Failed to parse email'); + console.error('API Error:', data); + return { + subject: null, + from: null, + to: null, + cc: null, + bcc: null, + date: null, + html: null, + text: data.error || 'Failed to parse email', + attachments: [], + headers: {} + }; + } + + // If we have a successful response but no content + if (!data.html && !data.text) { + return { + ...data, + date: data.date ? new Date(data.date) : null, + html: null, + text: 'No content available', + attachments: data.attachments || [], + headers: data.headers || {} + }; } - const data = await response.json(); return { ...data, date: data.date ? new Date(data.date) : null, text: data.text || null, - html: data.html || null + html: data.html || null, + attachments: data.attachments || [], + headers: data.headers || {} }; } catch (error) { console.error('Error parsing email:', error);