Aleksander Machniak
2014-04-24 f22de58087df469615ed1f24aaed54f8a4309237
plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
@@ -6,18 +6,18 @@
 * 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 free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
class rcube_sieve_script
@@ -38,7 +38,7 @@
        'imap4flags',               // RFC5232
        'include',                  // draft-ietf-sieve-include-12
        'index',                    // RFC5260
        'notify',                   // draft-ietf-sieve-notify-00
        'notify',                   // draft-martin-sieve-notify-01,
        'regex',                    // draft-ietf-sieve-regex-01
        'reject',                   // RFC5429
        'relational',               // RFC3431
@@ -260,7 +260,8 @@
                            $this->add_index($test, $tests[$i], $exts);
                        }
                        if (!empty($test['part'])) {
                        // :all address-part is optional, skip it
                        if (!empty($test['part']) && $test['part'] != 'all') {
                            $tests[$i] .= ' :' . $test['part'];
                            if ($test['part'] == 'user' || $test['part'] == 'detail') {
                                array_push($exts, 'subaddress');
@@ -410,38 +411,38 @@
                        array_push($exts, $notify);
                        $action_script .= 'notify';
                        // Here we support only 00 version of notify draft, there
                        // were a couple regressions in 00 to 04 changelog, we use
                        // the version used by Cyrus
                        $method = $action['method'];
                        unset($action['method']);
                        $action['options'] = (array) $action['options'];
                        // Here we support draft-martin-sieve-notify-01 used by Cyrus
                        if ($notify == 'notify') {
                            switch ($action['importance']) {
                                case 1: $action_script .= " :high"; break;
                                case 2: $action_script .= " :normal"; break;
                                //case 2: $action_script .= " :normal"; break;
                                case 3: $action_script .= " :low"; break;
                            }
                            // Old-draft way: :method "mailto" :options "email@address"
                            if (!empty($method)) {
                                $parts = explode(':', $method, 2);
                                $action['method'] = $parts[0];
                                array_unshift($action['options'], $parts[1]);
                            }
                            unset($action['importance']);
                            unset($action['from']);
                            unset($method);
                        }
                        foreach (array('from', 'importance', 'options', 'message') as $n_tag) {
                        foreach (array('id', 'importance', 'method', 'options', 'from', 'message') as $n_tag) {
                            if (!empty($action[$n_tag])) {
                                $action_script .= " :$n_tag " . self::escape_string($action[$n_tag]);
                            }
                        }
                        if (!empty($action['address'])) {
                            $method = 'mailto:' . $action['address'];
                            if (!empty($action['body'])) {
                                $method .= '?body=' . rawurlencode($action['body']);
                            }
                        }
                        else {
                            $method = $action['method'];
                        }
                        // method is optional in notify extension
                        if (!empty($method)) {
                            $action_script .= ($notify == 'notify' ? " :method " : " ") . self::escape_string($method);
                            $action_script .= ' ' . self::escape_string($method);
                        }
                        break;
@@ -584,6 +585,7 @@
                    if ($rule[0]['type'] == 'set') {
                        unset($rule[0]['type']);
                        $this->vars[] = $rule[0];
                        unset($rule);
                    }
                    else {
                        $rule = array('actions' => $rule);
@@ -847,13 +849,11 @@
            case 'notify':
                $action     = array('type' => 'notify');
                $priorities = array('high' => 1, 'normal' => 2, 'low' => 3);
                $vargs      = array('from', 'importance', 'options', 'message', 'method');
                $vargs      = array('from', 'id', 'importance', 'options', 'message', 'method');
                $args       = array_keys($priorities);
                $action    += $this->action_arguments($tokens, $args, $vargs);
                // Here we support only 00 version of notify draft, there
                // were a couple regressions in 00 to 04 changelog, we use
                // the version used by Cyrus
                // Here we'll convert draft-martin-sieve-notify-01 into RFC 5435
                if (!isset($action['importance'])) {
                    foreach ($priorities as $key => $val) {
                        if (isset($action[$key])) {
@@ -863,29 +863,19 @@
                    }
                }
                // unnamed parameter is a :method in enotify extension
                if (!isset($action['method'])) {
                    $action['method'] = array_pop($tokens);
                }
                $action['options'] = (array) $action['options'];
                $method_components = parse_url($action['method']);
                if ($method_components['scheme'] == 'mailto') {
                    $action['address'] = $method_components['path'];
                    $method_params = array();
                    if (array_key_exists('query', $method_components)) {
                        parse_str($method_components['query'], $method_params);
                    }
                    $method_params = array_change_key_case($method_params, CASE_LOWER);
                    // magic_quotes_gpc and magic_quotes_sybase affect the output of parse_str
                    if (ini_get('magic_quotes_gpc') || ini_get('magic_quotes_sybase')) {
                        array_map('stripslashes', $method_params);
                    }
                    $action['body'] = (array_key_exists('body', $method_params)) ? $method_params['body'] : '';
                // Old-draft way: :method "mailto" :options "email@address"
                if (!empty($action['method']) && !empty($action['options'])) {
                    $action['method'] .= ':' . array_shift($action['options']);
                }
                // unnamed parameter is a :method in enotify extension
                else if (!isset($action['method'])) {
                    $action['method'] = array_pop($tokens);
                }
                $result[] = $action;
                break;
            }
            if ($separator == $end)
@@ -938,22 +928,21 @@
            return;
        }
        // relational operator + comparator
        // relational operator
        if (preg_match('/^(value|count)-([gteqnl]{2})/', $test['type'], $m)) {
            array_push($exts, 'relational');
            array_push($exts, 'comparator-i;ascii-numeric');
            $out .= ' :' . $m[1] . ' "' . $m[2] . '" :comparator "i;ascii-numeric"';
            $out .= ' :' . $m[1] . ' "' . $m[2] . '"';
        }
        else {
            $this->add_comparator($test, $out, $exts);
            if ($test['type'] == 'regex') {
                array_push($exts, 'regex');
            }
            $out .= ' :' . $test['type'];
        }
        $this->add_comparator($test, $out, $exts);
    }
    /**