From: hickert Date: Mon, 5 Mar 2007 03:33:18 +0000 (+0000) Subject: Added missing file X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=95d90996ccd393a637ac532bf481e6347a9a2cf8;p=gosa.git Added missing file git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5742 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc new file mode 100644 index 000000000..18964bef5 --- /dev/null +++ b/include/sieve/class_sieveElement_If.inc @@ -0,0 +1,397 @@ +elements = $elements; + $this->_parsed = $this->_parse($elements['ELEMENTS'],1); + } + + + /* Return html element for IF */ + function execute() + { + /* Create title */ + $name = ""; + $name .= ""._("Condition").""; + if($this->TYPE == "if"){ + $name .= " - "._("If"); + }else{ + $name .= " - "._("Else"); + } + + /* Create new html block */ + $str =" + + + +
". + $name; + $str .= $this->get_as_html(); + + $str .= "
"; + return($str); + } + + + /* Returns all elements as html */ + function get_as_html($parsed = NULL) + { + $header_parts = array(":all",":localpart",":domain",":user",":detail"); + + + $ret =""; + if($parsed == NULL){ + $parsed = $this->_parsed; + } + + /* Walk through all elements */ + foreach($parsed as $key => $data){ + + /* Create Inverse Tag */ + if(isset($data['Inverse']) && $data['Inverse']){ + $str_inverse = ""._("Not")." "; + $Inverse = TRUE; + }else{ + $str_inverse = ""; + $Inverse = FALSE; + } + + /* Create elements */ + switch($key) + { + + /******************* + * TRUE FALSE + *******************/ + + 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; + } + + /* Return value */ + if($type){ + $ret = "
"._("Boolean true")."
"; + }else{ + $ret = "
"._("Boolean false")."
"; + } + } + break; + + + /******************* + * Header + *******************/ + + case "address" : + { + $ret =""; + + /* 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"); + break; + } + + + /******************* + * All of + *******************/ + + case "allof" : + { + $ret = " + + "; + $ret.= " + +
". + "".$str_inverse._("All of")."". + "". + ""; + foreach($data as $key => $dat){ + if($key == "Inverse" ){ + continue; + } + $ret.= $this->get_as_html($dat); + } + $ret.= "
"; + break ; + } + + + /******************* + * Any of + *******************/ + + case "anyof" : + { + $ret = " + + "; + $ret.= " + +
". + "".$str_inverse._("Any of")."". + "". + ""; + foreach($data as $key => $dat){ + if($key == "Inverse" ){ + continue; + } + $ret.= $this->get_as_html($dat); + } + $ret.= "
"; + break ; + } + default : + { + $ret = " + + + +
"; + $ret.= $key."
"; + $ret.= "
"; + + } + } + } + return($ret); + } + + + function _parse($data,$id = 0) + { + $av_methods = array("address","allof","anyof","exists","false","header","not","size","true","envelope"); + $av_match_type= array(":is",":contains",":matches",":over",":count",":value",":under"); + + $type = $data[$id]['text']; + + $tmp = array(); + + + /* Is there an identifier named 'not' to inverse this filter ? */ + $Inverse = FALSE; + if($data[$id]['class'] == "identifier" && $data[$id]['text'] == "not"){ + $Inverse = TRUE; + $id ++; + $type = $data[$id]['text']; + } + + switch($type) + { + + case "envelope" : + case "header": + case "address" : + { + /* Address matches are struckture as follows : + [not] + address + [address-part: tag] all|localpart|domain|user|detail + [comparator: tag] i;octet i;ascii-casemap i;ascii-numeric + [match-type: tag] is|contains|matches|count|value + + + */ + + + $part = "(:all|:localpart|:domain)"; + $operator = "(:contains|:is|:matches|:count|:value)"; + $value_op = "(lt|le|eq|ge|gt|ne)"; + + $Address_Part = ""; + $Comparator = ""; + $Match_type = ""; + $Match_type_value = ""; + + $Key_List = array(); + $Value_List = array(); + + for($i = 0 ; $i < count($data) ; $i ++){ + + /* Get next node */ + $node = $data[$i]; + + /* Check address part definition */ + if($node['class'] == "tag" && preg_match("/".$part."/i",$node['text'])){ + $Address_Part = $node['text']; + } + + /* Check for match type */ + elseif($node['class'] == "tag" && preg_match("/".$operator."/i",$node['text'])){ + $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']; + } + } + } + + /* Check for a comparator */ + elseif($node['class'] == "tag" && preg_match("/comparator/",$node['text'])){ + $i ++; + $node = $data[$i]; + $Comparator = $node['text']; + } + + /* Check for Key_List */ + elseif(count(sieve_get_strings($data,$i))){ + $tmp2 = sieve_get_strings($data,$i); + $i = $tmp2['OFFSET']; + + if(!count($Key_List)){ + $Key_List = $tmp2['STRINGS']; + }else{ + $Value_List = $tmp2['STRINGS']; + } + } + + } + + + /* Add to Tree */ + $values = array( "Inverse" => $Inverse, + "Comparator" => $Comparator, + "Match_type" => $Match_type, + "Match_type_value"=> $Match_type_value, + "Key_List" => $Key_List, + "Value_List" => $Value_List) ; + if($type == "address"){ + $values["Address_Part"] = $Address_Part; + } + $tmp[$type] = $values; + break; + } + + + case "size": + { + + $ops = "(:over|:under)"; + + $Match_type = ""; + + for($i = $id ; $i < count($data); $i++){ + + /* Get current node */ + $node = $data[$i]; + + /* Get tag (under / over) */ + if($node['class'] == "tag" && preg_match("/".$ops."/",$node['text'])){ + $Match_type = $node['text']; + } + + /* Get Value_List, the value that we want to match for */ + elseif(count(sieve_get_strings($data,$i))){ + $tmp2 = sieve_get_strings($data,$i); + $i = $tmp2['OFFSET']; + + $Value_List = $tmp2['STRINGS']; + } + } + + $tmp[$type]= array( "Inverse" => $Inverse, + "Match_type" => $Match_type, + "Value_List" => $Value_List); + break; + } + case "true": + { + $tmp['true'] = "true"; + break; + } + case "false": + { + $tmp['false'] = "false"; + break; + } + case "allof" : + { + $id ++; + $tmp2 = $this->get_parameter($data,$id); + + foreach($tmp2 as $parameter){ + $tmp['allof'][] = $this->_parse($parameter); + } + $tmp['allof']['Inverse'] = $Inverse; + break; + } + + case "anyof" : + { + $id ++; + $tmp2 = $this->get_parameter($data,$id); + + foreach($tmp2 as $parameter){ + $tmp['anyof'][] = $this->_parse($parameter); + } + $tmp['anyof']['Inverse'] = $Inverse; + break; + } + default : $tmp[$id] = $type; + } + + return($tmp); + } + + + function get_parameter($data,$id) + { + $par = array(); + $open_brakets = 0; + $next = NULL; + $num = 0; + for($i = $id ; $i < count($data) ; $i++ ){ + if(in_array($data[$i]['class'],array("left-parant","left-bracket"))){ + $open_brakets ++; + } + if($data[$i]['class'] == "comma" && $open_brakets == 1){ + $num ++; + } + if(!in_array($data[$i]['class'],array("comma","left-parant","right-parant")) || $open_brakets >1 ){ + $par[$num][] = $data[$i]; + } + if(in_array($data[$i]['class'],array("right-parant","right-bracket"))){ + $open_brakets --; + } + } + return($par); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?>