From ac573a17431516b283d6e77e75328707904185b7 Mon Sep 17 00:00:00 2001 From: moisseev Date: Thu, 4 Jul 2024 11:35:15 +0300 Subject: [PATCH] Add "Substitute folding white spaces (FWS)" option for Thunderbird 128 Beta and later. The option is enabled by default to ensure compatibility with existing user configurations. In Thunderbird 128 Beta, headers unfolding behavior was updated to retain folding white spaces (FWS) when encountered, whereas previous Thunderbird versions substituted FWS with spaces during unfolding. --- background.js | 40 +++++++++++++++++++++++++--------------- manifest.json | 4 ++-- options/options.html | 8 ++++++++ options/options.js | 41 ++++++++++++++++++++++++++--------------- 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/background.js b/background.js index 91cccef..ab40fac 100644 --- a/background.js +++ b/background.js @@ -24,15 +24,10 @@ function parseReceivedHeaders(headers, regexp) { return received; } -browser.storage.local.get(["headerNumbers", "regexp"]).then(({headerNumbers, regexp}) => { - if (!headerNumbers) browser.storage.local.set({headerNumbers: ""}); - if (!regexp) browser.storage.local.set({regexp: "(.*)"}); -}); - -function displayReceivedHeader(windowId, tabIndex, messageId) { +function displayReceivedHeader(windowId, tabIndex, messageId, majorVersion) { browser.messages.getFull(messageId).then((messagepart) => { - browser.storage.local.get(["headerNumbers", "regexp", "removeDuplicates", "singleLine"]) - .then(({headerNumbers, regexp, removeDuplicates, singleLine = false}) => { + browser.storage.local.get(["headerNumbers", "regexp", "removeDuplicates", "singleLine", "substituteFWS"]) + .then(({headerNumbers, regexp, removeDuplicates, singleLine = false, substituteFWS = true}) => { let headers = []; let numberFound = false; let separator = "🡄"; @@ -73,6 +68,13 @@ function displayReceivedHeader(windowId, tabIndex, messageId) { } if (headers.length) { + if (majorVersion >= 128 && substituteFWS) { + // Substitute folding white spaces (FWS) + const foldingWhiteSpaceRegex = /[\t ]+/g; + headers.forEach((header, i) => (headers[i] = header.replace(foldingWhiteSpaceRegex, " "))); + } + + const parsed = parseReceivedHeaders(headers, regexp); let filteredParsed = []; @@ -97,9 +99,19 @@ function displayReceivedHeader(windowId, tabIndex, messageId) { }); } +let lastDisplayedMessageId = null; + browser.runtime.getBrowserInfo().then((browserInfo) => { const [majorVersion] = browserInfo.version.split(".", 1); + // Default options + browser.storage.local.get(["headerNumbers", "regexp", "substituteFWS"]) + .then(({headerNumbers, regexp, substituteFWS}) => { + if (!headerNumbers) browser.storage.local.set({headerNumbers: ""}); + if (!regexp) browser.storage.local.set({regexp: "(.*)"}); + if (majorVersion >= 128 && !substituteFWS) browser.storage.local.set({substituteFWS: true}); + }); + browser.windows.getAll({populate: true, windowTypes: ["normal", "messageDisplay"]}).then((windows) => { windows.forEach(function (window) { window.tabs @@ -109,18 +121,16 @@ browser.runtime.getBrowserInfo().then((browserInfo) => { .forEach((tab) => { browser.messageDisplay.getDisplayedMessage(tab.id).then((message) => { if (!message) return; - displayReceivedHeader(tab.windowId, tab.index, message.id); + displayReceivedHeader(tab.windowId, tab.index, message.id, majorVersion); }); }); }); }); -}); -let lastDisplayedMessageId = null; - -browser.messageDisplay.onMessageDisplayed.addListener((tab, message) => { - lastDisplayedMessageId = message.id; - displayReceivedHeader(tab.windowId, tab.index, message.id); + browser.messageDisplay.onMessageDisplayed.addListener((tab, message) => { + lastDisplayedMessageId = message.id; + displayReceivedHeader(tab.windowId, tab.index, message.id, majorVersion); + }); }); browser.mailTabs.onSelectedMessagesChanged.addListener((tab, selectedMessages) => { diff --git a/manifest.json b/manifest.json index dac3b13..ddb6714 100644 --- a/manifest.json +++ b/manifest.json @@ -4,12 +4,12 @@ "gecko": { "id": "received@alexander.moisseev", "strict_min_version": "78.0", - "strict_max_version": "116.*" + "strict_max_version": "128.*" } }, "name": "Received", "description": "Displays the \"Received\" header parsed with a regular expression.", - "version": "2.5.3", + "version": "2.6.0", "author": "Alexander Moisseev (moiseev@mezonplus.ru)", "homepage_url": "https://github.com/moisseev/received", "icons": { diff --git a/options/options.html b/options/options.html index 945ef46..0a1d10a 100644 --- a/options/options.html +++ b/options/options.html @@ -36,6 +36,7 @@ .remark { font-size: smaller; color: var(--in-content-deemphasized-text); + display: block; } .received-examples { color: var(--in-content-deemphasized-text); @@ -67,6 +68,13 @@

+