/[drupal]/contributions/modules/reroute_email/reroute_email.module
ViewVC logotype

Diff of /contributions/modules/reroute_email/reroute_email.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.6, Thu Jul 24 14:32:35 2008 UTC revision 1.6.2.1, Fri Nov 21 23:24:23 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: reroute_email.module,v 1.1.2.5 2008/04/03 03:18:43 kbahey Exp $  // $Id: reroute_email.module,v 1.6 2008/07/24 14:32:35 kbahey Exp $
4    
5  define('REROUTE_EMAIL_ADDRESS',  'reroute_email_address');  define('REROUTE_EMAIL_ADDRESS', 'reroute_email_address');
6    
7  /**  /**
8   * Implementation of hook_perm().   * Implementation of hook_perm().
# Line 27  function reroute_email_menu() { Line 27  function reroute_email_menu() {
27    
28  function reroute_email_settings() {  function reroute_email_settings() {
29    $form[REROUTE_EMAIL_ADDRESS] = array(    $form[REROUTE_EMAIL_ADDRESS] = array(
30      '#type'          => 'textfield',      '#type'          => 'textarea',
31      '#title'         => t('Email address'),      '#title'         => t('Email addresses'),
32      '#required'      => TRUE,      '#required'      => TRUE,
33      '#default_value' => variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')),      '#default_value' => variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')),
34      '#size'          => 35,      '#cols'          => 35,
35      '#description'   => t('The email address to reroute all emails from the site to.')      '#rows'          => 5,
36        '#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.')
37    );    );
38    
39    return system_settings_form($form);    return system_settings_form($form);
# Line 41  function reroute_email_settings() { Line 42  function reroute_email_settings() {
42  function reroute_email_mail_alter(&$message) {  function reroute_email_mail_alter(&$message) {
43    global $base_url;    global $base_url;
44    
45    if (!empty($message) && is_array($message)) {    if (empty($message)) {
46      $mailkey = isset($message['id']) ? $message['id'] : t('<mail id> is missing');      return;
47      $to = isset($message['to']) ? $message['to'] : t('<to> is missing');    }
48    
49      if (!is_array($message)) {
50        return;
51      }
52    
53      $mailkey = isset($message['id']) ? $message['id'] : t('<mail id> is missing');
54      $to = isset($message['to']) ? $message['to'] : t('<to> is missing');
55    
56    // Suppress Bcc and Cc fields otherwise email will still go out to those addresses    // Suppress Bcc and Cc fields otherwise email will still go out to those addresses
57      if (isset($message['headers']) && is_array($message['headers'])) {    if (isset($message['headers']) && is_array($message['headers'])) {
58        if (isset($message['headers']['Bcc'])) {      if (isset($message['headers']['Bcc'])) {
59          unset($message['headers']['Bcc']);        unset($message['headers']['Bcc']);
60        }      }
61        if (isset($message['headers']['Cc'])) {      if (isset($message['headers']['Cc'])) {
62          unset($message['headers']['Cc']);        unset($message['headers']['Cc']);
       }  
63      }      }
64    }    }
65    
66    // Format a message to show at the top    // Split the address string on whitespace, ignoring any empty results
67    $msg[] = t("This email was rerouted.");    $addresslist = preg_split('/\s/', variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')), -1, PREG_SPLIT_NO_EMPTY);
   $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());  
68    
69    // Change the $to address to be the one we defined    if (in_array($to, $addresslist)) {
70    $message['to'] = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from'));      // To address is in the pass-through list, let it pass through
71        $message['to'] = $to;
72      }
73      else {
74        // Not on the list, so reroute to the first address in the list
75        $message['to'] = $addresslist[0];
76        // Format a message to show at the top
77        $msg[] = t("This email was rerouted.");
78        $msg[] = t("Web site: @site", array('@site' => $base_url));
79        $msg[] = t("Mail key: @key", array('@key' => $mailkey));
80        $msg[] = t("Originally to: <@to>", array('@to' => $to));
81        $msg[] = "-----------------------";
82    
83        // Prepend to the body of the email
84        // -- I really think we should simply this a bit -- Khalid
85        $message['body'] = array_merge($msg, isset($message['body']) ? (is_array($message['body']) ? $message['body'] : array($message['body'])) : array());
86      }
87  }  }
88    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.6.2.1

  ViewVC Help
Powered by ViewVC 1.1.2