summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-09-09 08:54:43 +0200
committerAleksander Machniak <alec@alec.pl>2013-09-09 08:54:43 +0200
commit09fed60218f971f2e81ac39c7db1b176088940f9 (patch)
tree179ff72dd9f5e8a691d93c2c3e51c9544fbd639d
parent4a40636cca6fbeaeb50b26e2d57e3fa31aeabce0 (diff)
Add common headers to header selector (#1489271)
-rw-r--r--plugins/managesieve/Changelog3
-rw-r--r--plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php78
-rw-r--r--plugins/managesieve/package.xml14
3 files changed, 73 insertions, 22 deletions
diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index 60b2f1831..e660ee1ee 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,3 +1,5 @@
+* version 7.0 [2013-09-09]
+-----------------------------------------------------------
- Add vacation-seconds extension support (RFC 6131)
- Several script parser code improvements
- Support string list arguments in filter form (#1489018)
@@ -5,6 +7,7 @@
- Split plugin file into two files
- Fix handling of &, <, > characters in scripts/filter names (#1489208)
- Support 'keep' action (#1489226)
+- Add common headers to header selector (#1489271)
* version 6.2 [2013-02-17]
-----------------------------------------------------------
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;
+ }
}
diff --git a/plugins/managesieve/package.xml b/plugins/managesieve/package.xml
index 9c02957a5..6ae53c250 100644
--- a/plugins/managesieve/package.xml
+++ b/plugins/managesieve/package.xml
@@ -17,10 +17,10 @@
<email>alec@alec.pl</email>
<active>yes</active>
</lead>
- <date>2013-02-17</date>
+ <date>2013-09-09</date>
<version>
- <release>6.2</release>
- <api>6.0</api>
+ <release>7.0</release>
+ <api>7.0</api>
</version>
<stability>
<release>stable</release>
@@ -38,6 +38,10 @@
<tasks:replace from="@name@" to="name" type="package-info"/>
<tasks:replace from="@package_version@" to="version" type="package-info"/>
</file>
+ <file name="lib/Roundcube/rcube_sieve.php" role="php"></file>
+ <file name="lib/Roundcube/rcube_sieve_engine.php" role="php"></file>
+ <file name="lib/Roundcube/rcube_sieve_script.php" role="php"></file>
+ <file name="lib/Net/Sieve.php" role="php"></file>
<file name="localization/be_BE.inc" role="data"></file>
<file name="localization/bg_BG.inc" role="data"></file>
<file name="localization/bs_BA.inc" role="data"></file>
@@ -106,10 +110,6 @@
<file name="skins/larry/images/down_small.gif" role="data"></file>
<file name="skins/larry/images/erase.png" role="data"></file>
<file name="skins/larry/images/up_small.gif" role="data"></file>
- <file name="lib/Roundcube/rcube_sieve.php" role="php"></file>
- <file name="lib/Roundcube/rcube_sieve_engine.php" role="php"></file>
- <file name="lib/Roundcube/rcube_sieve_script.php" role="php"></file>
- <file name="lib/Net/Sieve.php" role="php"></file>
<file name="config.inc.php.dist" role="data"></file>
</dir>
<!-- / -->