From b6fa7d54b852df88de1fa1b36d6221b143e85835 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 16 Mar 2013 16:29:17 +0100 Subject: Add vacation-seconds extension support (RFC 6131) --- plugins/managesieve/Changelog | 2 + plugins/managesieve/lib/Roundcube/rcube_sieve.php | 2 +- .../lib/Roundcube/rcube_sieve_script.php | 41 +++++++++++---------- plugins/managesieve/localization/en_US.inc | 3 ++ plugins/managesieve/managesieve.php | 43 +++++++++++++--------- plugins/managesieve/skins/classic/managesieve.css | 5 +++ plugins/managesieve/skins/larry/managesieve.css | 10 +++++ .../managesieve/tests/src/parser_vacation_seconds | 12 ++++++ 8 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 plugins/managesieve/tests/src/parser_vacation_seconds diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 5f31d311c..32d87a0d8 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,3 +1,5 @@ +- Add vacation-seconds extension support (RFC 6131) + * version 6.2 [2013-02-17] ----------------------------------------------------------- - Support tls:// prefix in managesieve_host option diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php index 736f73146..a04e3c2a4 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php @@ -84,7 +84,7 @@ class rcube_sieve return $this->_set_error(SIEVE_ERROR_LOGIN); } - $this->exts = $this->get_extensions(); + $this->exts = $this->get_extensions(); // disable features by config if (!empty($disabled)) { diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php index 36eb1bcf8..80f590f4b 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php @@ -33,6 +33,7 @@ class rcube_sieve_script 'ereject', // RFC5429 'copy', // RFC3894 'vacation', // RFC5230 + 'vacation-seconds', // RFC6131 'relational', // RFC3431 'regex', // draft-ietf-sieve-regex-01 'imapflags', // draft-melnikov-sieve-imapflags-06 @@ -447,8 +448,13 @@ class rcube_sieve_script case 'vacation': array_push($exts, 'vacation'); $action_script .= 'vacation'; - if (!empty($action['days'])) - $action_script .= " :days " . $action['days']; + if (isset($action['seconds'])) { + array_push($exts, 'vacation-seconds'); + $action_script .= " :seconds " . intval($action['seconds']); + } + else if (!empty($action['days'])) { + $action_script .= " :days " . intval($action['days']); + } if (!empty($action['addresses'])) $action_script .= " :addresses " . self::escape_string($action['addresses']); if (!empty($action['subject'])) @@ -477,8 +483,15 @@ class rcube_sieve_script } // requires - if (!empty($exts)) - $output = 'require ["' . implode('","', array_unique($exts)) . "\"];\n" . $output; + if (!empty($exts)) { + $exts = array_unique($exts); + + if (in_array('vacation-seconds', $exts) && ($key = array_search('vacation', $exts)) !== false) { + unset($exts[$key]); + } + + $output = 'require ["' . implode('","', $exts) . "\"];\n" . $output; + } if (!empty($this->prefix)) { $output = $this->prefix . "\n\n" . $output; @@ -816,24 +829,12 @@ class rcube_sieve_script for ($i=0, $len=count($tokens); $i<$len; $i++) { $tok = strtolower($tokens[$i]); - if ($tok == ':days') { - $vacation['days'] = $tokens[++$i]; - } - else if ($tok == ':subject') { - $vacation['subject'] = $tokens[++$i]; - } - else if ($tok == ':addresses') { - $vacation['addresses'] = $tokens[++$i]; - } - else if ($tok == ':handle') { - $vacation['handle'] = $tokens[++$i]; - } - else if ($tok == ':from') { - $vacation['from'] = $tokens[++$i]; - } - else if ($tok == ':mime') { + if ($tok == ':mime') { $vacation['mime'] = true; } + else if ($tok[0] == ':') { + $vacation[substr($tok, 1)] = $tokens[++$i]; + } } $result[] = $vacation; diff --git a/plugins/managesieve/localization/en_US.inc b/plugins/managesieve/localization/en_US.inc index 97c20aa76..2b391e0c5 100644 --- a/plugins/managesieve/localization/en_US.inc +++ b/plugins/managesieve/localization/en_US.inc @@ -57,6 +57,9 @@ $labels['sender'] = 'Sender'; $labels['recipient'] = 'Recipient'; $labels['vacationaddresses'] = 'My additional e-mail addresse(s) (comma-separated):'; $labels['vacationdays'] = 'How often send messages (in days):'; +$labels['vacationinterval'] = 'How often send messages:'; +$labels['days'] = 'days'; +$labels['seconds'] = 'seconds'; $labels['vacationreason'] = 'Message body (vacation reason):'; $labels['vacationsubject'] = 'Message subject:'; $labels['rulestop'] = 'Stop evaluating rules'; diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php index a667c06cd..817fa8650 100644 --- a/plugins/managesieve/managesieve.php +++ b/plugins/managesieve/managesieve.php @@ -663,7 +663,8 @@ class managesieve extends rcube_plugin $area_targets = rcube_utils::get_input_value('_action_target_area', rcube_utils::INPUT_POST, true); $reasons = rcube_utils::get_input_value('_action_reason', rcube_utils::INPUT_POST, true); $addresses = rcube_utils::get_input_value('_action_addresses', rcube_utils::INPUT_POST, true); - $days = rcube_utils::get_input_value('_action_days', rcube_utils::INPUT_POST); + $intervals = rcube_utils::get_input_value('_action_interval', rcube_utils::INPUT_POST); + $interval_types = rcube_utils::get_input_value('_action_interval_type', rcube_utils::INPUT_POST); $subject = rcube_utils::get_input_value('_action_subject', rcube_utils::INPUT_POST, true); $flags = rcube_utils::get_input_value('_action_flags', rcube_utils::INPUT_POST); $varnames = rcube_utils::get_input_value('_action_varname', rcube_utils::INPUT_POST); @@ -883,11 +884,12 @@ class managesieve extends rcube_plugin break; case 'vacation': - $reason = $this->strip_value($reasons[$idx]); + $reason = $this->strip_value($reasons[$idx]); + $interval_type = $interval_types[$idx] == 'seconds' ? 'seconds' : 'days'; $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); - $this->form['actions'][$i]['days'] = $days[$idx]; $this->form['actions'][$i]['subject'] = $subject[$idx]; $this->form['actions'][$i]['addresses'] = explode(',', $addresses[$idx]); + $this->form['actions'][$i][$interval_type] = $intervals[$idx]; // @TODO: vacation :mime, :from, :handle if ($this->form['actions'][$i]['addresses']) { @@ -905,8 +907,8 @@ class managesieve extends rcube_plugin if ($this->form['actions'][$i]['reason'] == '') $this->errors['actions'][$i]['reason'] = $this->gettext('cannotbeempty'); - if ($this->form['actions'][$i]['days'] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i]['days'])) - $this->errors['actions'][$i]['days'] = $this->gettext('forbiddenchars'); + if ($this->form['actions'][$i][$interval_type] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i][$interval_type])) + $this->errors['actions'][$i]['interval'] = $this->gettext('forbiddenchars'); break; case 'set': @@ -1411,14 +1413,14 @@ class managesieve extends rcube_plugin $tout .= $select_size_op->show($rule['test']=='size' ? $rule['type'] : ''); $tout .= 'error_class($id, 'test', 'sizetarget', 'rule_size_i') .' /> - '.$this->rc->gettext('B').' - '.$this->rc->gettext('KB').' - '.$this->rc->gettext('MB').' - '.$this->rc->gettext('GB'); + + + + '; $tout .= ''; // Advanced modifiers (address, envelope) @@ -1572,6 +1574,7 @@ class managesieve extends rcube_plugin . "\n"; // vacation + $vsec = in_array('vacation-seconds', $this->exts); $out .= '
'; $out .= ''. rcube::Q($this->gettext('vacationreason')) .'
' .'