diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-09-09 08:54:43 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-09-09 08:54:43 +0200 |
commit | 09fed60218f971f2e81ac39c7db1b176088940f9 (patch) | |
tree | 179ff72dd9f5e8a691d93c2c3e51c9544fbd639d /plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php | |
parent | 4a40636cca6fbeaeb50b26e2d57e3fa31aeabce0 (diff) |
Add common headers to header selector (#1489271)
Diffstat (limited to 'plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php')
-rw-r--r-- | plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php | 78 |
1 files changed, 63 insertions, 15 deletions
diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index bbbfa9d91..e4efef5b3 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -195,7 +195,7 @@ class rcube_sieve_engine } else { $this->exts = $this->sieve->get_extensions(); - $this->script = $this->sieve->script->as_array(); + $this->init_script(); $this->rc->output->set_env('currentset', $this->sieve->current); $_SESSION['managesieve_current'] = $this->sieve->current; } @@ -742,13 +742,22 @@ class rcube_sieve_engine $cust_header = (is_array($headers) && count($headers) == 1) ? $headers[0] : $headers; } + $header = $header == '...' ? $cust_header : $header; + + if (is_array($header)) { + foreach ($header as $h_index => $val) { + if (isset($this->headers[$val])) { + $header[$h_index] = $this->headers[$val]; + } + } + } + if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; - $this->form['tests'][$i]['arg'] = $header == '...' ? $cust_header : $header; + $this->form['tests'][$i]['arg'] = $header; } else { - $test = 'header'; - $header = $header == '...' ? $cust_header : $header; + $test = 'header'; if ($mod == 'address' || $mod == 'envelope') { $found = false; @@ -1258,27 +1267,33 @@ class rcube_sieve_engine $select_header = new html_select(array('name' => "_header[]", 'id' => 'header'.$id, 'onchange' => 'rule_header_select(' .$id .')')); - foreach ($this->headers as $name => $val) - $select_header->add(rcube::Q($this->plugin->gettext($name)), Q($val)); - $select_header->add(rcube::Q($this->plugin->gettext('...')), '...'); + foreach ($this->headers as $index => $header) { + $header = $this->rc->text_exists($index) ? $this->plugin->gettext($index) : $header; + $select_header->add($header, $index); + } + $select_header->add($this->plugin->gettext('...'), '...'); if (in_array('body', $this->exts)) - $select_header->add(rcube::Q($this->plugin->gettext('body')), 'body'); - $select_header->add(rcube::Q($this->plugin->gettext('size')), 'size'); + $select_header->add($this->plugin->gettext('body'), 'body'); + $select_header->add($this->plugin->gettext('size'), 'size'); if (in_array('date', $this->exts)) { - $select_header->add(rcube::Q($this->plugin->gettext('datetest')), 'date'); - $select_header->add(rcube::Q($this->plugin->gettext('currdate')), 'currentdate'); + $select_header->add($this->plugin->gettext('datetest'), 'date'); + $select_header->add($this->plugin->gettext('currdate'), 'currentdate'); } if (isset($rule['test'])) { if (in_array($rule['test'], array('header', 'address', 'envelope')) - && !is_array($rule['arg1']) && in_array($rule['arg1'], $this->headers) + && !is_array($rule['arg1']) + && ($header = strtolower($rule['arg1'])) + && isset($this->headers[$header]) ) { - $test = $rule['arg1']; + $test = $header; } else if ($rule['test'] == 'exists' - && !is_array($rule['arg']) && in_array($rule['arg'], $this->headers) + && !is_array($rule['arg']) + && ($header = strtolower($rule['arg'])) + && isset($this->headers[$header]) ) { - $test = $rule['arg']; + $test = $header; } else if (in_array($rule['test'], array('size', 'body', 'date', 'currentdate'))) { $test = $rule['test']; @@ -2120,4 +2135,37 @@ class rcube_sieve_engine return $result; } + + /** + * Initializes internal script data + */ + private function init_script() + { + $this->script = $this->sieve->script->as_array(); + + if (!$this->script) { + return; + } + + $headers = array(); + + // find common headers used in script, will be added to the list + // of available (predefined) headers (#1489271) + foreach ($this->script as $rule) { + foreach ((array) $rule['tests'] as $test) { + if ($test['test'] == 'header') { + foreach ((array) $test['arg1'] as $header) { + $lc_header = strtolower($header); + if (!isset($this->headers[$lc_header]) && !isset($headers[$lc_header])) { + $headers[$lc_header] = $header; + } + } + } + } + } + + ksort($headers); + + $this->headers += $headers; + } } |