From b6a1ad7d9d44a12ebedec4b8bf44b1c19a1f9d3b Mon Sep 17 00:00:00 2001 From: TooonyChen <26252739+TooonyChen@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:43:18 +1200 Subject: [PATCH] fix: keep anchor hrefs when stripping HTML and accept bare text/html fragments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forwarded mails (e.g. Yandex webmail) arrive as a single text/html part with no /
wrapper and no text/plain alternative. Two bugs made their codes unextractable: - stripHtmlTags dropped href attributes, so button-only mails (Netflix 'Get Code') reached the LLM with no URL at all → codeExist=0. Anchors now render as 'label [url]' with & decoded. - extractMailBodies only recognised single-part HTML wrapped in /, so htmlBody was null and the Rendered preview was empty. A bare fragment with Content-Type text/html now counts as the html body. Verified against the real forwarded Netflix mail from production raw_mails: content now carries the travel/verify link and classifies 5/5 as login_code. --- src/services/mime.ts | 33 ++++++++++++++++++++++++++------- test/mime.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/services/mime.ts b/src/services/mime.ts index 8ef3437..8499903 100644 --- a/src/services/mime.ts +++ b/src/services/mime.ts @@ -100,12 +100,25 @@ export function decodeMimeHeader(value: string | null): string | null { } export function stripHtmlTags(text: string): string { - return text - .replace(/