From 6bddf8fc026cafe8269b61df7dcac257e3957e20 Mon Sep 17 00:00:00 2001 From: Artem Savchenko Date: Fri, 23 May 2025 12:11:49 +0700 Subject: [PATCH] UBERF-11004: Reuse content type Signed-off-by: Artem Savchenko --- services/mail/pod-inbound-mail/src/utils.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/services/mail/pod-inbound-mail/src/utils.ts b/services/mail/pod-inbound-mail/src/utils.ts index 2987cf1c9e..ccbbf287bf 100644 --- a/services/mail/pod-inbound-mail/src/utils.ts +++ b/services/mail/pod-inbound-mail/src/utils.ts @@ -37,7 +37,7 @@ export async function parseContent ( return { content: mta.message.contents, attachments: [] } } - const email = await getEmailContent(mta.message.contents) + const email = await getEmailContent(mta.message.contents, contentType) let content = email.text ?? '' let isMarkdown = false @@ -88,7 +88,7 @@ export function getHeader (mta: MtaMessage, header: string): string | undefined return mta.message.headers.find((header) => header[0].toLowerCase() === h)?.[1]?.trim() } -async function getEmailContent (mtaContent: string): Promise { +async function getEmailContent (mtaContent: string, contentType: string): Promise { if (mtaContent == null) { return { text: '', @@ -97,9 +97,7 @@ async function getEmailContent (mtaContent: string): Promise { } as any } const contentRegex = /Content-Type/i - const content = contentRegex.test(mtaContent) - ? mtaContent - : `Content-Type: ${guessContentType(mtaContent)}\r\n${mtaContent}` + const content = contentRegex.test(mtaContent) ? mtaContent : `Content-Type: ${contentType}\r\n${mtaContent}` const email = await new Promise((resolve, reject) => { readEml(content, (err, json) => { if (err !== undefined && err !== null) { @@ -129,14 +127,6 @@ export function removeContentTypeHeader (content: string): string { return content.replace(contentTypeRegex, '') } -function guessContentType (content: string): string { - // Simple heuristic - if it contains HTML tags, it's likely HTML - if (/<[a-z][\s\S]*>/i.test(content)) { - return 'text/html; charset="UTF-8"' - } - return 'text/plain; charset="UTF-8"' -} - function isEmptyString (str: string | undefined): boolean { return str == null || str.trim() === '' }