Code

Several sieve filter updates
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 7 Mar 2007 05:43:58 +0000 (05:43 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 7 Mar 2007 05:43:58 +0000 (05:43 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5751 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_My_Parser.inc
include/sieve/class_My_Tree.inc
include/sieve/class_sieveElement_If.inc
include/sieve/class_sieveElements.inc
include/sieve/class_sieveManagement.inc
include/sieve/templates/element_address.tpl
include/sieve/templates/element_envelope.tpl
include/sieve/templates/element_header.tpl
plugins/personal/mail/class_mailAccount.inc

index 6d796cd8ae23d84fe9a22f31a53574ca8d0bbad4..b0ef7ea7654f2a45b273765176e2ab807d934d99 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-
+define("SIEVE_INDENT_TAB","  ");
 
 /* This class is inherited from the original 'Parser'
  *  class written by Heiko Hund
@@ -10,7 +10,8 @@ class My_Parser extends Parser
 
        function execute()
        {
-               return($this->dumpParseTree());
+               $ret = $this->dumpParseTree();
+               return($ret);
        }
        
 
@@ -35,7 +36,13 @@ class My_Parser extends Parser
         return $this->status_;
        }
 
-               
+       
+       function get_sieve_script()
+       {
+               return($this->tree_->get_sieve_script());
+       }               
+
+       
        function save_object()
        {
                $this->tree_->save_object();
index 942f64e4c03fb970a2fb94195e09dc87775a5adf..922156017b8d2e834833a613ce734938c090d4a1 100644 (file)
@@ -33,7 +33,7 @@ class My_Tree extends Tree
 
     /* Create html results */
     $this->dump_ ="<table width='100%'><tr><td style='background-color:#BBBBBB;border: 0px;padding-left:20px;'>";
-    foreach($this->pap as $object){
+    foreach($this->pap as $key => $object){
       if(is_object($object)){
         $this->dump_ .= preg_replace("/>/",">\n",$object->execute()); 
       }
@@ -143,9 +143,64 @@ class My_Tree extends Tree
       }
     }
   }
+
+  /* Need to be reviewed */
+  function get_sieve_script()
+  {
+    $tmp ="";
+    if(count($this->pap)){
+      $tmp = "#Generated by GOsa - Gonicus System Administrator\n";
+      $buffer = "";    
+      foreach($this->pap as $part)  {
+        if(get_class($part) == "sieve_block_end"){
+          $buffer = substr($buffer,0,strlen($buffer)-(strlen(SIEVE_INDENT_TAB)));
+        }
+        $tmp2 = $part->get_sieve_script_part();
+        $tmp3 = split("\n",$tmp2);
+        foreach($tmp3 as $str){
+          $str2 = trim($str);
+          if(empty($str2)) continue;
+          $tmp.= $buffer.$str."\n";
+        }
+        if(get_class($part) == "sieve_block_start"){
+          $buffer .= SIEVE_INDENT_TAB;
+        }
+      }
+    }
+    return($tmp);
+  }
 }
 
 
+/* Create valid sieve string/string-list 
+ *  out of a given array
+ */
+function sieve_create_strings($data)
+{
+  $ret = "";
+  if(is_array($data)){
+    if(count($data) == 1){
+      $ret = "\"";
+      foreach($data as $dat){
+        $ret .=$dat;
+      }
+      $ret.="\"";
+    }else{
+      foreach($data as $dat){
+        $ret.= "\"";
+        $ret.=$dat;
+        $ret.="\", ";
+      }
+      $ret = preg_replace("/,$/","",trim($ret));
+      $ret = "[".$ret."]";
+    }
+  }else{
+    $ret = "\"".$data."\"";
+  }
+  $ret = preg_replace("/\"\"/","\"",$ret);
+  return($ret);
+}
+
 /* This checks if there is a string at the current position 
  *  in the token array. 
  * If there is a string list at the current position,
index e0d8fb1b80f75ab61810aeb95c18a98fe76cec20..03934e4603e8bf963a60a520f5a60caf6956fab3 100644 (file)
@@ -7,24 +7,349 @@ class sieve_if
   var $TYPE    = "if";
   var $id     = -1;
 
+  var $address_parts    = array();
+  var $comparators      = array();
+  var $match_types      = array();
+  var $operators        = array();
 
+  
+  /* Initialize class 
+   *  $elements   contains all tokens that belongs to this if/else tag
+   *  $object_id  cotains an unique tag id, to be able to create uniqe html post names
+   */
   function sieve_if($elements,$object_id)
   {
+    /* Possible address parts we can select */
+    $this->address_parts = array( 
+        ":all"       => _("Complete adress")."&nbsp;("._("Default").")",
+        ":domain"    => _("Domian part") ,
+        ":localpart" => _("Local part"));
+
+    /* comparator type */
+    $this->comparators   = array( 
+        "i;ascii-casemap" => _("Case insensitive")."&nbsp;("._("Default").")",
+        "i;octet"         => _("Case sensitive"),
+        "i;ascii-numeric" => _("Numeric"));
+
+    /* Match types */
+    $this->match_types  = array(  
+        ":is"         => _("is"),
+        ":contains"   => _("contains"),
+        ":matches"    => _("matches"),
+        ":count"      => _("count"),
+        ":value"      => _("value is"));
+
+    /* Operators */
+    $this->operators = array(     
+        "lt"  => _("less than"),
+        "le"  => _("less or equal"),
+        "eq"  => _("equals"),
+        "ge"  => _("greater or equal"),
+        "gt"  => _("greater than"),
+        "ne"  => _("not equal"));
+
     $this->id       = $object_id;
     $this->elements = $elements;
     $this->_parsed  = $this->_parse($elements['ELEMENTS'],1);
   }
 
+
+  /* Returns the sieve script for this 
+   *  if/else tag.
+   */
+  function get_sieve_script_part()
+  {
+    $tmp = "if ".$this->get_sieve_script_part_recursive($parsed = NULL,$id = 1,$obj_id=1);
+    return($tmp);
+  } 
+
+
+  /* Recursivly create a sieve script out of the given 
+   *  tags and tokens provided by $parsed.
+   *  $id       specifies the depth of the current element.
+   *  $obj_id   is the current tag-id handled by this function
+   */
+  function get_sieve_script_part_recursive($parsed = NULL,$id = 1,$obj_id=1)
+  {
+    $script ="";
+    if($parsed == NULL){
+      $parsed = $this->_parsed;
+    }
+
+    /* Walk through all elements */
+    foreach($parsed as $key => $data){
+
+      /* Create Inverse Tag */
+      if(is_array($data) && isset($data['Inverse']) && $data['Inverse']){
+        $Inverse = TRUE;
+      }else{
+        $Inverse = FALSE;
+      }
+
+      /* Create elements */
+      switch($key)
+      {
+
+        /*******************
+         * True / False
+         *******************/
+
+        case "true" :
+        case "false" :
+        {
+          /* Invert this test if required */
+          if($Inverse){
+            $script .= "not ";
+          }
+          $script .= $key;
+   
+          break;
+        }
+
+
+        /*******************
+         * Address
+         *******************/
+
+        case "address" :   
+        {
+          /* [not] address 
+                        [address-part: tag] 
+                        [comparator: tag] 
+                        [match-type: tag] 
+                        <header-list: string-list> 
+                        <key-list: string-list> 
+          */
+
+          /* Invert this test if required */
+          if($Inverse){
+            $script .= "not ";
+          }
+  
+          $script .="address ";
+          /* Add address part tag */ 
+          if(!empty($data['Address_Part']) && $data['Address_Part'] != ":all"){
+            $script .= $data['Address_Part']." ";
+          }
+
+          /* Add comparator */
+          if(!empty($data['Comparator']) && $data['Comparator'] != ""){
+            $script .= ":comparator ".$data['Comparator']." ";
+          }
+    
+          /* Add match type */
+          $script .= $data['Match_type']." ";
+
+          /* Add special match type for count and value */
+          if(in_array($data['Match_type'], array(":value",":count")) && !empty($data['Match_type_value'])) {
+            $script .= $data['Match_type_value']." ";
+          }
+
+          $script .= sieve_create_strings($data['Key_List']);
+          $script .= " ";
+          $script .= sieve_create_strings($data['Value_List']);
+          break;
+        }
+
+
+        /*******************
+         * Header
+         *******************/
+
+        case "header" :   
+        {
+          /* [not] header   
+                [comparator: tag] 
+                [match-type: tag] 
+                <header-names: string-list> 
+                <key-list: string-list>
+          */
+
+          /* Invert ? */
+          if($Inverse){
+            $script .= "not ";
+          }
   
+          $script .="header ";
+          /* Add address part tag */ 
+          if(!empty($data['Address_Part']) && $data['Address_Part'] != ":all"){
+            $script .= $data['Address_Part']." ";
+          }
+
+          /* Add comparator */
+          if(!empty($data['Comparator']) && $data['Comparator'] != ""){
+            $script .= ":comparator ".$data['Comparator']." ";
+          }
+    
+          /* Add match type */
+          $script .= $data['Match_type']." ";
+
+          /* Add special match type for count and value */
+          if(in_array($data['Match_type'], array(":value",":count")) && !empty($data['Match_type_value'])) {
+            $script .= $data['Match_type_value']." ";
+          }
+
+          $script .= sieve_create_strings($data['Key_List']);
+          $script .= " ";
+          $script .= sieve_create_strings($data['Value_List']);
+          break;
+        }
+
+
+        /*******************
+         * Envelope
+         *******************/
+
+        case "envelope" :   
+        {
+          /* [not]  envelope 
+                    [address-part: tag] 
+                    [comparator: tag] 
+                    [match-type: tag] 
+                    <envelope-part: string-list> 
+                    <key-list: string-list> 
+          */
+
+          /* Invert */
+          if($Inverse){
+            $script .= "not ";
+          }
+  
+          $script .="envelope ";
+          /* Add address part tag */ 
+          if(!empty($data['Address_Part']) && $data['Address_Part'] != ":all"){
+            $script .= $data['Address_Part']." ";
+          }
+
+          /* Add comparator */
+          if(!empty($data['Comparator']) && $data['Comparator'] != ""){
+            $script .= ":comparator ".$data['Comparator']." ";
+          }
+    
+          /* Add match type */
+          $script .= $data['Match_type']." ";
+
+          /* Add special match type for count and value */
+          if(in_array($data['Match_type'], array(":value",":count")) && !empty($data['Match_type_value'])) {
+            $script .= $data['Match_type_value']." ";
+          }
+
+          $script .= sieve_create_strings($data['Key_List']);
+          $script .= " ";
+          $script .= sieve_create_strings($data['Value_List']);
+          break;
+        }
+
+
+        /*******************
+         * Exists
+         *******************/
+        case "exists" : 
+        {
+          /* [not] exists 
+              <header-names: string-list> 
+          */
+
+          /* Invert ? */
+          if($Inverse){
+            $script .= "not ";
+          }
+
+          $script .= "exists ".sieve_create_strings($data['Values']);
+          break;
+        }
+
+
+        /*******************
+         * Size
+         *******************/
+        case "size" : 
+        {
+          /* [not] size 
+                <":over" / ":under"> 
+                <limit: number> 
+          */
+
+          /* Invert ? */
+          if($Inverse){
+            $script .= "not ";
+          }
+          /* Add size test */ 
+          $script .="size ";
+          $script .=$data['Match_type']." ";
+          foreach($data['Value_List'] as $val){
+            $script .= $val." ";
+          }
+          break;
+        }
+
+
+        /*******************
+         * Allof
+         *******************/
+        case "anyof" :
+        case "allof" :
+        {
+          /* allof <tests: test-list>
+             anyof <tests: test-list> */
+
+          /* Add spaces, to indent the code.*/ 
+          $block = "\n";
+          for($i = 0 ; $i < $id ; $i ++){
+            $block .= SIEVE_INDENT_TAB;
+          }          
+
+          /* Add allof/anyof tag */
+          $script.= " ".$key." ( ";
+
+          /* Add each test parameter */
+          foreach($data as $key2 => $dat){
+            if(($key2 === "Inverse") && ($key2 == "Inverse")){
+              continue;
+            }
+            $script.= $block.$this->get_sieve_script_part_recursive($dat, ($id +1),$key2).", ";
+          }
+    
+          /* Remove last _,_ and close the tag */
+          $script = preg_replace("/,$/","",trim($script));
+          $script.= $block.")";
+          break ;
+        }
+
+        default :
+        {
+          $script .= "THERE IS SOME IMPLEMENTATION MISSING FOR SIEVE SCRIPT CREATION :".$key;
+        }
+      }
+    }
+    return($script);
+  }
+
+
+  /* Ensure that all changes made on the ui 
+   *  will be saved. 
+   */
   function save_object()
   {
     $tmp = $this->save_object_recursive($parsed = NULL,$id = 1,$obj_id=1);
     $this->_parsed = $tmp;
   }
 
+
+  /* Recursivly save all ui changes for the 
+   *  tags and tokens provided by $parsed.
+   *  $id       specifies the depth of the current element.
+   *  $obj_id   is the current tag-id handled by this function
+   */
   function save_object_recursive($parsed = NULL,$id = 1,$obj_id=1)
   {
-
+    /* Variable initialization */ 
     $ret ="";
     if($parsed == NULL){
       $parsed = $this->_parsed;
@@ -40,42 +365,45 @@ class sieve_if
       switch($key)
       {
  
         /*******************
-         * TRUE FALSE 
+         * Address 
          *******************/
 
+        case "envelope" :
+        case "header" : 
         case "address" : 
         {
-          /* address [address-part: tag] [comparator: tag] [match-type: tag] <header-list: string-list> <key-list: string-list> */
-          $address_parts = array( ":all"       => _("Complete adress"),
-                                  ":domain"    => _("Domian part") ,
-                                  ":localpart" => _("Local part"));
-
-          /* comparator type */
-          $comparators   = array( "i;octet"         => _("Normal"),
-                                  "i;ascii-casemap" =>_("Case sensitive"),
-                                  "i;ascii-numeric" =>_("Numeric"));
-
-          /* Match types */
-          $match_types  = array(  ":is"         => _("is"),
-                                  ":contains"   => _("contains"),
-                                  ":matches"    => _("matches"),
-                                  ":count"      => _("count"),
-                                  ":value"      => _("value is"));
-
-          /* Operators */
-          $operators = array(     "lt"  => _("less than"),
-                                  "le"  => _("less or equal"),
-                                  "eq"  => _("equals"),
-                                  "ge"  => _("greater or equal"),
-                                  "gt"  => _("greater than"),
-                                  "ne"  => _("not equal"));
-
+          /* [not] address 
+                        [address-part: tag] 
+                        [comparator: tag] 
+                        [match-type: tag] 
+                        <header-list: string-list> 
+                        <key-list: string-list> 
+          */
+
+          /* Possible address parts we can select */
+          $address_parts = $this->address_parts;
+          $comparators   = $this->comparators;
+          $match_types   = $this->match_types; 
+          $operators     = $this->operators;
+
+          /* Toggle Inverse ? */
+          if(isset($_POST['toggle_inverse_'.$element_id])){
+            $parsed[$key]['Inverse'] = !$parsed[$key]['Inverse'];
+          }
 
           /* Check if we want to toggle the expert mode */
           if(isset($_POST['Toggle_Expert_'.$element_id])){
-            $parsed['address']['Expert'] = !$parsed['address']['Expert'];
+            $parsed[$key]['Expert'] = !$parsed[$key]['Expert'];
+          }
+
+          /* Get address part */
+          if(isset($_POST['address_part_'.$element_id])){
+            $ap = $_POST['address_part_'.$element_id];
+
+            if(isset($address_parts[$ap])){
+              $parsed[$key]['Address_Part'] = $ap;
+            }
           }
 
           /* Check if match type has changed */
@@ -83,48 +411,55 @@ class sieve_if
             $mt = $_POST['matchtype_'.$element_id];
 
             if(isset($match_types[$mt])){
-              $parsed['address']['Match_type'] = $mt;
+              $parsed[$key]['Match_type'] = $mt;
+            }
+          }
+
+          /* Get the comparator tag, if posted */
+          if(isset($_POST['comparator_'.$element_id])){
+            $cp = $_POST['comparator_'.$element_id];
+
+            if(isset($comparators[$cp])){
+              $parsed[$key]['Comparator'] = $cp;
             }
           }
 
           /* In case of :count and :value match types 
            *  we have a special match operator we should save.
            */
-          if(in_array($parsed['address']['Match_type'],array(":value",":count"))){
+          if(in_array($parsed[$key]['Match_type'],array(":value",":count"))){
             if(isset($_POST['operator_'.$element_id])){
               $op = $_POST['operator_'.$element_id];
 
               if(isset($operators[$op])){
-                $parsed['address']['Match_type_value'] = $op;
+                $parsed[$key]['Match_type_value'] = $op;
               }
             }
           }
 
           /* Get the address fields we should check, they are seperated by , */
           if(isset($_POST['keys_'.$element_id])){
-            $vls = $_POST['keys_'.$element_id];
+            $vls = stripslashes($_POST['keys_'.$element_id]);
             $tmp = array();
 
             $tmp2 = split(",",$vls);
             foreach($tmp2 as $val){
               $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
             }
-            $parsed['address']['Key_List'] = $tmp;
+            $parsed[$key]['Key_List'] = $tmp;
           }
 
           /* Get the values should check for, they are seperated by , */
           if(isset($_POST['values_'.$element_id])){
-            $vls = $_POST['values_'.$element_id];
+            $vls = stripslashes($_POST['values_'.$element_id]);
             $tmp = array();
 
             $tmp2 = split(",",$vls);
             foreach($tmp2 as $val){
               $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
             }
-            $parsed['address']['Value_List'] = $tmp;
+            $parsed[$key]['Value_List'] = $tmp;
           }
-
-
           break;
         }
  
@@ -154,7 +489,7 @@ class sieve_if
         {
           /* get list of match values */
           if(isset($_POST['Values_'.$element_id])){
-            $vls = $_POST['Values_'.$element_id];
+            $vls = stripslashes($_POST['Values_'.$element_id]);
             $tmp = array();          
   
             $tmp2 = split(",",$vls);
@@ -340,28 +675,10 @@ class sieve_if
 
         case "header": 
         {
-          /* comparator type */
-          $comparators   = array( "i;octet"         => _("Normal"),
-                                  "i;ascii-casemap" =>_("Case sensitive"),
-                                  "i;ascii-numeric" =>_("Numeric"));
-
-          /* Match types */
-          $match_types  = array(  ":is"         => _("is"),
-                                  ":contains"   => _("contains"),
-                                  ":matches"    => _("matches"),
-                                  ":over"       => _("is over"),
-                                  ":count"      => _("count"),
-                                  ":value"      => _("value is"),
-                                  ":under"      => _("is under"));
-  
-          /* Operators */
-          $operators = array(     ""    => "-",
-                                  "lt"  => _("less than"),
-                                  "le"  => _("less or equal"),
-                                  "eq"  => _("equals"),
-                                  "ge"  => _("greater or equal"),
-                                  "gt"  => _("greater than"),
-                                  "ne"  => _("not equal"));
+          $address_parts = $this->address_parts;
+          $comparators   = $this->comparators;
+          $match_types   = $this->match_types; 
+          $operators     = $this->operators;
 
           $smarty = get_smarty();
           $smarty->assign("comparators",$comparators);
@@ -386,7 +703,9 @@ class sieve_if
           $values = preg_replace("/,$/","",trim($values));
 
           $smarty->assign("keys",$keys);
+          $smarty->assign("Inverse",$Inverse);
           $smarty->assign("values",$values);
+          $smarty->assign("Expert", $data['Expert']);
 
  
           $smarty->assign("ID"  , $element_id); 
@@ -396,31 +715,15 @@ class sieve_if
 
         case "envelope":
         {
-          /* comparator type */
-          $comparators   = array( "i;octet"         => _("Normal"),
-                                  "i;ascii-casemap" =>_("Case sensitive"),
-                                  "i;ascii-numeric" =>_("Numeric"));
-
-          /* Match types */
-          $match_types  = array(  ":is"         => _("is"),
-                                  ":contains"   => _("contains"),
-                                  ":matches"    => _("matches"),
-                                  ":over"       => _("is over"),
-                                  ":count"      => _("count"),
-                                  ":value"      => _("value is"),
-                                  ":under"      => _("is under"));
-  
-          /* Operators */
-          $operators = array(     ""    => "-",
-                                  "lt"  => _("less than"),
-                                  "le"  => _("less or equal"),
-                                  "eq"  => _("equals"),
-                                  "ge"  => _("greater or equal"),
-                                  "gt"  => _("greater than"),
-                                  "ne"  => _("not equal"));
+          $address_parts = $this->address_parts;
+          $comparators   = $this->comparators;
+          $match_types   = $this->match_types; 
+          $operators     = $this->operators;
 
           $smarty = get_smarty();
+          $smarty->assign("Inverse",$Inverse);
           $smarty->assign("comparators",$comparators);
+          $smarty->assign("Expert", $data['Expert']);
           $smarty->assign("match_types",$match_types);
           $smarty->assign("operators",$operators);
 
@@ -449,32 +752,13 @@ class sieve_if
 
         case "address" : 
         {
-          /* address [address-part: tag] [comparator: tag] [match-type: tag] <header-list: string-list> <key-list: string-list> */
-          $address_parts = array( ":all"       => _("Complete adress"), 
-                                  ":domain"    => _("Domian part") , 
-                                  ":localpart" => _("Local part"));
-
-          /* comparator type */
-          $comparators   = array( "i;octet"         => _("Normal"),
-                                  "i;ascii-casemap" =>_("Case sensitive"),
-                                  "i;ascii-numeric" =>_("Numeric"));
-
-          /* Match types */
-          $match_types  = array(  ":is"         => _("is"),
-                                  ":contains"   => _("contains"),
-                                  ":matches"    => _("matches"),
-                                  ":count"      => _("count"),
-                                  ":value"      => _("value is"));
-  
-          /* Operators */
-          $operators = array(     "lt"  => _("less than"),
-                                  "le"  => _("less or equal"),
-                                  "eq"  => _("equals"),
-                                  "ge"  => _("greater or equal"),
-                                  "gt"  => _("greater than"),
-                                  "ne"  => _("not equal"));
+          $address_parts = $this->address_parts;
+          $comparators   = $this->comparators;
+          $match_types   = $this->match_types; 
+          $operators     = $this->operators;
 
           $smarty = get_smarty();
+          $smarty->assign("Inverse",$Inverse);
           $smarty->assign("address_parts",$address_parts);
           $smarty->assign("comparators",$comparators);
           $smarty->assign("match_types",$match_types);
@@ -489,13 +773,13 @@ class sieve_if
         
           $keys = "";
           foreach($data['Key_List'] as $key){
-            $keys .= stripslashes($key).", ";
+            $keys .= $key.", ";
           }
           $keys = preg_replace("/,$/","",trim($keys));
    
           $values = "";
           foreach($data['Value_List'] as $key){
-            $values .= stripslashes($key).", ";
+            $values .= $key.", ";
           }
           $values = preg_replace("/,$/","",trim($values));
           $smarty->assign("keys",$keys);
@@ -556,7 +840,7 @@ class sieve_if
  
           $Values = "";
           foreach($data['Values'] as $val){
-            $Values .= stripslashes($val).", ";
+            $Values .= $val.", ";
           }
           $Values = preg_replace("/,$/","",trim($Values));
 
index e8d70feba652c8a55fb58bec1511e53c679e6c15..768a4dfc67646dff31bc64f75c6d4197a3b5a798 100644 (file)
@@ -10,7 +10,11 @@ class sieve_elsif extends sieve_if
 class sieve_comment 
 {
   var $data = "";
+
+  function get_sieve_script_part()
+  {
+    return($this->data."\n");
+  } 
     
   function sieve_comment($data)
   {
@@ -43,6 +47,12 @@ class sieve_require
     }
   }
 
+  function get_sieve_script_part()
+  {
+    $tmp = sieve_create_strings($this->data);
+    return("require ".$tmp.";\n");
+  } 
+    
   function execute()
   {
     $str = "<table cellspacing=0 width='100%'><tr><td style='width:100%;background-color:#DDDDFF;'>"._("Script includes");
@@ -62,6 +72,11 @@ class sieve_discard
   {
   }
 
+  function get_sieve_script_part()
+  {
+    return("discard;\n");
+  } 
+    
   function execute()
   {
     $str = "<table cellspacing=0 width='100%'><tr><td style='width:100%;background-color:red;'>"._("Discard message");
@@ -87,6 +102,11 @@ class sieve_reject
     $this->data = preg_replace("/\"/","",$str);
   }
 
+  function get_sieve_script_part()
+  {
+    return("reject ".sieve_create_strings($this->data)."\n");
+  } 
+    
   function execute()
   {
     $str = "<table cellspacing=0 width='100%'><tr><td style='width:100%;background-color:gray;'>"._("Reject mail");
@@ -109,6 +129,17 @@ class sieve_redirect
     }
   }
 
+  function get_sieve_script_part()
+  {
+    $tmp = "";
+    foreach($this->data as $dat){
+      $tmp.= "\"".$dat."\", ";
+    }
+    $tmp = "[".preg_replace("/,$/","",trim($tmp))."]";
+    $tmp = preg_replace ("/\"\"/","\"",$tmp);
+    return("redirect ".$tmp."\n");
+  } 
+    
   function execute()
   {
     $str = "<table cellspacing=0 width='100%'><tr><td style='width:100%;background-color:brown;'>"._("Redirect to");
@@ -133,6 +164,17 @@ class sieve_fileinto
     }
   }
 
+  function get_sieve_script_part()
+  {
+    $tmp = "";
+    foreach($this->data as $dat){
+      $tmp.= "\"".$dat."\", ";
+    }
+    $tmp = "[".preg_replace("/,$/","",trim($tmp))."]";
+    $tmp = preg_replace ("/\"\"/","\"",$tmp);
+    return("fileinto ".$tmp."\n");
+  } 
+    
   function execute()
   {
     $str = "<table cellspacing=0 width='100%'><tr><td style='width:100%;background-color:green;'>"._("File into");
@@ -205,6 +247,23 @@ class sieve_vacation
     }
   }
 
+  function get_sieve_script_part()
+  {
+    $str = "vacation ";
+    if($this->days){
+      $str.= ":days ".$this->days;
+    }
+    $str .= ":addresses ".sieve_create_strings($this->addresses);
+    if($this->subject){
+      $str.= ":subject ".sieve_create_strings($this->subject);
+    }
+    if($this->mime){
+      $str.= ":mime ".sieve_create_strings($this->mime);
+    }
+    $str .= " ".sieve_create_strings($this->reason);
+    return($str."\n");
+  } 
+    
 
   function execute()
   {
@@ -230,6 +289,11 @@ class sieve_block_start
                 </td>
                 <td style='background-color:#BBBBBB;border: solid 2px #FFFFFF;'>");
   }
+  function get_sieve_script_part()
+  {
+    return("{\n");
+  } 
+    
 }
 
 class sieve_block_end 
@@ -240,6 +304,11 @@ class sieve_block_end
               </tr>
             </table>");
   }
+  function get_sieve_script_part()
+  {
+    return("}\n");
+  } 
+    
 }
 
 /* This class handles the keep statement */
@@ -256,6 +325,11 @@ class sieve_keep
             </table>";
     return($str);
   }
+  function get_sieve_script_part()
+  {
+    return("keep;\n");
+  } 
+    
 }
 
 /* This class handles the stop statement */
@@ -272,6 +346,12 @@ class sieve_stop
             </table>";
     return($str);
   }
+
+  function get_sieve_script_part()
+  {
+    return("stop; \n");
+  } 
+    
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 59d9436e3c803b6cc4804defbd36072fa4b20a12..eae9426885851dc30d6921d76c72b064cc736655 100644 (file)
@@ -32,6 +32,7 @@ class sieveManagement extends plugin
   var $parent = NULL;
   var $scripts= array();  
 
+  var $current_script  = -1;
   var $current_handler = NULL;
  
   /* Initialize the class and load all sieve scripts 
@@ -101,16 +102,31 @@ class sieveManagement extends plugin
         $script = preg_replace("/_(x|y)/","",$script);
         $once = FALSE;
 
+        $this->current_script = $script;
         $this->current_handler = $this->scripts[$script]['PARSER'];
       }
     }
 
-    if(isset($_GET['xx'])){
+    /* Abort saving */
+    if(isset($_POST['cancel_sieve_changes'])){
+      $this->current_handler = NULL;
+    }
+
+    /* Save currently edited sieve script. */
+    if(isset($_POST['save_sieve_changes'])){
+      $this->scripts[$this->current_script]['PARSER'] = $this->current_handler;
       $this->current_handler = NULL; 
     }
 
+    /* Create output for currently opened sieve script */
     if($this->current_handler){
-        return($this->current_handler->execute());
+      $ret = $this->current_handler->execute();
+      $ret .= "<div class='seperator' style='text-align:right; width:100%;'>
+        <input type='submit' name='save_sieve_changes' value='"._("Save")."'>
+        &nbsp;
+      <input type='submit' name='cancel_sieve_changes' value='"._("Cancel")."'>
+        </div>";
+      return($ret);
     }
 
     /* Create list of available sieve scripts 
@@ -127,8 +143,17 @@ class sieveManagement extends plugin
       $field4 = array("string" => "<input type='image' name='editscript_".$key."' src='images/edit.png'>");
       $List ->AddEntry(array($field1,$field2,$field3,$field4)); 
     }
-
-    return($List->DrawList());
+  
+    $display ="<h2>Sieve script management</h2>";
+    $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
+    $display .=  $List->DrawList();
+    
+    $display .= "<p style=\"text-align:right\">\n";
+    $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
+    $display .= "&nbsp;\n";
+    $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
+    $display .= "</p>";
+    return($display);;
   }
 
   function save_object()
@@ -137,7 +162,17 @@ class sieveManagement extends plugin
       $this->current_handler->save_object();
     }
   }
-}
 
+
+  function save()
+  {
+    $ret = "<textarea style='width:100%;height:400px;'>";
+    foreach($this->scripts as $script){
+      $ret .= ($script['PARSER']->get_sieve_script());
+    }
+    $ret .= "</textarea>";
+    echo $ret;
+  }
+}
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 6d1644088d1568ae11741d580830acef23fccd49..80e4384abdc86d43a8ec74c2c831424345146365 100755 (executable)
@@ -1,11 +1,5 @@
 
-<table>
-       <tr>
-               <td colspan=3>
-                       <b>{t}Address{/t}</b>
-                       <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Toggle expert mode{/t}'>
-               </td>
-       </tr>
+<table cellspacing=0 cellpadding=2 style='background-color:#EEEEDD;width:100%; border: solid 1px #CCCCCC'>
        {if $Expert}
        <tr>
                <td>
                        </select>
 
                </td>
+               <td>
+                       {t}Invert test{/t}?
+               </td>
+               <td>
+                       {if $Inverse}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}Yes{/t}'>
+                       {else}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}No{/t}'>
+                       {/if}
+               </td>
+               <td style='text-align:right; vertical-align:top;'>
+                       <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Normal mode{/t}'>
+               </td>
        </tr>
        <tr>
                <td>
                                {html_options options=$operators selected=$operator}
                        </select>
                </td>
+               {else}
+               <td style='text-align:right;'>
+                       &nbsp;
+               </td>
                {/if}
+               <td style='text-align:right;'>
+                       &nbsp;
+               </td>
        </tr>
        <tr>
                <td>
                        {t}Address fields to include{/t}
                </td>
                <td>
-                       <textarea name='keys_{$ID}'>{$keys}</textarea>
+                       <textarea style='width:95%;height:50px;' name='keys_{$ID}'>{$keys}</textarea>
                </td>
                <td>
                        {t}Values to match for{/t}
                </td>
                <td>
-                       <textarea name='values_{$ID}'>{$values}</textarea>
+                       <textarea style='width:95%;height:50px;' name='values_{$ID}'>{$values}</textarea>
                </td>
        </tr>
        {else}
                <td style='vertical-align:top;'>
                        {t}If{/t}
                        &nbsp;
+                       <b>{t}Address{/t}</b>
+               
+                       {if $Inverse}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}Not{/t}'>
+                       {else}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}-{/t}'>
+                       {/if}
+                       &nbsp;
                        <select onChange='document.mainform.submit();' name='matchtype_{$ID}' title='{t}Boolean value{/t}'> 
                                {html_options options=$match_types selected=$match_type}
                        </select>
                        {/if}
                </td>
                <td>
-                       <textarea style='height:30px;' name='keys_{$ID}'>{$keys}</textarea>
-                       <textarea style='height:30px;' name='values_{$ID}'>{$values}</textarea>
+                       <textarea style='width:45%;height:20px;' name='keys_{$ID}'>{$keys}</textarea>
+                       <textarea style='width:45%;height:20px;' name='values_{$ID}'>{$values}</textarea>
+               </td>
+               <td style='text-align:right; vertical-align:top;'>
+                       <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Expert mode{/t}'>
                </td>
        </tr>
        {/if}
index e1aace841b42d0b7eb9e44535ec79284dc484f06..c99cfdd3c8cac0f293205cb8d68f21de6d01845e 100755 (executable)
@@ -1,8 +1,28 @@
 
-<table>
+<table cellspacing=0 cellpadding=2 style='background-color:#EEEEDD;width:100%; border: solid 1px #CCCCCC'>
+       {if $Expert}
        <tr>
-               <td colspan=3>
-                       <b>{t}Envelope{/t}</b>
+               <td>
+                       {t}Match type{/t}
+               </td>
+               <td>
+                       <select name='matchtype_{$ID}' title='{t}Boolean value{/t}' onChange='document.mainform.submit();'> 
+                               {html_options options=$match_types selected=$match_type}
+                       </select>
+
+               </td>
+               <td>
+                       {t}Invert test{/t}?
+               </td>
+               <td>
+                       {if $Inverse}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}Yes{/t}'>
+                       {else}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}No{/t}'>
+                       {/if}
+               </td>
+               <td style='text-align:right; vertical-align:top;'>
+                       <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Normal mode{/t}'>
                </td>
        </tr>
        <tr>
                                {html_options options=$comparators selected=$comparator}
                        </select>
                </td>
-               <td>
-                       {t}Match type{/t}
-               </td>
-               <td>
-                       <select name='matchtype_{$ID}' title='{t}Boolean value{/t}'> 
-                               {html_options options=$match_types selected=$match_type}
-                       </select>
-
-               </td>
+               {if $match_type == ":count" || $match_type == ":value"}
                <td>
                        {t}operator{/t}
                </td>
                <td>
-                       <select name='operator_{$ID}' title='{t}Boolean value{/t}'>
+                       <select name='operator_{$ID}' title='{t}Boolean value{/t}' onChange='document.mainform.submit();'>
                                {html_options options=$operators selected=$operator}
                        </select>
                </td>
+               {else}
+               <td style='text-align:right;'>
+                       &nbsp;
+               </td>
+               {/if}
+               <td style='text-align:right;'>
+                       &nbsp;
+               </td>
        </tr>
        <tr>
                <td>
-                       {t}Address fields{/t}
+                       {t}Address fields to include{/t}
                </td>
                <td>
-                       <textarea name='keys_{$ID}'>{$keys}</textarea>
+                       <textarea style='width:95%;height:50px;' name='keys_{$ID}'>{$keys}</textarea>
                </td>
                <td>
-                       {t}Match values{/t}
+                       {t}Values to match for{/t}
                </td>
                <td>
-                       <textarea name='values_{$ID}'>{$values}</textarea>
+                       <textarea style='width:95%;height:50px;' name='values_{$ID}'>{$values}</textarea>
+               </td>
+       </tr>
+       {else}
+       <tr>
+               <td style='vertical-align:top;'>
+                       {t}If{/t}
+                       &nbsp;
+                       <b>{t}Envelope{/t}</b>
+               
+                       {if $Inverse}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}Not{/t}'>
+                       {else}
+                               <input type='submit' name='toggle_inverse_{$ID}' value='{t}-{/t}'>
+                       {/if}
+                       &nbsp;
+                       <select onChange='document.mainform.submit();' name='matchtype_{$ID}' title='{t}Boolean value{/t}'> 
+                               {html_options options=$match_types selected=$match_type}
+                       </select>
+
+                       {if $match_type == ":count" || $match_type == ":value"}
+                       <select name='operator_{$ID}' title='{t}Boolean value{/t}' onChange='document.mainform.submit();'>
+                               {html_options options=$operators selected=$operator}
+                       </select>
+                       {/if}
+               </td>
+               <td>
+                       <textarea style='width:45%;height:20px;' name='keys_{$ID}'>{$keys}</textarea>
+                       <textarea style='width:45%;height:20px;' name='values_{$ID}'>{$values}</textarea>
+               </td>
+               <td style='text-align:right; vertical-align:top;'>
+                       <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Expert mode{/t}'>
                </td>
        </tr>
+       {/if}
 </table>
index e32d8f678abb2504204c5774f402d593d4937e4a..c88466f1aed4918ff3e70fb9eb2f83106ec8288c 100755 (executable)
 
 <table>
-       <tr>
-               <td colspan=3>
-                       <b>{t}Header{/t}</b>
-               </td>
-       </tr>
-       <tr>
-               <td>
-                       {t}Comparator{/t}
-               </td>
-               <td>
-                       <select name='comparator_{$ID}' title='{t}Boolean value{/t}'> 
-                               {html_options options=$comparators selected=$comparator}
-                       </select>
-               </td>
-               <td>
-                       {t}Match type{/t}
-               </td>
-               <td>
-                       <select name='matchtype_{$ID}' title='{t}Boolean value{/t}'> 
-                               {html_options options=$match_types selected=$match_type}
-                       </select>
+       {if $Expert}
 
-               </td>
-               <td>
-                       {t}operator{/t}
-               </td>
-               <td>
-                       <select name='operator_{$ID}' title='{t}Boolean value{/t}'>
-                               {html_options options=$operators selected=$operator}
-                       </select>
-               </td>
-       </tr>
-       <tr>
-               <td>
-                       {t}Address fields{/t}
-               </td>
-               <td>
-                       <textarea name='keys_{$ID}'>{$keys}</textarea>
-               </td>
-               <td>
-                       {t}Match values{/t}
-               </td>
-               <td>
-                       <textarea name='values_{$ID}'>{$values}</textarea>
-               </td>
-       </tr>
+        <tr>
+        <td>
+            {t}Match type{/t}
+        </td>
+        <td>
+            <select name='matchtype_{$ID}' title='{t}Boolean value{/t}' onChange='document.mainform.submit();'>
+                {html_options options=$match_types selected=$match_type}
+            </select>
+
+        </td>
+        <td>
+            {t}Invert test{/t}?
+        </td>
+        <td>
+            {if $Inverse}
+                <input type='submit' name='toggle_inverse_{$ID}' value='{t}Yes{/t}'>
+            {else}
+                <input type='submit' name='toggle_inverse_{$ID}' value='{t}No{/t}'>
+            {/if}
+        </td>
+        <td style='text-align:right; vertical-align:top;'>
+            <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Normal mode{/t}'>
+        </td>
+    </tr>
+    <tr>
+        <td>
+            <select name='address_part_{$ID}' title='{t}Boolean value{/t}'>
+                {html_options options=$address_parts selected=$address_part}
+            </select>
+        </td>
+        <td>
+            {t}Comparator{/t}
+        </td>
+        <td>
+            <select name='comparator_{$ID}' title='{t}Boolean value{/t}'>
+                {html_options options=$comparators selected=$comparator}
+            </select>
+        </td>
+        {if $match_type == ":count" || $match_type == ":value"}
+        <td>
+            {t}operator{/t}
+        </td>
+        <td>
+            <select name='operator_{$ID}' title='{t}Boolean value{/t}' onChange='document.mainform.submit();'>
+                {html_options options=$operators selected=$operator}
+            </select>
+        </td>
+        {else}
+        <td style='text-align:right;'>
+            &nbsp;
+        </td>
+        {/if}
+        <td style='text-align:right;'>
+            &nbsp;
+        </td>
+    </tr>
+    <tr>
+        <td>
+            {t}Address fields to include{/t}
+        </td>
+        <td>
+            <textarea style='width:95%;height:50px;' name='keys_{$ID}'>{$keys}</textarea>
+        </td>
+        <td>
+            {t}Values to match for{/t}
+        </td>
+        <td>
+            <textarea style='width:95%;height:50px;' name='values_{$ID}'>{$values}</textarea>
+        </td>
+    </tr>
+
+       {else}
+                <tr>
+        <td style='vertical-align:top;'>
+            {t}If{/t}
+            &nbsp;
+            <b>{t}Envelope{/t}</b>
+
+            {if $Inverse}
+                <input type='submit' name='toggle_inverse_{$ID}' value='{t}Not{/t}'>
+            {else}
+                <input type='submit' name='toggle_inverse_{$ID}' value='{t}-{/t}'>
+            {/if}
+            &nbsp;
+            <select onChange='document.mainform.submit();' name='matchtype_{$ID}' title='{t}Boolean value{/t}'>
+                {html_options options=$match_types selected=$match_type}
+            </select>
+
+            {if $match_type == ":count" || $match_type == ":value"}
+            <select name='operator_{$ID}' title='{t}Boolean value{/t}' onChange='document.mainform.submit();'>
+                {html_options options=$operators selected=$operator}
+            </select>
+            {/if}
+        </td>
+        <td>
+            <textarea style='width:45%;height:20px;' name='keys_{$ID}'>{$keys}</textarea>
+            <textarea style='width:45%;height:20px;' name='values_{$ID}'>{$values}</textarea>
+        </td>
+        <td style='text-align:right; vertical-align:top;'>
+            <input type='submit' name='Toggle_Expert_{$ID}' value='{t}Expert mode{/t}'>
+        </td>
+    </tr>
+
+       {/if}
 </table>
index a09a9ae4cd011a2b64a9b15464e4385975bb6a64..b755e260b60e2fc5067bd056eeb37044c2308037 100644 (file)
@@ -243,7 +243,18 @@ class mailAccount extends plugin
     if(isset($_POST['sieveManagement'])) {
       $this->dialog = new sieveManagement($this->config,$this->dn,$this);
     }
-    
+   
+    /* Cancel sieve edit */
+    if(isset($_POST['sieve_cancel'])){
+      $this->dialog = NULL;
+    }
+    /* Save sieve changes */
+    if(isset($_POST['sieve_finish'])){
+      $this->dialog->save();
+      $this->dialog = NULL;
+    }
     if(is_object($this->dialog)){
       $this->dialog->save_object();
       return($this->dialog->execute());