compose mime

This commit is contained in:
alma 2025-04-24 20:19:34 +02:00
parent 5bd57d731d
commit 2945e42367

View File

@ -22,9 +22,20 @@ export interface ParsedEmail {
export async function decodeEmail(emailContent: string): Promise<ParsedEmail> { export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
try { try {
// Ensure the email content is properly formatted // Ensure the email content is properly formatted
const formattedContent = emailContent.trim(); const formattedContent = emailContent?.trim();
if (!formattedContent) { 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', { const response = await fetch('/api/parse-email', {
@ -32,7 +43,7 @@ export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ emailContent: formattedContent }), body: JSON.stringify({ email: formattedContent }),
}); });
if (!response.ok) { if (!response.ok) {
@ -43,11 +54,24 @@ export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
const data = await response.json(); const data = await response.json();
return { return {
...data, ...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) { } catch (error) {
console.error('Error parsing email:', 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: {}
};
} }
} }