compose mime
This commit is contained in:
parent
5bd57d731d
commit
2945e42367
@ -22,9 +22,20 @@ export interface ParsedEmail {
|
||||
export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
|
||||
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<ParsedEmail> {
|
||||
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<ParsedEmail> {
|
||||
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: {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user