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 }),
|
body: JSON.stringify({ email: formattedContent }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
console.error('API Error:', data);
|
||||||
throw new Error(errorData.error || 'Failed to parse email');
|
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 {
|
return {
|
||||||
...data,
|
...data,
|
||||||
date: data.date ? new Date(data.date) : null,
|
date: data.date ? new Date(data.date) : null,
|
||||||
text: data.text || null,
|
text: data.text || null,
|
||||||
html: data.html || null
|
html: data.html || null,
|
||||||
|
attachments: data.attachments || [],
|
||||||
|
headers: data.headers || {}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing email:', error);
|
console.error('Error parsing email:', error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user