From 5e1d99125e57f6cedd716c1a714f9c0bfb9fb458 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 30 Jan 2026 11:12:53 +0700 Subject: [PATCH] TF-4265 Exclude our signature by add `removeTMailSignature` option to `extractPlainText` method --- core/lib/utils/html/html_utils.dart | 4 ++ core/test/utils/html_utils_test.dart | 73 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/core/lib/utils/html/html_utils.dart b/core/lib/utils/html/html_utils.dart index ea1beb2f6..5cad7a2d7 100644 --- a/core/lib/utils/html/html_utils.dart +++ b/core/lib/utils/html/html_utils.dart @@ -916,6 +916,7 @@ class HtmlUtils { bool removeQuotes = true, bool removeStyle = true, bool removeScript = true, + bool removeTMailSignature = true, }) { var cleaned = html; @@ -934,6 +935,9 @@ class HtmlUtils { if (removeScript) { doc.querySelectorAll('script').forEach((e) => e.remove()); } + if (removeTMailSignature) { + doc.querySelectorAll('div.tmail-signature').forEach((e) => e.remove()); + } cleaned = doc.outerHtml; diff --git a/core/test/utils/html_utils_test.dart b/core/test/utils/html_utils_test.dart index 567c8e8ba..091f487b9 100644 --- a/core/test/utils/html_utils_test.dart +++ b/core/test/utils/html_utils_test.dart @@ -515,6 +515,79 @@ void main() { const html = '<weird>X</weird>Y'; expect(HtmlUtils.extractPlainText(html), 'XY'); }); + + test('removes tmail-signature div by default', () { + const html = ''' +

Hello world

+
+ Sent from my iPhone +
+ '''; + expect(HtmlUtils.extractPlainText(html), 'Hello world'); + }); + + test('keeps tmail-signature when removeTMailSignature is false', () { + const html = ''' +

Content

+
My Signature
+ '''; + expect( + HtmlUtils.extractPlainText(html, removeTMailSignature: false), + 'Content My Signature', + ); + }); + + test('removes tmail-signature containing nested html elements', () { + const html = ''' +
Actual message
+
+
+ Sent from my Android +
+ Get Outlook for Android +
+ '''; + expect(HtmlUtils.extractPlainText(html), 'Actual message'); + }); + + test('removes multiple tmail-signature divs', () { + const html = ''' +
Old Sig
+

New Content

+
New Sig
+ '''; + expect(HtmlUtils.extractPlainText(html), 'New Content'); + }); + + test('removes tmail-signature even when combined with other classes', () { + const html = ''' +

Main text

+
+ Should be removed +
+ '''; + expect(HtmlUtils.extractPlainText(html), 'Main text'); + }); + + test('ignores divs looking like signature but with wrong class name', () { + const html = ''' +

Main text

+
Should keep this
+
And this
+ '''; + expect(HtmlUtils.extractPlainText(html), 'Main text Should keep this And this'); + }); + + test('removes tmail-signature inside blockquote if both flags are true', () { + const html = ''' +

Start

+
+
Sig inside quote
+
+

End

+ '''; + expect(HtmlUtils.extractPlainText(html), 'Start End'); + }); }); group('HtmlUtils.wrapPlainTextLinks', () {