You are here

class Messaging_Mail_Method in Messaging 6.3

Same name and namespace in other branches
  1. 7 messaging_mail/messaging_mail.inc \Messaging_Mail_Method

Base class for mail sending methods

Hierarchy

Expanded class hierarchy of Messaging_Mail_Method

1 string reference to 'Messaging_Mail_Method'
messaging_mail_messaging in messaging_mail/messaging_mail.module
Implementation of hook_messaging()

File

classes/messaging_method.class.inc, line 316
Drupal Messaging Framework - Send_Method class file

View source
class Messaging_Mail_Method extends Messaging_Send_Method {
  public $default_from;
  function __construct($info, $method) {
    parent::__construct($info, $method);
    $this->default_from = variable_get('site_mail', ini_get('sendmail_from'));
  }
  function get_default_sender() {
    return array(
      'name' => variable_get('site_name', 'Drupal'),
      'from' => $this->default_from,
    );
  }

  /**
   * Rebuild message in Drupal mail format
   * @param $message
   *   Message object
   */
  function message_prepare($message) {
    if (empty($message->params['from'])) {
      if (!empty($message->sender_account) && !empty($message->sender_account->mail)) {
        $from = check_plain($message->sender_account->name) . ' <' . $message->sender_account->mail . '>';
      }
      elseif (!empty($message->sender_name) && $default_from) {
        $from = check_plain($message->sender_name) . ' <' . $this->default_from . '>';
      }
      else {
        $from = $this->default_from;
      }
      $message->params['from'] = $from;
    }
    $message->params['mail_headers'] = $this
      ->mail_headers($message);
  }

  /**
   * Get mail headers. Helper function for mail methods
   */
  function mail_headers($message) {
    $headers = !empty($message->params['headers']) ? $message->params['headers'] : array();

    // Add some default headers
    $headers += array(
      'MIME-Version' => '1.0',
      'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
      'Content-Transfer-Encoding' => '8Bit',
      'X-Mailer' => 'Drupal',
    );
    $from = !empty($message->params['from']) ? $message->params['from'] : $this->default_from;

    // Set default headers depending on data
    $headers += array(
      'From' => $from,
      'Reply-To' => $from,
    );
    if ($this->default_from) {

      // To prevent e-mail from looking like spam, the addresses in the Sender and
      // Return-Path headers should have a domain authorized to use the originating
      // SMTP server. Errors-To is redundant, but shouldn't hurt.
      $more_headers['Sender'] = $more_headers['Return-Path'] = $more_headers['Errors-To'] = $this->default_from;
      $headers += $more_headers;
    }
    return $headers;
  }

  /**
   * Message ready for sending, invoke mail alter
   */
  function message_presend($message) {
    $mail = array(
      'id' => 'messaging_' . (!empty($message->type) ? 'message-' . $message->type : 'message'),
      'to' => $message->destination,
      'from' => $message->params['from'],
      'language' => $message
        ->get_language(),
      'params' => $message->params,
      'subject' => $message->subject,
      'body' => $message->body,
      'headers' => $message->params['mail_headers'],
      'attachments' => !empty($message->files) ? $message->files : array(),
    );

    // Invoke hook_mail_alter()
    drupal_alter('mail', $mail);

    // Rebuild message with results
    $message->destination = $mail['to'];
    $message->params = $mail['params'];
    $message->params['from'] = $mail['from'];
    $message->params['mail_headers'] = $mail['headers'];
    $message->subject = $mail['subject'];
    $message->body = $mail['body'];

    // Other parts are not suppossed to change, like language, files
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Messaging_Mail_Method::$default_from public property
Messaging_Mail_Method::get_default_sender function
Messaging_Mail_Method::mail_headers function Get mail headers. Helper function for mail methods
Messaging_Mail_Method::message_prepare function Rebuild message in Drupal mail format
Messaging_Mail_Method::message_presend function Message ready for sending, invoke mail alter
Messaging_Mail_Method::__construct function