friedPotat0 / Spam-Scores

Thunderbird add-on to display spam scores according to mail headers. Supports spam/ham score headers of Rspamd and SpamAssassin. The add-on adds a column with the overall spam score to the mail list view and shows details of any matched spam/ham rule.
https://addons.thunderbird.net/de/thunderbird/addon/spam-scores/
Other
42 stars 6 forks source link

XPCom -> WebExtensions #43

Closed dlh2 closed 2 years ago

dlh2 commented 2 years ago

As said in #38, now the idea by far is to mutate the code from XPCom to WebExtensions.

dlh2 commented 2 years ago

As suggested in this code in experiments.js

 const staticHeaders = ['x-spam-status', 'x-spamd-result', 'x-spam-score', 'x-rspamd-score', 'x-spam-report']
 const prefs = Services.prefs

  const customDBHeaders = prefs.getCharPref('mailnews.customDBHeaders')
  const customHeaders = prefs.getCharPref('mailnews.customHeaders')

  let newCustomDBHeaders = customDBHeaders
  let newCustomHeaders = customHeaders

  for (const header of staticHeaders) {
    if (customDBHeaders.indexOf(header) === -1) newCustomDBHeaders += ` ${header}`
    if (customHeaders.indexOf(`${header}:`) === -1) newCustomHeaders += ` ${header}:`
  }
  for (const header of dynamicHeaders) {
    if (customDBHeaders.indexOf(header) === -1) newCustomDBHeaders += ` ${header}`
    if (customHeaders.indexOf(`${header}:`) === -1) newCustomHeaders += ` ${header}:`
  }

  prefs.getBranch('mailnews').setCharPref('.customDBHeaders', newCustomDBHeaders.trim())
  prefs.getBranch('mailnews').setCharPref('.customHeaders', newCustomHeaders.trim())

There's no relevant code here, the idea behind it, is to save the headers in mailnews space, which should be used in another place, but there's no "mailnews" in another part of the project, therefore I'm going to delete this code.

dlh2 commented 2 years ago

From Added a way to log the experiments code 89dd827

As shown in https://github.com/thundernest/sample-extensions/tree/master/experiment

There's a way to see the data that is happening but is through an alert.

Also by the extended Firefox Documentation https://firefox-source-docs.mozilla.org/toolkit/components/extensions/webextensions/basics.html#globals-available-in-the-api-scripts-global

There's some globals that we don't need to import

dlh2 commented 2 years ago

Removing MailServices, it never appears on the project.

dlh2 commented 2 years ago

WebExtensionPolicy a thing that is global in our context, has the properties of extension.

dlh2 commented 2 years ago

From here it's going to be code optimization, I'm scared to do a optimization branch, when right now is +1,110 −216 (even if most of it is just for JSDoc.)

dlh2 commented 2 years ago

0109d85 For achieving storage.local.get as error, it's mostly when for some reason the I/O, cache, memory, is at its peakpoint, it could solve some problems in the future but I'd rather let the program crash itself

a32e759 We can check faster with double vertical bar, and I changed the rework function, because it made sense in some way but in this way it's more readable.

dlh2 commented 2 years ago

93a5b15 Okay this one is special.

I see that somehow we save at "win" the good boy SpamScore, but also we give to SpamScore the "win" part therefore:

win.SpamScore.win.SpamScore.win.Spamscore...win

Gradly compiler is quite smart and says a thing about it, but let's make it easier for it and divide the win with the things that we need.

Also, let's use correctly the class

dlh2 commented 2 years ago

https://archive.org is god

Now I'll get into "Thunderbird Good Practices"

dlh2 commented 2 years ago

In Thunderbird, all WebExtension API can be accessed through the browser. namespace, as with Firefox, but also through the messenger. namespace, which is a better fit for Thunderbird.

https://webextension-api.thunderbird.net/en/91/index.html?highlight=messenger#thunderbird-webextension-api-documentation

dlh2 commented 2 years ago

In the previous commit, we would reload the script everytime we changed Mail Folders, therefore we have an I/O delay (even if it's small), then reload all the resources then put in the "window" variable, therefore everytime we would load/unload the script.

Now we load the script in an "invented scope" instead of window, and everytime we need to apply the changes...

We'll just call it so it populates the column, then destroy the column when we swap folders.

Also in this way we remove "legacy code" which is supposed to be deprecated at some moment


Note: I feel that I don't need to Restart Thunderbird, neither Repair Folder


Question for @friedPotat0 : When is not mail:3pane? custom_score_column.js:186

dlh2 commented 2 years ago

At the moment, the only solution for not using "Components" is to create another addon as "Theme" as I can't combine the Addon with the Theme, in one extension.

dlh2 commented 2 years ago

Well well, I did it!

We really forgot about getImageSrc (after all it's legacy code and we don't even know how it worked), so we used it and we can now forget about the strange css selector injection.

Also made some optimizations on the way.

Note: seems that getImageSrc doesn't support SVG images

dlh2 commented 2 years ago

I'm scared of this warning:

Reading manifest: Warning processing web_accesible_resources: An unexpected property was found in the WebExtension manifest.

dlh2 commented 2 years ago

options.js had a general save for each modification, that way we atomize the operations

dlh2 commented 2 years ago

Sidenote:

Okay if I create a new profile the images and the score won't appear on column...

Probably because of this:

"Reading manifest: Warning processing web_accesible_resources: An unexpected property was found in the WebExtension manifest."

dlh2 commented 2 years ago

Yeah now working as expected.

Note: But we need to repair and restart