MozillaZine


Thunderbird macro possible?

User Help for Mozilla Thunderbird
kerft
 
Posts: 585
Joined: January 30th, 2019, 9:38 am

Post Posted September 25th, 2019, 7:34 am

This is probably too obvious to be worth saying, but Thunderbird has its own spam filtering capabilities (that can be improved with extensions) and for some users disabling spam filtering by the ISP and enabling it in Thunderbird is more convenient. This can often be done in options in the email provider's website for email (webmail).

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

Post Posted September 25th, 2019, 10:41 am

Psychonaut wrote:I was rather hoping that someone might be able to offer up some workaround that could be done within Thunderbird 68 itself.

Key Binding Example: viewtopic.php?p=14845566#p14845566

You can test these filter code snippets in the error console. I'm not exactly sure what you want.

Code: Select all
// open message filters window
goDoCommand("cmd_displayMsgFilters");

Code: Select all
// run filters on selected folder
goDoCommand("cmd_applyFilters");

Code: Select all
// run filters on selected message
goDoCommand("cmd_applyFiltersToSelection");

Code: Select all
// run a filter with a given filter name on selected message
// remember to edit the filter name below
(function () {
  function createDummyFilterClone(filter, filterList) {
    var retval = filterList.createFilter(filter.filterName);
    retval.filterType = filter.filterType;
    retval.temporary = true;
    retval.enabled = true;
    retval.filterDesc = filter.filterDesc;
    retval.filterList = filterList;
    retval.scope = filter.scope;
    var nrActions = filter.actionCount;
    for (var i = 0; i < nrActions; i++) {
      retval.appendAction(filter.getActionAt(i));
    }
    return retval;
  }
  var filterName = "Example"; // filter name in message filters window
  var filterService = Components.classes["@mozilla.org/messenger/services/filters;1"].
    getService(Components.interfaces.nsIMsgFilterService);
  var msg = gFolderDisplay.selectedMessage;
  var folder = msg.folder;
  var curFilterList = folder.getFilterList(msgWindow);
  var filter = curFilterList.getFilterNamed(filterName);
  if (filter) {
    var tempFilterList = filterService.getTempFilterList(folder);
    var msgList = Components.classes["@mozilla.org/array;1"].
      createInstance(Components.interfaces.nsIMutableArray);
    msgList.appendElement(msg, false);
    tempFilterList.logStream = curFilterList.logStream;
    tempFilterList.loggingEnabled = curFilterList.loggingEnabled;
    tempFilterList.insertFilterAt(0, createDummyFilterClone(filter, tempFilterList));
    folder.setFilterList(tempFilterList);
    try {
      console.log("Running filter '" + filter.filterName + "' on message '" + msg.mime2DecodedSubject + "'");
      filterService.applyFilters(Components.interfaces.nsMsgFilterType.All, msgList, folder, msgWindow);
      console.log("Done running filter");
    } finally {
      folder.setFilterList(curFilterList);
    }
  } else {
    console.log("No filter with '" + filterName + "' filter name");
  }
})();

I got the last code snippet in the following extension.

Filter Button
http://addons.thunderbird.net/thunderbird/addon/407832

Reference
http://dxr.mozilla.org/comm-release/source/mailnews/base/search/public/nsIMsgFilterService.idl
http://dxr.mozilla.org/comm-release/source/mail/config/version.txt

Psychonaut

User avatar
 
Posts: 100
Joined: April 7th, 2008, 3:56 am
Location: Vienna

Post Posted September 26th, 2019, 1:35 am

morat wrote:
Psychonaut wrote:I was rather hoping that someone might be able to offer up some workaround that could be done within Thunderbird 68 itself.

Key Binding Example: viewtopic.php?p=14845566#p14845566

You can test these filter code snippets in the error console. I'm not exactly sure what you want.

I've got my MTA set up to pipe all incoming mail through SpamAssassin and to perform the following actions on any high-scoring messages: (1) report it to SpamCop and various blacklists, (2) use it as a training example for SpamAssassin's Bayesian classifier, and (3) move it to a dedicated folder for confirmed spam. For any spam that slips through into my inbox, I need some way of manually running these three steps, or at least for running Step 3 (i.e., moving it to a dedicated folder, whence the spam can be picked up by some external script of mine running on a cron job). So basically the simplest possible thing I need is some keyboard shortcut for moving the currently selected message(s) to a certain spam folder. I can set this up quite easily in other MUAs like Claws Mail and KMail, but there seems to be no native way of doing this in Thunderbird.

However, I think the "run a filter with a given filter name on selected message" userChromeJS script you posted will probably do the trick for me. I'll test it out soon. Thanks for the pointer!

JYLD
 
Posts: 286
Joined: July 18th, 2019, 9:59 am

Post Posted September 26th, 2019, 9:31 am

Psychonaut wrote:Thank you, JYLD, for that very detailed and informative explanation. In his own inimitable way, Frank Lion has already indicated that AutoHotKey runs under Wine, so I'll see if I can get it working, or something with similar functionality, for my own spam-reporting workflow.


I'm not sure but AutoHotKey may come in a Linux version. You should check around on their website, or maybe you have already.

Return to Thunderbird Support


Who is online

Users browsing this forum: D.Dancer, Google [Bot] and 5 guests