Code

Added simple direct add of sieve elements.
[gosa.git] / include / sieve / class_sieveElement_Fileinto.inc
index 1c1707ef45d4b64bf7f36734bb2e305f00216d15..f357d37d96d961bd4e1ea2065d8468deb9f985b8 100644 (file)
@@ -2,7 +2,7 @@
 
 class sieve_fileinto 
 {
-  var $data     = array();
+  var $data     = "";
   var $object_id= -1;
   var $options  = array();
   var $parent   = NULL;
@@ -13,8 +13,7 @@ class sieve_fileinto
     $mbs = $this->get_mail_boxes();
     
     if(isset($_POST['fileinto_'.$this->object_id])){
-      $mb = $_POST['fileinto_'.$this->object_id];
-
+      $mb = stripslashes($_POST['fileinto_'.$this->object_id]);
 
       /* Depending on the user mode we only accept 
        *  existing mailboxes 
@@ -38,6 +37,7 @@ class sieve_fileinto
   {
     $this->object_id = $object_id;
     $this->parent = $parent;
+    $this->parent->add_require("fileinto");
 
     $mbs = $this->get_mail_boxes();
       
@@ -46,10 +46,14 @@ class sieve_fileinto
       $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => $mbs[key($mbs)])));
     }
 
-    /* Set mailbox */
-    foreach($data['ELEMENTS'] as $node ){
-      if(in_array($node['class'],array("quoted-string","text"))){
-        $this->data = preg_replace("/\"/","",$node['text']);
+    /* Load element contents, should normaly be only one string 
+     *  but if we found more than one, just append the following strings.
+     */
+    for($i = 0 ; $i < count($data['ELEMENTS']) ; $i++){
+      $tmp = sieve_get_strings($data['ELEMENTS'],$i);
+      $i  = $i + $tmp['OFFSET'];
+      foreach($tmp['STRINGS'] as $str){
+        $this->data .= $str;
       }
     }
 
@@ -64,22 +68,22 @@ class sieve_fileinto
   function get_sieve_script_part()
   {
     $tmp = "";
-      $tmp.= "\"".$this->data."\", ";
+    $tmp.= "\"".$this->data."\", ";
     $tmp = preg_replace("/,$/","",trim($tmp));
     $tmp = preg_replace ("/\"\"/","\"",$tmp);
-    return("fileinto ".$tmp.";\n");
+    return("fileinto ".$tmp.";");
   } 
     
   function execute()
   {
     $smarty = get_smarty();
-    $smarty->assign("Selected",$this->data);
+    $smarty->assign("Selected",htmlentities($this->data));
     $smarty->assign("Boxes", $this->get_mail_boxes());
     $smarty->assign("User_Mode", $this->user_mode);
     $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);
+    $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
 
     return($str);
   }