From 2d379669698603ca3aa005a41366a0e475ab94e7 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Thu, 28 Apr 2011 23:35:42 -0400
Subject: [PATCH] Issue #800434 by bar.hanssens, pillarsdotnet: Allow hook_mail_alter implementations to cancel mail.

---
 developer/hooks/core.php |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/developer/hooks/core.php b/developer/hooks/core.php
index 4901c5fb29869e17316b3215073cd746676ed44b..81368e17d82e665db51a43e1ad5d4658083c3d1a 100755
--- a/developer/hooks/core.php
+++ b/developer/hooks/core.php
@@ -1090,12 +1090,18 @@ function hook_profile_alter(&$account) {
  *   - 'params'
  *     An array of optional parameters supplied by the caller of drupal_mail()
  *     that is used to build the message before hook_mail_alter() is invoked.
- *   - language'
+ *   - 'language'
  *     The language object used to build the message before hook_mail_alter()
  *     is invoked.
+ *  - 'cancel':
+ *     Set to TRUE to abort sending this message.
  */
 function hook_mail_alter(&$message) {
   if ($message['id'] == 'modulename_messagekey') {
+    // If the recipient has not opted to receive such messages, cancel sending.
+    if (!modulename_messagekey_optin($message['to'])) {
+      $message['cancel'] = TRUE;
+    }
     $message['body'][] = "--\nMail sent out from " . variable_get('sitename', t('Drupal'));
   }
 }
-- 
1.7.1

