You are here

function reroute_email_test_mail in Reroute Email 7

Same name and namespace in other branches
  1. 8 tests/modules/reroute_email_test/reroute_email_test.module \reroute_email_test_mail()
  2. 2.x tests/modules/reroute_email_test/reroute_email_test.module \reroute_email_test_mail()

Implements hook_mail().

This function allows testing Reroute Email's handling of a string passed for message's body instead of an Array as required by drupal_mail. It also allows testing the robustness of the handling of Cc and Bcc header keys. Body, Cc and Bcc values are initialized from test case through $params.

File

tests/reroute_email_test.module, line 31
Provides Mail hook implementations for testing the Reroute Email module.

Code

function reroute_email_test_mail($key, &$message, $params) {
  if ($key != 'test_reroute_email') {
    return;
  }
  $message['subject'] = 'Reroute Email Test: Message body is a string, Cc and Bcc header keys have a special case';

  // Body is provided as a string.
  if (!empty($params['body'])) {
    $message['body'] = $params['body'];
  }

  // Provide Cc and Bcc headers with an unexpected case.
  if (!empty($params['headers']['test_cc_key']) && !empty($params['headers'][$params['headers']['test_cc_key']])) {
    $message['headers'][$params['headers']['test_cc_key']] = $params['headers'][$params['headers']['test_cc_key']];
  }
  if (!empty($params['headers']['test_bcc_key']) && !empty($params['headers'][$params['headers']['test_bcc_key']])) {
    $message['headers'][$params['headers']['test_bcc_key']] = $params['headers'][$params['headers']['test_bcc_key']];
  }
}