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)
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 /* Query mailqueue
54 */
55 $ids = array();
56 $res = $this->send_data("gosa_mailqueue_query",$server,array(),TRUE);
57 $items = array();
58 if(isset($res['XML'][0])){
59 foreach($res['XML'][0] as $name => $entry){
60 if(preg_match("/^ANSWER[0-9]*$/",$name)){
61 $attrs = array(
62 "MSG_SIZE" => "Size",
63 "RECIPIENT" => "Recipient",
64 "SENDER" => "Sender",
65 "ARRIVAL_TIME" => "Arrival",
66 "MSG_ID" => "MailID");
67 $val = array();
68 foreach($attrs as $source => $dest){
69 $val[$dest] = $entry[0][$source][0]['VALUE'];
70 }
71 $ids[] = $val['MailID'];
72 $attrs = array(
73 "MSG_HOLD" => "Hold",
74 "MSG_ACTIVE" => "Active",
75 "ERROR" => "Error");
76 foreach($attrs as $source => $dest){
77 if(isset($entry[0][$source][0]['VALUE'])){
78 $val[$dest] = $entry[0][$source][0]['VALUE'];
79 }else{
80 $val[$dest] = FALSE;
81 }
82 }
84 $val['Server'] = $server;
85 $val['Arrival'] = strtotime($val['Arrival']);
86 $n = $val[$sortby]."-".microtime(1);
87 while(isset($items[$n])){
88 $n = $val[$sortby]."-".microtime(1);
89 }
90 $items[$n] = $val;
91 }
92 }
93 }
95 /* Sort entries by given direction
96 */
97 if($direction == "down"){
98 ksort($items);
99 }else{
100 krsort($items);
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);
112 $attrs = array(
113 "RECIPIENT",
114 "SENDER",
115 "SUBJECT");
117 $data = array();
118 if(isset($res['XML'])){
119 foreach($attrs as $attr){
120 $data[$attr] = "";
121 if(isset($res['XML'][0][$attr])){
122 $data[$attr] = $res['XML'][0][$attr][0]['VALUE'];
123 }
124 }
125 }
126 return($data);
127 }
130 /*! \brief Returns a list of all mail queue entries
131 @return Array s.a.
132 */
133 public function send_queue_action($msg_ids,$server, $action)
134 {
135 $data = array();
137 /* Check given msg_ids, must be array.
138 */
139 if(!is_array($msg_ids)){
140 trigger_error("Invalid msg_id given. Array expected.");
141 return(FALSE);
142 }
144 /* Check triggered action
145 */
146 $allowed_actions = array("hold","unhold","requeue","del");
147 if(!in_array($action,$allowed_actions)){
148 trigger_error("Unknown queue action triggered '".$action."'. Request aborted.");
149 return(FALSE);
150 }
152 $data['msg_id'] = $msg_ids;
153 $this->send_data("gosa_mailqueue_".$action,$this->target,$data,FALSE);
154 // There is no answer for this requests
155 }
156 }
157 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
158 ?>