You are here

function mimemail_compress_clean_message in Mime Mail 7

Same name and namespace in other branches
  1. 6 modules/mimemail_compress/mimemail_compress.inc \mimemail_compress_clean_message()

Separates CSS from HTML for processing.

1 call to mimemail_compress_clean_message()
mimemail_compress_mail_post_process in modules/mimemail_compress/mimemail_compress.module
Implements mail_post_process().

File

modules/mimemail_compress/mimemail_compress.inc, line 13
Converts CSS styles into inline style attributes.

Code

function mimemail_compress_clean_message($message) {
  $parts = array();
  preg_match('|(<style[^>]+)>(.*)</style>|mis', $message, $matches);
  if (isset($matches[0]) && isset($matches[2])) {
    $css = str_replace('<!--', '', $matches[2]);
    $css = str_replace('-->', '', $css);
    $css = preg_replace('|\\{|', "\n{\n", $css);
    $css = preg_replace('|\\}|', "\n}\n", $css);
    $html = str_replace($matches[0], '', $message);
    $parts = array(
      'html' => $html,
      'css' => $css,
    );
  }
  return $parts;
}