You are here

public function MailhandlerCommandsHeaders::process in Mailhandler 7.2

Same name and namespace in other branches
  1. 6.2 plugins/mailhandler/commands/MailhandlerCommandsHeaders.class.php \MailhandlerCommandsHeaders::process()

Set known sources and parse additional sources from body.

Overrides MailhandlerCommands::process

File

plugins/mailhandler/commands/MailhandlerCommandsHeaders.class.php, line 15
MailhandlerCommandsHeaders class.

Class

MailhandlerCommandsHeaders
Provides commands for basic headers.

Code

public function process(&$message, $source) {

  // Populate $message with all values from 'header' object.
  $parts = (array) $message['header'];
  foreach ($parts as $key => $value) {

    // Some keys are already taken, so do not overwrite them.
    if (!in_array($key, array(
      'header',
      'body_text',
      'body_html',
      'mimeparts',
      'mailbox',
      'attachments',
    ))) {

      // Some headers are arrays of objects.
      if (in_array($key, array(
        'to',
        'from',
        'reply_to',
        'sender',
        'cc',
        'bcc',
        'return_path',
      ))) {
        $message[$key . '-name'] = array();
        $message[$key . '-address'] = array();
        $message[$key . '-mailbox'] = array();
        $message[$key . '-host'] = array();
        foreach ($value as $valkey => $val) {
          $message[$key . '-name'][$valkey] = isset($val->personal) ? iconv_mime_decode($val->personal, 0, "UTF-8") : '';
          $message[$key . '-address'][$valkey] = isset($val->mailbox) && isset($val->host) ? $val->mailbox . '@' . $val->host : '';
          $message[$key . '-mailbox'] = isset($val->mailbox) ? $val->mailbox : '';
          $message[$key . '-host'] = isset($val->host) ? $val->host : '';
        }
      }
      else {
        $message[$key] = iconv_mime_decode($value, 0, "UTF-8");
      }
    }
  }
}