From 0fab110790df62ad7fe3b9b7aa9f65e005beaf13 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 5 Mar 2007 05:59:06 +0000 Subject: [PATCH] Some changes for the sieve filter git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5744 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_My_Parser.inc | 11 +++ include/sieve/class_My_Tree.inc | 36 +++++++-- include/sieve/class_sieveElement_If.inc | 85 +++++++++++++-------- include/sieve/class_sieveManagement.inc | 24 ++++-- include/sieve/templates/element_address.tpl | 29 +++++++ include/sieve/templates/element_boolean.tpl | 5 ++ 6 files changed, 143 insertions(+), 47 deletions(-) create mode 100755 include/sieve/templates/element_address.tpl create mode 100755 include/sieve/templates/element_boolean.tpl diff --git a/include/sieve/class_My_Parser.inc b/include/sieve/class_My_Parser.inc index f0a3f9d89..b59cfecd4 100644 --- a/include/sieve/class_My_Parser.inc +++ b/include/sieve/class_My_Parser.inc @@ -1,7 +1,16 @@ status_text = "incomplete"; @@ -20,6 +29,8 @@ class My_Parser extends Parser return $this->status_; } + + /* Should be obsolete in the end. */ function dumpToken_(&$token) { if (is_array($token)) diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index 744f974c0..e76290c8b 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -1,5 +1,13 @@ mode_stack); - $this->handle_elements($tmp); - $this->handle_elements(array("TYPE" => "block_start")); + $this->handle_elements($tmp,$node_id); + $this->handle_elements(array("TYPE" => "block_start"),$node_id); } /* This closes the last mode */ if($node['class'] == "block-end"){ $tmp = array_pop($this->mode_stack); - $this->handle_elements($tmp); - $this->handle_elements(array("TYPE" => "block_end")); + $this->handle_elements($tmp,$node_id); + $this->handle_elements(array("TYPE" => "block_end"),$node_id); } /* Semicolon indicates a new command */ if($node['class'] == "semicolon"){ $tmp =array_pop($this->mode_stack); - $this->handle_elements($tmp); + $this->handle_elements($tmp,$node_id); } /* Handle comments */ @@ -82,7 +92,7 @@ class My_Tree extends Tree /* Remove last mode from mode stack, cause it was only valid for a single line */ if($rewoke_last){ $tmp =array_pop($this->mode_stack); - $this->handle_elements($tmp); + $this->handle_elements($tmp,$node_id); } /* If this is a sub element, just call this for all childs */ @@ -101,7 +111,10 @@ class My_Tree extends Tree } - function handle_elements($data) + /* Create a class for each resolved object. + * And append this class to a list of objects. + */ + function handle_elements($data,$id) { if(!isset($data['TYPE'])){ return; @@ -110,7 +123,7 @@ class My_Tree extends Tree $class_name= "sieve_".$type ; if(class_exists($class_name)){ - $this->pap[] = new $class_name($data); + $this->pap[] = new $class_name($data,$id); }else{ echo "Missing : ".$class_name.""."
"; } @@ -118,6 +131,13 @@ class My_Tree extends Tree } +/* 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, + * this function will return a complete list of all + * strings used in this list. + * It also returns an offset of the last token position + */ function sieve_get_strings($data,$id) { $ret = array(); diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc index 18964bef5..20a10b41a 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -5,9 +5,11 @@ class sieve_if { var $_parsed = array(); var $TYPE = "if"; + var $id = -1; - function sieve_if($elements) + function sieve_if($elements,$object_id) { + $this->id = $object_id; $this->elements = $elements; $this->_parsed = $this->_parse($elements['ELEMENTS'],1); } @@ -31,7 +33,6 @@ class sieve_if ". $name; $str .= $this->get_as_html(); - $str .= " "; @@ -40,11 +41,10 @@ class sieve_if /* Returns all elements as html */ - function get_as_html($parsed = NULL) + 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; @@ -62,6 +62,9 @@ class sieve_if $Inverse = FALSE; } + /* Id used to have unique html names */ + $element_id = $this->id."_".$id."_".$obj_id; + /* Create elements */ switch($key) { @@ -73,27 +76,23 @@ class sieve_if case "true" : case "false" : { - /* Set default */ - $type = TRUE; - - /* Use false as default if element is false */ - if($key == "false"){ - $type = FALSE; - } - /* Inverse element if required */ if($Inverse){ - $type = !$type; + if($key == "true"){ + $key = "false"; + }else{ + $key = "true"; + } } - /* Return value */ - if($type){ - $ret = "
"._("Boolean true")."
"; - }else{ - $ret = "
"._("Boolean false")."
"; - } + /* Get template */ + $smarty = get_smarty(); + $smarty->assign("values" , array("false" => _("False"), "true" => _("True"))); + $smarty->assign("selected" , $key); + $smarty->assign("ID" , $element_id); + $ret .= $smarty->fetch(get_template_path("templates/element_boolean.tpl",TRUE,dirname(__FILE__))); + break; } - break; /******************* @@ -103,18 +102,38 @@ class sieve_if case "address" : { $ret =""; + + print_a($data); + + $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 = get_smarty(); + $smarty->assign("c_values" , $comparators); + $smarty->assign("c_selected" , $data['Comparator']); + + $smarty->assign("match_types",$av_match_type); + $smarty->assign("match_type",$data['Match_type']); + + $smarty->assign("match_type_value",$data['Match_type_value']); + $smarty->assign("match_type_values",$mtv); - /* Create comparator */ - $ret .= _("Match type")." "; - $arr =array("i;octet" => _("Normal"),"i;ascii-casemap"=>_("Case sensitive"),"i;ascii-numeric"=>_("Numeric")); - $ret .= ""; - - /* Create address part */ - $ret.= _("Checking Header"); + + $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_address.tpl",TRUE,dirname(__FILE__))); break; } @@ -137,7 +156,7 @@ class sieve_if if($key == "Inverse" ){ continue; } - $ret.= $this->get_as_html($dat); + $ret.= $this->get_as_html($dat, ($id +1),$key); } $ret.= " @@ -164,7 +183,7 @@ class sieve_if if($key == "Inverse" ){ continue; } - $ret.= $this->get_as_html($dat); + $ret.= $this->get_as_html($dat, ($id + 1),$key); } $ret.= " @@ -364,7 +383,7 @@ class sieve_if } default : $tmp[$id] = $type; } - + return($tmp); } diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index 945a6d284..44ea8c8cf 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -18,12 +18,24 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* The sieve management class displays a list of sieve + * scripts for the given mail account. + * The account is identified by the parents uid attribute. + * + * $config The config object + * $dn The object edited + * $parent The parent object that provides the uid attribute + */ class sieveManagement extends plugin { var $parent = NULL; var $scripts= array(); - + + /* Initialize the class and load all sieve scripts + * try to parse them and display errors + */ function sieveManagement($config,$dn,$parent) { $this->parent = $parent; @@ -76,6 +88,9 @@ class sieveManagement extends plugin } } + + /* Handle sieve list + */ function execute() { $once = TRUE; @@ -93,21 +108,18 @@ class sieveManagement extends plugin } + /* Create list of available sieve scripts + */ $List = new divSelectBox("sieveManagement"); - foreach($this->scripts as $key => $script){ - $field1 = array("string" => $script['NAME']); - if($script['STATUS']){ $field2 = array("string" => _("Parse successful")); }else{ $field2 = array("string" => _("Parse failed") .$script['MSG']); } - $field3 = array("string" => _("Script length")." : ".strlen($script['SCRIPT'])); $field4 = array("string" => ""); - $List ->AddEntry(array($field1,$field2,$field3,$field4)); } diff --git a/include/sieve/templates/element_address.tpl b/include/sieve/templates/element_address.tpl new file mode 100755 index 000000000..ecd879fd9 --- /dev/null +++ b/include/sieve/templates/element_address.tpl @@ -0,0 +1,29 @@ +{t}Address{/t} +
+ +{t}Comparator{/t} + +
+ +{t}Match type{/t} + +
+ +{if $match_type == ":value"} + {t}Match type operator{/t} + +
+ + +
+ + +{/if} + + diff --git a/include/sieve/templates/element_boolean.tpl b/include/sieve/templates/element_boolean.tpl new file mode 100755 index 000000000..f1da4a378 --- /dev/null +++ b/include/sieve/templates/element_boolean.tpl @@ -0,0 +1,5 @@ +{t}Bool{/t} + +
-- 2.30.2