diff options
Diffstat (limited to 'plugins/managesieve/lib/rcube_sieve.php')
| -rw-r--r-- | plugins/managesieve/lib/rcube_sieve.php | 91 |
1 files changed, 34 insertions, 57 deletions
diff --git a/plugins/managesieve/lib/rcube_sieve.php b/plugins/managesieve/lib/rcube_sieve.php index 7f989e098..7b7ea6eb6 100644 --- a/plugins/managesieve/lib/rcube_sieve.php +++ b/plugins/managesieve/lib/rcube_sieve.php @@ -1,13 +1,27 @@ <?php /** - Classes for managesieve operations (using PEAR::Net_Sieve) - - Author: Aleksander Machniak <alec@alec.pl> - - $Id$ - -*/ + * Classes for managesieve operations (using PEAR::Net_Sieve) + * + * Copyright (C) 2008-2011, The Roundcube Dev Team + * Copyright (C) 2011, Kolab Systems AG + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * $Id$ + * + */ // Managesieve Protocol: RFC5804 @@ -195,7 +209,7 @@ class rcube_sieve { if ($this->exts) return $this->exts; - + if (!$this->sieve) return $this->_set_error(SIEVE_ERROR_INTERNAL); @@ -286,23 +300,28 @@ class rcube_sieve */ private function _parse($txt) { - // try to parse from Roundcube format + // parse $script = new rcube_sieve_script($txt, $this->disabled, $this->exts); - // ... else try to import from different formats - if (empty($script->content)) { - $script = $this->_import_rules($txt); - $script = new rcube_sieve_script($script, $this->disabled, $this->exts); - + // fix/convert to Roundcube format + if (!empty($script->content)) { // replace all elsif with if+stop, we support only ifs foreach ($script->content as $idx => $rule) { + if (empty($rule['type']) || !preg_match('/^(if|elsif|else)$/', $rule['type'])) { + continue; + } + + $script->content[$idx]['type'] = 'if'; + // 'stop' not found? foreach ($rule['actions'] as $action) { if (preg_match('/^(stop|vacation)$/', $action['type'])) { continue 2; } } - $script->content[$idx]['actions'][] = array('type' => 'stop'); + if (empty($script->content[$idx+1]) || $script->content[$idx+1]['type'] != 'if') { + $script->content[$idx]['actions'][] = array('type' => 'stop'); + } } } @@ -343,48 +362,6 @@ class rcube_sieve return $this->save_script($name, $content); } - private function _import_rules($script) - { - $i = 0; - $name = array(); - - // Squirrelmail (Avelsieve) - if (preg_match('/(#START_SIEVE_RULE.*END_SIEVE_RULE)\r?\n/', $script)) { - $tokens = preg_split('/(#START_SIEVE_RULE.*END_SIEVE_RULE)\r?\n/', $script, -1, PREG_SPLIT_DELIM_CAPTURE); - foreach ($tokens as $token) { - if (preg_match('/^#START_SIEVE_RULE.*/', $token, $matches)) { - $name[$i] = "unnamed rule ".($i+1); - $content .= "# rule:[".$name[$i]."]\n"; - } - elseif (isset($name[$i])) { - // This preg_replace is added because I've found some Avelsieve scripts - // with rules containing "if" here. I'm not sure it was working - // before without this or not. - $token = preg_replace('/^if\s+/', '', trim($token)); - $content .= "if $token\n"; - $i++; - } - } - } - // Horde (INGO) - else if (preg_match('/(# .+)\r?\n/', $script)) { - $tokens = preg_split('/(# .+)\r?\n/', $script, -1, PREG_SPLIT_DELIM_CAPTURE); - foreach($tokens as $token) { - if (preg_match('/^# (.+)/', $token, $matches)) { - $name[$i] = $matches[1]; - $content .= "# rule:[" . $name[$i] . "]\n"; - } - elseif (isset($name[$i])) { - $token = str_replace(":comparator \"i;ascii-casemap\" ", "", $token); - $content .= $token . "\n"; - $i++; - } - } - } - - return $content; - } - private function _set_error($error) { $this->error = $error; |
