Skip to content

Commit

Permalink
Add vacation-seconds extension support (RFC 6131)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Mar 16, 2013
1 parent bb080af commit b6fa7d5
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 38 deletions.
2 changes: 2 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion plugins/managesieve/lib/Roundcube/rcube_sieve.php
Expand Up @@ -84,7 +84,7 @@ public function __construct($username, $password='', $host='localhost', $port=20
return $this->_set_error(SIEVE_ERROR_LOGIN);
}

$this->exts = $this->get_extensions();
$this->exts = $this->get_extensions();

// disable features by config
if (!empty($disabled)) {
Expand Down
41 changes: 21 additions & 20 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
Expand Up @@ -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
Expand Down Expand Up @@ -447,8 +448,13 @@ public function as_text()
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']))
Expand Down Expand Up @@ -477,8 +483,15 @@ public function as_text()
}

// 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;
Expand Down Expand Up @@ -816,24 +829,12 @@ private function _parse_actions(&$content, $end = '}')

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;
Expand Down
3 changes: 3 additions & 0 deletions plugins/managesieve/localization/en_US.inc
Expand Up @@ -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';
Expand Down
43 changes: 26 additions & 17 deletions plugins/managesieve/managesieve.php
Expand Up @@ -663,7 +663,8 @@ function managesieve_save()
$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);
Expand Down Expand Up @@ -883,11 +884,12 @@ function managesieve_save()
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']) {
Expand All @@ -905,8 +907,8 @@ function managesieve_save()

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':
Expand Down Expand Up @@ -1411,14 +1413,14 @@ function rule_div($fid, $id, $div=true)
$tout .= $select_size_op->show($rule['test']=='size' ? $rule['type'] : '');
$tout .= '<input type="text" name="_rule_size_target[]" id="rule_size_i'.$id.'" value="'.$sizetarget.'" size="10" '
. $this->error_class($id, 'test', 'sizetarget', 'rule_size_i') .' />
<input type="radio" name="_rule_size_item['.$id.']" value=""'
. (!$sizeitem ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('B').'
<input type="radio" name="_rule_size_item['.$id.']" value="K"'
. ($sizeitem=='K' ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('KB').'
<input type="radio" name="_rule_size_item['.$id.']" value="M"'
. ($sizeitem=='M' ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('MB').'
<input type="radio" name="_rule_size_item['.$id.']" value="G"'
. ($sizeitem=='G' ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('GB');
<label><input type="radio" name="_rule_size_item['.$id.']" value=""'
. (!$sizeitem ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('B').'</label>
<label><input type="radio" name="_rule_size_item['.$id.']" value="K"'
. ($sizeitem=='K' ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('KB').'</label>
<label><input type="radio" name="_rule_size_item['.$id.']" value="M"'
. ($sizeitem=='M' ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('MB').'</label>
<label><input type="radio" name="_rule_size_item['.$id.']" value="G"'
. ($sizeitem=='G' ? ' checked="checked"' : '') .' class="radio" />'.$this->rc->gettext('GB').'</label>';
$tout .= '</div>';

// Advanced modifiers (address, envelope)
Expand Down Expand Up @@ -1572,6 +1574,7 @@ function action_div($fid, $id, $div=true)
. "</textarea>\n";

// vacation
$vsec = in_array('vacation-seconds', $this->exts);
$out .= '<div id="action_vacation' .$id.'" style="display:' .($action['type']=='vacation' ? 'inline' : 'none') .'">';
$out .= '<span class="label">'. rcube::Q($this->gettext('vacationreason')) .'</span><br />'
.'<textarea name="_action_reason['.$id.']" id="action_reason' .$id. '" '
Expand All @@ -1585,10 +1588,16 @@ function action_div($fid, $id, $div=true)
.'<input type="text" name="_action_addresses['.$id.']" id="action_addr'.$id.'" '
.'value="' . (is_array($action['addresses']) ? rcube::Q(implode(', ', $action['addresses']), 'strict', false) : $action['addresses']) . '" size="35" '
. $this->error_class($id, 'action', 'addresses', 'action_addr') .' />';
$out .= '<br /><span class="label">' . rcube::Q($this->gettext('vacationdays')) . '</span><br />'
.'<input type="text" name="_action_days['.$id.']" id="action_days'.$id.'" '
.'value="' .rcube::Q($action['days'], 'strict', false) . '" size="2" '
. $this->error_class($id, 'action', 'days', 'action_days') .' />';
$out .= '<br /><span class="label">' . rcube::Q($this->gettext($vsec ? 'vacationinterval' : 'vacationdays')) . '</span><br />'
.'<input type="text" name="_action_interval['.$id.']" id="action_interval'.$id.'" '
.'value="' .rcube::Q(isset($action['seconds']) ? $action['seconds'] : $action['days'], 'strict', false) . '" size="2" '
. $this->error_class($id, 'action', 'interval', 'action_interval') .' />';
if ($vsec) {
$out .= '&nbsp;<label><input type="radio" name="_action_interval_type['.$id.']" value="days"'
. (!isset($action['seconds']) ? ' checked="checked"' : '') .' class="radio" />'.$this->gettext('days').'</label>'
. '&nbsp;<label><input type="radio" name="_action_interval_type['.$id.']" value="seconds"'
. (isset($action['seconds']) ? ' checked="checked"' : '') .' class="radio" />'.$this->gettext('seconds').'</label>';
}
$out .= '</div>';

// flags
Expand Down
5 changes: 5 additions & 0 deletions plugins/managesieve/skins/classic/managesieve.css
Expand Up @@ -236,6 +236,11 @@ span.label
white-space: nowrap;
}

td.rowtargets label
{
color: black;
}

#footer
{
padding-top: 5px;
Expand Down
10 changes: 10 additions & 0 deletions plugins/managesieve/skins/larry/managesieve.css
Expand Up @@ -197,6 +197,11 @@ input.radio
margin-top: 0;
}

input.radio
{
vertical-align: middle;
}

select.operator_selector
{
width: 200px;
Expand All @@ -210,6 +215,11 @@ span.label
white-space: nowrap;
}

td.rowtargets label
{
color: black;
}

#footer
{
padding-top: 5px;
Expand Down
12 changes: 12 additions & 0 deletions plugins/managesieve/tests/src/parser_vacation_seconds
@@ -0,0 +1,12 @@
require ["vacation-seconds"];
# rule:[test-vacation]
if header :contains "Subject" "vacation"
{
vacation :seconds 0 text:
# test
test test /* test */
test
.
;
stop;
}

0 comments on commit b6fa7d5

Please sign in to comment.