Code

3eb055bde5f576fed9d53d28dc24c389fdf9df65
[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,$search_str,$time)
36   {
37     $attrs = array("Size","Recipient","Sender","Arrival","MailID","Hold","Active","Status","Server");
39     /* Prepare search filter 
40      */
41     $search_str = preg_replace("/\\\\\*/",".*",preg_quote($search_str, '/'));
43     /* Query mailqueue 
44      */
45     $ids = array();
46     $res = $this->send_data("gosa_mailqueue_query",$server,array(),TRUE);
47     $items = array(); 
48     if(isset($res['XML'][0])){
49       foreach($res['XML'][0] as $name => $entry){
51         if(preg_match("/^ANSWER[0-9]*$/",$name)){
52           $attrs = array(
53               "MSG_SIZE"      => "Size",
54               "MSG_STATUS"    => "Status",
55               "RECIPIENT"     => "Recipient",
56               "SENDER"        => "Sender",
57               "ARRIVAL_TIME"  => "Arrival",
58               "MSG_ID"        => "MailID");  
59           $val = array();
60           foreach($attrs as $source => $dest){
61             $val[$dest] = $entry[0][$source][0]['VALUE'];
62           }
63           $ids[] = $val['MailID'];
64           $attrs = array(  
65               "MSG_HOLD"   => "Hold",
66               "MSG_ACTIVE" => "Active");
67           foreach($attrs as $source => $dest){
68             if(isset($entry[0][$source][0]['VALUE'])){
69               $val[$dest] = $entry[0][$source][0]['VALUE'];
70             }else{
71               $val[$dest] = FALSE;
72             }
73           }
75           $val['Server'] = $server;
76           $val['Arrival'] = strtotime($val['Arrival']);
78           /* Check arrival time.
79            */
80           if($time != -1 && !empty($val['Arrival'])){
81             if( ! ($val['Arrival'] > (time() - $time))){
82               continue;
83             }
84           }
86           /* Check if search string matches 
87            */
88           $found = FALSE;
89           foreach($val as $name => $value){
90             if(preg_match("/^".$search_str."$/",$value)){
91               $found =TRUE;
92               break;
93             }
94           }
95           if($found){
96             $items[] = $val;
97           }
98         }
99       }
100     }   
101     return($items);
102   }
105   public function header($msg_id, $server)
106   {
107     $data = array();
108     $data['msg_id'] = $msg_id;
109     $res = $this->send_data("gosa_mailqueue_header",$server,$data,TRUE);
110     if(isset($res['XML'][0]['MSG_HEADER'][0]['VALUE'])){
111       return($res['XML'][0]['MSG_HEADER'][0]['VALUE']);
112     }
113     return("");
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;
141     $this->send_data("gosa_mailqueue_".$action,$server,$data,FALSE);
142     // There is no answer for this requests 
143   }
145 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
146 ?>