How do you cancel sending an email in Thunderbird? [Solved]


(Musiquegraeme) #1

I have an addon with an EventListener that pops up when an email is to be sent and, if certain criteria are not met, should cancel the send. I can’t figure out, with bootstrapped addons, this can be done. Any ideas?
Blessings


#2

Presumably refers to this addon?


(Musiquegraeme) #3

What version of the addon are you referring to. That addon was updated around then and works fine as far as I know. It works for me. You should have version 1.5. Is your TB set to automatically update?
The question I raised was because I’m trying to move the addon into a restartless one which will be necessary for it to keep working as Tb moves to TB 60.
Blessings


#4

I was merely clarifying you question by linking to your own earlier question. You didn’t mention Thunderbird at all. Most questions here refer to Firefox.


(Musiquegraeme) #5

OK.
I found the answer as well.
By adding event to the action for the event listener as
var myAlertForClosure = function(event) {myAlertToSend(event);}

mySendButton.addEventListener( “command”, myAlertForClosure );

Then in the function
function myAlertToSend(e) {
I can put
e.preventDefault();
and the default action of the event is stopped.!
Blessings


#6

Good. I suggest you tag any future questions ‘thunderbird’ - maybe you can do that in retrospect - don’t know. I wonder if there should be a separate sub-forum for TB?
I don’t use your addon, but I’ll now go and check the ones I do use for future compatibility.


(Musiquegraeme) #7

It turned out the e.preventDefault method only works for cancelling click events on the toolbar. If the send is the result of a short cut key, like Cntrl-Enter or Cntrl- Shift-Enter, or even a click on the menu, e.preventDefault doesn’t work.

When using an overlay it was possible to respond to either SendMessage or SendMessageLater or SendWithCheck but these don’t seem to be events one can have listeners for. How can all the different ways of sending be caught?
Blessings


(Musiquegraeme) #8

OK. Solved again. Picked up all the other ways of sending email with
document.addEventListener(“command”,myAlertForClosureCommand,true);

The function
function myAlertToSendCommand(e) {

switch (e.target.id) {
	case "key_sendLater":
	case "key_send":
	case "cmd_sendNow":
	case "cmd_sendLater":
		e.stopPropagation();
		myAlertToSend(e);
	}
}

uses e.stopPropagation to stop everything…
in myAlertToSend I use
switch (e.target.id) {
case “key_send”:
console.log(“KeySend”);
win.SendMessageWithCheck();
break;
case “cmd_sendNow”:
console.log(“SendNow”);
win.SendMessage();
break;
case “key_sendLater”:
case “cmd_sendLater”:
console.log(“SendLater”);
win.SendMessageLater();
break;
}

to use the relavent functions to send the mail if required. :slight_smile: