index 8f9a5ec404390c2ecb5ff013c360b2efe2331a86..99f170df244e134473815505e191704b24f9c672 100644 (file)
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;
+ $this->object_id = $object_id;
+
/* Possible address parts we can select */
$this->address_parts = array(
":all" => _("Complete adress")." ("._("Default").")",
/* Match types */
$this->match_types = array(
":is" => _("is"),
+ ":regex" => _("regex"),
":contains" => _("contains"),
":matches" => _("matches"),
":count" => _("count"),
"gt" => _("greater than"),
"ne" => _("not equal"));
- $this->object_id = $object_id;
- if($elements!=NULL){
- $this->elements = $elements;
- $this->_parsed = $this->_parse($elements['ELEMENTS'],1);
+ /* Skip parsing if this element is new */
+ if($elements != NULL){
+
+ /* Remove comments from tests */
+ $tmp = array();
+ foreach($elements['ELEMENTS'] as $ele){
+ if($ele['class'] != "comment"){
+ $tmp[] = $ele;
+ }
+ }
+ $elements['ELEMENTS'] = $tmp;
+
+ if($elements!=NULL){
+ $this->elements = $elements;
+ $this->_parsed = $this->_parse($elements['ELEMENTS'],1);
+ }
}
}
*/
function get_sieve_script_part()
{
- $tmp = "if ".$this->get_sieve_script_part_recursive($parsed = NULL,$id = 1,$obj_id=1);
+ $tmp = $this->TYPE." ".$this->get_sieve_script_part_recursive($parsed = NULL,$id = 1,$obj_id=1);
return($tmp);
}
}
break;
}
+
+ /*******************
+ * True / False
+ *******************/
+
+ case "true" :
+ case "false" :
+ {
+ /* Can't fail anyway */
+ break;
+ }
/*******************
* Default
{
if(isset($data['LastError']) && !empty($data['LastError'])){
$ret[] = $data['LastError'];
-
- echo "'".$data['LastError']."' ".$key."<br>" ;
}
}
}
$parsed = $this->_parsed;
}
+
+ if(!is_array($parsed)){
+ return;
+ }
+
/* Walk through all elements */
foreach($parsed as $key => $data){
}
/* Add allof/anyof tag */
- $script.= " ".$key." ( ";
+ if($Inverse){
+ $script .= "not ";
+ }
+ $script.= $key." ( ";
/* Add each test parameter */
foreach($data as $key2 => $dat){
"LastError" => "",
"Match_type" => ":contains",
"Match_type_value"=> "",
- "Key_List" => array("emtpy"),
- "Value_List" => array("empty")) ;
+ "Key_List" => array(_("emtpy")),
+ "Value_List" => array(_("empty"))) ;
if($type == "address"){
$values["Address_Part"] = ":all";
}
$data[$type]=$values;
+
+ $this->parent->add_require("relational");
+ if($type == "envelope"){
+ $this->parent->add_require("envelope");
+ }
+
+
break;
}
case "allof" :
$data[$type] = array("Inverse" => FALSE);
break;
}
-
+ case "size" :
+ {
+ $tmp= array(
+ "Inverse" => FALSE,
+ "Match_type" => ":over",
+ "Value_List" => array("1M"));
+
+ $tmp['LastError'] = "";
+ $data[$type] = $tmp;
+ break;
+ }
+ case "true":
+ {
+ $data['true'] = "true";
+ $data['true']['LastError'] = "";
+ break;
+ }
+ case "false":
+ {
+ $data['false'] = "false";
+ $data['false']['LastError'] = "";
+ break;
+ }
+ case "exists" :
+ {
+ $data['exists'] = array('Inverse' => FALSE,
+ 'Values' => array(_("Nothing specified right now")),
+ 'LastError' => "");
+ break;
+ }
+ default : echo "Still buggy ";exit;
}
return($data);
if(!isset($match_types[$mt])){
$parsed[$key]['LastError'] = _("Invalid match type given.");
}
+ if($mt == ":regex"){
+ $this->parent->add_require("regex");
+ }
$parsed[$key]['Match_type'] = $mt;
}
$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
$Match_types = array( ":over" => _("greater than") ,
":under" => _("lower than"));
- $Units = array( "M" => _("Megabyte") ,
- "K" => _("Kilobyte"));
+ $Units = array( "M" => _("Megabyte"),
+ "K" => _("Kilobyte"),
+ "" => _("Bytes"));
+
+ /* Toggle Inverse ? */
+ if(isset($_POST['toggle_inverse_'.$element_id])){
+ $parsed[$key]['Inverse'] = !$parsed[$key]['Inverse'];
+ }
/* Reset error */
- $parsed['size']['LastError'] ="";
+ $parsed[$key]['LastError'] ="";
/* Get match type */
if(isset($_POST['Match_type_'.$element_id])){
$mt = $_POST['Match_type_'.$element_id];
if(!isset($Match_types[$mt])){
- $parsed['size']['LastError'] = _("Please select a valid match type in the list box below.");
+ $parsed[$key]['LastError'] = _("Please select a valid match type in the list box below.");
}
+ $parsed[$key]['Match_type'] = $mt;
}
/* Get old values */
- $value = preg_replace("/[^0-9]*$/","",$parsed['size']['Value_List'][0]);
- $unit = preg_replace("/^[0-9]*/","",$parsed['size']['Value_List'][0]);
+ $value = preg_replace("/[^0-9]*$/","",$parsed[$key]['Value_List'][0]);
+ $unit = preg_replace("/^[0-9]*/","",$parsed[$key]['Value_List'][0]);
/* Get value */
if(isset($_POST['Value_'.$element_id])){
$vl = $_POST['Value_'.$element_id];
if(!(is_numeric($vl) && preg_match("/^[0-9]*$/",$vl))){
- $parsed['size']['LastError'] = _("Only numeric values are allowed here.");
+ $parsed[$key]['LastError'] = _("Only numeric values are allowed here.");
}
- $value = $vl;
+ $value = preg_replace("/[^0-9]/","",$vl);
}
/* Get unit */
$ut = $_POST['Value_Unit_'.$element_id];
if(!isset($Units[$ut])){
- $parsed['size']['LastError'] = _("No valid unit selected");
+ $parsed[$key]['LastError'] = _("No valid unit selected");
}
$unit = $ut;
- }
-
- $parsed['size']['Value_List'][0] = $value.$unit;
+ }
+ $parsed[$key]['Value_List'] = array();
+ $parsed[$key]['Value_List'][0] = $value.$unit;
break;
}
$name .= "<b>"._("Condition")."</b>";
if($this->TYPE == "if"){
$name .= " - "._("If");
+ }elseif($this->TYPE == "elsif"){
+ $name .= " - "._("Else if");
}else{
$name .= " - "._("Else");
}
$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);
+
+ if($this->TYPE == "if"){
+ $object = $smarty->fetch(get_template_path("templates/element_if.tpl",TRUE,dirname(__FILE__)));
+ }else{
+ $object = $smarty->fetch(get_template_path("templates/element_elsif.tpl",TRUE,dirname(__FILE__)));
+ }
+ $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
return($str);
}
$values .= $key.", ";
}
$values = preg_replace("/,$/","",trim($values));
+
$smarty->assign("keys",$keys);
- $smarty->assign("values",$values);
+ $smarty->assign("values", $values);
$smarty->assign("ID" , $element_id);
- $ret .= $smarty->fetch(get_template_path("templates/element_address.tpl",TRUE,dirname(__FILE__)));
+ $str = $smarty->fetch(get_template_path("templates/element_address.tpl",TRUE,dirname(__FILE__)));
+ $ret .= $str;
break;
}
$Match_types = array( ":over" => _("greater than") ,
":under" => _("lower than"));
- $Units = array( "M" => _("Megabyte") ,
- "K" => _("Kilobyte"));
+ $Units = array( "M" => _("Megabyte"),
+ "K" => _("Kilobyte"),
+ "" => _("Bytes"));
$Match_type = $data['Match_type'];
$Value = preg_replace("/[^0-9]/","",$data['Value_List'][0]);
}
$Contents .= $this->get_as_html($dat, ($id +1),$key."-".$obj_id);
}
+
$smarty = get_smarty();
- $smarty->assign("Inverse",$Inverse);
- $smarty->assign("Contents",$Contents);
$smarty->assign("ID" , $element_id);
- $tmp = $smarty->fetch(get_template_path("templates/element_allof.tpl",TRUE,dirname(__FILE__)));
-
$smarty->assign("DisplayAdd",TRUE);
$smarty->assign("DisplayDel",FALSE);
- $str = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
- $ret .= preg_replace("/%%OBJECT_CONTENT%%/",$tmp,$str);
+ $cont_tmp = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
+ $cont_tmp = preg_replace("/%%OBJECT_CONTENT%%/",_("Click here to add a new test"),$cont_tmp);
+
+ $smarty->assign("Inverse",$Inverse);
+ $smarty->assign("Contents",$cont_tmp.$Contents);
+ $smarty->assign("ID" , $element_id);
+ $allof_tmp = $smarty->fetch(get_template_path("templates/element_allof.tpl",TRUE,dirname(__FILE__)));
+ $ret = $allof_tmp;
break ;
}
$Contents .= $this->get_as_html($dat, ($id +1),$key."-".$obj_id);
}
$smarty = get_smarty();
- $smarty->assign("Inverse",$Inverse);
- $smarty->assign("Contents",$Contents);
$smarty->assign("ID" , $element_id);
- $tmp = $smarty->fetch(get_template_path("templates/element_anyof.tpl",TRUE,dirname(__FILE__)));
-
$smarty->assign("DisplayAdd",TRUE);
$smarty->assign("DisplayDel",FALSE);
- $str = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
- $ret .= preg_replace("/%%OBJECT_CONTENT%%/",$tmp,$str);
+ $cont_tmp = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
+ $cont_tmp = preg_replace("/%%OBJECT_CONTENT%%/",_("Klick here to add a new test"),$cont_tmp);
+
+ $smarty->assign("Inverse",$Inverse);
+ $smarty->assign("Contents",$cont_tmp.$Contents);
+ $allof_tmp = $smarty->fetch(get_template_path("templates/element_anyof.tpl",TRUE,dirname(__FILE__)));
+
+ $ret = $allof_tmp;
break ;
}
default :
{
- $ret = "<table width='100%' cellspacing=0 cellpadding=0>
- <tr>
- <td style='background-color: #FEDCA9 ; border: solid 1px #EEEEEE'>";
- $ret.= $key."<br>";
- $ret.= " </td>
- </tr>
- </table>";
+ trigger_error(_("Unhandled switch type"));
}
}
}
}
$smarty->assign("ID",$element_id);
- $smarty->assign("DisplayAdd",TRUE);
+ $smarty->assign("DisplayAdd",FALSE);
$smarty->assign("DisplayDel",TRUE);
$str = $smarty->fetch(get_template_path("templates/object_test_container.tpl",TRUE,dirname(__FILE__)));
- $ret = preg_replace("/%%OBJECT_CONTENT%%/",$ret,$str);
+ $ret = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($ret,"\\"),$str);
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");
+ $av_match_type = array();
+ foreach($this->match_types as $name => $description){
+ $av_match_type[] = $name;
+ }
+ $av_match_type[] = ":over";
+ $av_match_type[] = ":under";
+
+
+
+ $av_methods= array("address","allof","anyof","exists","false","header","not","size","true","envelope");
$type = $data[$id]['text'];
$tmp = array();
$part = "(:all|:localpart|:domain)";
- $operator = "(:contains|:is|:matches|:count|:value)";
+ $operator = "(:regex|:contains|:is|:matches|:count|:value)";
$value_op = "(lt|le|eq|ge|gt|ne)";
$Address_Part = "";