Code

Mailqueue addon
[gosa.git] / gosa-plugins / mail / addons / mailqueue / class_si_mailqueue.inc
1 <?php
3 /*! \brief  This is the opsi base class, it handles
4   .          gosa daemon requests and prepares data for opsi plugins.
5  */
6 class si_mailqueue extends gosaSupportDaemon
7 {
8   private $config = NULL;
9   protected $use_alternative_xml_parse_method = TRUE;
11   /*! \brief    Create opsi object.
12     @param
13     @return
14    */
15   public function __construct($config)
16   {
17     $this->config = $config;
18     gosaSupportDaemon::__construct($config);
19     $this->target = "00:01:6c:9d:b9:fa";
20   }
22     
23   /*! \brief  Returns TRUE or FALSE, whether the plugin is enabled or disabled .
24       @return Boolean  s.a.
25    */
26   public function enabled()
27   {
28     return(TRUE);
29   }
32   /*! \brief  Returns a list of all mail queue entries 
33       @return Array   s.a.
34    */
35   public function query_mailqueue($server,$sortby,$direction,$search_str,$time)
36   {
37     $attrs = array("Size","Recipient","Sender","Arrival","MailID","Hold","Active","Error","Server");
39     /* Check sorting paramter 
40      */
41     if(!in_array($sortby,$attrs)){
42       trigger_error("Invalid sorting option '".$sortby."'.");
43       $sortby = "Arrival";
44     }
46     /* Check sorting direction 
47      */
48     if(!in_array($direction,array("down","up"))){
49       trigger_error("Invalid sorting direction '".$direction."'.");
50       $direction = "down";
51     }
53     /* Prepare search filter 
54      */
55     $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($search_str));
57     /* Query mailqueue 
58      */
59     $ids = array();
60     $res = $this->send_data("gosa_mailqueue_query",$server,array(),TRUE);
61     $items = array(); 
62     if(isset($res['XML'][0])){
63       foreach($res['XML'][0] as $name => $entry){
65         if(preg_match("/^ANSWER[0-9]*$/",$name)){
66           $attrs = array(
67               "MSG_SIZE"      => "Size",
68               "RECIPIENT"     => "Recipient",
69               "SENDER"        => "Sender",
70               "ARRIVAL_TIME"  => "Arrival",
71               "MSG_ID"        => "MailID");  
72           $val = array();
73           foreach($attrs as $source => $dest){
74             $val[$dest] = $entry[0][$source][0]['VALUE'];
75           }
76           $ids[] = $val['MailID'];
77           $attrs = array(  
78               "MSG_HOLD"   => "Hold",
79               "MSG_ACTIVE" => "Active",
80               "ERROR"      => "Error");
81           foreach($attrs as $source => $dest){
82             if(isset($entry[0][$source][0]['VALUE'])){
83               $val[$dest] = $entry[0][$source][0]['VALUE'];
84             }else{
85               $val[$dest] = FALSE;
86             }
87           }
89           $val['Server'] = $server;
90           $val['Arrival'] = strtotime($val['Arrival']);
92           /* Check arrival time.
93            */
94           if($time != -1 && !empty($val['Arrival'])){
95             if( ! ($val['Arrival'] > (time() - $time))){
96               continue;
97             }
98           }
100           /* Check if search string matches 
101            */
102           $found = FALSE;
103           foreach($val as $name => $value){
104             if(preg_match("/^".$search_str."$/",$value)){
105               $found =TRUE;
106               break;
107             }
108           }
109        
110           if($found){ 
111             $n = uniqid($val[$sortby]);
112             $items[$n] = $val;
113           }
114         }
115       }
116     }   
118     /* Sort entries by given direction 
119      */
120     if($direction == "down"){
121       ksort($items);
122     }else{
123       krsort($items);
124     }
125     return($items);
126   }
129   public function header($msg_id, $server)
130   {
131     $data = array();
132     $data['msg_id'] = $msg_id;
133     $res = $this->send_data("gosa_mailqueue_header",$server,$data,TRUE);
134     if(isset($res['XML'][0]['MSG_HEADER'][0]['VALUE'])){
135       return($res['XML'][0]['MSG_HEADER'][0]['VALUE']);
136     }
137     return("");
138   }
140  
141   /*! \brief  Returns a list of all mail queue entries 
142       @return Array   s.a.
143    */
144   public function send_queue_action($msg_ids,$server, $action)
145   {
146     $data = array();
148     /* Check given msg_ids, must be array.
149      */
150     if(!is_array($msg_ids)){
151       trigger_error("Invalid msg_id given. Array expected.");
152       return(FALSE);
153     }
155     /* Check triggered action 
156      */
157     $allowed_actions = array("hold","unhold","requeue","del");
158     if(!in_array($action,$allowed_actions)){
159       trigger_error("Unknown queue action triggered '".$action."'. Request aborted.");  
160       return(FALSE);
161     }    
162     
163     $data['msg_id'] = $msg_ids;
165     print_a(array("gosa_mailqueue_".$action,$server,$data));;
166     $this->send_data("gosa_mailqueue_".$action,$server,$data,FALSE);
167     // There is no answer for this requests 
168   }
170 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
171 ?>