You are here

public function MandrillMailSystem::format in Mandrill 6

Same name and namespace in other branches
  1. 7.2 lib/mandrill.mail.inc \MandrillMailSystem::format()
  2. 7 lib/mandrill.mail.inc \MandrillMailSystem::format()

Concatenate and wrap the email body for either plain-text or HTML emails.

Parameters

$message: A message array, as described in hook_mail_alter().

Return value

The formatted $message.

File

./mandrill.mail.inc, line 27
Class for sending mails via Mandrill.

Class

MandrillMailSystem
Modify the drupal mail system to use Mandrill when sending emails.

Code

public function format(array $message) {

  // Join the body array into one string.
  if (is_array($message['body'])) {
    $message['body'] = implode("\n\n", $message['body']);
  }

  // Undoes damage to the HTML e-mail done by drupal_wrap_mail() because this can break
  // check_markup() depending on the filters you're using -- particularly the newline filter.
  // Ideally, we'd run check_markup() before the message is passed to drupal_wrap_mail(), but
  // I don't see a good way to do that!
  $message['body'] = preg_replace_callback('/<[^<>]*>/s', '_mandrill_remove_newlines', $message['body']);
  return $message;
}