- $result = NULL;
-
- // supported actions
- $patterns[] = '^\s*discard;';
- $patterns[] = '^\s*keep;';
- $patterns[] = '^\s*stop;';
- $patterns[] = '^\s*redirect\s+(.*?[^\\\]);';
- if (in_array('fileinto', $this->supported))
- $patterns[] = '^\s*fileinto\s+(.*?[^\\\]);';
- if (in_array('reject', $this->supported)) {
- $patterns[] = '^\s*reject\s+text:(.*)\n\.\n;';
- $patterns[] = '^\s*reject\s+(.*?[^\\\]);';
- $patterns[] = '^\s*ereject\s+text:(.*)\n\.\n;';
- $patterns[] = '^\s*ereject\s+(.*?[^\\\]);';
- }
- if (in_array('vacation', $this->supported))
- $patterns[] = '^\s*vacation\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/', $content))
- {
- $result[] = array('type' => 'fileinto', '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('/^vacation\s+(.*);$/sm', $content, $matches))
- {
- $vacation = array('type' => 'vacation');
-
- if (preg_match('/:(days)\s+([0-9]+)/', $content, $vm)) {
- $vacation['days'] = $vm[2];
- $content = preg_replace('/:(days)\s+([0-9]+)/', '', $content);
- }
- if (preg_match('/:(subject)\s+(".*?[^\\\]")/', $content, $vm)) {
- $vacation['subject'] = $vm[2];
- $content = preg_replace('/:(subject)\s+(".*?[^\\\]")/', '', $content);
- }
- if (preg_match('/:(addresses)\s+\[(.*?[^\\\])\]/', $content, $vm)) {
- $vacation['addresses'] = $this->_parse_list($vm[2]);
- $content = preg_replace('/:(addresses)\s+\[(.*?[^\\\])\]/', '', $content);
- }
- if (preg_match('/:(handle)\s+(".*?[^\\\]")/', $content, $vm)) {
- $vacation['handle'] = $vm[2];
- $content = preg_replace('/:(handle)\s+(".*?[^\\\]")/', '', $content);
- }
- if (preg_match('/:(from)\s+(".*?[^\\\]")/', $content, $vm)) {
- $vacation['from'] = $vm[2];
- $content = preg_replace('/:(from)\s+(".*?[^\\\]")/', '', $content);
- }
- $content = preg_replace('/^vacation/', '', $content);
- $content = preg_replace('/;$/', '', $content);
- $content = trim($content);
- if (preg_match('/^:(mime)/', $content, $vm)) {
- $vacation['mime'] = true;
- $content = preg_replace('/^:mime/', '', $content);
- }
-
- $vacation['reason'] = $this->_parse_string($content);
-
- $result[] = $vacation;
- }