function print_mail_mail in Printer, email and PDF versions 7.2
Same name and namespace in other branches
- 5.3 print_mail/print_mail.inc \print_mail_mail()
- 6 print_mail/print_mail.inc \print_mail_mail()
- 7 print_mail/print_mail.module \print_mail_mail()
- 5.x print_mail/print_mail.inc \print_mail_mail()
Implements hook_mail().
File
- print_mail/
print_mail.module, line 189 - Displays Printer-friendly versions of Drupal pages.
Code
function print_mail_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
if (isset($params['from'])) {
$message['headers']['Reply-To'] = $params['from'];
}
$sendlink_plain = '';
$sendlink_html = '';
switch ($key) {
case 'sendpage':
$message['body'][] = check_plain($params['body']);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
case 'sendlink':
// Generate plain-text and html versions of message with link.
$sendlink_plain = theme('print_mail_sendlink_plain', $params);
$sendlink_html = theme('print_mail_sendlink_html', $params);
// Send HTML-only version if MIME library not present.
if (!class_exists('Mail_mime')) {
$message['body'][] = check_plain($sendlink_html);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
}
// No break on purpose.
case 'plain-attachment':
case 'inline-attachment':
// Configure new MIME object.
$mime = new Mail_mime("\n");
$mime_params['html_encoding'] = '7bit';
$mime_params['html_charset'] = 'utf-8';
$mime_params['text_charset'] = 'utf-8';
// Pass message contents into MIME object.
switch ($key) {
case 'sendlink':
$mime
->setTxtBody($sendlink_plain);
$mime
->setHTMLBody($sendlink_html);
break;
case 'inline-attachment':
$mime
->setHTMLBody($params['body']);
// No break on purpose.
case 'plain-attachment':
$mime
->setTxtBody($params['message']);
$mime
->addAttachment($params['body'], 'text/html', 'Attachment.html', FALSE);
break;
}
// Store MIME message output in message array.
$message['body'][] = check_plain($mime
->get($mime_params));
$message['headers'] = $mime
->headers($message['headers']);
// Strip special characters from Content-Type header. Required to prevent
// mime_header_encode() from disrupting Content-Type header.
$message['headers']['Content-Type'] = preg_replace('/[^\\x20-\\x7E]/', '', $message['headers']['Content-Type']);
break;
}
}