diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-10-03 11:49:33 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-10-03 11:49:33 +0000 |
| commit | 7c3bcde7b32ed8ec5566ad5db0b07754b5e3f7fd (patch) | |
| tree | 12cc992763c0cc22619e1b89df9d75e679ffb817 /plugins/managesieve/lib/rcube_sieve.php | |
| parent | e4def8a1bd65cb1ae33d6c0e7c44f3f516c8edc8 (diff) | |
- Fixed doubled Filter tab on page refresh
- Added filters set selector in filter form when invoked in mail task
- Improved script parser, added support for include and variables extensions
- Added Kolab's KEP:14 support (http://wiki.kolab.org/User:Greve/Drafts/KEP:14)
git-svn-id: https://svn.roundcube.net/trunk@5300 208e9e7b-5314-0410-a742-e7e81cd9613c
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; |
