From be5bd4261ad2e241ed510384ec7c6ca415eeaa74 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 19 Mar 2007 10:00:33 +0000 Subject: [PATCH] Added require entries automatically git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5814 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_My_Tree.inc | 29 +++++++++++++++++++ include/sieve/class_sieveElement_Fileinto.inc | 1 + include/sieve/class_sieveElement_If.inc | 16 ++++++++-- include/sieve/class_sieveElement_Reject.inc | 6 ++-- include/sieve/class_sieveElement_Require.inc | 20 +++++++++++-- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index 8792f98f7..a5bf7af3a 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -571,6 +571,35 @@ class My_Tree extends Tree } return($msgs); } + + + /* We are forced to add a new require. + * This function is called by the + * sieveElement_Classes->parent->add_require() + */ + function add_require($str) + { + $require_id = -1; + foreach($this->pap as $key => $obj){ + if(get_class($obj) == "sieve_require"){ + $require_id = $key; + } + } + + /* No require found, add one */ + if($require_id == -1){ + $require = new sieve_require(NULL,preg_replace("/[^0-9]/","",microtime())); + $require -> Add_Require($str); + $new = array(); + $new[] = $require; + foreach($this->pap as $obj){ + $new[] = $obj; + } + $this->pap = $new; + } else { + $this->pap[$require_id]->Add_Require($str); + } + } } diff --git a/include/sieve/class_sieveElement_Fileinto.inc b/include/sieve/class_sieveElement_Fileinto.inc index 1c1707ef4..71024ba06 100644 --- a/include/sieve/class_sieveElement_Fileinto.inc +++ b/include/sieve/class_sieveElement_Fileinto.inc @@ -38,6 +38,7 @@ class sieve_fileinto { $this->object_id = $object_id; $this->parent = $parent; + $this->parent->add_require("fileinto"); $mbs = $this->get_mail_boxes(); diff --git a/include/sieve/class_sieveElement_If.inc b/include/sieve/class_sieveElement_If.inc index edaec6c04..ef726c91a 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -11,14 +11,16 @@ class sieve_if var $comparators = array(); var $match_types = array(); var $operators = array(); - + var $parent = NULL; /* Initialize class * $elements contains all tokens that belongs to this if/else tag * $object_id cotains an unique tag id, to be able to create uniqe html post names */ - function sieve_if($elements,$object_id) + function sieve_if($elements,$object_id,$parent) { + $this->parent = $parent; + /* Possible address parts we can select */ $this->address_parts = array( ":all" => _("Complete adress")." ("._("Default").")", @@ -426,6 +428,12 @@ class sieve_if $values["Address_Part"] = ":all"; } $data[$type]=$values; + + if($type == "envelope"){ + $this->parent->add_require("envelope"); + } + + break; } case "allof" : @@ -583,6 +591,10 @@ class sieve_if $parsed[$key]['LastError'] = _("Invalid operator given."); } $parsed[$key]['Comparator'] = $cp; + + if($cp == "i;ascii-numeric"){ + $this->parent->add_require("comparator-i;ascii-numeric"); + } } /* In case of :count and :value match types diff --git a/include/sieve/class_sieveElement_Reject.inc b/include/sieve/class_sieveElement_Reject.inc index 6c0a6f5b6..8bf9bb61b 100644 --- a/include/sieve/class_sieveElement_Reject.inc +++ b/include/sieve/class_sieveElement_Reject.inc @@ -4,7 +4,7 @@ class sieve_reject { var $data = ""; var $object_id = -1; - + var $parent = NULL; function save_object() { @@ -20,9 +20,11 @@ class sieve_reject return(array()); } - function sieve_reject($data,$object_id) + function sieve_reject($data,$object_id,$parent) { $this->object_id = $object_id; + $this->parent = $parent; + $this->parent->add_require("reject"); /* If the given data is emtpy * (This is the case when we add new elements in the ui) diff --git a/include/sieve/class_sieveElement_Require.inc b/include/sieve/class_sieveElement_Require.inc index 3b91b8205..c7138deb5 100644 --- a/include/sieve/class_sieveElement_Require.inc +++ b/include/sieve/class_sieveElement_Require.inc @@ -18,6 +18,22 @@ class sieve_require } } + /* Add a new require statement and ensure + * that it is not specified twice + */ + function Add_Require($str) + { + $current = array(); + + foreach($this->data as $dat){ + $current[] = preg_replace("/\"/","",$dat); + } + if(!in_array($str,$current)){ + $this->data[] = $str; + } + $this->data = array_unique($this->data);; + } + function save_object() { /* Get the values should check for, they are seperated by , */ @@ -32,7 +48,7 @@ class sieve_require if(empty($val)) continue; - $tmp[] = "\"".$val."\""; + $tmp[] = $val; } $this->data = $tmp; } @@ -58,7 +74,7 @@ class sieve_require { $Require = ""; foreach($this->data as $key){ - $Require .= $key.", "; + $Require .= "\"".$key."\"".", "; } $Require = preg_replace("/,$/","",trim($Require)); -- 2.30.2