From fa5d4f7116f6592143cf24fbea8eb4d342ef368d Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 5 Mar 2007 11:47:08 +0000 Subject: [PATCH] some sieve filter updates git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5746 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_My_Parser.inc | 12 + include/sieve/class_My_Tree.inc | 25 +- include/sieve/class_sieveElement.inc | 30 --- include/sieve/class_sieveElement_If.inc | 254 ++++++++++++++++--- include/sieve/class_sieveElements.inc | 2 +- include/sieve/class_sieveManagement.inc | 19 +- include/sieve/templates/element_address.tpl | 82 ++++-- include/sieve/templates/element_boolean.tpl | 1 + include/sieve/templates/element_envelope.tpl | 49 ++++ include/sieve/templates/element_header.tpl | 49 ++++ 10 files changed, 425 insertions(+), 98 deletions(-) delete mode 100644 include/sieve/class_sieveElement.inc create mode 100755 include/sieve/templates/element_envelope.tpl create mode 100755 include/sieve/templates/element_header.tpl diff --git a/include/sieve/class_My_Parser.inc b/include/sieve/class_My_Parser.inc index b59cfecd4..6d796cd8a 100644 --- a/include/sieve/class_My_Parser.inc +++ b/include/sieve/class_My_Parser.inc @@ -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) diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index e76290c8b..942f64e4c 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -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_ =""; $ret.= " "; $ret.= "
"; foreach($this->pap as $object){ if(is_object($object)){ @@ -128,6 +133,16 @@ class My_Tree extends Tree echo "Missing : ".$class_name.""."
"; } } + + 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 index 596bd6d00..000000000 --- a/include/sieve/class_sieveElement.inc +++ /dev/null @@ -1,30 +0,0 @@ -data = @$data->dumpParseTree(); - } - - function execute() - { - return($this->data); - } -} - - - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc index 20a10b41a..f9e099d2d 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -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 = ""; + $name = ""; $name .= ""._("Condition").""; if($this->TYPE == "if"){ $name .= " - "._("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 = ""._("Not")." "; $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] */ + $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
". "".$str_inverse._("All of")."". - "". + "". ""; + 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 ". "".$str_inverse._("Any of")."". - "". + "". ""; 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 ++; diff --git a/include/sieve/class_sieveElements.inc b/include/sieve/class_sieveElements.inc index 37031994e..e8d70feba 100644 --- a/include/sieve/class_sieveElements.inc +++ b/include/sieve/class_sieveElements.inc @@ -226,7 +226,7 @@ class sieve_block_start return("
- + "); } diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index 44ea8c8cf..59d9436e3 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -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(); + } } } diff --git a/include/sieve/templates/element_address.tpl b/include/sieve/templates/element_address.tpl index ecd879fd9..6f7eda051 100755 --- a/include/sieve/templates/element_address.tpl +++ b/include/sieve/templates/element_address.tpl @@ -1,29 +1,57 @@ -{t}Address{/t} -
- -{t}Comparator{/t} - -
- -{t}Match type{/t} - -
- -{if $match_type == ":value"} - {t}Match type operator{/t} - -
- - -
- - -{/if} + + + + + + + + + + + + + + + + + + + + +
+ {t}Address{/t} +
+ {t}Address part{/t} + + + + {t}Comparator{/t} + + + + {t}Match type{/t} + + + + {t}operator{/t} + + +
+ {t}Address fields{/t} + + + + {t}Match values{/t} + + +
diff --git a/include/sieve/templates/element_boolean.tpl b/include/sieve/templates/element_boolean.tpl index f1da4a378..61578ddb7 100755 --- a/include/sieve/templates/element_boolean.tpl +++ b/include/sieve/templates/element_boolean.tpl @@ -2,4 +2,5 @@ +
diff --git a/include/sieve/templates/element_envelope.tpl b/include/sieve/templates/element_envelope.tpl new file mode 100755 index 000000000..e1aace841 --- /dev/null +++ b/include/sieve/templates/element_envelope.tpl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + +
+ {t}Envelope{/t} +
+ {t}Comparator{/t} + + + + {t}Match type{/t} + + + + + {t}operator{/t} + + +
+ {t}Address fields{/t} + + + + {t}Match values{/t} + + +
diff --git a/include/sieve/templates/element_header.tpl b/include/sieve/templates/element_header.tpl new file mode 100755 index 000000000..e32d8f678 --- /dev/null +++ b/include/sieve/templates/element_header.tpl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + +
+ {t}Header{/t} +
+ {t}Comparator{/t} + + + + {t}Match type{/t} + + + + + {t}operator{/t} + + +
+ {t}Address fields{/t} + + + + {t}Match values{/t} + + +
-- 2.30.2