MozillaZine

Editing format (and more?) of received emails

User Help for Mozilla Thunderbird
cwinte
 
Posts: 10
Joined: August 5th, 2019, 5:06 am

Post Posted August 12th, 2019, 3:36 am

I'd like to automate some simple changes in display format. Ideally this might work like a filter rule so I can use those features to control which emails get attention.
The actual mods would be one or more simple edits such as "sed 's/<String1>10px/<String1>5px/g'" invocations, if that were possible.
This would change the display of maybe 15% of the lines of text in a long, typically 250kB email.

Issues: this is a IMAP account so modifying the source file might be more complex or even undesirable.
Ideally it is a display modification only. The actual display text is html styled but not CSS in this case.
If the email format were set by CSS then a feature to apply overrides on received CSS styles would be a good way to go.

Any ideas, pointer, suggestions, starting points and aspects to consider??
I'm willing to do a bit of coding, especially if I can start from a good template but this is only to fix a minor annoyance in emails I read every day (Google alerts) so I can only rationally spend a little time on the idea.
Thanks in advance.

tanstaafl
Moderator

User avatar
 
Posts: 45678
Joined: July 30th, 2003, 5:06 pm

Post Posted August 12th, 2019, 5:58 am

Take a look at the support page for FiltaQuilla - http://www.mesquilla.net/mesquillacom/e ... ltaquilla/ . It supports running a file as a message filter action, and executing javascript as a action. The latter might be more useful if you only want to modify the display.

morat
 
Posts: 3377
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 12th, 2019, 6:11 am

If you can select the text with css selectors, then you can use the userContent.css file to style the text.

Code: Select all
/* Thunderbird userContent.css */

@-moz-document url-prefix("imap:") {
  body {
    background-color: orange !important;
  }
}

http://kb.mozillazine.org/UserContent.css

CSS Reference
http://developer.mozilla.org/en-US/docs/Web/CSS/Reference#Selectors

cwinte
 
Posts: 10
Joined: August 5th, 2019, 5:06 am

Post Posted August 12th, 2019, 8:11 am

Wow, truly impressed. What can I say? Kudos, thanks, and wow again.

Great depth, detail and info from both...

I'm starting with a go at the FiltaQuilla javascript body action, although it warns in multipart Imap things can be complex (that's how we learn).
If I knew who to contact at Google I'd suggest they make their alerts more user configurable via CSS, ideally config in your google account but at least if they tag list structure in a modern meaningful way...

morat
 
Posts: 3377
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 12th, 2019, 2:38 pm

cwinte wrote:Ideally it is a display modification only.

I would create a simple extension similar to the Filter Button extension.

More info: viewtopic.php?f=19&t=3046668

The following example styles the message body dependent on the properties of the selected message.

Subject: Security alert
From: Google <no-reply@accounts.google.com>
Folder Name: Inbox

You can test the code in the console. ( i.e. tools > developer tools > error console )

Code: Select all
(function () {
  var browser = document.getElementById("messagepane");
  if (browser) {
    browser.addEventListener("load", function (event) {
      var msgHdr = gFolderDisplay.selectedMessage;
      console.log(event);
      console.log(msgHdr);
      if (msgHdr) {
        if (msgHdr.folder.prettyName == "Inbox" &&
            msgHdr.mime2DecodedAuthor == "Google <no-reply@accounts.google.com>" &&
            msgHdr.mime2DecodedSubject == "Security alert") {
          event.target.body.setAttribute("style", "background-color: orange");
        }
      }
    }, true);
  }
})();
Last edited by morat on August 12th, 2019, 4:46 pm, edited 1 time in total.

morat
 
Posts: 3377
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 12th, 2019, 4:09 pm

You can use the userChromeJS extension to run the code at startup.

Code: Select all
/* Thunderbird userChrome.js */

(function () {

  if (location == "chrome://messenger/content/messenger.xul") {
    setTimeout(function () {
      var browser = document.getElementById("messagepane");
      if (browser) {
        browser.addEventListener("load", function (event) {
          var msgHdr = gFolderDisplay.selectedMessage;
          if (msgHdr) {
            if (msgHdr.folder.prettyName == "Inbox" &&
                msgHdr.mime2DecodedAuthor == "Google <no-reply@accounts.google.com>" &&
                msgHdr.mime2DecodedSubject == "Security alert") {
              event.target.body.setAttribute("style", "background-color: orange");
            }
          }
        }, true);
      }
    }, 1000);
  }
  if (location == "chrome://messenger/content/messageWindow.xul") {}
  if (location == "chrome://messenger/content/messengercompose/messengercompose.xul") {}

})();

userChromeJS by Jonathan Kamens
http://addons.thunderbird.net/thunderbird/addon/986610

userChromeJS by alta88 (obsolete)
http://userchromejs.mozdev.org/
http://userchromejs.mozdev.org/faq.html

Instructions:

1. install userChromeJS extension
2. close email client
3. create or edit the userChrome.js file in the chrome folder in the profile folder
4. open email client with the -purgecaches command line option

i.e.

thunderbird.exe -purgecaches
ThunderbirdPortable.exe -purgecaches

You have to purge the caches only after creating or editing the userChrome.js file.

cwinte
 
Posts: 10
Joined: August 5th, 2019, 5:06 am

Post Posted August 13th, 2019, 1:10 am

I appreciate the help!
I need to get a start point grip on how to explore the DOM objects and methods structures.
DOMi extension does not seem to offer any access points into exploring TB/emails, but maybe I'm just missing some sort of starter method or code - it seemed easy enough in Firefox last time I was there (some years ago now).
Maybe DOMi no longer works, as the installer page hinted but then I'd assume the installer would say "no go" as it does for many other extensions. I've not been able to locate much via searches yet this morning (UK) but not had much time yet... This might be a bit of a holiday project!
Any pointers would be appreciated, as you can probably tell!

My first quick tests using JS on body load seemed to modify my local copy of the email (if I copied modded email to another account it was still modified but looking at the IMAP server via web the mail was not modified: guess this is OK but ideally I'd mod a cached version of the email -maybe via the window object?). Actually the subject line, with [Hello] prepended, only changes the emails list pane, not the actual email contents display pane (in both the original and copied email cases). Maybe I should see how to do that the on other pane!

Ahh! Toosl > Developer Tools > Developer Toolbox and the console allows me to get autocompletions so
win(dow).(list of objects and methods). So I have a toe hold but not much map yet, blind exploration of the territory will be fun but could take a while!
Ahhh.2: If I use the cog to display the DOM options then I get to see what the tool is looking at (TB app) and the windows etc within it. Great, what I needed for some traction!

I'm using TB 60.8.0 on MacOS X10.11.6 El Capitan

morat
 
Posts: 3377
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 13th, 2019, 4:36 am

DOM Inspector Plus! 2.0.17.1.5 works well with Thunderbird 60.

http://addons.thunderbird.net/thunderbird/addon/254571

In Thunderbird, the Browser Console is called the Error Console and the Browser Toolbox is called the Developer Toolbox.

http://developer.mozilla.org/docs/Tools/Browser_Console
http://developer.mozilla.org/docs/Tools/Browser_Toolbox

Header Tools Lite allows the user to modify the message on the IMAP server.

http://addons.thunderbird.net/thunderbird/addon/356507

Return to Thunderbird Support


Who is online

Users browsing this forum: No registered users and 8 guests