You are here

function print_mail_mail in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.3 print_mail/print_mail.inc \print_mail_mail()
  2. 7.2 print_mail/print_mail.module \print_mail_mail()
  3. 7 print_mail/print_mail.module \print_mail_mail()
  4. 5.x print_mail/print_mail.inc \print_mail_mail()

Implementation of hook_mail().

File

print_mail/print_mail.inc, line 361

Code

function print_mail_mail($key, &$message, $params) {
  $message['subject'] = $params['subject'];
  if (isset($params['from'])) {
    $message['headers']['Reply-To'] = $params['from'];
  }
  switch ($key) {
    case 'sendpage':
      $message['body'] = module_exists('mailsystem') ? check_plain($params['body']) : $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 = $params['message'] . '\\n\\n' . $params['link'];
      $sendlink_html = $params['message'] . '<br/><br/>' . l($params['title'], $params['link']);

      // Send HTML-only version if MIME library not present
      if (!class_exists('Mail_mime')) {
        $message['body'] = module_exists('mailsystem') ? check_plain($sendlink_html) : $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'] = $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;
  }
}