From f69179438fb169f25482a34fb3dc8c19e5a79573 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 11 Nov 2025 09:20:37 +0700 Subject: [PATCH] TF-4139 Fix attachment reminder mistakenly shown when replying to an email --- core/lib/utils/html/html_utils.dart | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/core/lib/utils/html/html_utils.dart b/core/lib/utils/html/html_utils.dart index 65e166903..8c83d4503 100644 --- a/core/lib/utils/html/html_utils.dart +++ b/core/lib/utils/html/html_utils.dart @@ -685,14 +685,31 @@ class HtmlUtils { }); '''; - static String extractPlainText(String html) { + static String extractPlainText( + String html, { + bool removeQuotes = true, + bool removeStyle = true, + bool removeScript = true, + }) { var cleaned = html; - // Delete the blockquote and the content inside - final blockquoteRegex = RegExp( - r'', - caseSensitive: false, - ); - cleaned = html.replaceAll(blockquoteRegex, ''); + + if (cleaned.isEmpty) return ''; + + // Parse DOM + final doc = parser.parse(cleaned); + + // Remove unwanted nodes by CSS selector + if (removeQuotes) { + doc.querySelectorAll('blockquote').forEach((e) => e.remove()); + } + if (removeStyle) { + doc.querySelectorAll('style').forEach((e) => e.remove()); + } + if (removeScript) { + doc.querySelectorAll('script').forEach((e) => e.remove()); + } + + cleaned = doc.outerHtml; // Decode HTML entities up to 5 times (& → &,   → space, <div> →
, ...) int iterations = 0;