Code

Updated mailqueue text
[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, $Limit)
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     /* Check entry limit 
54      */  
55     if(!is_numeric($Limit) || $Limit < 1){
56       trigger_error("Invalid entry limt '".$Limit."'.");
57       $Limit = 20;
58     }
60     /* Query mailqueue 
61      */
62     $res = $this->send_data("gosa_mailqueue_query",$server,array(),TRUE);
63     $items = array(); 
64     if(isset($res['XML'][0])){
65       foreach($res['XML'][0] as $name => $entry){
66         if(preg_match("/^ANSWER[0-9]*$/",$name)){
67           $attrs = array(
68               "MSG_SIZE"      => "Size",
69               "RECIPIENT"     => "Recipient",
70               "SENDER"        => "Sender",
71               "ARRIVAL_TIME"  => "Arrival",
72               "MSG_ID"        => "MailID");  
73           $val = array();
74           foreach($attrs as $source => $dest){
75             $val[$dest] = $entry[0][$source][0]['VALUE'];
76           }
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']);
91           $items[$val[$sortby]] = $val;
92         }
93       }
94     }   
96     /* Sort entries by given direction 
97      */
98     if($direction == "down"){
99       ksort($items);
100     }else{
101       krsort($items);
102     }
104     return($items);
105   }
108   public function header($msg_id, $server)
109   {
110     $data = array();
111     $data['msg_id'] = $msg_id;
112     $res = $this->send_data("gosa_mailqueue_header",$this->target,$data,TRUE);
113     print_a($res);
114   }
116  
117   /*! \brief  Returns a list of all mail queue entries 
118       @return Array   s.a.
119    */
120   public function send_queue_action($msg_ids,$server, $action)
121   {
122     $data = array();
124     /* Check given msg_ids, must be array.
125      */
126     if(!is_array($msg_ids)){
127       trigger_error("Invalid msg_id given. Array expected.");
128       return(FALSE);
129     }
131     /* Check triggered action 
132      */
133     $allowed_actions = array("hold","unhold","requeue","del");
134     if(!in_array($action,$allowed_actions)){
135       trigger_error("Unknown queue action triggered '".$action."'. Request aborted.");  
136       return(FALSE);
137     }    
138     
139     $data['msg_id'] = $msg_ids;
140     $this->send_data("gosa_mailqueue_".$action,$this->target,$data,FALSE);
141     // There is no answer for this requests 
142   }
144 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
145 ?>