From 9facfc5f5135462743d386db041b9cb2682afd01 Mon Sep 17 00:00:00 2001 From: mic Date: Wed, 20 Aug 2025 15:48:42 +0200 Subject: [PATCH 1/5] version set to 3.6.1_issue_469 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 24110b01..83252691 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "ThunderAI", "description": "__MSG_extensionDescription__", - "version": "3.6.1", + "version": "3.6.1_issue_469", "author": "Mic (m@micz.it)", "homepage_url": "https://micz.it/thunderbird-addon-thunderai/", "browser_specific_settings": { From 2fa356ee6d1960941bf85f26c8cf23161b07e112 Mon Sep 17 00:00:00 2001 From: mic Date: Wed, 20 Aug 2025 15:49:06 +0200 Subject: [PATCH 2/5] trying a new way to get the plain text email in auto fetaures. see #469 --- mzta-background.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mzta-background.js b/mzta-background.js index d15795e5..4f507230 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -976,10 +976,16 @@ async function processEmails(messages, addTagsAuto, spamFilter) { if (addTagsAuto || spamFilter) { curr_fullMessage = await browser.messages.getFull(message.id); msg_text = getMailBody(curr_fullMessage); - body_text = msg_text.text.replace(/\s+/g, ' ').trim(); + // body_text = msg_text.text.replace(/\s+/g, ' ').trim(); + // if( body_text.length == 0 ){ + // taLog.log("No text found in the message body, trying to convert HTML to plain text..."); + // body_text = htmlBodyToPlainText(msg_text.html); + // } + taLog.log("Startin from the HTML body if present and converting to plain text..."); + body_text = htmlBodyToPlainText(msg_text.html); if( body_text.length == 0 ){ - taLog.log("No text found in the message body, trying to convert HTML to plain text..."); - body_text = htmlBodyToPlainText(msg_text.html); + taLog.log("No HTML found in the message body, using plain text..."); + body_text = msg_text.text.replace(/\s+/g, ' ').trim(); } } From a96702b0a866e8a189c59313340b2cbf331bbddc Mon Sep 17 00:00:00 2001 From: Kilian Singer Date: Wed, 20 Aug 2025 18:10:18 +0200 Subject: [PATCH 3/5] used DOMParser to convert HTML to plain text --- js/mzta-utils.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/js/mzta-utils.js b/js/mzta-utils.js index 732e29b0..a5870971 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -198,19 +198,24 @@ export function stripHtmlKeepLines(htmlString) { .replace(/<[^>]*>/g, '') // removes any other HTML tags .trim(); // removes leading/trailing whitespace } - -export function htmlBodyToPlainText(html) { - return html - .replace(//gi, '') - .replace(//gi, '\n') - .replace(/<\/p\s*>/gi, '\n') - .replace(//gi, '') - .replace(/<\/(div|section|article|li|ul|ol|table|tr|td|th)>/gi, '\n') // newline for block tags - .replace(/<[^>]*>/g, '') // remove all other tags with no extra spaces - .replace(/[ \t]+\n/g, '\n') - .replace(/\n{2,}/g, '\n') - .replace(/[ \t]+/g, ' ') - .trim(); +function htmlBodyToPlainText(htmlString) { + // Create a new DOMParser instance + const parser = new DOMParser(); + // Parse the HTML string + const doc = parser.parseFromString(htmlString, 'text/html'); + + // remove invisible elements https://stackoverflow.com/questions/39813081/queryselector-where-display-is-not-none + // return doc; + const docsan=doc.querySelectorAll('[style*="visibility:hidden"]').forEach(e => e.remove());//.querySelector('html').children.not(':visible').remove() + // Extract text content + const textContent = doc.body.textContent || ""; + // Trim whitespace + return textContent + .replace(/[ \t]+\n/g, '\n') + .replace(/\n{2,}/g, '\n') + .replace(/[ \t]+/g, ' ') + .replace(/ /gi,"") + .trim(); } export function convertNewlinesToBr(text) { From c24097245bbc520f9453f3319a271231a85d464c Mon Sep 17 00:00:00 2001 From: Kilian Singer Date: Wed, 20 Aug 2025 18:21:04 +0200 Subject: [PATCH 4/5] added export keyword --- js/mzta-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/mzta-utils.js b/js/mzta-utils.js index a5870971..effa0f75 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -198,7 +198,7 @@ export function stripHtmlKeepLines(htmlString) { .replace(/<[^>]*>/g, '') // removes any other HTML tags .trim(); // removes leading/trailing whitespace } -function htmlBodyToPlainText(htmlString) { +export function htmlBodyToPlainText(htmlString) { // Create a new DOMParser instance const parser = new DOMParser(); // Parse the HTML string From 09d620c2948cc6b04a554b1fdd278f31b5ae0cda Mon Sep 17 00:00:00 2001 From: Kilian Singer Date: Wed, 20 Aug 2025 18:42:36 +0200 Subject: [PATCH 5/5] also removing