Code

Heimdal stuff not needed. It's too insecure to read m-keys by php.
[gosa.git] / include / sieve / class_sieveElement_Vacation.inc
index 95e6ef216e45d965c9a42bd2e0500055c8b61c6e..43c7546377215877efee4065959c00d61d3a8980 100644 (file)
@@ -7,13 +7,18 @@ class sieve_vacation
   var $from     = "";
   var $mime     = "";
   var $handle   = "";
-  var $reason   = "";
+  var $reason   = "\"I am not available, currently.\"";
   var $addresses= array();
   var $object_id= -1;
   var $Expert   = FALSE;
+  var $parent   = NULL;
 
-  function sieve_vacation($data,$object_id)
+  function sieve_vacation($data,$object_id,$parent)
   {
+    $this->parent = $parent;
+    $this->object_id = $object_id;
+    $this->parent->add_require("vacation");
+
     /* Usage:   vacation [":days" number] [":subject" string]
        [":from" string] [":addresses" string-list]
        [":mime"] [":handle" string] <reason: string> */
@@ -21,8 +26,12 @@ class sieve_vacation
     /* Not all attribute types are supported by the sieve class right now */
     $known_attrs = array(":days",":subject",":from",":mime",":handle");
 
+    /* skip if empty */
+    if(($data === NULL) || !is_array($data)) return;
+
     /* Walk through elements */
-    for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){
+    $p= count($data['ELEMENTS']);
+    for ($i= 0; $i < $p; $i++){
 
       /* get current element */
       $node = $data['ELEMENTS'][$i];
@@ -49,13 +58,21 @@ class sieve_vacation
             }
           }
         }else{
-              $this->addresses[] = $data['ELEMENTS'][$i]['text'] ;
+              $this->addresses[] =  preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']);
         }
       }
 
       /* Add the vacation message */
-      if($node['class'] == "quoted-string"){
-        $this->reason = $node['text'];
+      if(in_array($node['class'],array("quoted-string","multi-line"))){
+
+        $tmp = sieve_get_strings($data['ELEMENTS'],$i);
+        $strs= $tmp['STRINGS'];
+        $data = ""; 
+        foreach($strs as $str){
+          $data .= $str;
+        }
+        $this->reason = $data;
       }
     }
   }
@@ -66,14 +83,22 @@ class sieve_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(count($this->addresses)){
+      $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);
+  
+    /* Append reason and ensure that this will be 
+     *  handled as multiline text element 
+     *  by adding a "\n" new line 
+     */
+    $str .= "\n ".sieve_create_strings($this->reason."\n");
     return($str." ; \n");
   }
 
@@ -81,7 +106,7 @@ class sieve_vacation
   {
     /* Get release date */
     if(isset($_POST['vacation_release_'.$this->object_id])){
-      $this->days = $_POST['vacation_release_'.$this->object_id];
+      $this->days = stripslashes($_POST['vacation_release_'.$this->object_id]);
     }
 
     /* Check if we want to toggle the expert mode */
@@ -95,7 +120,10 @@ class sieve_vacation
       $tmp = array();
       $tmp2 = split(",",$vr);
       foreach($tmp2 as $val){
-        $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
+        $ad = trim($val);
+        if(!empty($ad)){
+          $tmp[] = $ad;
+        }
       }
       $this->addresses = $tmp;
     }
@@ -103,13 +131,23 @@ class sieve_vacation
     /* Get reason */
     if(isset($_POST['vacation_reason_'.$this->object_id])){
       $vr = stripslashes ($_POST['vacation_reason_'.$this->object_id]);
-      $this->reason = "\"".trim(preg_replace("/\"/","",$vr))."\"";
+      $this->reason = trim($vr);
     }
   }
 
   function check()
   {
-    return(array())  ;
+    $msgs = array();
+    $err = FALSE;
+    foreach($this->addresses as $addr){
+      if(!is_email($addr)){
+        $err = true;
+      }
+    }
+    if($err){
+      $msgs[] = _("Alternative sender address must be a valid email addresses.");
+    }
+    return($msgs);
   }
 
   function execute()
@@ -119,14 +157,21 @@ class sieve_vacation
       $Addresses .= $key.", ";
     }
     $Addresses = preg_replace("/,$/","",trim($Addresses));
+
     $smarty = get_smarty();
+    $smarty->assign("LastError",$this->check());
+    $smarty->assign("LastErrorCnt",count($this->check()));
     $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__))));
+
+    $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
+    $object= $smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__)));
+    $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
+    return($str);
   }
 }