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,$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 }
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);
135 $attrs = array(
136 "RECIPIENT",
137 "SENDER",
138 "SUBJECT");
140 $data = array();
141 if(isset($res['XML'])){
142 foreach($attrs as $attr){
143 $data[$attr] = "";
144 if(isset($res['XML'][0][$attr])){
145 $data[$attr] = $res['XML'][0][$attr][0]['VALUE'];
146 }
147 }
148 }
149 return($data);
150 }
153 /*! \brief Returns a list of all mail queue entries
154 @return Array s.a.
155 */
156 public function send_queue_action($msg_ids,$server, $action)
157 {
158 $data = array();
160 /* Check given msg_ids, must be array.
161 */
162 if(!is_array($msg_ids)){
163 trigger_error("Invalid msg_id given. Array expected.");
164 return(FALSE);
165 }
167 /* Check triggered action
168 */
169 $allowed_actions = array("hold","unhold","requeue","del");
170 if(!in_array($action,$allowed_actions)){
171 trigger_error("Unknown queue action triggered '".$action."'. Request aborted.");
172 return(FALSE);
173 }
175 $data['msg_id'] = $msg_ids;
177 print_a(array("gosa_mailqueue_".$action,$server,$data));;
178 $this->send_data("gosa_mailqueue_".$action,$server,$data,FALSE);
179 // There is no answer for this requests
180 }
181 }
182 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
183 ?>