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 }
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","Error","Server");
39 /* Prepare search filter
40 */
41 $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($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 "ERROR" => "Error");
68 foreach($attrs as $source => $dest){
69 if(isset($entry[0][$source][0]['VALUE'])){
70 $val[$dest] = $entry[0][$source][0]['VALUE'];
71 }else{
72 $val[$dest] = FALSE;
73 }
74 }
76 $val['Server'] = $server;
77 $val['Arrival'] = strtotime($val['Arrival']);
79 /* Check arrival time.
80 */
81 if($time != -1 && !empty($val['Arrival'])){
82 if( ! ($val['Arrival'] > (time() - $time))){
83 continue;
84 }
85 }
87 /* Check if search string matches
88 */
89 $found = FALSE;
90 foreach($val as $name => $value){
91 if(preg_match("/^".$search_str."$/",$value)){
92 $found =TRUE;
93 break;
94 }
95 }
96 if($found){
97 $items[] = $val;
98 }
99 }
100 }
101 }
102 return($items);
103 }
106 public function header($msg_id, $server)
107 {
108 $data = array();
109 $data['msg_id'] = $msg_id;
110 $res = $this->send_data("gosa_mailqueue_header",$server,$data,TRUE);
111 if(isset($res['XML'][0]['MSG_HEADER'][0]['VALUE'])){
112 return($res['XML'][0]['MSG_HEADER'][0]['VALUE']);
113 }
114 return("");
115 }
118 /*! \brief Returns a list of all mail queue entries
119 @return Array s.a.
120 */
121 public function send_queue_action($msg_ids,$server, $action)
122 {
123 $data = array();
125 /* Check given msg_ids, must be array.
126 */
127 if(!is_array($msg_ids)){
128 trigger_error("Invalid msg_id given. Array expected.");
129 return(FALSE);
130 }
132 /* Check triggered action
133 */
134 $allowed_actions = array("hold","unhold","requeue","del");
135 if(!in_array($action,$allowed_actions)){
136 trigger_error("Unknown queue action triggered '".$action."'. Request aborted.");
137 return(FALSE);
138 }
140 $data['msg_id'] = $msg_ids;
142 print_a(array("gosa_mailqueue_".$action,$server,$data));;
143 $this->send_data("gosa_mailqueue_".$action,$server,$data,FALSE);
144 // There is no answer for this requests
145 }
146 }
147 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
148 ?>