From b6fa7d54b852df88de1fa1b36d6221b143e85835 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 16 Mar 2013 11:29:17 -0400
Subject: [PATCH] Add vacation-seconds extension support (RFC 6131)

---
 plugins/managesieve/lib/Roundcube/rcube_sieve_script.php |   41 +++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
index 36eb1bc..80f590f 100644
--- a/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
+++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
@@ -33,6 +33,7 @@
         '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 @@
                     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 @@
         }
 
         // 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 @@
 
                 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;

--
Gitblit v1.9.1