Thunderbird macro possible?

User Help for Mozilla Thunderbird
tajkkj
Posts: 12
Joined: December 22nd, 2014, 3:46 pm

Thunderbird macro possible?

Post by tajkkj »

Hello, my ISP sometimes passes on e-mail they think is spam, and prepend "--SPAM--" to the subject. To inform this ISP not to consider this spam (they get a lot of false positives), I forward the e-mail to their "not spam" address. This requires several steps to start a forward composition note, and put in the not spam e-mail address. I find myself preforming this task many times a day, and it gets tiresome.

Is there a way to write a macro to do these steps, and bind it to a key so I can automate this process? Thanks.
--Tim
User avatar
DanRaisch
Moderator
Posts: 127231
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Thunderbird macro possible?

Post by DanRaisch »

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

Re: Thunderbird macro possible?

Post by morat »

You can create a keyboard shortcut with the Keyconfig extension.

Keyconfig
http://addons.thunderbird.net/thunderbird/addon/602486

Code: Select all

// forward, add recipient, change subject, insert text, send now
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
  getService(Components.interfaces.nsIWindowMediator);
var msgHdr = gFolderDisplay.selectedMessage;
var listener = {
  onWindowTitleChange: function () {},
  onCloseWindow: function () {},
  onOpenWindow: function (aWindow) {
    wm.removeListener(this);
    this.compose = aWindow.docShell.
      QueryInterface(Components.interfaces.nsIInterfaceRequestor).
      getInterface(Components.interfaces.nsIDOMWindow);
    this.compose.addEventListener("compose-window-init", this, true);
  },
  handleEvent: function (event) {
    event.currentTarget.removeEventListener(event.type, this, true);
    event.currentTarget.gMsgCompose.RegisterStateListener(listener);
  },
  NotifyComposeFieldsReady: function () {},
  NotifyComposeBodyReady: function () {
    this.compose.gMsgCompose.UnregisterStateListener(this);
    this.compose.window.setTimeout(function () {
      this.AddRecipient("addr_to", "foo bar <test@invalid.com>");
      this.awDeleteRow(this.awGetMaxRecipients());
      this.GetMsgSubjectElement().value = "--SPAM-- " + this.
        GetMsgSubjectElement().value;
      this.GetCurrentEditor().insertText("Abracadabra.");
      this.goDoCommand("cmd_sendNow");
    }, 0);
  }
}
wm.addListener(listener);
MsgForwardMessage(null);
More info: http://forums.mozillazine.org/viewtopic ... #p14725693
tajkkj
Posts: 12
Joined: December 22nd, 2014, 3:46 pm

Re: Thunderbird macro possible?

Post by tajkkj »

Morat, thank you very much. That was what I was looking for.
User avatar
Psychonaut
Posts: 109
Joined: April 7th, 2008, 3:56 am
Location: Winnipeg
Contact:

Re: Thunderbird macro possible?

Post by Psychonaut »

Unfortunately, the Keyconfig extension does not work with Thunderbird 68. And Thunderbird still isn't able to natively bind a keyboard shortcut to a message filter. (This is the ten-year-old Bug 543717.)

I have a similar use case to the OP. My rather kludgy workaround is to manually drag the offending spam e-mails to a dedicated IMAP folder. I then use a different e-mail client (Claws Mail) to manually run the filter actions on the messages on that folder. I do these in batches once or twice per day.

If anyone has a better solution, please let me know.
JYLD
Posts: 305
Joined: July 18th, 2019, 9:59 am

Re: Thunderbird macro possible?

Post by JYLD »

morat wrote:You can create a keyboard shortcut with the Keyconfig extension.

Keyconfig
http://addons.thunderbird.net/thunderbird/addon/602486

Code: Select all

// forward, add recipient, change subject, insert text, send now
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
  getService(Components.interfaces.nsIWindowMediator);
var msgHdr = gFolderDisplay.selectedMessage;
var listener = {
  onWindowTitleChange: function () {},
  onCloseWindow: function () {},
  onOpenWindow: function (aWindow) {
    wm.removeListener(this);
    this.compose = aWindow.docShell.
      QueryInterface(Components.interfaces.nsIInterfaceRequestor).
      getInterface(Components.interfaces.nsIDOMWindow);
    this.compose.addEventListener("compose-window-init", this, true);
  },
  handleEvent: function (event) {
    event.currentTarget.removeEventListener(event.type, this, true);
    event.currentTarget.gMsgCompose.RegisterStateListener(listener);
  },
  NotifyComposeFieldsReady: function () {},
  NotifyComposeBodyReady: function () {
    this.compose.gMsgCompose.UnregisterStateListener(this);
    this.compose.window.setTimeout(function () {
      this.AddRecipient("addr_to", "foo bar <test@invalid.com>");
      this.awDeleteRow(this.awGetMaxRecipients());
      this.GetMsgSubjectElement().value = "--SPAM-- " + this.
        GetMsgSubjectElement().value;
      this.GetCurrentEditor().insertText("Abracadabra.");
      this.goDoCommand("cmd_sendNow");
    }, 0);
  }
}
wm.addListener(listener);
MsgForwardMessage(null);
More info: http://forums.mozillazine.org/viewtopic ... #p14725693

Where would this code be placed?
JYLD
Posts: 305
Joined: July 18th, 2019, 9:59 am

Re: Thunderbird macro possible?

Post by JYLD »

Psychonaut wrote:Unfortunately, the Keyconfig extension does not work with Thunderbird 68. And Thunderbird still isn't able to natively bind a keyboard shortcut to a message filter. (This is the ten-year-old Bug 543717.)

I have a similar use case to the OP. My rather kludgy workaround is to manually drag the offending spam e-mails to a dedicated IMAP folder. I then use a different e-mail client (Claws Mail) to manually run the filter actions on the messages on that folder. I do these in batches once or twice per day.

If anyone has a better solution, please let me know.

Macro Express, AutoIT, or AutoHotKey could take the place of Keyconfig. With some effort they could also be configured to accomplish the task in a slightly different way by using automated mouse and keystrokes to select the emails and forward them, etc.
User avatar
Psychonaut
Posts: 109
Joined: April 7th, 2008, 3:56 am
Location: Winnipeg
Contact:

Re: Thunderbird macro possible?

Post by Psychonaut »

Thanks, but I don't use proprietary software. Do you know of any solution that uses only free software?
User avatar
DanRaisch
Moderator
Posts: 127231
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Thunderbird macro possible?

Post by DanRaisch »

It pays to check suggested links before rejecting advice. AutoHotkey is a free, open-source scripting language for Windows.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Thunderbird macro possible?

Post by morat »

The keyconfig developer is active and asking for help so don't give up hope. (two developers said they can help)

More info: http://forums.mozillazine.org/viewtopic ... #p14845278

You can use the userChromeJS extension to modify key bindings.

More info
http://github.com/trlkly/dorando-keycon ... -530343943

userChromeJS
http://addons.thunderbird.net/thunderbird/addon/986610
User avatar
Psychonaut
Posts: 109
Joined: April 7th, 2008, 3:56 am
Location: Winnipeg
Contact:

Re: Thunderbird macro possible?

Post by Psychonaut »

DanRaisch wrote:It pays to check suggested links before rejecting advice. AutoHotkey is a free, open-source scripting language for Windows.
And Microsoft Windows is also free software now? :-k
User avatar
Frank Lion
Posts: 21177
Joined: April 23rd, 2004, 6:59 pm
Location: ... The Exorcist....United Kingdom
Contact:

Re: Thunderbird macro possible?

Post by Frank Lion »

Psychonaut wrote:And Microsoft Windows is also free software now? :-k
Don't try to be clever, pal, No one is going to know you mean the OS when you write like this -
Psychonaut wrote:Thanks, but I don't use proprietary software. Do you know of any solution that uses only free software?
Just how much hand-holding do you need? AutoHotkey well works under Wine on Linux and Xnee works directly and I've used both.

But, it's time for you to hit a non-proprietary search engine and find stuff yourself, I reckon.
"The only thing necessary for the triumph of evil, is for good men to do nothing." - Edmund Burke (attrib.)
.
User avatar
Psychonaut
Posts: 109
Joined: April 7th, 2008, 3:56 am
Location: Winnipeg
Contact:

Re: Thunderbird macro possible?

Post by Psychonaut »

Frank Lion wrote:
Psychonaut wrote:And Microsoft Windows is also free software now? :-k
Don't try to be clever, pal, No one is going to know you mean the OS when you write like this -
Psychonaut wrote:Thanks, but I don't use proprietary software. Do you know of any solution that uses only free software?
You didn't consider it the least bit strange that someone who claimed to make a point of not using proprietary software would be perfectly happy using a proprietary OS?

More to the point, I was rather hoping that someone might be able to offer up some workaround that could be done within Thunderbird 68 itself (possibly with the help of some add-on other than Keyconfig). Relying on external programs, and particularly on mouse/keystroke scripters, can be brittle and non-portable.
JYLD
Posts: 305
Joined: July 18th, 2019, 9:59 am

Re: Thunderbird macro possible?

Post by JYLD »

Psychonaut wrote:Relying on external programs, and particularly on mouse/keystroke scripters, can be brittle and non-portable.
Macro Express and I assume AutoIT, and AutoHotKey can do far more than simple sendkey commands and mouse movements. They can access .dll and Win32 API commands, send windows messages, access scripts from other languages, access items by window controls, etc.

So for example in this case, a macro could use thunderbird's built-in hotkey to forward a message, then access the window control for the recipient line in the forwarded message and fill in that control, then access the window control for the subject line and fill in that control, then access the window control for the message body and fill in that control, then use thunderbird's built-in hotkey to send the message. So the macro wouldn't rely on simple mouse movements and would likely be quite portable if necessary to other installations of Thunderbird. The macro could be set to run when a hotkey is pressed and/or added to a macro pop-up menu that appears when you do something say like alt-right click on a particular message.

In some important ways the macro is MORE portable than an add-on, because it will work across Thunderbird updates, can work when applicable in other programs besides TB or limited just to TB, etc. Macros are add-ons that the user can program and customize without being a programmer, that is especially true of Macro Express because of its gui interface. But for a programmer who knows other scripting languages, the windows API, and windows messages, the power of these macros would be quite extensive.

AutoHotkey macros can be compiled into stand alone executables that don't require AutoHotKey to be installed on the machine running the macro. Macro Express macros can be turned into executables but they still require Macro Express to be installed on the machine running the Macro. AutoHotkey requires macros to be running in the background waiting to be activated. With many macros all waiting in the background those separate processes can add up and possibly be a bit confusing. With Macro Express all macros are contained within the Macro Express program that sits in your tray. So you don't have a bunch of separate macros all waiting in the background to be activated.
User avatar
Psychonaut
Posts: 109
Joined: April 7th, 2008, 3:56 am
Location: Winnipeg
Contact:

Re: Thunderbird macro possible?

Post by Psychonaut »

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.
Post Reply