[Svn] r4522 - in trunk/plugins/managesieve: . lib localization skins/default/templates

trac at roundcube.net trac at roundcube.net
Thu Feb 10 09:13:13 CET 2011


Author: alec
Date: 2011-02-10 02:13:13 -0600 (Thu, 10 Feb 2011)
New Revision: 4522

Modified:
   trunk/plugins/managesieve/Changelog
   trunk/plugins/managesieve/lib/rcube_sieve.php
   trunk/plugins/managesieve/localization/en_US.inc
   trunk/plugins/managesieve/localization/pl_PL.inc
   trunk/plugins/managesieve/managesieve.php
   trunk/plugins/managesieve/skins/default/templates/filteredit.html
Log:
- Added setflag/addflag/removeflag support (#1487449) 


Modified: trunk/plugins/managesieve/Changelog
===================================================================
--- trunk/plugins/managesieve/Changelog	2011-02-10 08:10:03 UTC (rev 4521)
+++ trunk/plugins/managesieve/Changelog	2011-02-10 08:13:13 UTC (rev 4522)
@@ -1,5 +1,6 @@
 - Fix STARTTLS for timsieved < 2.3.10
 - Added :regex and :matches support (#1487746)
+- Added setflag/addflag/removeflag support (#1487449)
 
 * version 3.0 [2011-02-01]
 -----------------------------------------------------------

Modified: trunk/plugins/managesieve/lib/rcube_sieve.php
===================================================================
--- trunk/plugins/managesieve/lib/rcube_sieve.php	2011-02-10 08:10:03 UTC (rev 4521)
+++ trunk/plugins/managesieve/lib/rcube_sieve.php	2011-02-10 08:13:13 UTC (rev 4522)
@@ -406,7 +406,9 @@
         'vacation',                 // RFC5230
         'relational',               // RFC3431
         'regex',                    // draft-ietf-sieve-regex-01
-    // TODO: (most wanted first) body, imapflags, notify
+        'imapflags',
+        'imap4flags',               // RFC5232
+        // TODO: (most wanted first) body, notify
     );
 
     /**
@@ -569,6 +571,7 @@
             // action(s)
             foreach ($rule['actions'] as $action) {
                 switch ($action['type']) {
+
                 case 'fileinto':
                     array_push($exts, 'fileinto');
                     $script .= "\tfileinto ";
@@ -578,6 +581,7 @@
                     }
                     $script .= self::escape_string($action['target']) . ";\n";
                     break;
+
                 case 'redirect':
                     $script .= "\tredirect ";
                     if ($action['copy']) {
@@ -586,17 +590,29 @@
                     }
                     $script .= self::escape_string($action['target']) . ";\n";
                     break;
+
                 case 'reject':
                 case 'ereject':
                     array_push($exts, $action['type']);
                     $script .= "\t".$action['type']." "
                         . self::escape_string($action['target']) . ";\n";
                     break;
+
+                case 'addflag':
+                case 'setflag':
+                case 'removeflag':
+                    $imapflags = strtolower($action['mode']) == 'imap4flags' ? 'imap4flags' : 'imapflags';
+                    array_push($exts, $imapflags);
+                    $script .= "\t".$action['type']." "
+                        . self::escape_string($action['target']) . ";\n";
+                    break;
+
                 case 'keep':
                 case 'discard':
                 case 'stop':
                     $script .= "\t" . $action['type'] .";\n";
                     break;
+
                 case 'vacation':
                     array_push($exts, 'vacation');
                     $script .= "\tvacation";
@@ -879,6 +895,15 @@
 
                 $result[] = $vacation;
                 break;
+
+            case 'setflag':
+            case 'addflag':
+            case 'removeflag':
+                $result[] = array('type' => $token,
+                    // Flags list: last token (skip optional variable)
+                    'target' => $tokens[count($tokens)-1]
+                );
+                break;
             }
         }
 

Modified: trunk/plugins/managesieve/localization/en_US.inc
===================================================================
--- trunk/plugins/managesieve/localization/en_US.inc	2011-02-10 08:10:03 UTC (rev 4521)
+++ trunk/plugins/managesieve/localization/en_US.inc	2011-02-10 08:13:13 UTC (rev 4522)
@@ -68,6 +68,14 @@
 $labels['valueislessthanequal'] = 'value is less than or equal to';
 $labels['valueequals'] = 'value is equal to';
 $labels['valuenotequals'] = 'value does not equal';
+$labels['setflags'] = 'Set flags to the message';
+$labels['addflags'] = 'Add flags to the message';
+$labels['removeflags'] = 'Remove flags from the message';
+$labels['flagread'] = 'Read';
+$labels['flagdeleted'] = 'Deleted';
+$labels['flaganswered'] = 'Answered';
+$labels['flagflagged'] = 'Flagged';
+$labels['flagdraft'] = 'Draft';
 
 $messages = array();
 $messages['filterunknownerror'] = 'Unknown server error';

Modified: trunk/plugins/managesieve/localization/pl_PL.inc
===================================================================
--- trunk/plugins/managesieve/localization/pl_PL.inc	2011-02-10 08:10:03 UTC (rev 4521)
+++ trunk/plugins/managesieve/localization/pl_PL.inc	2011-02-10 08:13:13 UTC (rev 4522)
@@ -69,6 +69,14 @@
 $labels['valueislessthanequal'] = 'wartość jest równa lub mniejsza od';
 $labels['valueequals'] = 'wartość jest równa';
 $labels['valuenotequals'] = 'wartość jest różna od';
+$labels['setflags'] = 'Ustaw flagi wiadomości';
+$labels['addflags'] = 'Dodaj flagi do wiadomości';
+$labels['removeflags'] = 'Usuń flagi wiadomości';
+$labels['flagread'] = 'Przeczytana';
+$labels['flagdeleted'] = 'Usunięta';
+$labels['flaganswered'] = 'Z odpowiedzią';
+$labels['flagflagged'] = 'Oflagowana';
+$labels['flagdraft'] = 'Szkic';
 
 $messages = array();
 $messages['filterunknownerror'] = 'Nieznany błąd serwera';

Modified: trunk/plugins/managesieve/managesieve.php
===================================================================
--- trunk/plugins/managesieve/managesieve.php	2011-02-10 08:10:03 UTC (rev 4521)
+++ trunk/plugins/managesieve/managesieve.php	2011-02-10 08:13:13 UTC (rev 4522)
@@ -360,6 +360,7 @@
             $reasons = $_POST['_action_reason'];
             $addresses = $_POST['_action_addresses'];
             $days = $_POST['_action_days'];
+            $flags = $_POST['_action_flags'];
 
             // we need a "hack" for radiobuttons
             foreach ($sizeitems as $item)
@@ -373,12 +374,13 @@
 
             if ($name == '')
                 $this->errors['name'] = $this->gettext('cannotbeempty');
-            else
+            else {
                 foreach($this->script as $idx => $rule)
                     if($rule['name'] == $name && $idx != $fid) {
                         $this->errors['name'] = $this->gettext('ruleexist');
                         break;
                     }
+            }
 
             $i = 0;
             // rules
@@ -481,6 +483,7 @@
                 $target = $this->strip_value($act_targets[$idx]);
 
                 switch ($type) {
+
                 case 'fileinto':
                 case 'fileinto_copy':
                     $mailbox = $this->strip_value($mailboxes[$idx]);
@@ -490,6 +493,7 @@
                         $this->form['actions'][$i]['copy'] = true;
                     }
                     break;
+
                 case 'reject':
                 case 'ereject':
                     $target = $this->strip_value($area_targets[$idx]);
@@ -498,6 +502,7 @@
  //                 if ($target == '')
 //                      $this->errors['actions'][$i]['targetarea'] = $this->gettext('cannotbeempty');
                     break;
+
                 case 'redirect':
                 case 'redirect_copy':
                     $this->form['actions'][$i]['target'] = $target;
@@ -512,6 +517,25 @@
                         $this->form['actions'][$i]['copy'] = true;
                     }
                     break;
+
+                case 'addflag':
+                case 'setflag':
+                case 'removeflag':
+                    $_target = array();
+                    if (empty($flags[$idx])) {
+                        $this->errors['actions'][$i]['target'] = $this->gettext('noflagset');
+                    }
+                    else {
+                        foreach ($flags[$idx] as $flag) {
+                            $_target[] = $this->strip_value($flag);
+                        }
+                    }
+                    $this->form['actions'][$i]['target'] = $_target;
+                    if (in_array('imap4flags', $this->exts)) {
+                        $this->form['actions'][$i]['mode'] = 'imap4flags';
+                    }
+                    break;
+
                 case 'vacation':
                     $reason = $this->strip_value($reasons[$idx]);
                     $this->form['actions'][$i]['reason']    = str_replace("\r\n", "\n", $reason);
@@ -995,6 +1019,11 @@
         if (in_array('vacation', $this->exts))
             $select_action->add(Q($this->gettext('messagereply')), 'vacation');
         $select_action->add(Q($this->gettext('messagedelete')), 'discard');
+        if (in_array('imapflags', $this->exts) || in_array('imap4flags', $this->exts)) {
+            $select_action->add(Q($this->gettext('setflags')), 'setflag');
+            $select_action->add(Q($this->gettext('addflags')), 'addflag');
+            $select_action->add(Q($this->gettext('removeflags')), 'removeflag');
+        }
         $select_action->add(Q($this->gettext('rulestop')), 'stop');
 
         $select_type = $action['type'];
@@ -1034,6 +1063,25 @@
             . $this->error_class($id, 'action', 'days', 'action_days') .' />';
         $out .= '</div>';
 
+        // flags
+        $flags = array(
+            'read'      => '\\\\Seen',
+            'answered'  => '\\\\Answered',
+            'flagged'   => '\\\\Flagged',
+            'deleted'   => '\\\\Deleted',
+            'draft'     => '\\\\Draft',
+        );
+        $action['target'] = (array)$action['target'];
+        $out .= '<div id="action_flags' .$id.'" style="display:' 
+            . (preg_match('/^(set|add|remove)flag$/', $action['type']) ? 'inline' : 'none') . '"'
+            . $this->error_class($id, 'action', 'flags', 'action_flags') . '>';
+        foreach ($flags as $fidx => $flag) {
+            $out .= '<nobr><input type="checkbox" name="_action_flags[' .$id .'][]" value="' . $flag . '"'
+                . (in_array_nocase($flag, $action['target']) ? 'checked="checked"' : '') . ' />'
+                . Q($this->gettext('flag'.$fidx)) .'</nobr> ';
+        }
+        $out .= '</div>';
+
         // mailbox select
         $out .= '<select id="action_mailbox' .$id. '" name="_action_mailbox[]" style="display:'
             .(!isset($action) || $action['type']=='fileinto' ? 'inline' : 'none'). '">';

Modified: trunk/plugins/managesieve/skins/default/templates/filteredit.html
===================================================================
--- trunk/plugins/managesieve/skins/default/templates/filteredit.html	2011-02-10 08:10:03 UTC (rev 4521)
+++ trunk/plugins/managesieve/skins/default/templates/filteredit.html	2011-02-10 08:13:13 UTC (rev 4522)
@@ -11,81 +11,65 @@
 
 function header_select(id)
 {
-    var obj = document.getElementById('header'+id);
+    var obj = document.getElementById('header' + id),
+	    size = document.getElementById('rule_size' + id),
+	    op = document.getElementById('rule_op' + id),
+	    target = document.getElementById('rule_target' + id),
+	    header = document.getElementById('custom_header' + id);
 
-    if (obj.value == 'size')
-    {
-	document.getElementById('rule_size' + id).style.display = 'inline';
-	document.getElementById('rule_op' + id).style.display = 'none';
-	document.getElementById('rule_target' + id).style.display = 'none';
-	document.getElementById('custom_header' + id).style.display = 'none';
+    if (obj.value == 'size') {
+	    size.style.display = 'inline';
+	    op.style.display = 'none';
+	    target.style.display = 'none';
+	    header.style.display = 'none';
     }
-    else
-    {
-	if (obj.value != '...')
-	    document.getElementById('custom_header' + id).style.display = 'none';
-	else
-	    document.getElementById('custom_header' + id).style.display = 'inline';
-    
-	document.getElementById('rule_size' + id).style.display = 'none';
-	document.getElementById('rule_op' + id).style.display = 'inline';
-	rule_op_select(id);
+    else {
+        header.style.display = obj.value != '...' ? 'none' : 'inline';
+	    size.style.display = 'none';
+	    op.style.display = 'inline';
+	    rule_op_select(id);
     }
 }
 
 function rule_op_select(id)
 {
-    var obj = document.getElementById('rule_op'+id);
+    var obj = document.getElementById('rule_op' + id),
+        target = document.getElementById('rule_target' + id);
 
-    if (obj.value == 'exists' || obj.value == 'notexists')
-    {
-	document.getElementById('rule_target' + id).style.display = 'none';
-    }
-    else
-    {
-	document.getElementById('rule_target' + id).style.display = 'inline';
-    }
+  	target.style.display = obj.value == 'exists' || obj.value == 'notexists' ? 'none' : 'inline';
 }
 
 function action_type_select(id)
 {
-    var obj = document.getElementById('action_type'+id);
+    var obj = document.getElementById('action_type' + id),
+    	enabled = {},
+        elems = {
+            mailbox: document.getElementById('action_mailbox' + id),
+	        target: document.getElementById('action_target' + id),
+	        target_area: document.getElementById('action_target_area' + id),
+	        flags: document.getElementById('action_flags' + id),
+	        vacation: document.getElementById('action_vacation' + id)
+        };
 
-    if (obj.value == 'fileinto' || obj.value == 'fileinto_copy')
-    {
-	document.getElementById('action_mailbox' + id).style.display = 'inline';
-	document.getElementById('action_target' + id).style.display = 'none';
-	document.getElementById('action_target_area' + id).style.display = 'none';
-	document.getElementById('action_vacation' + id).style.display = 'none';
+    if (obj.value == 'fileinto' || obj.value == 'fileinto_copy') {
+	    enabled.mailbox = 1;
     }
-    else if (obj.value == 'redirect' || obj.value == 'redirect_copy')
-    {
-	document.getElementById('action_target' + id).style.display = 'inline';
-	document.getElementById('action_mailbox' + id).style.display = 'none';
-	document.getElementById('action_target_area' + id).style.display = 'none';
-	document.getElementById('action_vacation' + id).style.display = 'none';
+    else if (obj.value == 'redirect' || obj.value == 'redirect_