--- reroute_email.module (revision 24988) +++ reroute_email.module (working copy) @@ -3,6 +3,7 @@ // $Id: reroute_email.module,v 1.6 2008/07/24 14:32:35 kbahey Exp $ define('REROUTE_EMAIL_ADDRESS', 'reroute_email_address'); +define('REROUTE_EMAIL_SILENT', 'reroute_email_silent'); /** * Implementation of hook_perm(). @@ -34,7 +35,13 @@ '#size' => 35, '#description' => t('The email address to reroute all emails from the site to.') ); - + $form[REROUTE_EMAIL_SILENT] = array( + '#type' => 'checkbox', + '#title' => t('Silent BCC'), + '#default_value' => variable_get(REROUTE_EMAIL_SILENT, 0), + '#description' => t('Reroute all emails silently by sending out both orginal recipents and the reroute recipient.'), + ); + return system_settings_form($form); } @@ -44,28 +51,44 @@ if (!empty($message) && is_array($message)) { $mailkey = isset($message['id']) ? $message['id'] : t(' is missing'); $to = isset($message['to']) ? $message['to'] : t(' 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 (variable_get(REROUTE_EMAIL_SILENT, 0)) { + if (isset($message['headers']) && is_array($message['headers'])) { + if (isset($message['headers']['Bcc'])) { + $message['headers']['Bcc'] .= ', ' . variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')); + } else { + $message['headers']['Bcc'] = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')); + } } - if (isset($message['headers']['Cc'])) { - unset($message['headers']['Cc']); + } else { + // 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']); + } } + } } // 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[] = "-----------------------"; + if (variable_get(REROUTE_EMAIL_SILENT, 0)) { + watchdog('content', 'BCC to "@bcc-address" of an E-Mail to "@to-address".', $variables = array('@to-address' => $message['to'], '@bcc-address' => variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')))); + } else { + $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 + $message['body'] = array_merge($msg, isset($message['body']) ? (is_array($message['body']) ? $message['body'] : array($message['body'])) : array()); - // Prepend to the body of the email - $message['body'] = array_merge($msg, isset($message['body']) ? (is_array($message['body']) ? $message['body'] : array($message['body'])) : array()); - - // Change the $to address to be the one we defined - $message['to'] = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')); + // Change the $to address to be the one we defined + $message['to'] = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')); + } + }