function reroute_email_test_mail_alter in Reroute Email 7
Same name and namespace in other branches
- 8 tests/modules/reroute_email_test/reroute_email_test.module \reroute_email_test_mail_alter()
- 2.x tests/modules/reroute_email_test/reroute_email_test.module \reroute_email_test_mail_alter()
Implements hook_mail_alter().
This helper function is necessary to catch message's body if it is a string to make it an array to be compliant with drupal_mail and prevent a Warning: implode(): Invalid arguments passed in DefaultMailSystem->format().
File
- tests/
reroute_email_test.module, line 57 - Provides Mail hook implementations for testing the Reroute Email module.
Code
function reroute_email_test_mail_alter(&$message) {
// Only alter the email for the key test_reroute_email.
if ($message['key'] != 'test_reroute_email') {
return;
}
// Prevent Warning from drupal_mail because body is not an array, only if
// message has already been processed by reroute_email.
if (is_string($message['body']) && isset($message['headers']['X-Rerouted-Mail-Key'])) {
// Record to be checked in test in the log entries.
watchdog('reroute_email_test', 'A String was detected in the body: <pre>!body</pre>', array(
'!body' => $message['body'],
), WATCHDOG_NOTICE);
// Convert body to an Array.
$message['body'] = array(
$message['body'],
);
}
}