From 92a030d928246cfc5f3c0b1f2538dc1bfb4777e3 Mon Sep 17 00:00:00 2001 From: Paweł Słowik Date: Tue, 4 Sep 2012 14:59:15 +0200 Subject: Added tests, fixed PHP warnings --- plugins/managesieve/tests/src/parser_notify_a | 16 ++++++++++++++++ plugins/managesieve/tests/src/parser_notify_b | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 plugins/managesieve/tests/src/parser_notify_a create mode 100644 plugins/managesieve/tests/src/parser_notify_b (limited to 'plugins/managesieve/tests') diff --git a/plugins/managesieve/tests/src/parser_notify_a b/plugins/managesieve/tests/src/parser_notify_a new file mode 100644 index 000000000..324805ad4 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_notify_a @@ -0,0 +1,16 @@ +require ["enotify","variables"]; +if header :contains "from" "boss@example.org" +{ + notify :importance "1" :message "This is probably very important" "mailto:alm@example.com"; + stop; +} +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +if header :matches "From" "*" +{ + set "from" "${1}"; +} +notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; + diff --git a/plugins/managesieve/tests/src/parser_notify_b b/plugins/managesieve/tests/src/parser_notify_b new file mode 100644 index 000000000..537898567 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_notify_b @@ -0,0 +1,15 @@ +require ["envelope","variables","enotify"]; +if envelope :all :matches "from" "*" +{ + set "env_from" " [really: ${1}]"; +} +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +if address :all :matches "from" "*" +{ + set "from_addr" "${1}"; +} +notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; + -- cgit v1.2.3 From 3c99599794948686960ee4e340374b0c3a1527b2 Mon Sep 17 00:00:00 2001 From: Paweł Słowik Date: Fri, 14 Sep 2012 14:27:58 +0200 Subject: Sieve enotify/notify: - GUI for importance setting - make tests usable for checking the GUI --- plugins/managesieve/localization/en_GB.inc | 4 ++++ plugins/managesieve/localization/en_US.inc | 4 ++++ plugins/managesieve/localization/pl_PL.inc | 4 ++++ plugins/managesieve/managesieve.php | 16 ++++++++++++++++ plugins/managesieve/tests/src/parser_notify_a | 5 ++++- plugins/managesieve/tests/src/parser_notify_b | 5 ++++- 6 files changed, 36 insertions(+), 2 deletions(-) (limited to 'plugins/managesieve/tests') diff --git a/plugins/managesieve/localization/en_GB.inc b/plugins/managesieve/localization/en_GB.inc index 7b02c8218..f9075b8e0 100644 --- a/plugins/managesieve/localization/en_GB.inc +++ b/plugins/managesieve/localization/en_GB.inc @@ -102,6 +102,10 @@ $labels['notifyaddress'] = 'To e-mail address:'; $labels['notifybody'] = 'Notification body:'; $labels['notifysubject'] = 'Notification subject:'; $labels['notifyfrom'] = 'Notification sender:'; +$labels['notifyimportance'] = 'Importance:'; +$labels['notifyimportancelow'] = 'low'; +$labels['notifyimportancenormal'] = 'normal'; +$labels['notifyimportancehigh'] = 'high'; $labels['filtercreate'] = 'Create filter'; $labels['usedata'] = 'Use following data in the filter:'; $labels['nextstep'] = 'Next Step'; diff --git a/plugins/managesieve/localization/en_US.inc b/plugins/managesieve/localization/en_US.inc index bcef9139e..cb223c18f 100644 --- a/plugins/managesieve/localization/en_US.inc +++ b/plugins/managesieve/localization/en_US.inc @@ -93,6 +93,10 @@ $labels['notifyaddress'] = 'To e-mail address:'; $labels['notifybody'] = 'Notification body:'; $labels['notifysubject'] = 'Notification subject:'; $labels['notifyfrom'] = 'Notification sender:'; +$labels['notifyimportance'] = 'Importance:'; +$labels['notifyimportancelow'] = 'low'; +$labels['notifyimportancenormal'] = 'normal'; +$labels['notifyimportancehigh'] = 'high'; $labels['filtercreate'] = 'Create filter'; $labels['usedata'] = 'Use following data in the filter:'; $labels['nextstep'] = 'Next Step'; diff --git a/plugins/managesieve/localization/pl_PL.inc b/plugins/managesieve/localization/pl_PL.inc index 5b51900e6..734a4ebcf 100644 --- a/plugins/managesieve/localization/pl_PL.inc +++ b/plugins/managesieve/localization/pl_PL.inc @@ -108,6 +108,10 @@ $labels['notifyaddress'] = 'Na adres e-mail:'; $labels['notifybody'] = 'Treść powiadomienia:'; $labels['notifysubject'] = 'Temat powiadomienia:'; $labels['notifyfrom'] = 'Nadawca powiadomienia:'; +$labels['notifyimportance'] = 'Priorytet:'; +$labels['notifyimportancelow'] = 'niski'; +$labels['notifyimportancenormal'] = 'normalny'; +$labels['notifyimportancehigh'] = 'wysoki'; $labels['filtercreate'] = 'Utwórz filtr'; $labels['usedata'] = 'Użyj następujących danych do utworzenia filtra:'; $labels['nextstep'] = 'Następny krok'; diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php index 16c451845..e3033016b 100644 --- a/plugins/managesieve/managesieve.php +++ b/plugins/managesieve/managesieve.php @@ -629,6 +629,7 @@ class managesieve extends rcube_plugin $notifybodies = get_input_value('_action_notifybody', RCUBE_INPUT_POST); $notifymessages = get_input_value('_action_notifymessage', RCUBE_INPUT_POST); $notifyfrom = get_input_value('_action_notifyfrom', RCUBE_INPUT_POST); + $notifyimp = get_input_value('_action_notifyimportance', RCUBE_INPUT_POST); // we need a "hack" for radiobuttons foreach ($sizeitems as $item) @@ -897,6 +898,7 @@ class managesieve extends rcube_plugin $this->form['actions'][$i]['body'] = $notifybodies[$idx]; $this->form['actions'][$i]['message'] = $notifymessages[$idx]; $this->form['actions'][$i]['from'] = $notifyfrom[$idx]; + $this->form['actions'][$i]['importance'] = $notifyimp[$idx]; break; } @@ -1613,6 +1615,20 @@ class managesieve extends rcube_plugin .'error_class($id, 'action', 'from', 'action_notifyfrom') .' />'; + $importance_options = array( + 3 => 'notifyimportancelow', + 2 => 'notifyimportancenormal', + 1 => 'notifyimportancehigh' + ); + $select_importance = new html_select(array( + 'name' => '_action_notifyimportance[' . $id . ']', + 'id' => '_action_notifyimportance' . $id, + 'class' => $this->error_class($id, 'action', 'importance', 'action_notifyimportance'))); + foreach ($importance_options as $io_v => $io_n) { + $select_importance->add(Q($this->gettext($io_n)), $io_v); + } + $out .= '
' . Q($this->gettext('notifyimportance')) . '
'; + $out .= $select_importance->show(array(intval($action['importance']))); $out .= ''; // mailbox select diff --git a/plugins/managesieve/tests/src/parser_notify_a b/plugins/managesieve/tests/src/parser_notify_a index 324805ad4..68a9ef5cc 100644 --- a/plugins/managesieve/tests/src/parser_notify_a +++ b/plugins/managesieve/tests/src/parser_notify_a @@ -1,16 +1,19 @@ require ["enotify","variables"]; +# rule:[notify1] if header :contains "from" "boss@example.org" { notify :importance "1" :message "This is probably very important" "mailto:alm@example.com"; stop; } +# rule:[subject] if header :matches "Subject" "*" { set "subject" "${1}"; } +# rule:[from notify2] if header :matches "From" "*" { set "from" "${1}"; + notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; } -notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; diff --git a/plugins/managesieve/tests/src/parser_notify_b b/plugins/managesieve/tests/src/parser_notify_b index 537898567..8854658f4 100644 --- a/plugins/managesieve/tests/src/parser_notify_b +++ b/plugins/managesieve/tests/src/parser_notify_b @@ -1,15 +1,18 @@ require ["envelope","variables","enotify"]; +# rule:[from] if envelope :all :matches "from" "*" { set "env_from" " [really: ${1}]"; } +# rule:[subject] if header :matches "Subject" "*" { set "subject" "${1}"; } +# rule:[from notify] if address :all :matches "from" "*" { set "from_addr" "${1}"; + notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; } -notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; -- cgit v1.2.3 From 7641e4aaab279e060cf4f4a981869f07f3a02f45 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 19 Sep 2012 11:14:23 +0200 Subject: Improve capabilities list handling in parser tests --- plugins/managesieve/tests/Parser.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'plugins/managesieve/tests') diff --git a/plugins/managesieve/tests/Parser.php b/plugins/managesieve/tests/Parser.php index 00915cc20..2f24870e2 100644 --- a/plugins/managesieve/tests/Parser.php +++ b/plugins/managesieve/tests/Parser.php @@ -15,7 +15,15 @@ class Parser extends PHPUnit_Framework_TestCase */ function test_parser($input, $output, $message) { - $script = new rcube_sieve_script($input); + // get capabilities list from the script + $caps = array(); + if (preg_match('/require \[([a-z0-9", ]+)\]/', $input, $m)) { + foreach (explode(',', $m[1]) as $cap) { + $caps[] = trim($cap, '" '); + } + } + + $script = new rcube_sieve_script($input, $caps); $result = $script->as_text(); $this->assertEquals(trim($result), trim($output), $message); -- cgit v1.2.3 From eb1ee0803e51fbbdd3f8966c511b5212aed91524 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 20 Sep 2012 12:23:44 +0200 Subject: Support old notify extension --- plugins/managesieve/Changelog | 1 + plugins/managesieve/lib/rcube_sieve_script.php | 33 ++++++++++++++++++-------- plugins/managesieve/package.xml | 4 ++-- plugins/managesieve/tests/src/parser_notify_a | 7 +++--- plugins/managesieve/tests/src/parser_notify_b | 5 ++-- 5 files changed, 31 insertions(+), 19 deletions(-) (limited to 'plugins/managesieve/tests') diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 482cff0ca..32eb3cb14 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,4 +1,5 @@ - Fixed issue with DBMail bug [http://pear.php.net/bugs/bug.php?id=19077] (#1488594) +- Added support for enotify/notify (RFC5435, RFC5436, draft-ietf-sieve-notify-04) * version 5.2 [2012-07-24] ----------------------------------------------------------- diff --git a/plugins/managesieve/lib/rcube_sieve_script.php b/plugins/managesieve/lib/rcube_sieve_script.php index debe9c124..fe63141fe 100644 --- a/plugins/managesieve/lib/rcube_sieve_script.php +++ b/plugins/managesieve/lib/rcube_sieve_script.php @@ -41,7 +41,9 @@ class rcube_sieve_script 'variables', // RFC5229 'body', // RFC5173 'subaddress', // RFC5233 - // @TODO: enotify/notify, spamtest+virustest, mailbox, date + 'enotify', // RFC5435 + 'notify', // draft-ietf-sieve-notify-04 + // @TODO: spamtest+virustest, mailbox, date ); /** @@ -198,6 +200,9 @@ class rcube_sieve_script } } + $imapflags = in_array('imap4flags', $this->supported) ? 'imap4flags' : 'imapflags'; + $notify = in_array('enotify', $this->supported) ? 'enotify' : 'notify'; + // rules foreach ($this->content as $rule) { $extension = ''; @@ -370,11 +375,7 @@ class rcube_sieve_script case 'addflag': case 'setflag': case 'removeflag': - if (in_array('imap4flags', $this->supported)) - array_push($exts, 'imap4flags'); - else - array_push($exts, 'imapflags'); - + array_push($exts, $imapflags); $action_script .= $action['type'].' ' . self::escape_string($action['target']); break; @@ -404,8 +405,9 @@ class rcube_sieve_script break; case 'notify': - array_push($exts, 'enotify'); + array_push($exts, $notify); $action_script .= 'notify'; + foreach (array('from', 'importance', 'options', 'message') as $n_tag) { if (!empty($action[$n_tag])) { $action_script .= " :$n_tag " . self::escape_string($action[$n_tag]); @@ -420,7 +422,12 @@ class rcube_sieve_script else { $method = $action['method']; } - $action_script .= " " . self::escape_string($method); + + // method is optional in notify extension + if (!empty($method)) { + $action_script .= ($notify == 'notify' ? " :method " : " ") . self::escape_string($method); + } + break; case 'vacation': @@ -861,15 +868,21 @@ class rcube_sieve_script break; case 'notify': - $notify = array('type' => 'notify', 'method' => array_pop($tokens)); + $notify = array('type' => 'notify'); // Parameters: :from, :importance, :options, :message + // additional (optional) :method parameter for notify extension for ($i=0, $len=count($tokens); $i<$len; $i++) { $tok = strtolower($tokens[$i]); if ($tok[0] == ':') { - $notify[substr($tok, 1)] = $tokens[$i+1]; + $notify[substr($tok, 1)] = $tokens[++$i]; + } + else { + // unnamed parameter is a :method in enotify extension + $notify['method'] = $tokens[$i]; } } + $method_components = parse_url($notify['method']); if ($method_components['scheme'] == 'mailto') { $notify['address'] = $method_components['path']; diff --git a/plugins/managesieve/package.xml b/plugins/managesieve/package.xml index cde78c9a3..20fec7895 100644 --- a/plugins/managesieve/package.xml +++ b/plugins/managesieve/package.xml @@ -17,9 +17,9 @@ alec@alec.pl yes - 2012-06-21 + 2012-07-24 - 5.1 + 5.2 5.0 diff --git a/plugins/managesieve/tests/src/parser_notify_a b/plugins/managesieve/tests/src/parser_notify_a index 68a9ef5cc..a8b44c583 100644 --- a/plugins/managesieve/tests/src/parser_notify_a +++ b/plugins/managesieve/tests/src/parser_notify_a @@ -1,8 +1,8 @@ -require ["enotify","variables"]; +require ["notify","variables"]; # rule:[notify1] if header :contains "from" "boss@example.org" { - notify :importance "1" :message "This is probably very important" "mailto:alm@example.com"; + notify :importance "1" :message "This is probably very important"; stop; } # rule:[subject] @@ -14,6 +14,5 @@ if header :matches "Subject" "*" if header :matches "From" "*" { set "from" "${1}"; - notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; + notify :importance "3" :message "${from}: ${subject}" :method "mailto:test@example.org"; } - diff --git a/plugins/managesieve/tests/src/parser_notify_b b/plugins/managesieve/tests/src/parser_notify_b index 8854658f4..cf80a9701 100644 --- a/plugins/managesieve/tests/src/parser_notify_b +++ b/plugins/managesieve/tests/src/parser_notify_b @@ -1,4 +1,4 @@ -require ["envelope","variables","enotify"]; +require ["envelope","variables","notify"]; # rule:[from] if envelope :all :matches "from" "*" { @@ -13,6 +13,5 @@ if header :matches "Subject" "*" if address :all :matches "from" "*" { set "from_addr" "${1}"; - notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; + notify :message "${from_addr}${env_from}: ${subject}" :method "sms:1234567890"; } - -- cgit v1.2.3 From cd97f0ad1190f4fe1f65542389b517936bf32b5d Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 20 Sep 2012 13:15:03 +0200 Subject: Support only 00 version of draft-ietf-sieve-notify which is more common (Cyrus 2.4) --- plugins/managesieve/Changelog | 2 +- plugins/managesieve/lib/rcube_sieve_script.php | 29 +++++++++++++++++++++++--- plugins/managesieve/tests/src/parser_notify_a | 4 ++-- 3 files changed, 29 insertions(+), 6 deletions(-) (limited to 'plugins/managesieve/tests') diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 32eb3cb14..6fcd17a95 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,5 +1,5 @@ - Fixed issue with DBMail bug [http://pear.php.net/bugs/bug.php?id=19077] (#1488594) -- Added support for enotify/notify (RFC5435, RFC5436, draft-ietf-sieve-notify-04) +- Added support for enotify/notify (RFC5435, RFC5436, draft-ietf-sieve-notify-00) * version 5.2 [2012-07-24] ----------------------------------------------------------- diff --git a/plugins/managesieve/lib/rcube_sieve_script.php b/plugins/managesieve/lib/rcube_sieve_script.php index fe63141fe..36eb1bcf8 100644 --- a/plugins/managesieve/lib/rcube_sieve_script.php +++ b/plugins/managesieve/lib/rcube_sieve_script.php @@ -42,7 +42,7 @@ class rcube_sieve_script 'body', // RFC5173 'subaddress', // RFC5233 'enotify', // RFC5435 - 'notify', // draft-ietf-sieve-notify-04 + 'notify', // draft-ietf-sieve-notify-00 // @TODO: spamtest+virustest, mailbox, date ); @@ -408,11 +408,25 @@ class rcube_sieve_script 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 + if ($notify == 'notify') { + switch ($action['importance']) { + case 1: $action_script .= " :high"; break; + case 2: $action_script .= " :normal"; break; + case 3: $action_script .= " :low"; break; + + } + unset($action['importance']); + } + foreach (array('from', 'importance', 'options', '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'])) { @@ -869,13 +883,22 @@ class rcube_sieve_script case 'notify': $notify = array('type' => 'notify'); + $priorities = array(':high' => 1, ':normal' => 2, ':low' => 3); // Parameters: :from, :importance, :options, :message // additional (optional) :method parameter for notify extension for ($i=0, $len=count($tokens); $i<$len; $i++) { $tok = strtolower($tokens[$i]); if ($tok[0] == ':') { - $notify[substr($tok, 1)] = $tokens[++$i]; + // 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 + if (isset($priorities[$tok])) { + $notify['importance'] = $priorities[$tok]; + } + else { + $notify[substr($tok, 1)] = $tokens[++$i]; + } } else { // unnamed parameter is a :method in enotify extension @@ -891,7 +914,7 @@ class rcube_sieve_script 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 */ + // 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); } diff --git a/plugins/managesieve/tests/src/parser_notify_a b/plugins/managesieve/tests/src/parser_notify_a index a8b44c583..f1a57540e 100644 --- a/plugins/managesieve/tests/src/parser_notify_a +++ b/plugins/managesieve/tests/src/parser_notify_a @@ -2,7 +2,7 @@ require ["notify","variables"]; # rule:[notify1] if header :contains "from" "boss@example.org" { - notify :importance "1" :message "This is probably very important"; + notify :low :message "This is probably very important"; stop; } # rule:[subject] @@ -14,5 +14,5 @@ if header :matches "Subject" "*" if header :matches "From" "*" { set "from" "${1}"; - notify :importance "3" :message "${from}: ${subject}" :method "mailto:test@example.org"; + notify :high :message "${from}: ${subject}" :method "mailto:test@example.org"; } -- cgit v1.2.3 From 74e6cf2f58a663b50a9b443dd815e44451f7d770 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 20 Sep 2012 15:59:07 +0200 Subject: Re-add enotify tests --- plugins/managesieve/tests/src/parser_enotify_a | 19 +++++++++++++++++++ plugins/managesieve/tests/src/parser_enotify_b | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 plugins/managesieve/tests/src/parser_enotify_a create mode 100644 plugins/managesieve/tests/src/parser_enotify_b (limited to 'plugins/managesieve/tests') diff --git a/plugins/managesieve/tests/src/parser_enotify_a b/plugins/managesieve/tests/src/parser_enotify_a new file mode 100644 index 000000000..68a9ef5cc --- /dev/null +++ b/plugins/managesieve/tests/src/parser_enotify_a @@ -0,0 +1,19 @@ +require ["enotify","variables"]; +# rule:[notify1] +if header :contains "from" "boss@example.org" +{ + notify :importance "1" :message "This is probably very important" "mailto:alm@example.com"; + stop; +} +# rule:[subject] +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +# rule:[from notify2] +if header :matches "From" "*" +{ + set "from" "${1}"; + notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; +} + diff --git a/plugins/managesieve/tests/src/parser_enotify_b b/plugins/managesieve/tests/src/parser_enotify_b new file mode 100644 index 000000000..8854658f4 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_enotify_b @@ -0,0 +1,18 @@ +require ["envelope","variables","enotify"]; +# rule:[from] +if envelope :all :matches "from" "*" +{ + set "env_from" " [really: ${1}]"; +} +# rule:[subject] +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +# rule:[from notify] +if address :all :matches "from" "*" +{ + set "from_addr" "${1}"; + notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; +} + -- cgit v1.2.3