 reroute_email.test              | 91 +++++++++++++++++++++++++++++++++++++++++
 tests/reroute_email_test.info   |  5 +++
 tests/reroute_email_test.module | 52 +++++++++++++++++++++++
 3 files changed, 148 insertions(+)

diff --git a/reroute_email.test b/reroute_email.test
index 8c38ce6..85f4d88 100644
--- a/reroute_email.test
+++ b/reroute_email.test
@@ -268,3 +268,94 @@ class RerouteEmailTestEmailTestCase extends DrupalWebTestCase {
     $this->assertTrue($mail['headers']['Bcc'] == $post['bcc'], format_string('Bcc is correctly set to submitted value: @address', array('@address' => $post['bcc'])));
   }
 }
+
+/**
+ * Test special cases for body as a string, robustness of cc and bcc headers.
+ */
+class RerouteEmailSpecialTestCase extends DrupalWebTestCase {
+  protected $adminUser;
+
+  /**
+   * Implements DrupalWebTestCase::getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Body string and robust headers',
+      'description' => "Support message's body passed as a string and Cc/Bcc header keys with an unexpected case.",
+      'group' => 'Reroute Email',
+    );
+  }
+
+  /**
+   * Enable modules and create user with specific permissions.
+   */
+  public function setUp() {
+    // Include hidden test helper sub-module.
+    parent::setUp('reroute_email', 'reroute_email_test');
+    $this->adminUser = $this->drupalCreateUser(array(
+      'administer reroute email',
+      // Needed to access log messages in test.
+      'access site reports',
+    ));
+  }
+
+  /**
+   * Test handling of message body as a string and header keys' robustness.
+   */
+  public function testBodyStringRobustHeaders() {
+    $reroute_destination = "rerouted@example.com";
+    $original_destination = "original@example.com";
+    // Initialize Cc and Bcc keys with a special case.
+    $test_cc_key = 'cC';
+    $test_bcc_key = 'bCc';
+    // Login the admin user.
+    $this->drupalLogin($this->adminUser);
+
+    // Configure to reroute normally to rerouted@example.com.
+    $post = array(
+      'reroute_email_address' => $reroute_destination,
+      'reroute_email_enable' => TRUE,
+      'reroute_email_enable_message' => TRUE,
+    );
+    $this->drupalPost("admin/config/development/reroute_email", $post, t('Save configuration'));
+    $this->assertText(t("The configuration options have been saved."));
+
+    // Print test email values for comparing values on test results page.
+    $test_message = array(
+      'to' => $original_destination,
+      'params' => array(
+        'body' => "Test Message body is a string.",
+        'headers' => array(
+          'test_cc_key' => $test_cc_key,
+          'test_bcc_key' => $test_bcc_key,
+          $test_cc_key => "test_cc_key@example.com",
+          $test_bcc_key => "test_bcc_key@example.com"
+        ),
+      ),
+    );
+    // Send test helper sub-module's email.
+    drupal_mail('reroute_email_test', 'test_reroute_email', $test_message['to'], language_default(), $test_message['params']);
+    $this->verbose(t('Test email message values: <pre>@test_message</pre>', array('@test_message' => var_export($test_message, TRUE))));
+
+    $mails = $this->drupalGetMails();
+    $mail = end($mails);
+    // Check rerouted email to.
+    $this->assertMail('to', $reroute_destination, format_string('To email address was rerouted to @address.', array('@address' => $reroute_destination)));
+
+    // Check original to.
+    $search_for = t("Originally to: @to", array('@to' => $original_destination));
+    $has_info = preg_match("/$search_for/", $mail['body']);
+    $this->assertTrue($has_info, t('Found the correct "Originally to" line in the body'));
+    $this->verbose(t('Email body was: <pre>@mail_body</pre>', array('@mail_body' => $mail['body'])));
+    // Check if test message body is found although provided as a string.
+    $this->assertTrue(strpos($mail['body'], $test_message['params']['body']) !== FALSE, 'Email body contains original message body although it was provided as a string.');
+
+    // Check the watchdog entry logged by reroute_email_test_mail_alter.
+    $this->drupalGet('admin/reports/dblog');
+    $this->assertRaw(t('A String was detected in the body'), 'Recorded in recent log messages: a String was detected in the body.');
+
+    // Test the robustness of the CC and BCC keys in headers.
+    $this->assertTrue($mail['headers']['X-Rerouted-Original-Cc'] == $test_message['params']['headers'][$test_cc_key], format_string('X-Rerouted-Original-Cc is correctly set to @test_cc_address, although Cc header message key provided was: @test_cc_key', array('@test_cc_address' => $test_message['params']['headers'][$test_cc_key], '@test_cc_key' => $test_cc_key)));
+    $this->assertTrue($mail['headers']['X-Rerouted-Original-Bcc'] == $test_message['params']['headers'][$test_bcc_key], format_string('X-Rerouted-Original-Bcc is correctly set to @test_bcc_address, although Bcc header message key provided was: @test_bcc_key', array('@test_bcc_address' => $test_message['params']['headers'][$test_bcc_key], '@test_bcc_key' => $test_bcc_key)));
+  }
+}
diff --git a/tests/reroute_email_test.info b/tests/reroute_email_test.info
new file mode 100644
index 0000000..12c2124
--- /dev/null
+++ b/tests/reroute_email_test.info
@@ -0,0 +1,5 @@
+name = "Reroute Email Test"
+description = "Helper module for the reroute email tests."
+core = 7.x
+package = Testing
+hidden = TRUE
diff --git a/tests/reroute_email_test.module b/tests/reroute_email_test.module
new file mode 100644
index 0000000..0baaea5
--- /dev/null
+++ b/tests/reroute_email_test.module
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * @file
+ * Provides Mail hook implementations for testing the Reroute Email module.
+ */
+
+/**
+ * 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. Body, Cc and
+ * Bcc values are initialized from test case through $params.
+ */
+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']];
+  }
+}
+
+/**
+ * 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().
+ */
+function reroute_email_test_mail_alter(&$message) {
+  if ($message['key'] != 'test_reroute_email') {
+    return;
+  }
+  // Prevent Warning from drupal_mail because body is not an array.
+  if (is_string($message['body'])) {
+    // 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']);
+  }
+}
