Code

some sieve filter updates
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 5 Mar 2007 11:47:08 +0000 (11:47 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 5 Mar 2007 11:47:08 +0000 (11:47 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5746 594d385d-05f5-0310-b6e9-bd551577e9d8

include/sieve/class_My_Parser.inc
include/sieve/class_My_Tree.inc
include/sieve/class_sieveElement.inc [deleted file]
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_boolean.tpl
include/sieve/templates/element_envelope.tpl [new file with mode: 0755]
include/sieve/templates/element_header.tpl [new file with mode: 0755]

index b59cfecd4b1a3fd0d6b5688be0e9232e84ed72d6..6d796cd8ae23d84fe9a22f31a53574ca8d0bbad4 100644 (file)
@@ -8,6 +8,12 @@
 class My_Parser extends Parser 
 {
 
+       function execute()
+       {
+               return($this->dumpParseTree());
+       }
+       
+
        /* Initiate parser, but use some other 
      *  classes, that are rewritten.
      */
@@ -29,6 +35,12 @@ class My_Parser extends Parser
         return $this->status_;
        }
 
+               
+       function save_object()
+       {
+               $this->tree_->save_object();
+       }
+
 
        /* Should be obsolete in the end. */
        function dumpToken_(&$token)
index e76290c8baa84b94637279a5101e61a580a9ad5b..942f64e4c03fb970a2fb94195e09dc87775a5adf 100644 (file)
@@ -21,12 +21,17 @@ class My_Tree extends Tree
    */
   function dump()
   {
-    error_reporting(E_ALL);    
-    $this->dump_ = "";
-    $this->mode_stack = array();
-    $this->pap = array();
-    $this->doDump_(0, '', true);
+    error_reporting(E_ALL);
+
+    /* Only parse the tokens once */
+    if(!count($this->pap)){
+      $this->dump_ = "";
+      $this->mode_stack = array();
+      $this->pap = array();
+      $this->doDump_(0, '', true);
+    }
 
+    /* Create html results */
     $this->dump_ ="<table width='100%'><tr><td style='background-color:#BBBBBB;border: 0px;padding-left:20px;'>";
     foreach($this->pap as $object){
       if(is_object($object)){
@@ -128,6 +133,16 @@ class My_Tree extends Tree
       echo "<font color='red'>Missing : ".$class_name."</font>"."<br>";
     }
   }
+
+  function save_object()
+  {
+    foreach($this->pap as $key => $obj){
+
+      if(in_array(get_class($obj),array("sieve_if"))){
+        $this->pap[$key]->save_object();
+      }
+    }
+  }
 }
 
 
diff --git a/include/sieve/class_sieveElement.inc b/include/sieve/class_sieveElement.inc
deleted file mode 100644 (file)
index 596bd6d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-class sieveElement 
-{
-       
-       var $name                       = "Unknown";
-       var $responsible_for= array();  
-
-  var $data ="";
-
-       function sieveElement()
-       {
-       
-       }
-
-  function resolve_to_object($data)
-  {
-    $this->data = @$data->dumpParseTree();
-  }
-
-  function execute()
-  {
-    return($this->data);
-  }
-}      
-
-
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
index 20a10b41a72436a6fb74768df5b78eb10a4b91e3..f9e099d2db94a2e181e9497cb21b4c25390ea1d3 100644 (file)
@@ -7,6 +7,7 @@ class sieve_if
   var $TYPE    = "if";
   var $id     = -1;
 
+
   function sieve_if($elements,$object_id)
   {
     $this->id = $object_id;
@@ -14,12 +15,82 @@ class sieve_if
     $this->_parsed = $this->_parse($elements['ELEMENTS'],1);
   }
 
+  
+  function save_object()
+  {
+    $tmp = $this->save_object_recursive($parsed = NULL,$id = 1,$obj_id=1);
+    $this->_parsed = $tmp;
+  }
+
+  function save_object_recursive($parsed = NULL,$id = 1,$obj_id=1)
+  {
+
+    $ret ="";
+    if($parsed == NULL){
+      $parsed = $this->_parsed;
+    }
+
+    /* Walk through all elements */
+    foreach($parsed as $key => $data){
+
+      /* Id used to have unique html names */
+      $element_id = $this->id."_".$id."_".$obj_id;
+
+      /* Create elements */
+      switch($key)
+      {
+  
+        /*******************
+         * TRUE FALSE 
+         *******************/
+
+        case "true" :
+        case "false" : 
+        {
+          $name = 'boolean_'.$element_id;
+          if(isset($_POST[$name])){
+            $key2 = $_POST[$name];
+            
+            if($key != $key2) {
+              $parsed = array($key2 => $key2); 
+            }
+          }
+          break;
+        }
+     
+        case "allof" : 
+        {
+          foreach($data as $key2 => $dat){
+            if(($key2 === "Inverse") && ($key2 == "Inverse")){
+              continue;
+            }
+            $parsed[$key][$key2] = $this->save_object_recursive($dat, ($id +1),$key2);
+          }
+          break ;
+        } 
+
+
+        case "anyof" : 
+        {
+          foreach($data as $key2 => $dat){
+            if(($key2 === "Inverse") && ($key2 == "Inverse")){
+              continue;
+            }
+            $parsed[$key][$key2] =  $this->save_object_recursive($dat, ($id + 1),$key2);
+          }
+          break ;
+        } 
+      }
+    }
+    return($parsed);
+  }  
+
 
   /* Return html element for IF */ 
   function execute()
   {
     /* Create title */
-    $name  = "<img src='images/small_filter.png' class='center'>";
+    $name  = "<img alt='' src='images/small_filter.png' class='center'>";
     $name .= "<b>"._("Condition")."</b>";
     if($this->TYPE == "if"){
       $name .= "&nbsp;-&nbsp;"._("If");
@@ -43,8 +114,6 @@ class sieve_if
   /* Returns all elements as html */
   function get_as_html($parsed = NULL,$id = 1,$obj_id=1)
   {
-    $header_parts = array(":all",":localpart",":domain",":user",":detail");
-
     $ret ="";
     if($parsed == NULL){
       $parsed = $this->_parsed;
@@ -54,7 +123,7 @@ class sieve_if
     foreach($parsed as $key => $data){
 
       /* Create Inverse Tag */
-      if(isset($data['Inverse']) && $data['Inverse']){
+      if(is_array($data) && isset($data['Inverse']) && $data['Inverse']){
         $str_inverse = "<font color='red'><b>"._("Not")."</b></font>&nbsp;";
         $Inverse = TRUE;
       }else{
@@ -96,29 +165,157 @@ class sieve_if
 
 
         /*******************
-         * Header  
+         * Header 
          *******************/
 
-        case "address" 
+        case "header"
         {
-          $ret ="";    
+          /* 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"));
 
-          print_a($data);
+          $smarty = get_smarty();
+          $smarty->assign("comparators",$comparators);
+          $smarty->assign("match_types",$match_types);
+          $smarty->assign("operators",$operators);
 
-          $comparators = array("i;octet" => _("Normal"),"i;ascii-casemap"=>_("Case sensitive"),"i;ascii-numeric"=>_("Numeric"));
-          $av_match_type= array(":is",":contains",":matches",":over",":count",":value",":under");
-          $mtv = array("lt","le","eq","ge","gt","ne");
+          $smarty->assign("match_type", $data['Match_type']);
+          $smarty->assign("operator"  , preg_replace("/\"/","",$data['Match_type_value']));
+          $smarty->assign("comparator", $data['Comparator']);
+        
+
+          $keys = "";
+          foreach($data['Key_List'] as $key){
+            $keys .= $key."\n";
+          }
+   
+          $values = "";
+          foreach($data['Value_List'] as $key){
+            $values .= $key."\n";
+          }
+          $smarty->assign("keys",$keys);
+          $smarty->assign("values",$values);
+
+          $smarty->assign("ID"  , $element_id); 
+          $ret .= $smarty->fetch(get_template_path("templates/element_header.tpl",TRUE,dirname(__FILE__)));
+          break;
+        }
+
+        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"));
 
           $smarty = get_smarty();
-          $smarty->assign("c_values"    , $comparators);
-          $smarty->assign("c_selected"  , $data['Comparator']);
+          $smarty->assign("comparators",$comparators);
+          $smarty->assign("match_types",$match_types);
+          $smarty->assign("operators",$operators);
 
-          $smarty->assign("match_types",$av_match_type);
-          $smarty->assign("match_type",$data['Match_type']);
+          $smarty->assign("match_type", $data['Match_type']);
+          $smarty->assign("operator"  , preg_replace("/\"/","",$data['Match_type_value']));
+          $smarty->assign("comparator", $data['Comparator']);
+        
+
+          $keys = "";
+          foreach($data['Key_List'] as $key){
+            $keys .= $key."\n";
+          }
+   
+          $values = "";
+          foreach($data['Value_List'] as $key){
+            $values .= $key."\n";
+          }
+          $smarty->assign("keys",$keys);
+          $smarty->assign("values",$values);
 
-          $smarty->assign("match_type_value",$data['Match_type_value']);
-          $smarty->assign("match_type_values",$mtv);
  
+          $smarty->assign("ID"  , $element_id); 
+          $ret .= $smarty->fetch(get_template_path("templates/element_envelope.tpl",TRUE,dirname(__FILE__)));
+          break;
+        }
+
+        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"),
+                                  ":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"));
+
+          $smarty = get_smarty();
+          $smarty->assign("address_parts",$address_parts);
+          $smarty->assign("comparators",$comparators);
+          $smarty->assign("match_types",$match_types);
+          $smarty->assign("operators",$operators);
+
+          $smarty->assign("match_type", $data['Match_type']);
+          $smarty->assign("operator"  , preg_replace("/\"/","",$data['Match_type_value']));
+          $smarty->assign("comparator", $data['Comparator']);
+          $smarty->assign("address_part", $data['Address_Part']);
+        
+
           $keys = "";
           foreach($data['Key_List'] as $key){
             $keys .= $key."\n";
@@ -149,11 +346,12 @@ class sieve_if
                       <td style='text-align:center; vertical-align: middle; width:45px; 
                                  background-color: #BDBDBD; border: solid 1px #EEEEEE'>".
                         "<b>".$str_inverse._("All of")."</b>".
-                        "<img class='center' src='images/select_ogroup.png'>".
+                        "<img alt='' class='center' src='images/select_ogroup.png'>".
                      "</td>";
           $ret.= "    <td style='background-color:#BDBDBD ; border: solid 1px #EEEEEE'>";
+
           foreach($data as $key => $dat){
-            if($key == "Inverse" ){
+            if(($key === "Inverse") && ($key == "Inverse")){
               continue;
             }
             $ret.=        $this->get_as_html($dat, ($id +1),$key);
@@ -176,11 +374,11 @@ class sieve_if
                       <td style='text-align:center; vertical-align: middle; width:45px; 
                                  background-color: #AAAAAA; border: solid 1px #EEEEEE'>".
                         "<b>".$str_inverse._("Any of")."</b>".
-                        "<img class='center' src='images/select_department.png'>".
+                        "<img alt='' class='center' src='images/select_department.png'>".
                      "</td>";
           $ret.= "    <td style='background-color: #AAAAAA ; border: solid 1px #EEEEEE'>";
           foreach($data as $key => $dat){
-            if($key == "Inverse" ){
+            if(($key === "Inverse") && ($key == "Inverse")){
               continue;
             }
             $ret.=        $this->get_as_html($dat, ($id + 1),$key);
@@ -270,16 +468,14 @@ class sieve_if
             $Match_type = $node['text'];
 
             /* Get value operator */
-            if($Match_type == ":value"){
-              $i ++;        
-              $node = $data[$i];
-              
-              if($node['class'] == "quoted-string" && preg_match("/".$value_op."/",$node['text'])){
-                $Match_type_value = $node['text'];
-              }
+            $i ++;        
+            $node = $data[$i];
+
+            if($node['class'] == "quoted-string" && preg_match("/".$value_op."/",$node['text'])){
+              $Match_type_value = $node['text'];
             }
           } 
-  
+
           /* Check for a comparator */
           elseif($node['class'] == "tag" && preg_match("/comparator/",$node['text'])){
             $i ++;
index 37031994e2b24c3e3417150dae538f6314db0677..e8d70feba652c8a55fb58bec1511e53c679e6c15 100644 (file)
@@ -226,7 +226,7 @@ class sieve_block_start
     return("<table cellspacing=0 width='100%'>
               <tr>
                 <td style='width:20px;'>
-                  <img src='images/forward.png' class='center'>
+                  <img alt='' src='images/forward.png' class='center'>
                 </td>
                 <td style='background-color:#BBBBBB;border: solid 2px #FFFFFF;'>");
   }
index 44ea8c8cf81545774bcbb62428f452605aa46871..59d9436e3c803b6cc4804defbd36072fa4b20a12 100644 (file)
@@ -32,6 +32,7 @@ class sieveManagement extends plugin
   var $parent = NULL;
   var $scripts= array();  
 
+  var $current_handler = NULL;
  
   /* Initialize the class and load all sieve scripts 
    *  try to parse them and display errors 
@@ -95,18 +96,22 @@ class sieveManagement extends plugin
   {
     $once = TRUE;
     foreach($_POST as $name => $value){
-      if(preg_match("/^editscript_/",$name) && $once){
+      if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){
         $script = preg_replace("/^editscript_/","",$name);
         $script = preg_replace("/_(x|y)/","",$script);
         $once = FALSE;
 
-        $obj_handler = new sieveElement;
-        $data = $this->scripts[$script]['PARSER'];
-        $obj_handler->resolve_to_object($data);
-        return($obj_handler->execute());
+        $this->current_handler = $this->scripts[$script]['PARSER'];
       }
     }
 
+    if(isset($_GET['xx'])){
+      $this->current_handler = NULL; 
+    }
+
+    if($this->current_handler){
+        return($this->current_handler->execute());
+    }
 
     /* Create list of available sieve scripts 
      */
@@ -128,7 +133,9 @@ class sieveManagement extends plugin
 
   function save_object()
   {
-    
+    if($this->current_handler){
+      $this->current_handler->save_object();
+    }
   }
 }
 
index ecd879fd910f5427a213d224ee1c674ab4b9381c..6f7eda0517c18847e603703b04f90ce0eb635019 100755 (executable)
@@ -1,29 +1,57 @@
-<b>{t}Address{/t}</b>
-<br>
-
-{t}Comparator{/t}
-<select name='comparator_{$ID}' title='{t}Boolean value{/t}'> 
-       {html_options options=$c_values selected=$c_selected}
-</select>
-<br>
-
-{t}Match type{/t}
-<select name='matchtype_{$ID}' title='{t}Boolean value{/t}'> 
-       {html_options values=$match_types output=$match_types selected=$match_type}
-</select>
-<br>
-
-{if $match_type == ":value"}
-       {t}Match type operator{/t}
-       <select name='matchtypeoperator_{$ID}' title='{t}Boolean value{/t}'>
-               {html_options values=$match_type_values output=$match_type_values selected=$match_type_value}
-       </select>
-<br>
-
-       <textarea name='keys_{$ID}'>{$keys}</textarea>
-<br>
-       <textarea name='values_{$ID}'>{$values}</textarea>
-       
-{/if}
 
+<table>
+       <tr>
+               <td colspan=3>
+                       <b>{t}Address{/t}</b>
+               </td>
+       </tr>
+       <tr>
+               <td>
+                       {t}Address part{/t}
+               </td>
+               <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>
+               <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>
+               <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>
+</table>
index f1da4a378658ed922c023b1574a41da9869289b3..61578ddb714f1a015a15be1dee3f00f4fa15bded 100755 (executable)
@@ -2,4 +2,5 @@
 <select name='boolean_{$ID}' title='{t}Boolean value{/t}'> 
        {html_options options=$values selected=$selected}
 </select>
+<input type='submit' value='{t}update{/t}'>
 <br>
diff --git a/include/sieve/templates/element_envelope.tpl b/include/sieve/templates/element_envelope.tpl
new file mode 100755 (executable)
index 0000000..e1aace8
--- /dev/null
@@ -0,0 +1,49 @@
+
+<table>
+       <tr>
+               <td colspan=3>
+                       <b>{t}Envelope{/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>
+
+               </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>
+</table>
diff --git a/include/sieve/templates/element_header.tpl b/include/sieve/templates/element_header.tpl
new file mode 100755 (executable)
index 0000000..e32d8f6
--- /dev/null
@@ -0,0 +1,49 @@
+
+<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>
+
+               </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>
+</table>