public function MailhandlerCommandsDefault::parse in Mailhandler 7.2
Same name and namespace in other branches
- 6.2 plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php \MailhandlerCommandsDefault::parse()
Parse commands from email body.
Parameters
array $message: Message including body fields.
object $source: Source config.
Overrides MailhandlerCommands::parse
File
- plugins/
mailhandler/ commands/ MailhandlerCommandsDefault.class.php, line 20 - MailhandlerCommandsDefault class.
Class
- MailhandlerCommandsDefault
- Provides default commands.
Code
public function parse(&$message, $source, $client) {
// 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;
}
}
}
}