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

Diff of /contributions/modules/mail_redirect/mail_redirect.module

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

revision 1.1, Tue Jun 10 00:27:15 2008 UTC revision 1.2, Fri Jun 27 16:06:34 2008 UTC
# Line 4  Line 4 
4  /* redirect any system generated email to your configured email domain  /* redirect any system generated email to your configured email domain
5  *    usage:  *    usage:
6  *       - in your test site's settings.php set:  *       - in your test site's settings.php set:
7  *       $conf = array('lifewire_debug_mail_domain' => "mydomain.com");  *       $conf = array('mail_redirect_domain' => "mydomain.com");
8  *  *
9  *   result:  *   result:
10  *       - input $to:    john_smith@about.com  *       - input $to:    john_smith@about.com
# Line 71  function mail_redirect_admin_settings() Line 71  function mail_redirect_admin_settings()
71  */  */
72  function mail_redirect_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {  function mail_redirect_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {
73    
74    $mydomain = variable_get('mail_redirect_mail_domain', 'NA');    $mydomain = variable_get('mail_redirect_domain', 'NA');
75    
76    if ($mydomain != 'NA') {    if ($mydomain != 'NA') {
77      drupal_set_message("The following TO address or list: $to has been redirected to the following TEST DOMAIN: $mydomain", 'status');      drupal_set_message(t("The following TO address or list: %to has been redirected to the following TEST DOMAIN: %mydomain",
78      $to = preg_replace('^((.+)@.+)^', "$2@$mydomain", $to);        array('%to' => htmlentities($to), '%mydomain' => $mydomain), 'status'));
79    
80        /* need to handle RFC2822 formats for $to:
81        *    user@example.com
82        *    user@example.com, anotheruser@example.com
83        *    User <user@example.com>
84        *    User <user@example.com>, Another User <anotheruser@example.com>
85        */
86    
87        if (stristr($to, ",")) {      // then we have a list
88          $tos = split(",", $to);
89          array_walk($tos, '_mail_redirect_trim_array_values');
90        }
91        else $tos = (array)$to;
92    
93        foreach ($tos as $key => $to) {
94          if (stristr($to, "<")) $tos[$key] = preg_replace('^(.*)<((.+)@.+)>^', "$1<$3@$mydomain>", $to);
95          else $tos[$key] = preg_replace('^((.+)@.+)^', "$2@$mydomain", $to);
96        }
97    
98        $to = join(",", $tos);
99    
100    }    }
101  }  }
102    
# Line 117  function mail_redirect_requirements($pha Line 138  function mail_redirect_requirements($pha
138    }    }
139    return $requirements;    return $requirements;
140  }  }
141    
142    function _mail_redirect_trim_array_values(&$value) {
143      $value = trim($value);
144    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2