You are here

function Messaging_HTML_MailSystem::mimemail_html_body in Messaging 7

Generate a multipart message body with a text alternative for some html text

Parameters

$body An HTML message body:

$subject The message subject:

Return value

an array containing the elements 'header' and 'body'. 'body' is the mime encoded multipart body of a mail. 'headers' is an array that includes some headers for the mail to be sent.

The first mime part is a multipart/alternative containing mime-encoded sub-parts for HTML and plaintext. Each subsequent part is the required image/attachment

1 call to Messaging_HTML_MailSystem::mimemail_html_body()
Messaging_HTML_MailSystem::format in messaging_htmlmail/messaging_htmlmail.inc
Concatenate and wrap the e-mail body for plain-text mails.

File

messaging_htmlmail/messaging_htmlmail.inc, line 203
Drupal Messaging Framework - Send_Method class file

Class

Messaging_HTML_MailSystem
Sendgrid mail system

Code

function mimemail_html_body($body, $subject, $text = NULL, $attachments = array()) {
  if (empty($text)) {

    // todo: remove this preg_replace once filter_xss() is properly handling
    // direct descendant css selectors '>' in inline CSS. For now this cleans
    // up our plain text part. See mimemail #364198, drupal #370903
    $text = preg_replace('|<style.*?</style>|mis', '', $body);
    $text = drupal_html_to_text($text);
  }
  $content_type = 'multipart/related; type="multipart/alternative"';
  $text_part = array(
    'Content-Type' => 'text/plain; charset=utf-8',
    'content' => $text,
  );

  /**
       * @todo When replacing links we break the ones that are yet to be replaced (tokens)
      //expand all local links
      $pattern = '/(<a[^>]+href=")([^"]*)/mi';
      $body = preg_replace_callback($pattern, '_messaging_htmlmail_expand_links', $body);
      **/
  $mime_parts = $this
    ->mimemail_extract_files($body);
  $content = array(
    $text_part,
    array_shift($mime_parts),
  );
  $content = $this
    ->mimemail_multipart_body($content, 'multipart/alternative', TRUE);
  $parts = array(
    array(
      'Content-Type' => $content['headers']['Content-Type'],
      'content' => $content['body'],
    ),
  );
  if ($mime_parts) {
    $parts = array_merge($parts, $mime_parts);
  }
  foreach ($attachments as $a) {
    $a = (object) $a;

    // Check the list parameter if its set or ignore it (Upload module support).
    if (!isset($a->list) || $a->list) {
      _messaging_htmlmail_file($a->filepath, $a->filename, $a->filemime, 'attachment');
      $parts = array_merge($parts, _messaging_htmlmail_file());
    }
  }
  return $this
    ->mimemail_multipart_body($parts, $content_type);
}