You are here

public function MailhandlerCommandsDefault::parse in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php \MailhandlerCommandsDefault::parse()

Parse commands from email body.

Parameters

$message: Message including body fields.

$source: Source config.

Overrides MailhandlerCommands::parse

File

plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php, line 17
MailhandlerCommandsDefault class.

Class

MailhandlerCommandsDefault
@file MailhandlerCommandsDefault class.

Code

public function parse(&$message, $source, $client) {
  $config = $source->importer
    ->getConfig();

  // Prepend the default commands.
  // User-added commands will override the default commands.
  $source_config = $source
    ->getConfigFor($client);
  $authid = $message['authenticated_uid'];
  if ($source_config['default_commands']) {
    $message['body_text'] = trim($source_config['default_commands']) . "\n" . $message['body_text'];
  }
  $commands = $this
    ->getCommands($message['body_text'], $client, $source, $authid);
  $this->commands = $commands;
  foreach ($commands as $key => $value) {
    $message['body_html'] = str_replace($key . ': ' . $value, '', $message['body_html']);
    $message['body_html'] = preg_replace('/<br[^>\\r\\n]*>/', '', $message['body_html'], 1);
  }
  if ($message['authenticated_uid'] == 0) {
    $commands = $this
      ->getCommands($source_config['commands_failed_auth'], $client, $source, $authid);
    foreach ($commands as $key => $value) {
      if (isset($this->commands[$key])) {
        $this->commands[$key] = $value;
      }
    }
  }
}