Question

I am working on writing an add-on for Thunderbird and would like to be able to cancel the sending of an email under certain conditions. I have the following code which allows me to execute code before the email is sent, but I don't know how to stop it.

document.getElementById("msgcomposeWindow").addEventListener( "compose-send-message", function(){
  var msgcomposeWindow = document.getElementById( "msgcomposeWindow" );
  var msg_type = msgcomposeWindow.getAttribute( "msgtype" );

  // do not continue unless this is an actual send event
  if( !(msg_type == nsIMsgCompDeliverMode.Now || msg_type == nsIMsgCompDeliverMode.Later) )
      return;


  alert('Sending Message...');//works fine
  if(true){ //eventually this would have more logic...
    //stop email
  }else{
    //let email go
  }
}, true );

What do I need to do to stop the email?

Était-ce utile?

La solution

In order to prevent the email from being sent you'd need to prevent the event from bubbling up:

function send_event_handler( evt ) {
    if(shouldStopEmail) {
        evt.preventDefault();
        return false;
    }
}

window.addEventListener( "compose-send-message", send_event_handler, true );
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top