From 16064d36151890be03d391132f445d7fb3cf1e74 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 13 Mar 2007 10:01:12 +0000 Subject: [PATCH] Put each class in a single file. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5771 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_My_Parser.inc | 9 + include/sieve/class_My_Tree.inc | 13 + .../sieve/class_sieveElement_Block_End.inc | 25 + .../sieve/class_sieveElement_Block_Start.inc | 26 + include/sieve/class_sieveElement_Comment.inc | 55 ++ include/sieve/class_sieveElement_Fileinto.inc | 63 ++ include/sieve/class_sieveElement_If.inc | 119 ++-- include/sieve/class_sieveElement_Keep.inc | 38 ++ include/sieve/class_sieveElement_Redirect.inc | 48 ++ include/sieve/class_sieveElement_Reject.inc | 60 ++ include/sieve/class_sieveElement_Require.inc | 75 +++ include/sieve/class_sieveElement_Stop.inc | 39 ++ include/sieve/class_sieveElement_Vacation.inc | 128 ++++ include/sieve/class_sieveElements.inc | 562 ------------------ include/sieve/class_sieveManagement.inc | 12 +- include/sieve/templates/element_address.tpl | 32 + include/sieve/templates/element_envelope.tpl | 34 ++ include/sieve/templates/element_header.tpl | 33 + include/sieve/templates/element_redirect.tpl | 21 + include/sieve/templates/element_require.tpl | 26 + 20 files changed, 818 insertions(+), 600 deletions(-) create mode 100644 include/sieve/class_sieveElement_Block_End.inc create mode 100644 include/sieve/class_sieveElement_Block_Start.inc create mode 100644 include/sieve/class_sieveElement_Comment.inc create mode 100644 include/sieve/class_sieveElement_Fileinto.inc create mode 100644 include/sieve/class_sieveElement_Keep.inc create mode 100644 include/sieve/class_sieveElement_Redirect.inc create mode 100644 include/sieve/class_sieveElement_Reject.inc create mode 100644 include/sieve/class_sieveElement_Require.inc create mode 100644 include/sieve/class_sieveElement_Stop.inc create mode 100644 include/sieve/class_sieveElement_Vacation.inc delete mode 100644 include/sieve/class_sieveElements.inc diff --git a/include/sieve/class_My_Parser.inc b/include/sieve/class_My_Parser.inc index a45d24e83..ea45beb99 100644 --- a/include/sieve/class_My_Parser.inc +++ b/include/sieve/class_My_Parser.inc @@ -45,6 +45,15 @@ class My_Parser extends Parser } + /* Check if there are errors, collect them and return them */ + function check() + { + return($this->tree_->check()); + } + + + + /* Initiate parser, but use some other * classes, that are rewritten. */ diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index 78522ba2a..1cb41a3a7 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -535,6 +535,19 @@ class My_Tree extends Tree $tmp = array("ELEMENTS" => array(array("class" => "qouted-string","text"=> "Bla bla, later more"))); $this->pap[] = new sieve_comment($tmp,rand(1000,100000)); } + + function check() + { + $msgs = array(); + foreach($this->pap as $obj){ + + $o_msgs = $obj->check(); + foreach($o_msgs as $o_msg){ + $msgs[] = $o_msg; + } + } + return($msgs); + } } diff --git a/include/sieve/class_sieveElement_Block_End.inc b/include/sieve/class_sieveElement_Block_End.inc new file mode 100644 index 000000000..403585f89 --- /dev/null +++ b/include/sieve/class_sieveElement_Block_End.inc @@ -0,0 +1,25 @@ +fetch(get_template_path("templates/element_block_end.tpl",TRUE,dirname(__FILE__)))); + } + function check() + { + return(array()); + } + + function get_sieve_script_part() + { + return("}\n"); + } + function save_object() + { + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Block_Start.inc b/include/sieve/class_sieveElement_Block_Start.inc new file mode 100644 index 000000000..799f1fa84 --- /dev/null +++ b/include/sieve/class_sieveElement_Block_Start.inc @@ -0,0 +1,26 @@ +fetch(get_template_path("templates/element_block_start.tpl",TRUE,dirname(__FILE__)))); + } + + function check() + { + return(array()); + } + + function save_object() + { + } + + function get_sieve_script_part() + { + return("{\n"); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Comment.inc b/include/sieve/class_sieveElement_Comment.inc new file mode 100644 index 000000000..d3f6747dd --- /dev/null +++ b/include/sieve/class_sieveElement_Comment.inc @@ -0,0 +1,55 @@ +data."\n"); + } + + function sieve_comment($data,$object_id) + { + $this->object_id = $object_id; + foreach($data['ELEMENTS'] as $node){ + $this->data .= $node['text']; + } + } + + function save_object() + { + if(isset($_POST['comment_'.$this->object_id])){ + $cm = $_POST['comment_'.$this->object_id]; + $this->data = "/*".$cm."*/"; + } + } + + function execute() + { + $smarty = get_smarty(); + $smarty->assign("ID", $this->object_id); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $Comment = $this->data; + + /* Remove comment tags */ + if(preg_match("/^#/",$Comment)){ + $Comment = preg_replace("/^#/","",$Comment); + }elseif(preg_match("#\/\*#",$Comment)){ + $Comment = preg_replace("#^\/\*#","",$Comment); + $Comment = preg_replace("#\*\/$#","",$Comment); + } + + /* Create html object */ + $smarty = get_smarty(); + $smarty->assign("Comment",$Comment); + $smarty->assign("ID",$this->object_id); + $object = $smarty->fetch(get_template_path("templates/element_comment.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Fileinto.inc b/include/sieve/class_sieveElement_Fileinto.inc new file mode 100644 index 000000000..e595250aa --- /dev/null +++ b/include/sieve/class_sieveElement_Fileinto.inc @@ -0,0 +1,63 @@ +get_mail_boxes(); + + if(isset($_POST['fileinto_'.$this->object_id])){ + $mb = $_POST['fileinto_'.$this->object_id]; + + if(isset($mbs[$mb])) { + $this->data[0] = $mb; + } + } + } + + function sieve_fileinto($data,$object_id) + { + $this->object_id = $object_id; + foreach($data['ELEMENTS'] as $node ){ + if(in_array($node['class'],array("quoted-string","text"))){ + $this->data[] = preg_replace("/\"/","",$node['text']); + } + } + } + + function get_sieve_script_part() + { + $tmp = ""; + foreach($this->data as $dat){ + $tmp.= "\"".$dat."\", "; + } + $tmp = preg_replace("/,$/","",trim($tmp)); + $tmp = preg_replace ("/\"\"/","\"",$tmp); + return("fileinto ".$tmp.";\n"); + } + + function execute() + { + $smarty = get_smarty(); + $smarty->assign("Selected",$this->data[0]); + $smarty->assign("Boxes", $this->get_mail_boxes()); + $smarty->assign("ID", $this->object_id); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + + return($str); + } + + function get_mail_boxes() + { + return(array("not"=>"not","impplemented/yet"=>"impplemented/yet")); + } +} + +// 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 c35c91a86..2cd0a6504 100644 --- a/include/sieve/class_sieveElement_If.inc +++ b/include/sieve/class_sieveElement_If.inc @@ -64,6 +64,63 @@ class sieve_if } + /* Return error msgs */ + function check() + { + $check = $this->check_recursive(); + return($check); + } + + + /* Recursivly fetch all error msgs */ + function check_recursive($parsed = NULL,$id = 1,$obj_id=1) + { + $ret = array(); + if($parsed == NULL){ + $parsed = $this->_parsed; + } + + /* Walk through all elements */ + foreach($parsed as $key => $data){ + + /* Create elements */ + switch($key) + { + /******************* + * Allof / Anyof + *******************/ + case "anyof" : + case "allof" : + { + foreach($data as $key2 => $dat){ + if(($key2 === "Inverse") && ($key2 == "Inverse")){ + continue; + } + $msgs = $this->check_recursive($dat, ($id +1),$key2); + + foreach($msgs as $msg){ + $ret[] = $msg; + } + } + break; + } + + /******************* + * Default + *******************/ + + default: + { + if(isset($data['LastError']) && !empty($data['LastError'])){ + $ret[] = $data['LastError']; + } + } + } + } + return($ret); + } + + /* Recursivly create a sieve script out of the given * tags and tokens provided by $parsed. * $id specifies the depth of the current element. @@ -101,9 +158,7 @@ class sieve_if if($Inverse){ $script .= "not "; } - $script .= $key; - break; } @@ -387,6 +442,8 @@ class sieve_if $match_types = $this->match_types; $operators = $this->operators; + $parsed[$key]['LastError'] = ""; + /* Toggle Inverse ? */ if(isset($_POST['toggle_inverse_'.$element_id])){ $parsed[$key]['Inverse'] = !$parsed[$key]['Inverse']; @@ -401,27 +458,30 @@ class sieve_if if(isset($_POST['address_part_'.$element_id])){ $ap = $_POST['address_part_'.$element_id]; - if(isset($address_parts[$ap])){ - $parsed[$key]['Address_Part'] = $ap; + if(!isset($address_parts[$ap])){ + $parsed[$key]['LastError'] = _("Invalid type of address part.") ; } + $parsed[$key]['Address_Part'] = $ap; } /* Check if match type has changed */ if(isset($_POST['matchtype_'.$element_id])){ $mt = $_POST['matchtype_'.$element_id]; - if(isset($match_types[$mt])){ - $parsed[$key]['Match_type'] = $mt; + if(!isset($match_types[$mt])){ + $parsed[$key]['LastError'] = _("Invalid match type given."); } + $parsed[$key]['Match_type'] = $mt; } /* Get the comparator tag, if posted */ if(isset($_POST['comparator_'.$element_id])){ $cp = $_POST['comparator_'.$element_id]; - if(isset($comparators[$cp])){ - $parsed[$key]['Comparator'] = $cp; + if(!isset($comparators[$cp])){ + $parsed[$key]['LastError'] = _("Invalid operator given."); } + $parsed[$key]['Comparator'] = $cp; } /* In case of :count and :value match types @@ -431,9 +491,10 @@ class sieve_if if(isset($_POST['operator_'.$element_id])){ $op = $_POST['operator_'.$element_id]; - if(isset($operators[$op])){ - $parsed[$key]['Match_type_value'] = $op; + if(!isset($operators[$op])){ + $parsed[$key]['LastError'] = _("Please specify a valid operator."); } + $parsed[$key]['Match_type_value'] = $op; } } @@ -524,9 +585,7 @@ class sieve_if /* Get match type */ if(isset($_POST['Match_type_'.$element_id])){ $mt = $_POST['Match_type_'.$element_id]; - if(isset($Match_types[$mt])){ - $parsed['size']['Match_type'] = $mt; - }else{ + if(!isset($Match_types[$mt])){ $parsed['size']['LastError'] = _("Please select a valid match type in the list box below."); } } @@ -539,22 +598,20 @@ class sieve_if if(isset($_POST['Value_'.$element_id])){ $vl = $_POST['Value_'.$element_id]; - if(is_numeric($vl) && preg_match("/^[0-9]*$/",$vl)){ - $value = $vl; - }else{ + if(!(is_numeric($vl) && preg_match("/^[0-9]*$/",$vl))){ $parsed['size']['LastError'] = _("Only numeric values are allowed here."); } + $value = $vl; } /* Get unit */ if(isset($_POST['Value_Unit_'.$element_id])){ $ut = $_POST['Value_Unit_'.$element_id]; - if(isset($Units[$ut])){ - $unit = $ut; - }else{ + if(!isset($Units[$ut])){ $parsed['size']['LastError'] = _("No valid unit selected"); } + $unit = $ut; } $parsed['size']['Value_List'][0] = $value.$unit; @@ -627,12 +684,7 @@ class sieve_if $smarty->assign("Name", $name); $smarty->assign("Contents", $this->get_as_html()); $object = $smarty->fetch(get_template_path("templates/element_if_else.tpl",TRUE,dirname(__FILE__))); - - - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - - return($str); } @@ -650,10 +702,8 @@ class sieve_if /* Create Inverse Tag */ if(is_array($data) && isset($data['Inverse']) && $data['Inverse']){ - $str_inverse = ""._("Not")." "; $Inverse = TRUE; }else{ - $str_inverse = ""; $Inverse = FALSE; } @@ -705,11 +755,10 @@ class sieve_if $smarty->assign("comparators",$comparators); $smarty->assign("match_types",$match_types); $smarty->assign("operators",$operators); - + $smarty->assign("LastError",$data['LastError']); $smarty->assign("match_type", $data['Match_type']); $smarty->assign("operator" , preg_replace("/\"/","",$data['Match_type_value'])); $smarty->assign("comparator", preg_replace("/\"/","",$data['Comparator'])); - $keys = ""; foreach($data['Key_List'] as $key){ @@ -727,7 +776,6 @@ class sieve_if $smarty->assign("Inverse",$Inverse); $smarty->assign("values",$values); $smarty->assign("Expert", $data['Expert']); - $smarty->assign("ID" , $element_id); $ret .= $smarty->fetch(get_template_path("templates/element_header.tpl",TRUE,dirname(__FILE__))); @@ -752,7 +800,7 @@ class sieve_if $smarty->assign("Expert", $data['Expert']); $smarty->assign("match_types",$match_types); $smarty->assign("operators",$operators); - + $smarty->assign("LastError",$data['LastError']); $smarty->assign("match_type", $data['Match_type']); $smarty->assign("operator" , preg_replace("/\"/","",$data['Match_type_value'])); $smarty->assign("comparator", preg_replace("/\"/","",$data['Comparator'])); @@ -793,13 +841,12 @@ class sieve_if $smarty->assign("address_parts",$address_parts); $smarty->assign("comparators",$comparators); $smarty->assign("match_types",$match_types); + $smarty->assign("LastError",$data['LastError']); $smarty->assign("operators",$operators); - $smarty->assign("match_type", $data['Match_type']); $smarty->assign("operator" , preg_replace("/\"/","",$data['Match_type_value'])); $smarty->assign("comparator", preg_replace("/\"/","",$data['Comparator'])); $smarty->assign("address_part", $data['Address_Part']); - $smarty->assign("Expert", $data['Expert']); $keys = ""; @@ -815,8 +862,6 @@ class sieve_if $values = preg_replace("/,$/","",trim($values)); $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; @@ -860,7 +905,6 @@ class sieve_if /******************* * Exists *******************/ - case "exists" : { @@ -1054,6 +1098,7 @@ class sieve_if $values["Address_Part"] = $Address_Part; } $tmp[$type] = $values; + $tmp[$type]['LastError'] = ""; break; } @@ -1091,6 +1136,7 @@ class sieve_if $tmp[$type]= array( "Inverse" => $Inverse, "Match_type" => $Match_type, "Value_List" => $Value_List); + $tmp[$type]['LastError'] = ""; break; } @@ -1102,11 +1148,13 @@ class sieve_if case "true": { $tmp['true'] = "true"; + $tmp[$type]['LastError'] = ""; break; } case "false": { $tmp['false'] = "false"; + $tmp[$type]['LastError'] = ""; break; } @@ -1131,6 +1179,7 @@ class sieve_if $tmp['exists'] = array('Inverse' => $Inverse, 'Values' => $tmp2['STRINGS']); + $tmp[$type]['LastError'] = ""; break; } diff --git a/include/sieve/class_sieveElement_Keep.inc b/include/sieve/class_sieveElement_Keep.inc new file mode 100644 index 000000000..8a8a412b3 --- /dev/null +++ b/include/sieve/class_sieveElement_Keep.inc @@ -0,0 +1,38 @@ +object_id = $object_id; + } + + function save_object() + { + } + + function check() + { + return(array()); + } + + function execute() + { + $smarty = get_smarty(); + $smarty->assign("ID", $this->object_id); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object = $smarty->fetch(get_template_path("templates/element_keep.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); + } + function get_sieve_script_part() + { + return("keep;\n"); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Redirect.inc b/include/sieve/class_sieveElement_Redirect.inc new file mode 100644 index 000000000..13b851e72 --- /dev/null +++ b/include/sieve/class_sieveElement_Redirect.inc @@ -0,0 +1,48 @@ +object_id])){ + $rt = stripslashes($_POST['redirect_to_'.$this->object_id]); + + $rt = "\"".trim(preg_replace("/\"/","",$rt))."\""; + $this->data = $rt; + } + } + + + function sieve_redirect($data,$object_id) + { + foreach($data['ELEMENTS'] as $node ){ + if(in_array($node['class'],array("quoted-string","text"))){ + $this->data = $node['text']; + } + } + } + + + function get_sieve_script_part() + { + return("redirect ".sieve_create_strings($this->data).";\n"); + } + + + function execute() + { + $values = $this->data; + + $smarty = get_smarty(); + $smarty->assign("ID", $this->object_id); + $smarty->assign("Destinations" , $values); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_redirect.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Reject.inc b/include/sieve/class_sieveElement_Reject.inc new file mode 100644 index 000000000..0d5423845 --- /dev/null +++ b/include/sieve/class_sieveElement_Reject.inc @@ -0,0 +1,60 @@ +object_id])){ + $msg = stripslashes($_POST['reject_message_'.$this->object_id]); + + $this->data = $msg; + } + } + + function sieve_reject($data,$object_id) + { + $this->object_id = $object_id; + $str = ""; + foreach($data['ELEMENTS'] as $node ){ + if(in_array($node['class'],array("quoted-string","text","multi-line"))){ + + if($node['class'] == "multi-line"){ + $str .= preg_replace("/^text:[ \n\r]*/","",$node['text']); + $str = preg_replace("/[ \n\r]*\.[ \n\r]*$/","",$str); + }else{ + $str .= $node['text']; + } + } + } + $this->data = preg_replace("/\"/","",$str); + } + + function get_sieve_script_part() + { + return("reject ".sieve_create_strings($this->data).";\n"); + } + + function execute() + { + /* check if this will be a + * - single string "" + * - or a multi line text: ... ; + */ + $Multiline = preg_match("/\n/",$this->data); + + $smarty = get_smarty(); + $smarty->assign("ID", $this->object_id); + $smarty->assign("Message",$this->data); + $smarty->assign("Multiline",$Multiline); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_reject.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); + } +} + + diff --git a/include/sieve/class_sieveElement_Require.inc b/include/sieve/class_sieveElement_Require.inc new file mode 100644 index 000000000..dffbf375b --- /dev/null +++ b/include/sieve/class_sieveElement_Require.inc @@ -0,0 +1,75 @@ +object_id = $object_id; + foreach($data['ELEMENTS'] as $node ){ + if(in_array($node['class'],array("quoted-string","text"))){ + $this->data[] = preg_replace("/\"/","",$node['text']); + } + } + } + + function save_object() + { + /* Get the values should check for, they are seperated by , */ + if(isset($_POST['require_'.$this->object_id])){ + $vls = stripslashes($_POST['require_'.$this->object_id]); + $tmp = array(); + + $tmp2 = split(",",$vls); + foreach($tmp2 as $val){ + + $val = trim(preg_replace("/\"/","",$val)); + + if(empty($val)) continue; + + $tmp[] = "\"".$val."\""; + } + $this->data = $tmp; + } + } + + function check() + { + $msgs = array(); + + if(!count($this->data)){ + $msgs[] = _("Please specify at least one valid requirement."); + } + return($msgs); + } + + function get_sieve_script_part() + { + $tmp = sieve_create_strings($this->data); + return("require ".$tmp.";\n"); + } + + function execute() + { + $Require = ""; + foreach($this->data as $key){ + $Require .= $key.", "; + } + $Require = preg_replace("/,$/","",trim($Require)); + + $smarty = get_smarty(); + $smarty->assign("Require",$Require); + $tmp = $this->check(); + $smarty->assign("LastError",$tmp); + $smarty->assign("LastErrorCnt",count($tmp)); + $smarty->assign("ID", $this->object_id); + $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Stop.inc b/include/sieve/class_sieveElement_Stop.inc new file mode 100644 index 000000000..915b8d942 --- /dev/null +++ b/include/sieve/class_sieveElement_Stop.inc @@ -0,0 +1,39 @@ +object_id = $object_id; + } + + function save_object() + { + } + + function check() + { + return(array()); + } + + function execute() + { + $smarty = get_smarty(); + $smarty->assign("ID", $this->object_id); + $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); + $object= $smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__))); + $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); + return($str); + } + + function get_sieve_script_part() + { + return("stop; \n"); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElement_Vacation.inc b/include/sieve/class_sieveElement_Vacation.inc new file mode 100644 index 000000000..182f023df --- /dev/null +++ b/include/sieve/class_sieveElement_Vacation.inc @@ -0,0 +1,128 @@ + */ + + /* Not all attribute types are supported by the sieve class right now */ + $known_attrs = array(":days",":subject",":from",":mime",":handle"); + + /* Walk through elements */ + for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){ + + /* get current element */ + $node = $data['ELEMENTS'][$i]; + + /* Check if tag is in the specified list of attributes */ + if($node['class'] == "tag" && in_array($node['text'],$known_attrs)){ + + $var = preg_replace("/\:/","",$node['text']); + $this->$var = $data['ELEMENTS'][$i+1]['text']; + $i ++; + } + + /* Check for addresses */ + if($node['class'] == "tag" && $node['text'] == ":addresses") { + $this->addresses = array(); + $i ++; + + /* Multiple or single address given */ + if($data['ELEMENTS'][$i]['class'] == "left-bracket"){ + while($data['ELEMENTS'][$i]['class'] != "right-bracket" && ($i < count($data['ELEMENTS']))){ + $i ++; + if($data['ELEMENTS'][$i]['class'] == "quoted-string"){ + $this->addresses[] = preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']); + } + } + }else{ + $this->addresses[] = $data['ELEMENTS'][$i]['text'] ; + } + } + + /* Add the vacation message */ + if($node['class'] == "quoted-string"){ + $this->reason = $node['text']; + } + } + } + + function get_sieve_script_part() + { + $str = "vacation "; + if($this->days){ + $str.= ":days ".$this->days; + } + $str .= ":addresses ".sieve_create_strings($this->addresses); + if($this->subject){ + $str.= ":subject ".sieve_create_strings($this->subject); + } + if($this->mime){ + $str.= ":mime ".sieve_create_strings($this->mime); + } + $str .= "\n ".sieve_create_strings($this->reason); + return($str." ; \n"); + } + + function save_object() + { + /* Get release date */ + if(isset($_POST['vacation_release_'.$this->object_id])){ + $this->days = $_POST['vacation_release_'.$this->object_id]; + } + + /* Check if we want to toggle the expert mode */ + if(isset($_POST['Toggle_Expert_'.$this->object_id])){ + $this->Expert = !$this->Expert; + } + + /* Get release date */ + if(isset($_POST['vacation_receiver_'.$this->object_id])){ + $vr = stripslashes ($_POST['vacation_receiver_'.$this->object_id]); + $tmp = array(); + $tmp2 = split(",",$vr); + foreach($tmp2 as $val){ + $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\""; + } + $this->addresses = $tmp; + } + + /* Get reason */ + if(isset($_POST['vacation_reason_'.$this->object_id])){ + $vr = stripslashes ($_POST['vacation_reason_'.$this->object_id]); + $this->reason = "\"".trim(preg_replace("/\"/","",$vr))."\""; + } + } + function execute() + { + $Addresses = ""; + foreach($this->addresses as $key){ + $Addresses .= $key.", "; + } + $Addresses = preg_replace("/,$/","",trim($Addresses)); + $smarty = get_smarty(); + $smarty->assign("Reason",$this->reason); + $smarty->assign("Addresses",$Addresses); + $smarty->assign("Subject",$this->subject); + $smarty->assign("Days",$this->days); + $smarty->assign("ID",$this->object_id); + $smarty->assign("Expert",$this->Expert); + return($smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__)))); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/sieve/class_sieveElements.inc b/include/sieve/class_sieveElements.inc deleted file mode 100644 index 3b84ebdf4..000000000 --- a/include/sieve/class_sieveElements.inc +++ /dev/null @@ -1,562 +0,0 @@ -object_id = $object_id; - } - - function save_object() - { - } - - function execute() - { - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__))); - $object= $smarty->fetch(get_template_path("templates/element_else.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } - - function get_sieve_script_part() - { - return(" else "); - } -} - - -/* Sieve comment tag */ -class sieve_comment -{ - var $data = ""; - var $object_id= -1; - - function get_sieve_script_part() - { - return($this->data."\n"); - } - - function sieve_comment($data,$object_id) - { - $this->object_id = $object_id; - foreach($data['ELEMENTS'] as $node){ - $this->data .= $node['text']; - } - } - - function save_object() - { - if(isset($_POST['comment_'.$this->object_id])){ - $cm = $_POST['comment_'.$this->object_id]; - $this->data = "/*".$cm."*/"; - } - } - - function execute() - { - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $Comment = $this->data; - - /* Remove comment tags */ - if(preg_match("/^#/",$Comment)){ - $Comment = preg_replace("/^#/","",$Comment); - }elseif(preg_match("#\/\*#",$Comment)){ - $Comment = preg_replace("#^\/\*#","",$Comment); - $Comment = preg_replace("#\*\/$#","",$Comment); - } - - /* Create html object */ - $smarty = get_smarty(); - $smarty->assign("Comment",$Comment); - $smarty->assign("ID",$this->object_id); - $object = $smarty->fetch(get_template_path("templates/element_comment.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } -} - - -class sieve_require -{ - var $data = array(); - var $object_id = -1; - - function sieve_require($data,$object_id) - { - $this->object_id = $object_id; - foreach($data['ELEMENTS'] as $node ){ - if(in_array($node['class'],array("quoted-string","text"))){ - $this->data[] = preg_replace("/\"/","",$node['text']); - } - } - } - - function save_object() - { - /* Get the values should check for, they are seperated by , */ - if(isset($_POST['require_'.$this->object_id])){ - $vls = stripslashes($_POST['require_'.$this->object_id]); - $tmp = array(); - - $tmp2 = split(",",$vls); - foreach($tmp2 as $val){ - $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\""; - } - $this->data = $tmp; - } - } - - function get_sieve_script_part() - { - $tmp = sieve_create_strings($this->data); - return("require ".$tmp.";\n"); - } - - function execute() - { - $Require = ""; - foreach($this->data as $key){ - $Require .= $key.", "; - } - $Require = preg_replace("/,$/","",trim($Require)); - - $smarty = get_smarty(); - $smarty->assign("Require",$Require); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__))); - $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } -} - -class sieve_discard -{ - var $data = array(); - var $object_id = -1; - - function sieve_discard($data,$object_id) - { - $this->object_id = $object_id; - } - - function get_sieve_script_part() - { - return("discard;\n"); - } - - function save_object() - { - - } - - function execute() - { - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $object = $smarty->fetch(get_template_path("templates/element_discard.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } -} - - - -class sieve_reject -{ - var $data = array(); - var $object_id = -1; - - - function save_object() - { - if(isset($_POST['reject_message_'.$this->object_id])){ - $msg = stripslashes($_POST['reject_message_'.$this->object_id]); - - $this->data = $msg; - } - } - - function sieve_reject($data,$object_id) - { - $this->object_id = $object_id; - $str = ""; - foreach($data['ELEMENTS'] as $node ){ - if(in_array($node['class'],array("quoted-string","text","multi-line"))){ - - if($node['class'] == "multi-line"){ - $str .= preg_replace("/^text:[ \n\r]*/","",$node['text']); - $str = preg_replace("/[ \n\r]*\.[ \n\r]*$/","",$str); - }else{ - $str .= $node['text']; - } - } - } - $this->data = preg_replace("/\"/","",$str); - } - - function get_sieve_script_part() - { - return("reject ".sieve_create_strings($this->data).";\n"); - } - - function execute() - { - /* check if this will be a - * - single string "" - * - or a multi line text: ... ; - */ - $Multiline = preg_match("/\n/",$this->data); - - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $smarty->assign("Message",$this->data); - $smarty->assign("Multiline",$Multiline); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $object= $smarty->fetch(get_template_path("templates/element_reject.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } -} - -class sieve_redirect -{ - var $data = array(); - var $object_id = -1; - - function save_object() - { - if(isset($_POST['redirect_to_'.$this->object_id])){ - $rt = stripslashes($_POST['redirect_to_'.$this->object_id]); - - $rt = "\"".trim(preg_replace("/\"/","",$rt))."\""; - $this->data = $rt; - } - } - - - function sieve_redirect($data,$object_id) - { - foreach($data['ELEMENTS'] as $node ){ - if(in_array($node['class'],array("quoted-string","text"))){ - $this->data = $node['text']; - } - } - } - - - function get_sieve_script_part() - { - return("redirect ".sieve_create_strings($this->data).";\n"); - } - - - function execute() - { - $values = $this->data; - - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $smarty->assign("Destinations" , $values); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $object= $smarty->fetch(get_template_path("templates/element_redirect.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } -} - -class sieve_fileinto -{ - var $data = array(); - var $object_id= -1; - var $options = array(); - - function save_object() - { - $mbs = $this->get_mail_boxes(); - - if(isset($_POST['fileinto_'.$this->object_id])){ - $mb = $_POST['fileinto_'.$this->object_id]; - - if(isset($mbs[$mb])) { - $this->data[0] = $mb; - } - } - } - - function sieve_fileinto($data,$object_id) - { - $this->object_id = $object_id; - foreach($data['ELEMENTS'] as $node ){ - if(in_array($node['class'],array("quoted-string","text"))){ - $this->data[] = preg_replace("/\"/","",$node['text']); - } - } - } - - function get_sieve_script_part() - { - $tmp = ""; - foreach($this->data as $dat){ - $tmp.= "\"".$dat."\", "; - } - $tmp = preg_replace("/,$/","",trim($tmp)); - $tmp = preg_replace ("/\"\"/","\"",$tmp); - return("fileinto ".$tmp.";\n"); - } - - function execute() - { - $smarty = get_smarty(); - $smarty->assign("Selected",$this->data[0]); - $smarty->assign("Boxes", $this->get_mail_boxes()); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } - - function get_mail_boxes() - { - return(array("not"=>"not","impplemented/yet"=>"impplemented/yet")); - } -} - -class sieve_vacation -{ - var $days = FALSE; - var $subject = FALSE; - var $from = ""; - var $mime = ""; - var $handle = ""; - var $reason = ""; - var $addresses= array(); - var $object_id= -1; - var $Expert = FALSE; - - function sieve_vacation($data,$object_id) - { - /* Usage: vacation [":days" number] [":subject" string] - [":from" string] [":addresses" string-list] - [":mime"] [":handle" string] */ - - /* Not all attribute types are supported by the sieve class right now */ - $known_attrs = array(":days",":subject",":from",":mime",":handle"); - - /* Walk through elements */ - for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){ - - /* get current element */ - $node = $data['ELEMENTS'][$i]; - - /* Check if tag is in the specified list of attributes */ - if($node['class'] == "tag" && in_array($node['text'],$known_attrs)){ - - $var = preg_replace("/\:/","",$node['text']); - $this->$var = $data['ELEMENTS'][$i+1]['text']; - $i ++; - } - - /* Check for addresses */ - if($node['class'] == "tag" && $node['text'] == ":addresses") { - $this->addresses = array(); - $i ++; - - /* Multiple or single address given */ - if($data['ELEMENTS'][$i]['class'] == "left-bracket"){ - while($data['ELEMENTS'][$i]['class'] != "right-bracket" && ($i < count($data['ELEMENTS']))){ - $i ++; - if($data['ELEMENTS'][$i]['class'] == "quoted-string"){ - $this->addresses[] = preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']); - } - } - }else{ - $this->addresses[] = $data['ELEMENTS'][$i]['text'] ; - } - } - - /* Add the vacation message */ - if($node['class'] == "quoted-string"){ - $this->reason = $node['text']; - } - } - } - - function get_sieve_script_part() - { - $str = "vacation "; - if($this->days){ - $str.= ":days ".$this->days; - } - $str .= ":addresses ".sieve_create_strings($this->addresses); - if($this->subject){ - $str.= ":subject ".sieve_create_strings($this->subject); - } - if($this->mime){ - $str.= ":mime ".sieve_create_strings($this->mime); - } - $str .= "\n ".sieve_create_strings($this->reason); - return($str." ; \n"); - } - - - function save_object() - { - /* Get release date */ - if(isset($_POST['vacation_release_'.$this->object_id])){ - $this->days = $_POST['vacation_release_'.$this->object_id]; - } - - /* Check if we want to toggle the expert mode */ - if(isset($_POST['Toggle_Expert_'.$this->object_id])){ - $this->Expert = !$this->Expert; - } - - /* Get release date */ - if(isset($_POST['vacation_receiver_'.$this->object_id])){ - $vr = stripslashes ($_POST['vacation_receiver_'.$this->object_id]); - $tmp = array(); - $tmp2 = split(",",$vr); - foreach($tmp2 as $val){ - $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\""; - } - $this->addresses = $tmp; - } - - /* Get reason */ - if(isset($_POST['vacation_reason_'.$this->object_id])){ - $vr = stripslashes ($_POST['vacation_reason_'.$this->object_id]); - $this->reason = "\"".trim(preg_replace("/\"/","",$vr))."\""; - } - } - - function execute() - { - $Addresses = ""; - foreach($this->addresses as $key){ - $Addresses .= $key.", "; - } - $Addresses = preg_replace("/,$/","",trim($Addresses)); - $smarty = get_smarty(); - $smarty->assign("Reason",$this->reason); - $smarty->assign("Addresses",$Addresses); - $smarty->assign("Subject",$this->subject); - $smarty->assign("Days",$this->days); - $smarty->assign("ID",$this->object_id); - $smarty->assign("Expert",$this->Expert); - return($smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__)))); - } -} - -class sieve_block_start -{ - function execute() - { - $smarty = get_smarty(); - return($smarty->fetch(get_template_path("templates/element_block_start.tpl",TRUE,dirname(__FILE__)))); - } - - function save_object() - { - } - - function get_sieve_script_part() - { - return("{\n"); - } -} - -class sieve_block_end -{ - function execute() - { - $smarty = get_smarty(); - return($smarty->fetch(get_template_path("templates/element_block_end.tpl",TRUE,dirname(__FILE__)))); - } - function get_sieve_script_part() - { - return("}\n"); - } - function save_object() - { - } - -} - -/* This class handles the keep statement */ -class sieve_keep -{ - var $object_id = -1; - - function sieve_keep($data,$object_id) - { - $this->object_id = $object_id; - } - - function save_object() - { - } - - function execute() - { - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $object = $smarty->fetch(get_template_path("templates/element_keep.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } - function get_sieve_script_part() - { - return("keep;\n"); - } - -} - -/* This class handles the stop statement */ -class sieve_stop -{ - var $object_id = -1; - - function sieve_stop($data,$object_id) - { - $this->object_id = $object_id; - } - - function save_object() - { - } - - function execute() - { - $smarty = get_smarty(); - $smarty->assign("ID", $this->object_id); - $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__))); - $object= $smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__))); - $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container); - return($str); - } - - function get_sieve_script_part() - { - return("stop; \n"); - } - -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index da36074a0..fdce9e31c 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -204,9 +204,15 @@ class sieveManagement extends plugin /* Save currently edited sieve script. */ if(isset($_POST['save_sieve_changes'])){ - $this->scripts[$this->current_script]['PARSER'] = $this->current_handler; - $this->scripts[$this->current_script]['EDITED'] = TRUE; - $this->current_handler = NULL; + $chk = $this->current_handler->check(); + if(!count($chk)){ + $this->scripts[$this->current_script]['PARSER'] = $this->current_handler; + $this->scripts[$this->current_script]['EDITED'] = TRUE; + $this->current_handler = NULL; + }else{ + print_a($chk); + print_red(_("Please fix all errors before saving.")); + } } /* Create output for currently opened sieve script */ diff --git a/include/sieve/templates/element_address.tpl b/include/sieve/templates/element_address.tpl index 80e4384ab..853e16190 100755 --- a/include/sieve/templates/element_address.tpl +++ b/include/sieve/templates/element_address.tpl @@ -1,6 +1,24 @@ +{if $LastError != ""} + + + + + +
+ {t}Error{/t} + +{/if} + {if $Expert} + {if $LastError != ""} + + + + + {/if} + {else} + {if $LastError != ""} + + + + + {/if} {/if}
+ {$LastError} +
{t}Match type{/t} @@ -75,6 +93,14 @@
+ {$LastError} +
{t}If{/t} @@ -107,3 +133,9 @@
+{if $LastError != ""} + +
+{/if} diff --git a/include/sieve/templates/element_envelope.tpl b/include/sieve/templates/element_envelope.tpl index c99cfdd3c..6bc8e2351 100755 --- a/include/sieve/templates/element_envelope.tpl +++ b/include/sieve/templates/element_envelope.tpl @@ -1,6 +1,26 @@ + +{if $LastError != ""} + + + + + +
+ {t}Error{/t} + +{/if} + {if $Expert} + {if $Expert} + {if $LastError != ""} + + + + + {/if} + {else} + {if $LastError != ""} + + + + + {/if} {/if}
+ {$LastError} +
{t}Match type{/t} @@ -67,6 +87,14 @@
+ {$LastError} +
{t}If{/t} @@ -99,3 +127,9 @@
+{if $LastError != ""} + +
+{/if} diff --git a/include/sieve/templates/element_header.tpl b/include/sieve/templates/element_header.tpl index 748345418..a96a78229 100755 --- a/include/sieve/templates/element_header.tpl +++ b/include/sieve/templates/element_header.tpl @@ -1,5 +1,24 @@ + +{if $LastError != ""} + + + + + +
+ {t}Error{/t} + +{/if} + {if $Expert} + {if $LastError != ""} + + + + + {/if} + {else} + {if $LastError != ""} + + + + + {/if}
+ {$LastError} +
@@ -68,6 +87,14 @@
+ {$LastError} +
{t}If{/t} @@ -101,3 +128,9 @@ {/if}
+{if $LastError != ""} + +
+{/if} diff --git a/include/sieve/templates/element_redirect.tpl b/include/sieve/templates/element_redirect.tpl index 0cac45fe6..bf624d913 100644 --- a/include/sieve/templates/element_redirect.tpl +++ b/include/sieve/templates/element_redirect.tpl @@ -1,8 +1,22 @@ +{if $LastError != ""} + + + + + +
+ {t}Error{/t} + +{/if} + @@ -11,3 +25,10 @@
{t}Redirect{/t} {t}Redirect mail to following recipients{/t} +   + {if $LastError != ""} +
+ {$LastError} + {/if}
+ +{if $LastError != ""} + +
+{/if} diff --git a/include/sieve/templates/element_require.tpl b/include/sieve/templates/element_require.tpl index 761e636b0..b4d74ff4d 100644 --- a/include/sieve/templates/element_require.tpl +++ b/include/sieve/templates/element_require.tpl @@ -1,4 +1,22 @@ +{if $LastErrorCnt != 0} + + + + + +
+ {t}Error{/t} + +{/if} + + + {foreach from=$LastError item=val key=key} + + + + + {/foreach}
+ {$LastError[$key]} +
{t}Require{/t} @@ -10,3 +28,11 @@
+ +{if $LastErrorCnt != 0} + +
+{/if} + -- 2.30.2