public function HTMLMailSystem::formatMailMIME in HTML Mail 8.2
Same name and namespace in other branches
- 6.2 htmlmail.mail.inc \HTMLMailSystem::formatMailMIME()
- 7.2 htmlmail.mail.inc \HTMLMailSystem::formatMailMIME()
Use the MailMime class to format the message body.
See also
http://drupal.org/project/mailmime
1 call to HTMLMailSystem::formatMailMIME()
- HTMLMailSystem::format in ./
htmlmail.mail.inc - Format emails according to module settings.
File
- ./
htmlmail.mail.inc, line 154 - Formats and sends mail using the MailMIME class.
Class
- HTMLMailSystem
- Implements MailSystemInterface.
Code
public function formatMailMIME(array &$message) {
$eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
$message['body'] = MailMIME::concat($message['body']);
// Build a full email message string.
$email = MailMIME::encodeEmail($message['headers'], $message['body']);
// Parse it into MIME parts.
if (!($mime = MailMIME::parse($email))) {
watchdog('HTMLMailSystem', 'Could not parse email message.', array(), WATCHDOG_ERROR);
return $message;
}
// Work on a copy so that the original $message['body'] remains unchanged.
$email = $message;
if (!($email['body'] = $mime
->getHTMLBody()) && !($email['body'] = $mime
->getTXTBody())) {
$email['body'] = '';
}
else {
// Wrap formatted plaintext in <pre> tags.
if ($email['body'] === strip_tags($email['body']) && preg_match('/.' . $eol . './', $email['body'])) {
$email['body'] = '<pre>' . $email['body'] . '</pre>';
}
}
// Theme with htmlmail.tpl.php.
$body = theme('htmlmail', $email);
$mime
->setHTMLBody($body);
// @todo Change to drupal_html_to_text when issue #299138 gets resolved.
$mime
->setTXTBody(mailsystem_html_to_text($body));
$message['MailMIME'] =& $mime;
return $body;
}