? enable-disable.patch
Index: reroute_email.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/reroute_email/reroute_email.module,v
retrieving revision 1.6.2.3
diff -u -p -r1.6.2.3 reroute_email.module
--- reroute_email.module	7 Oct 2009 17:52:44 -0000	1.6.2.3
+++ reroute_email.module	30 Dec 2009 08:06:14 -0000
@@ -3,6 +3,7 @@
 // $Id: reroute_email.module,v 1.6.2.3 2009/10/07 17:52:44 kbahey Exp $
 
 define('REROUTE_EMAIL_ADDRESS', 'reroute_email_address');
+define('REROUTE_ENABLE_ROUTING', 'reroute_enable_routing');
 
 /**
  * Implementation of hook_perm().
@@ -34,59 +35,69 @@ function reroute_email_settings() {
     '#rows'          => 5,
     '#description'   => t('Provide a list of email addresses to pass through. Any email addresses not on this list will be rerouted to the first address on the list.')
   );
+  
+  $form[REROUTE_ENABLE_ROUTING] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Enable routing'),
+    '#required'      => TRUE,
+    '#default_value' => variable_get(REROUTE_ENABLE_ROUTING, 1),
+    '#description'   => t('Check this box if you want to enable email rerouting. Uncheck to disable rerouting.'),
+  );  
 
   return system_settings_form($form);
 }
 
 function reroute_email_mail_alter(&$message) {
-  global $base_url;
+  if (variable_get(REROUTE_ENABLE_ROUTING, 1)) {
+    global $base_url;
 
-  if (!variable_get(REROUTE_EMAIL_ADDRESS, '')) {
-    // If email address not in settings, then do nothing.
-    return;
-  }
+    if (!variable_get(REROUTE_EMAIL_ADDRESS, '')) {
+      // If email address not in settings, then do nothing.
+      return;
+    }
 
-  if (empty($message)) {
-    return;
-  }
+    if (empty($message)) {
+      return;
+    }
   
-  if (!is_array($message)) {
-    return;
-  }
+    if (!is_array($message)) {
+      return;
+    }
 
-  $mailkey = isset($message['id']) ? $message['id'] : t('<mail id> is missing');
-  $to = isset($message['to']) ? $message['to'] : t('<to> is missing');
+    $mailkey = isset($message['id']) ? $message['id'] : t('<mail id> is missing');
+    $to = isset($message['to']) ? $message['to'] : t('<to> is missing');
 
-  // Suppress Bcc and Cc fields otherwise email will still go out to those addresses
-  if (isset($message['headers']) && is_array($message['headers'])) {
-    if (isset($message['headers']['Bcc'])) {
-      unset($message['headers']['Bcc']);
-    }
-    if (isset($message['headers']['Cc'])) {
-      unset($message['headers']['Cc']);
+    // Suppress Bcc and Cc fields otherwise email will still go out to those addresses
+    if (isset($message['headers']) && is_array($message['headers'])) {
+      if (isset($message['headers']['Bcc'])) {
+        unset($message['headers']['Bcc']);
+      }
+      if (isset($message['headers']['Cc'])) {
+        unset($message['headers']['Cc']);
+      }
     }
-  }
   
-  // Split the address string on whitespace, ignoring any empty results
-  $addresslist = preg_split('/\s/', variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')), -1, PREG_SPLIT_NO_EMPTY);
+    // Split the address string on whitespace, ignoring any empty results
+    $addresslist = preg_split('/\s/', variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')), -1, PREG_SPLIT_NO_EMPTY);
 
-  if (in_array($to, $addresslist)) {
-    // To address is in the pass-through list, let it pass through
-    $message['to'] = $to;
-  }
-  else {
-    // Not on the list, so reroute to the first address in the list
-    $message['to'] = $addresslist[0];
-    // Format a message to show at the top
-    $msg[] = t("This email was rerouted.");
-    $msg[] = t("Web site: @site", array('@site' => $base_url));
-    $msg[] = t("Mail key: @key", array('@key' => $mailkey));
-    $msg[] = t("Originally to: <@to>", array('@to' => $to));
-    $msg[] = "-----------------------";
-
-    // Prepend to the body of the email
-    // -- I really think we should simply this a bit -- Khalid
-    $message['body'] = array_merge($msg, isset($message['body']) ? (is_array($message['body']) ? $message['body'] : array($message['body'])) : array());
+    if (in_array($to, $addresslist)) {
+      // To address is in the pass-through list, let it pass through
+      $message['to'] = $to;
+    }
+    else {
+      // Not on the list, so reroute to the first address in the list
+      $message['to'] = $addresslist[0];
+      // Format a message to show at the top
+      $msg[] = t("This email was rerouted.");
+      $msg[] = t("Web site: @site", array('@site' => $base_url));
+      $msg[] = t("Mail key: @key", array('@key' => $mailkey));
+      $msg[] = t("Originally to: <@to>", array('@to' => $to));
+      $msg[] = "-----------------------";
+
+      // Prepend to the body of the email
+      // -- I really think we should simply this a bit -- Khalid
+      $message['body'] = array_merge($msg, isset($message['body']) ? (is_array($message['body']) ? $message['body'] : array($message['body'])) : array());
+    }
   }
 }
 
