Code

Added FAIstate to faiManagement
[gosa.git] / plugins / addons / mailqueue / class_parseMailQueue.inc
index 49c78752a0696d64c4d8894c024c06b933789bdf..b510cb3a7922294a90df9393a88cbb1cbf2efade 100644 (file)
@@ -9,17 +9,28 @@ class parseMailQueue
   /* Contructor
    * $s_data specifies the data that shuold be parse
    */
-       function parseMailQueue($s_data)
+       function parseMailQueue($s_data,$server)
        {
     $this->s_dataToParse = $s_data;            
-         $this->_parse();
+         $this->a_parsedData = array();
+    $this->_parse($s_data,$server);
   }
 
+
+  /* Remove all entries which are older than the last x hours
+   */
   function OnlyDaysAgo($str)
   {
+    /* Get current time */
     $cur = time();
-    if(is_numeric($str)){
-      $cur = $cur - ($str*(60*60*24));
+  
+    /* Only perform this filter, if the given parameter is valid */
+    if((is_numeric($str))&&($str != 0)){
+
+      /* hours are given as parameter */
+      $cur = $cur - ($str*(60*60));
+
+      /* Remove old entries */
       foreach($this->a_parsedData as $key => $data){
         if($data['Arrival'] < $cur){
           unset($this->a_parsedData[$key]);
@@ -28,22 +39,34 @@ class parseMailQueue
     }
   }
 
-  function Search($filter,$fields)
+
+  /* Only keep entries that contains the $filter
+   * in any of the given $fields
+   */
+  function Search($filter,$fields,$bool = false)
   {
+    /* Go through all entries */
     foreach($this->a_parsedData as $key => $data){
+
+      /* not found yet */
       $found = false;
 
       foreach($fields as $attr){
-        if(preg_match("/".str_replace("*",".*",$filter)."/i",$data[$attr])){
+        if(($bool)&&($data[$attr]==$filter)){
+          $found = true;
+        }elseif(preg_match("/".str_replace("*",".*",$filter)."/i",$data[$attr])){
           $found= true;
         }
       }
+  
+      /* if nothing found, delete this entry */
       if($found == false){
         unset($this->a_parsedData[$key]);
       }
     }
   }
 
+  /* Convert date from timestamp to human readable */
   function CreateDate()
   {
     foreach($this->a_parsedData as $key => $data){
@@ -51,25 +74,29 @@ class parseMailQueue
     }
   }
 
+  /* Order by specified field */
   function OrderBy($str = "Arrival",$type = "up" )
   {
     $tmp = array();
-    if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error"))){
+    /* If the given field is not valid */
+    if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error","Server"))){
       return(false);
     }
 
+    /* Size need special handling, cause it contains numbers 
+     */
     if($str == "Size"){
       foreach($this->a_parsedData as $data){
         $struse = "";
         for($i = strlen($data['Size']); $i < 10 ; $i++  ){
           $struse .="0";
         }
-        $struse .= $data[$str].$data['MailID'];
+        $struse .= $data[$str].$data['MailID'].$data['Server'];
         $tmp[$struse]= $data;
       }
     }else{
       foreach($this->a_parsedData as $data){
-        $tmp[strtolower($data[$str]).$data['MailID']]= $data;
+        $tmp[strtolower($data[$str]).$data['MailID']."-".$data['Server']]= $data;
       }
     } 
     ksort($tmp);
@@ -78,8 +105,9 @@ class parseMailQueue
     }
     $this->a_parsedData = array();
     foreach($tmp as $data){
-      $this->a_parsedData[$data['MailID']] = $data;
+      $this->a_parsedData[$data['MailID']."-".$data['Server']] = $data;
     }
+    return(true);
   }
   
   function GetAll()
@@ -87,15 +115,24 @@ class parseMailQueue
     return($this->a_parsedData);
   }
 
+  /* Checks if the given MailID exists */
   function IDExists($id)
   {
-    return(((isset($this->a_parsedData[$id]))&&(is_array($this->a_parsedData[$id]))));
+    foreach($this->a_parsedData as $entry){
+      if($entry['MailID'] == $id) return(true);
+    }
+    return(false);
+  }
+
+  function parseAdditionalQueue($str, $server)
+  {
+    $this->_parse($str, $server);
   }
 
   /* This function parses the given data 
    * it creates an array with all given queue entries
    */
-  function _parse()
+  function _parse($str, $server)
   {
     $i              =  0;       // Temp var 
     $entries        = array();  // Contains an array with the raw data for every single entry
@@ -110,7 +147,7 @@ class parseMailQueue
 
     /* Remove header
      */
-    $this->s_dataToParse = preg_replace("/^.*------\n/","",$this->s_dataToParse);
+    $this->s_dataToParse = preg_replace("/^.*------\n/","",$str);
 
     /* Create array with single entries
      */
@@ -145,16 +182,42 @@ class parseMailQueue
       $s_Error      = $s_buffer[1];
       $s_Recipient  = $s_buffer[2];
 
-      $this->a_parsedData[$s_mailID]['MailID']     = $s_mailID; 
-      $this->a_parsedData[$s_mailID]['Size']       = $s_Size; 
-      $this->a_parsedData[$s_mailID]['Arrival']    = $s_Arrival; 
-      $this->a_parsedData[$s_mailID]['Sender']     = $s_Sender; 
-      $this->a_parsedData[$s_mailID]['Recipient']  = $s_Recipient; 
-      $this->a_parsedData[$s_mailID]['Error']      = $this->_parseError($s_Error); 
+      /*
+              *      The message is in the active queue, i.e. the  message  is
+                     selected for delivery.
+
+              !      The  message is in the hold queue, i.e. no further deliv-delivery
+                     ery attempt will be made until  the  mail  is  taken  off
+                     hold.
+      */
+
+      $s_Hold = false;
+      if(preg_match("/\!/",$s_mailID)){
+        $s_mailID = preg_replace("/\!/","",$s_mailID);
+        $s_Hold = "true";
+      }
+      
+      $s_Active = false;
+      if(preg_match("/\*/",$s_mailID)){
+        $s_mailID = preg_replace("/\*/","",$s_mailID);
+        $s_Active = true;
+      }
+
+      /* Append data */
+      $this->a_parsedData[$s_mailID."-".$server]['Server']     = $server; 
+      $this->a_parsedData[$s_mailID."-".$server]['MailID']     = $s_mailID; 
+      $this->a_parsedData[$s_mailID."-".$server]['Size']       = $s_Size; 
+      $this->a_parsedData[$s_mailID."-".$server]['Arrival']    = $s_Arrival; 
+      $this->a_parsedData[$s_mailID."-".$server]['Sender']     = $s_Sender; 
+      $this->a_parsedData[$s_mailID."-".$server]['Recipient']  = $s_Recipient; 
+      $this->a_parsedData[$s_mailID."-".$server]['Hold']       = $s_Hold; 
+      $this->a_parsedData[$s_mailID."-".$server]['Active']     = $s_Active; 
+      $this->a_parsedData[$s_mailID."-".$server]['Error']      = $this->_parseError($s_Error); 
     }
     return($this->a_parsedData);
   }
 
+  /* Parse Error part of the entry */
   function _parseError($str)
   {
     $str   = trim(preg_replace("/[()]/","",$str));