From 2ac00a258b9aa859ea78da25cd906e1709df5b75 Mon Sep 17 00:00:00 2001 From: Paweł Słowik Date: Thu, 30 Aug 2012 19:31:40 +0200 Subject: Sieve enotify/notify - parser --- plugins/managesieve/lib/rcube_sieve_script.php | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'plugins/managesieve/lib') diff --git a/plugins/managesieve/lib/rcube_sieve_script.php b/plugins/managesieve/lib/rcube_sieve_script.php index aa3b9ab6e..66bedb52b 100644 --- a/plugins/managesieve/lib/rcube_sieve_script.php +++ b/plugins/managesieve/lib/rcube_sieve_script.php @@ -403,6 +403,20 @@ class rcube_sieve_script $action_script .= self::escape_string($action['name']) . ' ' . self::escape_string($action['value']); break; + case 'notify': + array_push($exts, 'enotify'); + $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]); + } + } + $method = (!empty($action['address']) && !empty($action['body'])) ? + sprintf('mailto:%s?body=%s', $action['address'], rawurlencode($action['body'])) : + $action['method']; + $action_script .= " " . self::escape_string($method); + break; + case 'vacation': array_push($exts, 'vacation'); $action_script .= 'vacation'; @@ -840,6 +854,32 @@ class rcube_sieve_script // $result[] = array('type' => 'require', 'target' => $tokens); break; + case 'notify': + $notify = array('type' => 'notify', 'method' => array_pop($tokens)); + + // Parameters: :from, :importance, :options, :message + for ($i=0, $len=count($tokens); $i<$len; $i++) { + $tok = strtolower($tokens[$i]); + if ($tok[0] == ':') { + $notify[substr($tok, 1)] = $tokens[$i+1]; + } + } + $method_components = parse_url($notify['method']); + if ($method_components['scheme'] == 'mailto') { + $notify['address'] = $method_components['path']; + $method_params = array(); + 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); + } + $notify['body'] = $method_params['body']; + } + + $result[] = $notify; + break; + } if ($separator == $end) -- cgit v1.2.3 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/lib/rcube_sieve_script.php | 6 ++++-- plugins/managesieve/tests/src/parser_notify_a | 16 ++++++++++++++++ plugins/managesieve/tests/src/parser_notify_b | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 plugins/managesieve/tests/src/parser_notify_a create mode 100644 plugins/managesieve/tests/src/parser_notify_b (limited to 'plugins/managesieve/lib') diff --git a/plugins/managesieve/lib/rcube_sieve_script.php b/plugins/managesieve/lib/rcube_sieve_script.php index 66bedb52b..3e418edd3 100644 --- a/plugins/managesieve/lib/rcube_sieve_script.php +++ b/plugins/managesieve/lib/rcube_sieve_script.php @@ -868,13 +868,15 @@ class rcube_sieve_script if ($method_components['scheme'] == 'mailto') { $notify['address'] = $method_components['path']; $method_params = array(); - parse_str($method_components['query'], $method_params); + 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); } - $notify['body'] = $method_params['body']; + $notify['body'] = (array_key_exists('body', $method_params)) ? $method_params['body'] : ''; } $result[] = $notify; 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 4c4496bccc46e15f05d54235b420c0bff1306db2 Mon Sep 17 00:00:00 2001 From: Paweł Słowik Date: Fri, 14 Sep 2012 14:48:30 +0200 Subject: Sieve enotify/notify - allow empty body --- plugins/managesieve/lib/rcube_sieve_script.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'plugins/managesieve/lib') diff --git a/plugins/managesieve/lib/rcube_sieve_script.php b/plugins/managesieve/lib/rcube_sieve_script.php index 3e418edd3..debe9c124 100644 --- a/plugins/managesieve/lib/rcube_sieve_script.php +++ b/plugins/managesieve/lib/rcube_sieve_script.php @@ -411,9 +411,15 @@ class rcube_sieve_script $action_script .= " :$n_tag " . self::escape_string($action[$n_tag]); } } - $method = (!empty($action['address']) && !empty($action['body'])) ? - sprintf('mailto:%s?body=%s', $action['address'], rawurlencode($action['body'])) : - $action['method']; + if (!empty($action['address'])) { + $method = 'mailto:' . $action['address']; + if (!empty($action['body'])) { + $method .= '?body=' . rawurlencode($action['body']); + } + } + else { + $method = $action['method']; + } $action_script .= " " . self::escape_string($method); break; -- 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/lib') 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/lib') 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