If you go the end of the function webform_submission_send_mail() inside the file webform.submissions.inc (inside weform module's include directory), you'll notice that the webform module using the function drupal_mail()
drupal_mail() to send the mail.
So a better place to change the behavior of the mail from being sent (alter in Drupal terms) is hook_mail_alter(), which is used to alter an email message created by using drupal_mail()
function.
Implementation of the hook to stop the e-mails:
function MODULE_mail_alter(&$message) {
//You can do your conditional check here and depending on that
//you can set the value of $message['send'] to false to stop the mail from being sent.
//place the line below inside conditional loop, or else it'll stop every mail from being sent ;-)
$message['send'] = FALSE;
}
Note: This hook will only work if the mail is generated by drupal_mail()
. If you're sending mail by some other menthod, it'll not be invoked. But, by default Webform module uses drupal_mail()
as mentioned earlier, so there's nothing to worry :-)
You'll also need to clear the caches to make the change effective.