public function MailhandlerCommandsDefault::getCommands in Mailhandler 7.2
Same name and namespace in other branches
- 6.2 plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php \MailhandlerCommandsDefault::getCommands()
Implements getCommands().
1 call to MailhandlerCommandsDefault::getCommands()
- MailhandlerCommandsDefault::parse in plugins/
mailhandler/ commands/ MailhandlerCommandsDefault.class.php - Parse commands from email body.
File
- plugins/
mailhandler/ commands/ MailhandlerCommandsDefault.class.php, line 120 - MailhandlerCommandsDefault class.
Class
- MailhandlerCommandsDefault
- Provides default commands.
Code
public function getCommands(&$string, $client = NULL, $source = NULL, $authid = NULL) {
if ($source) {
$config = $source->importer
->getConfig();
}
if ($client) {
$source_config = $source
->getConfigFor($client);
}
$commands = array();
$endcommands = NULL;
// Collect the commands and locate signature.
$lines = explode("\n", $string);
foreach ($lines as $i => $line) {
preg_match('/^([a-zA-Z0-9_-\\s\\.]+):{1}\\s+(.+)$/', $line, $matches);
if (count($matches) == 3) {
$key = trim($matches[1]);
$value = trim($matches[2]);
if (isset($config)) {
if (!(strpos($config['parser']['config']['available_commands'], $key) === FALSE)) {
$commands[$key] = $value;
}
}
elseif (isset($source_config)) {
if (!(strpos($config['parser']['source_config']['commands_failed_auth'], $key) === FALSE)) {
$commands[$key] = $value;
}
}
}
elseif (!empty($commands)) {
$endcommands = count($commands);
break;
}
elseif ($i == 0) {
$endcommands = 0;
break;
}
}
$string = implode("\n", array_slice($lines, $endcommands));
return $commands;
}