pap)){ $this->dump_ = ""; $this->mode_stack = array(); $this->pap = array(); $this->doDump_(0, '', true); } /* Create html results */ $this->dump_ ="
"; foreach($this->pap as $key => $object){ if(is_object($object)){ $this->dump_ .= preg_replace("/>/",">\n",$object->execute()); } } $this->dump_ .= "
"; return $this->dump_; } /* This function walks through the object tree generated by the "Parse" class. * All Commands will be resolved and grouped. So the Commands and their * parameter are combined. Like "IF" and ":comparator"... */ function doDump_($node_id, $prefix, $last,$num = 1) { /* Indicates that current comman will only be valid for a single line. * this command type will be removed from mode_stack after displaying it. */ $rewoke_last = FALSE; /* Get node */ $node = $this->nodes_[$node_id]; /* This closes the last mode */ if($node['class'] == "block-start"){ $tmp = array_pop($this->mode_stack); $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,$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,$node_id); } /* Handle comments */ if($node['class'] == "comment"){ $this->mode_stack[] = array("TYPE" => $node['class']); $rewoke_last = TRUE; } /* Handle identifiers */ $identifiers = array("else","if","elsif","end","reject","redirect","vacation","keep","discard","comment","fileinto","require","stop"); if($node['class'] == "identifier" && in_array($node['text'],$identifiers)){ $this->mode_stack[] = array("TYPE" => $node['text']); } /* Add current node to current command stack */ end($this->mode_stack); $key = key($this->mode_stack); $this->mode_stack[$key]['ELEMENTS'][] = $node; /* 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,$node_id); } /* If this is a sub element, just call this for all childs */ if(isset($this->childs_[$node_id])){ $childs = $this->childs_[$node_id]; for ($i=0; $idoDump_($childs[$i], "", $num); } } } /* 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; } $type = $data['TYPE']; $class_name= "sieve_".$type ; if(class_exists($class_name)){ $this->pap[] = new $class_name($data,$id); }else{ echo "Missing : ".$class_name.""."
"; } } function save_object() { foreach($this->pap as $key => $obj){ if(in_array(get_class($obj),array("sieve_if","sieve_elsif","sieve_vacation","sieve_comment","sieve_reject","sieve_fileinto","sieve_require","sieve_redirect"))){ $this->pap[$key]->save_object(); } } } /* Need to be reviewed */ function get_sieve_script() { $tmp =""; if(count($this->pap)){ $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(); if(get_class($part) == "sieve_reject"){ $tmp.=$tmp2; }else{ $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; } } } if(!preg_match("/Generated by GOsa - Gonicus System Administrator/",$tmp)){ $tmp = "#Generated by GOsa - Gonicus System Administrator \n ".$tmp; } 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{ $Multiline = preg_match("/\n/",$data); $data = preg_replace("/\r/","",$data);; if($Multiline){ $ret = "text: \r\n".$data."\r\n.\r\n"; }else{ $ret = "\"".$data."\""; } } $ret = preg_replace("/\"\"/","\"",$ret); $ret = preg_replace("/\n/","\r\n",$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, * 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(); if($data[$id]['class'] == "left-bracket"){ while($data[$id]['class'] != "right-bracket" && $id < count($data)){ if($data[$id]['class'] == "quoted-string"){ $ret[] = $data[$id]['text']; } $id ++; } }elseif($data[$id]['class'] == "quoted-string"){ $ret[] = $data[$id]['text']; }elseif($data[$id]['class'] == "number"){ $ret[] = $data[$id]['text']; } return(array("OFFSET" => $id, "STRINGS" => $ret)); } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>