mime change
This commit is contained in:
parent
1b9633f70b
commit
9e379f1c8a
@ -3,11 +3,12 @@ import { parseEmail } from '@/lib/server/email-parser';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { emailContent } = await request.json();
|
||||
const body = await request.json();
|
||||
const { emailContent } = body;
|
||||
|
||||
if (!emailContent) {
|
||||
if (!emailContent || typeof emailContent !== 'string') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Email content is required' },
|
||||
{ error: 'Invalid email content. Expected a string.' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@ -17,7 +18,7 @@ export async function POST(request: Request) {
|
||||
} catch (error) {
|
||||
console.error('Error parsing email:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to parse email' },
|
||||
{ error: 'Failed to parse email', details: error instanceof Error ? error.message : 'Unknown error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { simpleParser, ParsedMail, Attachment, HeaderValue, AddressObject } from 'mailparser';
|
||||
import DOMPurify from 'dompurify';
|
||||
import { JSDOM } from 'jsdom';
|
||||
|
||||
// Create a window object for DOMPurify
|
||||
const window = new JSDOM('').window;
|
||||
|
||||
@ -1,13 +1,20 @@
|
||||
import { simpleParser } from 'mailparser';
|
||||
import DOMPurify from 'isomorphic-dompurify';
|
||||
|
||||
function cleanHtml(html: string): string {
|
||||
try {
|
||||
return DOMPurify.sanitize(html, {
|
||||
ALLOWED_TAGS: ['p', 'br', 'div', 'span', 'a', 'img', 'strong', 'em', 'u', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
|
||||
ALLOWED_ATTR: ['href', 'src', 'alt', 'title', 'class', 'style'],
|
||||
ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
||||
});
|
||||
// Basic HTML cleaning without DOMPurify
|
||||
return html
|
||||
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '') // Remove script tags
|
||||
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '') // Remove style tags
|
||||
.replace(/<meta[^>]*>/gi, '') // Remove meta tags
|
||||
.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '') // Remove head
|
||||
.replace(/<title[^>]*>[\s\S]*?<\/title>/gi, '') // Remove title
|
||||
.replace(/<body[^>]*>/gi, '') // Remove body opening tag
|
||||
.replace(/<\/body>/gi, '') // Remove body closing tag
|
||||
.replace(/<html[^>]*>/gi, '') // Remove html opening tag
|
||||
.replace(/<\/html>/gi, '') // Remove html closing tag
|
||||
.replace(/\s+/g, ' ') // Clean up whitespace
|
||||
.trim();
|
||||
} catch (error) {
|
||||
console.error('Error cleaning HTML:', error);
|
||||
return html;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user