private function _parse_actions($content)
{
$content = str_replace("\r\n", "\n", $content);
$result = NULL;
// supported actions
$patterns[] = '^\\s*discard;';
$patterns[] = '^\\s*keep;';
$patterns[] = '^\\s*stop;';
$patterns[] = '^\\s*fileinto\\s+(:copy\\s+)?(:create\\s+)?(.*?[^\\\\]);';
$patterns[] = '^\\s*redirect\\s+(:copy\\s+)?(.*?[^\\\\]);';
$patterns[] = '^\\s*setflag\\s+(.*?[^\\\\]);';
$patterns[] = '^\\s*addflag\\s+(.*?[^\\\\]);';
$patterns[] = '^\\s*reject\\s+text:(.*)\\n\\.\\n;';
$patterns[] = '^\\s*ereject\\s+text:(.*)\\n\\.\\n;';
$patterns[] = '^\\s*reject\\s+(.*?[^\\\\]);';
$patterns[] = '^\\s*ereject\\s+(.*?[^\\\\]);';
$patterns[] = '^\\s*vacation\\s+(:(days|seconds)\\s+([0-9]+)\\s+)?(:addresses\\s+\\[(.*?[^\\\\])\\]\\s+)?(:subject\\s+(".*?[^"\\\\]")\\s+)?(:handle\\s+(".*?[^"\\\\]")\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(:mime\\s+)?text:(.*)\\n\\.\\n;';
$patterns[] = '^\\s*vacation\\s+(:(days|seconds)\\s+([0-9]+)\\s+)?(:addresses\\s+\\[(.*?[^\\\\])\\]\\s+)?(:subject\\s+(".*?[^"\\\\]")\\s+)?(:handle\\s+(".*?[^"\\\\]")\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(.*?[^\\\\]);';
$patterns[] = '^\\s*notify\\s+:method\\s+(".*?[^"\\\\]")\\s+(:options\\s+\\[(.*?[^\\\\])\\]\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(:importance\\s+(".*?[^"\\\\]")\\s+)?:message\\s+(".*?[^"\\\\]");';
$patterns[] = '^\\s*notify\\s+(:options\\s+\\[(.*?[^\\\\])\\]\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(:importance\\s+(".*?[^"\\\\]")\\s+)?:message\\s+(".*?[^"\\\\]")\\s+(.*?[^\\\\]);';
$patterns[] = '^\\s*addheader\\s+(:(last))?\\s*(".*?[^"\\\\]")\\s+(".*?[^"\\\\]");';
$patterns[] = '^\\s*deleteheader\\s+(:(last)|:index\\s([0-9])+)?\\s*(:(contains))?\\s*(".*?[^"\\\\]")\\s*(".*?[^"\\\\]")?;';
$patterns[] = '^\\s*set\\s+(".*?[^"\\\\]")\\s+(".*?[^"\\\\]");';
$pattern = '/(' . implode('$)|(', $patterns) . '$)/ms';
// parse actions body
if (preg_match_all($pattern, $content, $mm, PREG_SET_ORDER)) {
foreach ($mm as $m) {
$content = trim($m[0]);
if (preg_match('/^(discard|keep|stop)/', $content, $matches)) {
$result[] = array('type' => $matches[1]);
} elseif (preg_match('/^fileinto\\s+:copy/', $content)) {
$result[] = array('type' => 'fileinto_copy', 'target' => $this->_parse_string($m[sizeof($m) - 1]));
} elseif (preg_match('/^fileinto/', $content)) {
$result[] = array('type' => 'fileinto', 'target' => $this->_parse_string($m[sizeof($m) - 1]));
} elseif (preg_match('/^redirect\\s+:copy/', $content)) {
$result[] = array('type' => 'redirect_copy', 'target' => $this->_parse_string($m[sizeof($m) - 1]));
} elseif (preg_match('/^redirect/', $content)) {
$result[] = array('type' => 'redirect', 'target' => $this->_parse_string($m[sizeof($m) - 1]));
} elseif (preg_match('/^(reject|ereject)\\s+(.*);$/sm', $content, $matches)) {
$result[] = array('type' => $matches[1], 'target' => $this->_parse_string($matches[2]));
} elseif (preg_match('/^(setflag|addflag)/', $content)) {
if (in_array('imap4flags', $this->supported)) {
$result[] = array('type' => 'imap4flags', 'target' => $this->_parse_string($m[sizeof($m) - 1]));
} else {
$result[] = array('type' => 'imapflags', 'target' => $this->_parse_string($m[sizeof($m) - 1]));
}
} elseif (preg_match('/^vacation\\s+(:(days|seconds)\\s+([0-9]+)\\s+)?(:addresses\\s+\\[(.*?[^\\\\])\\]\\s+)?(:subject\\s+(".*?[^"\\\\]")\\s+)?(:handle\\s+(".*?[^"\\\\]")\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(.*);$/sm', $content, $matches)) {
$origsubject = "";
if (substr($matches[7], -13, 12) == ": \${subject}") {
$matches[7] = trim(substr($matches[7], 0, -13)) . "\"";
$origsubject = "1";
}
if ($matches[11] == "\"\${from}\"") {
$matches[11] = "\"auto\"";
}
// if (function_exists("mb_decode_mimeheader")) $matches[7] = mb_decode_mimeheader($matches[7]);
if (strpos($matches[12], 'Content-Type: multipart/alternative') !== false) {
$htmlmsg = true;
preg_match('/Content-Type: text\\/html; charset=([^\\r\\n]+).*<body>(.+)<\\/body>/sm', $matches[12], $htmlparts);
$msg = quoted_printable_decode($htmlparts[2]);
$charset = $htmlparts[1];
} else {
$htmlmsg = false;
$msg = $this->_parse_string($matches[12]);
$charset = $this->_parse_charset($matches[12]);
}
// unescape lines which start is a .
$msg = preg_replace('/(^|\\r?\\n)\\.\\./', "\$1.", $msg);
$result[] = array('type' => 'vacation', $matches[2] => $matches[3], 'subject' => $this->_parse_string($matches[7]), 'origsubject' => $origsubject, 'from' => $this->_parse_string($matches[11]), 'addresses' => $this->_parse_string(str_replace("\",\"", ",", $matches[5])), 'handle' => $this->_parse_string($matches[9]), 'msg' => $msg, 'htmlmsg' => $htmlmsg, 'charset' => $charset);
} elseif (preg_match('/^notify\\s+:method\\s+(".*?[^"\\\\]")\\s+(:options\\s+\\[(.*?[^\\\\])\\]\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(:importance\\s+(".*?[^"\\\\]")\\s+)?:message\\s+(".*?[^"\\\\]");$/sm', $content, $matches)) {
$result[] = array('type' => 'notify', 'method' => $this->_parse_string($matches[1]), 'options' => $this->_parse_string($matches[3]), 'from' => $this->_parse_string($matches[5]), 'importance' => $this->_parse_string($matches[7]), 'msg' => $this->_parse_string($matches[8]));
} elseif (preg_match('/^notify\\s+(:options\\s+\\[(.*?[^\\\\])\\]\\s+)?(:from\\s+(".*?[^"\\\\]")\\s+)?(:importance\\s+(".*?[^"\\\\]")\\s+)?:message\\s+(".*?[^"\\\\]")\\s+(.*);$/sm', $content, $matches)) {
$result[] = array('type' => 'enotify', 'method' => $this->_parse_string($matches[8]), 'options' => $this->_parse_string($matches[2]), 'from' => $this->_parse_string($matches[4]), 'importance' => $this->_parse_string($matches[6]), 'msg' => $this->_parse_string($matches[7]));
} elseif (preg_match('/^addheader/', $content)) {
$result[] = array('type' => 'editheaderadd', 'index' => $m[sizeof($m) - 3], 'name' => $this->_parse_string($m[sizeof($m) - 2]), 'value' => $this->_parse_string($m[sizeof($m) - 1]));
} elseif (preg_match('/^deleteheader/', $content)) {
$result[] = array('type' => 'editheaderrem', 'index' => $m[sizeof($m) - 6] == 'last' ? $m[sizeof($m) - 6] : $m[sizeof($m) - 5], 'operator' => $m[sizeof($m) - 3], 'name' => strlen($m[sizeof($m) - 2]) == 0 ? $this->_parse_string($m[sizeof($m) - 1]) : $this->_parse_string($m[sizeof($m) - 2]), 'value' => strlen($m[sizeof($m) - 2]) == 0 ? '' : $this->_parse_string($m[sizeof($m) - 1]));
} elseif (preg_match('/^set/', $content)) {
$result[] = array('type' => 'variables', 'name' => $this->_parse_string($m[sizeof($m) - 2]), 'value' => $this->_parse_string($m[sizeof($m) - 1]));
}
}
}
return $result;
}