compose mime
This commit is contained in:
parent
2945e42367
commit
8feec7bfd1
@ -46,17 +46,43 @@ export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
|
||||
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user