mime change

This commit is contained in:
alma 2025-04-24 16:30:22 +02:00
parent 71cb01d540
commit 75cb80df22
3 changed files with 20 additions and 4 deletions

View File

@ -4,11 +4,16 @@ import { parseEmail } from '@/lib/server/email-parser';
export async function POST(request: Request) {
try {
const body = await request.json();
console.log('Received request body:', body);
const { emailContent } = body;
console.log('Email content type:', typeof emailContent);
console.log('Email content length:', emailContent?.length);
if (!emailContent || typeof emailContent !== 'string') {
console.log('Invalid email content:', { emailContent, type: typeof emailContent });
return NextResponse.json(
{ error: 'Invalid email content. Expected a string.' },
{ error: 'Invalid email content. Expected a string.', received: { type: typeof emailContent, length: emailContent?.length } },
{ status: 400 }
);
}

View File

@ -114,7 +114,11 @@ async function renderEmailContent(email: Email) {
try {
if (!email.body) return null;
const parsedEmail = await decodeEmail(email.body);
// Ensure the email content is properly formatted
const formattedEmail = email.body.trim();
if (!formattedEmail) return null;
const parsedEmail = await decodeEmail(formattedEmail);
if (parsedEmail.html) {
return (

View File

@ -21,16 +21,23 @@ export interface ParsedEmail {
export async function decodeEmail(emailContent: string): Promise<ParsedEmail> {
try {
// Ensure the email content is properly formatted
const formattedContent = emailContent.trim();
if (!formattedContent) {
throw new Error('Email content is empty');
}
const response = await fetch('/api/parse-email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ emailContent }),
body: JSON.stringify({ emailContent: formattedContent }),
});
if (!response.ok) {
throw new Error('Failed to parse email');
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to parse email');
}
const data = await response.json();