From f9fc7e1edf2806edcf033a2479bbaed8f0bc9e13 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 19 Jul 2016 11:26:27 +0200 Subject: [PATCH] Managesieve: Improvements in 'string' test support --- CHANGELOG | 1 + plugins/managesieve/Changelog | 3 +- .../lib/Roundcube/rcube_sieve_engine.php | 6 ++-- plugins/managesieve/managesieve.js | 29 ++++++++++++------- .../managesieve/tests/src/parser_variables | 12 ++++++++ 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a6db41741..077e27fcb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ CHANGELOG Roundcube Webmail - Indicate that a collapsed thread has flagged children (#5013) - Implemented message/rfc822 attachment preview - Update to jsTimezoneDetect 1.0.6 +- Managesieve: Support 'string' test from variables extension [RFC 5229] (#5248) - Managesieve: Support 'duplicate' extension [RFC 7352] - Managesieve: Unhide advanced rule controls if there are inputs with errors - Managesieve: Display warning message when filter form contains errors diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 8fa7ac88f..5e1042307 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,5 +1,6 @@ -* version 8.7 [2016-] +* version 8.7 [2016-07-19] ----------------------------------------------------------- +- Support 'string' test from variables extension [RFC 5229] (#5248) - Support 'duplicate' extension [RFC 7352] - Unhide advanced rule controls if there are inputs with errors - Display warning message when filter form contains errors diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 5f5a6b072..6fc702729 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -1451,14 +1451,14 @@ class rcube_sieve_engine if (in_array('body', $this->exts)) { $select_header->add($this->plugin->gettext('body'), 'body'); } - if (in_array('variables', $this->exts)) { - $select_header->add($this->plugin->gettext('string'), 'string'); - } $select_header->add($this->plugin->gettext('size'), 'size'); if (in_array('date', $this->exts)) { $select_header->add($this->plugin->gettext('datetest'), 'date'); $select_header->add($this->plugin->gettext('currdate'), 'currentdate'); } + if (in_array('variables', $this->exts)) { + $select_header->add($this->plugin->gettext('string'), 'string'); + } if (in_array('duplicate', $this->exts)) { $select_header->add($this->plugin->gettext('message'), 'message'); } diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js index cfc60db7f..6cb5b3865 100644 --- a/plugins/managesieve/managesieve.js +++ b/plugins/managesieve/managesieve.js @@ -608,6 +608,7 @@ function rule_header_select(id) comp = document.getElementById('rule_comp' + id), datepart = document.getElementById('rule_date_part' + id), dateheader = document.getElementById('rule_date_header_div' + id), + rule = $('#rule_op' + id), h = obj.value; if (h == 'size') { @@ -634,11 +635,14 @@ function rule_header_select(id) if (dateheader) dateheader.style.display = h == 'date' ? '' : 'none'; + $('[value="exists"],[value="notexists"]', rule).prop('disabled', h == 'string'); + if (!rule.val() || rule.val().match(/^(exists|notexists)$/)) + rule.val('contains'); + rule_op_select(op, id, h); rule_mod_select(id, h); - - if (h == '...') obj.style.width = '40px'; - else if (h == 'string') obj.style.width = '90px'; + + obj.style.width = h == '...' ? '40px' : ''; }; function rule_op_select(obj, id, header) @@ -904,24 +908,27 @@ function sieve_formattime(hour, minutes) function sieve_form_init() { - // small resize for header element - $('select[name="_header[]"]', rcmail.gui_objects.sieveform).each(function() { - if (this.value == '...') this.style.width = '40px'; - if (this.value == 'string') this.style.width = '90px'; - }); + var form = rcmail.gui_objects.sieveform; // resize dialog window if (rcmail.env.action == 'plugin.managesieve' && rcmail.env.task == 'mail') { - parent.rcmail.managesieve_dialog_resize(rcmail.gui_objects.sieveform); + parent.rcmail.managesieve_dialog_resize(form); } - $('input[type="text"]:first', rcmail.gui_objects.sieveform).focus(); + $('input[type="text"]:first', form).focus(); // initialize smart list inputs - $('textarea[data-type="list"]', rcmail.gui_objects.sieveform).each(function() { + $('textarea[data-type="list"]', form).each(function() { smart_field_init(this); }); + // initialize rules form(s) + $('[name="_header[]"]', form).each(function() { + if (/([0-9]+)$/.test(this.id)) { + rule_header_select(RegExp.$1); + } + }); + // enable date pickers on date fields if ($.datepicker && rcmail.env.date_format) { $.datepicker.setDefaults({ diff --git a/plugins/managesieve/tests/src/parser_variables b/plugins/managesieve/tests/src/parser_variables index bd5941c02..c4ea2f72a 100644 --- a/plugins/managesieve/tests/src/parser_variables +++ b/plugins/managesieve/tests/src/parser_variables @@ -10,3 +10,15 @@ set :lower "b" "${a}"; set :upperfirst "b" "${a}"; set :upperfirst :lower "b" "${a}"; set :quotewildcard "b" "Rock*"; +if string :matches " ${state} " "* pending *" +{ + set "test1" "*"; +} +if string ["aaa","bbb"] ["aaa","bbb"] +{ + set "test2" "*"; +} +if string :is :comparator "i;octet" "bbb" "bbb" +{ + set "test3" "*"; +}