RealRaven2000 / FiltaQuilla

Adds many new mail filter actions to Thunderbird
http://quickfilters.quickfolders.org/filtaquilla.html
GNU General Public License v3.0
88 stars 17 forks source link

Example subject manipulation filter not working #146

Closed sandybrownlee closed 2 years ago

sandybrownlee commented 2 years ago

This is on Thunderbird 78.13.0 64 bit (Linux Mint) - FiltaQuilla 3.2

I use a variation of the example javascript action filter to amend the subject on some emails (my mailserver adds the prefix {SPAM?} quite often: rarely is this correct, but it has the ironic effect that when I reply to such emails, the replies end up in junk folders). The filter simply replaced the SPAM tag with a couple of underscores so I could see where it happened:

for (let index = 0; index < msgHdrs.length; index++)
{
  let hdr = msgHdrs.queryElementAt(index, Ci.nsIMsgDBHdr);
  hdr.subject = hdr.subject.replace("{SPAM?}", "__");
}

This has recently started failing with this error in Thunderbird's console:

msgHdrs queryElementAt is not a function

I don't know the cause as I'm not all that familiar with Thunderbird's update cyctem. Maybe it's an API change somewhere. Anyway, I fixed it by doing this:

for (let index = 0; index < msgHdrs.length; index++)
{
    msgHdrs[index].subject = msgHdrs[index].subject.replace("{SPAM?}", "__");
}

This now works fine. Assuming there is nothing else wrong with the above, it might be worth updating the example in the documentation for javascript actions to reflect that. (I was also not clear on what nsIMsgDBHdr objects - the type of the msgHdrs array - actually contain - is it possible to have a link to docs on that somewhere?)

Thanks!

RealRaven2000 commented 2 years ago

Yes - both Mozilla and Thunderbird change the code in the background all the time. If you use the JavaScript option you will have to live with fixing your code just like us legacy (or experimental API) Add-on developers. Note that you are not using an official API but are just hacking back-end code. FiltaQuilla merely exposes some of the relevant objects but does not control they way they are implemented.

In an API - based Add-on none of this access would be allowed at all because it cannot be controlled via the permissions system. Hence also the drakonian / threatening message when you install FiltaQuilla.

RealRaven2000 commented 2 years ago

I use a variation of the example javascript action filter to amend the subject on some emails (my mailserver adds the prefix {SPAM?} quite often: rarely is this correct, but it has the ironic effect that when I reply to such emails, the replies end up in junk folders). The filter simply replaced the SPAM tag with a couple of underscores so I could see where it happened:

for (let index = 0; index < msgHdrs.length; index++)
{
  let hdr = msgHdrs.queryElementAt(index, Ci.nsIMsgDBHdr);
  hdr.subject = hdr.subject.replace("{SPAM?}", "__");
}

I just checked, but - where is this example from? I have an updated one on my official site:

for (let index = 0; index < msgHdrs.length; index++)
  {
    let hdr = msgHdrs.queryElementAt ? msgHdrs.queryElementAt(index, Ci.nsIMsgDBHdr) : msgHdrs[index];
    hdr.subject = "[Hello, world] " + hdr.subject;
  }
sandybrownlee commented 2 years ago

Thanks!

Interesting, I'm sure that is the page that I got it from... Is it possible that in the time since I wrote this issue (originally posted in the wrong place - just copied here today) the example has been fixed? If so I guess this is redundant now.