1 <?php
3 class parseMailQueue
4 {
5 var $s_dataToParse;
6 var $a_parsedData;
7 var $i_count;
9 /* Contructor
10 * $s_data specifies the data that shuold be parse
11 */
12 function parseMailQueue($s_data)
13 {
14 $this->s_dataToParse = $s_data;
15 $this->_parse();
16 }
18 function OnlyDaysAgo($str)
19 {
20 $cur = time();
21 if((is_numeric($str))&&($str != 0)){
22 $cur = $cur - ($str*(60*60));
23 foreach($this->a_parsedData as $key => $data){
24 if($data['Arrival'] < $cur){
25 unset($this->a_parsedData[$key]);
26 }
27 }
28 }
29 }
31 function Search($filter,$fields)
32 {
33 foreach($this->a_parsedData as $key => $data){
34 $found = false;
36 foreach($fields as $attr){
37 if(preg_match("/".str_replace("*",".*",$filter)."/i",$data[$attr])){
38 $found= true;
39 }
40 }
41 if($found == false){
42 unset($this->a_parsedData[$key]);
43 }
44 }
45 }
47 function CreateDate()
48 {
49 foreach($this->a_parsedData as $key => $data){
50 $this->a_parsedData[$key]['Arrival'] = date("d.m.Y H:i:s",$data['Arrival']);
51 }
52 }
54 function OrderBy($str = "Arrival",$type = "up" )
55 {
56 $tmp = array();
57 if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error"))){
58 return(false);
59 }
61 if($str == "Size"){
62 foreach($this->a_parsedData as $data){
63 $struse = "";
64 for($i = strlen($data['Size']); $i < 10 ; $i++ ){
65 $struse .="0";
66 }
67 $struse .= $data[$str].$data['MailID'];
68 $tmp[$struse]= $data;
69 }
70 }else{
71 foreach($this->a_parsedData as $data){
72 $tmp[strtolower($data[$str]).$data['MailID']]= $data;
73 }
74 }
75 ksort($tmp);
76 if($type != "up"){
77 $tmp = array_reverse($tmp);
78 }
79 $this->a_parsedData = array();
80 foreach($tmp as $data){
81 $this->a_parsedData[$data['MailID']] = $data;
82 }
83 }
85 function GetAll()
86 {
87 return($this->a_parsedData);
88 }
90 function IDExists($id)
91 {
92 return(((isset($this->a_parsedData[$id]))&&(is_array($this->a_parsedData[$id]))));
93 }
95 /* This function parses the given data
96 * it creates an array with all given queue entries
97 */
98 function _parse()
99 {
100 $i = 0; // Temp var
101 $entries = array(); // Contains an array with the raw data for every single entry
102 $s_tmp = ""; // Buffer
104 $s_mailID = ""; // Queue ID
105 $s_Size = ""; // Mail size
106 $s_Arrival = ""; // Arrival time
107 $s_Sender = ""; // Sender
108 $s_Recipient = ""; // Recipient
109 $s_Error = ""; // Occured error
111 /* Remove header
112 */
113 $this->s_dataToParse = preg_replace("/^.*------\n/","",$this->s_dataToParse);
115 /* Create array with single entries
116 */
117 $entries = split("\n\n",$this->s_dataToParse);
119 /* The last entry in this array is not realy an valid entry, its some kind of status.
120 * It would be something like this : -- 795 Kbytes in 124 Requests.
121 */
122 $this->i_count = (count($entries))-1;
124 for($i = 0 ; $i < $this->i_count; $i ++ ){
126 while(strstr($entries[$i]," ")){
127 $entries[$i] = str_replace(" "," ",$entries[$i]);
128 }
130 $s_buffer = split("\n",preg_replace("/[\\n\\r\\t]/s","\n",$entries[$i]));
132 /* Get mailID */
133 $tmp = split(" ",$s_buffer[0]);
135 /* Get values */
136 $s_mailID = $tmp[0];
137 $s_Size = $tmp[1];
138 $s_Sender = $tmp[6];
140 /* Parse time */
141 $tmp3 = split(":",$tmp[5]);
142 $tmp2 = strtotime($tmp[4]." ".$tmp[3]." ".date("Y"));
143 $s_Arrival= mktime($tmp3[0],$tmp3[1],$tmp3[2],date("d",$tmp2),date("m",$tmp2),date("Y",$tmp2));
145 $s_Error = $s_buffer[1];
146 $s_Recipient = $s_buffer[2];
148 $this->a_parsedData[$s_mailID]['MailID'] = $s_mailID;
149 $this->a_parsedData[$s_mailID]['Size'] = $s_Size;
150 $this->a_parsedData[$s_mailID]['Arrival'] = $s_Arrival;
151 $this->a_parsedData[$s_mailID]['Sender'] = $s_Sender;
152 $this->a_parsedData[$s_mailID]['Recipient'] = $s_Recipient;
153 $this->a_parsedData[$s_mailID]['Error'] = $this->_parseError($s_Error);
154 }
155 return($this->a_parsedData);
156 }
158 function _parseError($str)
159 {
160 $str = trim(preg_replace("/[()]/","",$str));
161 $tmp2 = split(":",$str);
162 $tmp = array_reverse($tmp2);
163 $err = preg_replace("/#.*$/","",$tmp[0]);
164 $text = preg_replace("/said$/i","",trim($tmp2[0]));
165 return($err);
166 }
168 }
173 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
174 ?>