| 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 |
| 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 |
|
|
| 138 |
} |
} |
| 139 |
return $requirements; |
return $requirements; |
| 140 |
} |
} |
| 141 |
|
|
| 142 |
|
function _mail_redirect_trim_array_values(&$value) { |
| 143 |
|
$value = trim($value); |
| 144 |
|
} |