1 | <?php |
---|
2 | include_once("class.functions.inc.php"); |
---|
3 | include_once("class.ldap_functions.inc.php"); |
---|
4 | include_once("class.exporteml.inc.php"); |
---|
5 | |
---|
6 | class imap_functions |
---|
7 | { |
---|
8 | var $public_functions = array |
---|
9 | ( |
---|
10 | 'get_range_msgs' => True, |
---|
11 | 'get_info_msg' => True, |
---|
12 | 'get_folders_list' => True |
---|
13 | ); |
---|
14 | |
---|
15 | var $ldap; |
---|
16 | var $mbox; |
---|
17 | var $imap_port; |
---|
18 | var $has_cid; |
---|
19 | var $imap_options = ''; |
---|
20 | var $functions; |
---|
21 | |
---|
22 | function imap_functions (){ |
---|
23 | $this->username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
24 | $this->password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
25 | $this->imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
26 | $this->imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
27 | $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; |
---|
28 | $this->functions = new functions(); |
---|
29 | $this->has_cid = false; |
---|
30 | |
---|
31 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
32 | { |
---|
33 | $this->imap_options = '/tls/novalidate-cert'; |
---|
34 | } |
---|
35 | else |
---|
36 | { |
---|
37 | $this->imap_options = '/notls/novalidate-cert'; |
---|
38 | } |
---|
39 | } |
---|
40 | // BEGIN of functions. |
---|
41 | function open_mbox($folder = False) |
---|
42 | { |
---|
43 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); |
---|
44 | $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => imap_last_error()))); |
---|
45 | return $this->mbox; |
---|
46 | } |
---|
47 | |
---|
48 | function get_range_msgs2($params) |
---|
49 | { |
---|
50 | include("class.imap_attachment.inc.php"); |
---|
51 | $imap_attachment = new imap_attachment(); |
---|
52 | $folder = $params['folder']; |
---|
53 | $msg_range_begin = $params['msg_range_begin']; |
---|
54 | $msg_range_end = $params['msg_range_end']; |
---|
55 | $sort_box_type = $params['sort_box_type']; |
---|
56 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
57 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
58 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
59 | |
---|
60 | $return = array(); |
---|
61 | $i = 0; |
---|
62 | $num_msgs = (is_array($sort_array_msg) ? count($sort_array_msg) : 0); |
---|
63 | if($num_msgs) { |
---|
64 | for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++) |
---|
65 | { |
---|
66 | $msg_number = $sort_array_msg[$msg_range_begin-1]; |
---|
67 | |
---|
68 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
69 | if (!is_object($header)) |
---|
70 | return false; |
---|
71 | |
---|
72 | $return[$i]['Recent'] = $header->Recent; |
---|
73 | $return[$i]['Unseen'] = $header->Unseen; |
---|
74 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
75 | $return[$i]['Forwarded'] = 'F'; |
---|
76 | } |
---|
77 | else { |
---|
78 | $return[$i]['Answered'] = $header->Answered; |
---|
79 | $return[$i]['Draft'] = $header->Draft; |
---|
80 | } |
---|
81 | $return[$i]['Deleted'] = $header->Deleted; |
---|
82 | $return[$i]['Flagged'] = $header->Flagged; |
---|
83 | |
---|
84 | $return[$i]['msg_number'] = $msg_number; |
---|
85 | //$return[$i]['msg_folder'] = $folder; |
---|
86 | |
---|
87 | $date_msg = date("d/m/Y",$header->udate); |
---|
88 | if (date("d/m/Y") == $date_msg) |
---|
89 | $return[$i]['udate'] = date("H:i",$header->udate); |
---|
90 | else |
---|
91 | $return[$i]['udate'] = $date_msg; |
---|
92 | |
---|
93 | $from = $header->from; |
---|
94 | $return[$i]['from'] = array(); |
---|
95 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
96 | $return[$i]['from']['name'] = $this->decode_string($tmp[0]->text); |
---|
97 | $return[$i]['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; |
---|
98 | if(!$return[$i]['from']['name']) |
---|
99 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
100 | $to = $header->to; |
---|
101 | $return[$i]['to'] = array(); |
---|
102 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
103 | $return[$i]['to']['name'] = $this->decode_string($this->decode_string($tmp[0]->text)); |
---|
104 | $return[$i]['to']['email'] = $this->decode_string($to[0]->mailbox) . "@" . $to[0]->host; |
---|
105 | if(!$return[$i]['to']['name']) |
---|
106 | $return[$i]['to']['name'] = $return[$i]['to']['email']; |
---|
107 | $return[$i]['subject'] = $this->decode_string($header->fetchsubject); |
---|
108 | |
---|
109 | $return[$i]['Size'] = $header->Size; |
---|
110 | |
---|
111 | $return[$i]['attachment'] = array(); |
---|
112 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
113 | $i++; |
---|
114 | } |
---|
115 | } |
---|
116 | $return['num_msgs'] = $num_msgs; |
---|
117 | |
---|
118 | return $return; |
---|
119 | } |
---|
120 | |
---|
121 | function decode_string($string) |
---|
122 | { |
---|
123 | if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) |
---|
124 | { |
---|
125 | $tmp = imap_mime_header_decode($string); |
---|
126 | foreach ($tmp as $tmp1) |
---|
127 | $return .= $this->htmlspecialchars_encode($tmp1->text); |
---|
128 | return $return; |
---|
129 | } |
---|
130 | else if (strpos(strtolower($string), '=?utf-8') !== false) |
---|
131 | { |
---|
132 | $elements = imap_mime_header_decode($string); |
---|
133 | for($i = 0;$i < count($elements);$i++) { |
---|
134 | $charset = $elements[$i]->charset; |
---|
135 | $text =$elements[$i]->text; |
---|
136 | if(!strcasecmp($charset, "utf-8") || |
---|
137 | !strcasecmp($charset, "utf-7")) { |
---|
138 | $text = iconv($charset, "ISO-8859-1", $text); |
---|
139 | } |
---|
140 | $decoded .= $this->htmlspecialchars_encode($text); |
---|
141 | } |
---|
142 | return $decoded; |
---|
143 | } |
---|
144 | else |
---|
145 | return $this->htmlspecialchars_encode($string); |
---|
146 | } |
---|
147 | |
---|
148 | function get_info_msg($params) |
---|
149 | { |
---|
150 | $return = array(); |
---|
151 | $msg_number = $params['msg_number']; |
---|
152 | $msg_folder = $params['msg_folder']; |
---|
153 | |
---|
154 | if(!$this->mbox) |
---|
155 | $this->mbox = $this->open_mbox($msg_folder); |
---|
156 | |
---|
157 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
158 | if (!$header) { |
---|
159 | $return['status_get_msg_info'] = "false"; |
---|
160 | return $return; |
---|
161 | } |
---|
162 | $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); |
---|
163 | $return_get_body = $this->get_body_msg($msg_number, $msg_folder); |
---|
164 | |
---|
165 | $return['body'] = $return_get_body['body']; |
---|
166 | $return['attachments'] = $return_get_body['attachments']; |
---|
167 | $return['thumbs'] = $return_get_body['thumbs']; |
---|
168 | $return['signature'] = $return_get_body['signature']; |
---|
169 | |
---|
170 | foreach($all_header as $line) { |
---|
171 | if (eregi("^Disposition-Notification-To", $line)) { |
---|
172 | eregi("^([^:]*): (.*)", $line, &$arg); |
---|
173 | $return['DispositionNotificationTo'] = $arg[2]; |
---|
174 | } |
---|
175 | } |
---|
176 | $return['Recent'] = $header->Recent; |
---|
177 | $return['Unseen'] = $header->Unseen; |
---|
178 | $return['Deleted'] = $header->Deleted; |
---|
179 | $return['Flagged'] = $header->Flagged; |
---|
180 | |
---|
181 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
182 | $return['Forwarded'] = 'F'; |
---|
183 | } |
---|
184 | else { |
---|
185 | $return['Answered'] = $header->Answered; |
---|
186 | $return['Draft'] = $header->Draft; |
---|
187 | } |
---|
188 | |
---|
189 | $return['msg_number'] = $msg_number; |
---|
190 | $return['msg_folder'] = $msg_folder; |
---|
191 | |
---|
192 | $date_msg = date("d/m/Y",$header->udate); |
---|
193 | if (date("d/m/Y") == $date_msg) |
---|
194 | $return['udate'] = date("H:i",$header->udate); |
---|
195 | else |
---|
196 | $return['udate'] = $date_msg; |
---|
197 | |
---|
198 | $return['msg_day'] = $date_msg; |
---|
199 | $return['msg_hour'] = date("H:i",$header->udate); |
---|
200 | |
---|
201 | if (date("d/m/Y") == $date_msg) //no dia |
---|
202 | { |
---|
203 | $return['fulldate'] = date("d/m/Y H:i",$header->udate); |
---|
204 | $return['smalldate'] = date("H:i",$header->udate); |
---|
205 | |
---|
206 | $timestamp_now = strtotime("now"); |
---|
207 | $timestamp_msg_time = $header->udate; |
---|
208 | $timestamp_diff = $timestamp_now - $timestamp_msg_time; |
---|
209 | |
---|
210 | if (gmdate("H",$timestamp_diff) > 0) |
---|
211 | { |
---|
212 | $return['fulldate'] .= " (" . gmdate("H:i", $timestamp_diff) . ' ' . $this->functions->getLang('hours ago') . ')'; |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | if (gmdate("i",$timestamp_diff) == 0){ |
---|
217 | $return['fulldate'] .= ' ('. $this->functions->getLang('now').')'; |
---|
218 | } |
---|
219 | elseif (gmdate("i",$timestamp_diff) == 1){ |
---|
220 | $return['fulldate'] .= ' (1 '. $this->functions->getLang('minute ago').')'; |
---|
221 | } |
---|
222 | else{ |
---|
223 | $return['fulldate'] .= " (" . gmdate("i",$timestamp_diff) .' '. $this->functions->getLang('minutes ago') . ')'; |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | else{ |
---|
228 | $return['fulldate'] = date("d/m/Y H:i",$header->udate); |
---|
229 | $return['smalldate'] = date("d/m/Y",$header->udate); |
---|
230 | } |
---|
231 | |
---|
232 | $from = $header->from; |
---|
233 | $return['from'] = array(); |
---|
234 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
235 | $return['from']['name'] = $this->decode_string($tmp[0]->text); |
---|
236 | $return['from']['email'] = $this->decode_string($from[0]->mailbox . "@" . $from[0]->host); |
---|
237 | if ($return['from']['name']) |
---|
238 | { |
---|
239 | if (substr($return['from']['name'], 0, 1) == '"') |
---|
240 | $return['from']['full'] = $return['from']['name'] . ' ' . '<' . $return['from']['email'] . '>'; |
---|
241 | else |
---|
242 | $return['from']['full'] = '"' . $return['from']['name'] . '" ' . '<' . $return['from']['email'] . '>'; |
---|
243 | } |
---|
244 | else |
---|
245 | $return['from']['full'] = $return['from']['email']; |
---|
246 | |
---|
247 | // Sender attribute |
---|
248 | $sender = $header->sender; |
---|
249 | $return['sender'] = array(); |
---|
250 | $tmp = imap_mime_header_decode($sender[0]->personal); |
---|
251 | $return['sender']['name'] = $this->decode_string($tmp[0]->text); |
---|
252 | $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); |
---|
253 | if ($return['sender']['name']) |
---|
254 | { |
---|
255 | if (substr($return['sender']['name'], 0, 1) == '"') |
---|
256 | $return['sender']['full'] = $return['sender']['name'] . ' ' . '<' . $return['sender']['email'] . '>'; |
---|
257 | else |
---|
258 | $return['sender']['full'] = '"' . $return['sender']['name'] . '" ' . '<' . $return['sender']['email'] . '>'; |
---|
259 | } |
---|
260 | else |
---|
261 | $return['sender']['full'] = $return['sender']['email']; |
---|
262 | |
---|
263 | if($return['from']['full'] == $return['sender']['full']) |
---|
264 | $return['sender'] = null; |
---|
265 | $to = $header->to; |
---|
266 | $return['toaddress2'] = ""; |
---|
267 | if (!empty($to)) |
---|
268 | { |
---|
269 | foreach ($to as $tmp) |
---|
270 | { |
---|
271 | if (!empty($tmp->personal)) |
---|
272 | { |
---|
273 | $personal_tmp = imap_mime_header_decode($tmp->personal); |
---|
274 | $return['toaddress2'] .= '"' . $personal_tmp[0]->text . '"'; |
---|
275 | $return['toaddress2'] .= " "; |
---|
276 | $return['toaddress2'] .= "<"; |
---|
277 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
278 | $return['toaddress2'] .= ">"; |
---|
279 | $return['toaddress2'] .= ", "; |
---|
280 | } |
---|
281 | else |
---|
282 | { |
---|
283 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
284 | $return['toaddress2'] .= ", "; |
---|
285 | } |
---|
286 | } |
---|
287 | $return['toaddress2'] = $this->del_last_two_caracters($return['toaddress2']); |
---|
288 | } |
---|
289 | else |
---|
290 | { |
---|
291 | $return['toaddress2'] = "<Empty>"; |
---|
292 | } |
---|
293 | |
---|
294 | $cc = $header->cc; |
---|
295 | $return['cc'] = ""; |
---|
296 | if (!empty($cc)) |
---|
297 | { |
---|
298 | foreach ($cc as $tmp_cc) |
---|
299 | { |
---|
300 | if (!empty($tmp_cc->personal)) |
---|
301 | { |
---|
302 | $personal_tmp_cc = imap_mime_header_decode($tmp_cc->personal); |
---|
303 | $return['cc'] .= '"' . $personal_tmp_cc[0]->text . '"'; |
---|
304 | $return['cc'] .= " "; |
---|
305 | $return['cc'] .= "<"; |
---|
306 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
307 | $return['cc'] .= ">"; |
---|
308 | $return['cc'] .= ", "; |
---|
309 | } |
---|
310 | else |
---|
311 | { |
---|
312 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
313 | $return['cc'] .= ", "; |
---|
314 | } |
---|
315 | } |
---|
316 | $return['cc'] = $this->del_last_two_caracters($return['cc']); |
---|
317 | } |
---|
318 | else |
---|
319 | { |
---|
320 | $return['cc'] = ""; |
---|
321 | } |
---|
322 | |
---|
323 | $reply_to = $header->reply_to; |
---|
324 | $return['reply_to'] = ""; |
---|
325 | if (is_object($reply_to[0])) |
---|
326 | { |
---|
327 | if ($return['from']['email'] != ($reply_to[0]->mailbox."@".$reply_to[0]->host)) |
---|
328 | { |
---|
329 | if (!empty($reply_to[0]->personal)) |
---|
330 | { |
---|
331 | $personal_reply_to = imap_mime_header_decode($tmp_reply_to->personal); |
---|
332 | if(!empty($personal_reply_to[0]->text)) { |
---|
333 | $return['reply_to'] .= '"' . $personal_reply_to[0]->text . '"'; |
---|
334 | $return['reply_to'] .= " "; |
---|
335 | $return['reply_to'] .= "<"; |
---|
336 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
337 | $return['reply_to'] .= ">"; |
---|
338 | } |
---|
339 | else { |
---|
340 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
341 | } |
---|
342 | } |
---|
343 | else |
---|
344 | { |
---|
345 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | $return['reply_to'] = $this->decode_string($return['reply_to']); |
---|
350 | $return['subject'] = $this->decode_string($header->fetchsubject); |
---|
351 | $return['Size'] = $header->Size; |
---|
352 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
353 | return $return; |
---|
354 | } |
---|
355 | |
---|
356 | function get_body_msg($msg_number, $msg_folder) |
---|
357 | { |
---|
358 | include_once("class.message_components.inc.php"); |
---|
359 | $msg = &new message_components($this->mbox); |
---|
360 | $msg->fetch_structure($msg_number); |
---|
361 | $return = array(); |
---|
362 | $return['attachments'] = $this-> download_attachment($msg,$msg_number); |
---|
363 | if(!$this->has_cid) |
---|
364 | { |
---|
365 | $return['thumbs'] = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); |
---|
366 | $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
367 | } |
---|
368 | |
---|
369 | if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece |
---|
370 | { |
---|
371 | $attachment = array(); //No attachments |
---|
372 | |
---|
373 | $content = ''; |
---|
374 | if (strtolower($msg->structure[$msg_number]->subtype) == "plain") |
---|
375 | { |
---|
376 | $content .= nl2br($this->decodeBody((imap_body($this->mbox, $msg_number, FT_UID)), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0])); |
---|
377 | } |
---|
378 | else if (strtolower($msg->structure[$msg_number]->subtype) == "html") |
---|
379 | { |
---|
380 | $content .= $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); |
---|
381 | } |
---|
382 | } |
---|
383 | else |
---|
384 | { //Complicated message, multiple parts |
---|
385 | $html_body = ''; |
---|
386 | $content = ''; |
---|
387 | $has_multipart = true; |
---|
388 | $this->has_cid = false; |
---|
389 | |
---|
390 | if (strtolower($msg->structure[$msg_number]->subtype) == "related") |
---|
391 | $this->has_cid = true; |
---|
392 | |
---|
393 | if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") |
---|
394 | $show_only_html = true; |
---|
395 | else |
---|
396 | $show_only_html = false; |
---|
397 | |
---|
398 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
399 | { |
---|
400 | |
---|
401 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
402 | if($file_type == "message/rfc822") |
---|
403 | $has_multipart = false; |
---|
404 | |
---|
405 | if($file_type == "multipart/alternative") |
---|
406 | $has_multipart = false; |
---|
407 | |
---|
408 | if(($file_type == "text/plain" |
---|
409 | || $file_type == "text/html") |
---|
410 | && $file_type != 'attachment') |
---|
411 | { |
---|
412 | if($file_type == "text/plain" && !$show_only_html && $has_multipart) |
---|
413 | { |
---|
414 | // if TXT file size > 100kb, then it will not expand. |
---|
415 | if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { |
---|
416 | $content .= nl2br(htmlentities($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]))); |
---|
417 | } |
---|
418 | } |
---|
419 | // if HTML attachment file size > 300kb, then it will not expand. |
---|
420 | else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 307200) |
---|
421 | { |
---|
422 | $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
423 | $show_only_html = true; |
---|
424 | } |
---|
425 | } |
---|
426 | else if($file_type == "message/delivery-status"){ |
---|
427 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
428 | $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); |
---|
429 | |
---|
430 | } |
---|
431 | else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ |
---|
432 | |
---|
433 | include_once("class.imap_attachment.inc.php"); |
---|
434 | $att = new imap_attachment(); |
---|
435 | $attachments = $att -> get_attachment_info($this->mbox,$msg_number); |
---|
436 | if($attachments['number_attachments'] > 0) { |
---|
437 | foreach($attachments ['attachment'] as $index => $attachment){ |
---|
438 | if(strtolower($attachment['type']) == "delivery-status" || |
---|
439 | strtolower($attachment['type']) == "rfc822" || |
---|
440 | strtolower($attachment['type']) == "rfc822-headers" || |
---|
441 | strtolower($attachment['type']) == "plain" |
---|
442 | ){ |
---|
443 | $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); |
---|
444 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
445 | $content .= "<br><table style='margin:2px;border:1px solid black;background:#EAEAEA'>"; |
---|
446 | $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; |
---|
447 | $content .= "<tr><td><b>".$this->functions->getLang("From").":</b></td><td>".$this->decode_string($obj->from[0]->mailbox."@".$obj->from[0]->host)."</td></tr>"; |
---|
448 | $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; |
---|
449 | $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; |
---|
450 | $content .= !$obj->cc ? "</table><br>" :"<tr><td><b>".$this->functions->getLang("CC").":</b></td><td>".$this->decode_string($obj->cc[0]->mailbox."@".$obj->cc[0]->host)."</td></tr></table><br>"; |
---|
451 | $ix_part = strtolower($attachment['type']) == "delivery-status" ? 1 : 0; |
---|
452 | $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, ($attachment['part_in_msg']+$ix_part).".1", FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); |
---|
453 | break; |
---|
454 | } |
---|
455 | } |
---|
456 | } |
---|
457 | } |
---|
458 | } |
---|
459 | if($file_type == "text/plain" && ($show_only_html && $msg_part == 1) || (!$show_only_html && $msg_part == 3)){ |
---|
460 | if(strtolower($msg->structure[$msg_number]->subtype) == "mixed" && $msg_part == 1) |
---|
461 | $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); |
---|
462 | else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") |
---|
463 | $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); |
---|
464 | } |
---|
465 | } |
---|
466 | // Force message with flag Seen (imap_fetchbody not works correctly) |
---|
467 | $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); |
---|
468 | $this->set_messages_flag($params); |
---|
469 | $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); |
---|
470 | $content = $this->replace_special_characters($content); |
---|
471 | $return['body'] = $content; |
---|
472 | return $return; |
---|
473 | } |
---|
474 | |
---|
475 | function htmlfilter($body) |
---|
476 | { |
---|
477 | require_once('htmlfilter.inc'); |
---|
478 | |
---|
479 | $tag_list = Array( |
---|
480 | false, |
---|
481 | 'blink', |
---|
482 | 'object', |
---|
483 | 'meta', |
---|
484 | 'html', |
---|
485 | 'link', |
---|
486 | 'frame', |
---|
487 | 'iframe', |
---|
488 | 'layer', |
---|
489 | 'ilayer', |
---|
490 | 'plaintext' |
---|
491 | ); |
---|
492 | |
---|
493 | /** |
---|
494 | * A very exclusive set: |
---|
495 | */ |
---|
496 | // $tag_list = Array(true, "b", "a", "i", "img", "strong", "em", "p"); |
---|
497 | $rm_tags_with_content = Array( |
---|
498 | 'script', |
---|
499 | 'style', |
---|
500 | 'applet', |
---|
501 | 'embed', |
---|
502 | 'head', |
---|
503 | 'frameset', |
---|
504 | 'xml', |
---|
505 | 'xmp' |
---|
506 | ); |
---|
507 | |
---|
508 | $self_closing_tags = Array( |
---|
509 | 'img', |
---|
510 | 'br', |
---|
511 | 'hr', |
---|
512 | 'input' |
---|
513 | ); |
---|
514 | |
---|
515 | $force_tag_closing = true; |
---|
516 | |
---|
517 | $rm_attnames = Array( |
---|
518 | '/.*/' => |
---|
519 | Array( |
---|
520 | '/target/i', |
---|
521 | //'/^on.*/i', -> onClick, dos compromissos da agenda. |
---|
522 | '/^dynsrc/i', |
---|
523 | '/^datasrc/i', |
---|
524 | '/^data.*/i', |
---|
525 | '/^lowsrc/i' |
---|
526 | ) |
---|
527 | ); |
---|
528 | |
---|
529 | /** |
---|
530 | * Yeah-yeah, so this looks horrible. Check out htmlfilter.inc for |
---|
531 | * some idea of what's going on here. :) |
---|
532 | */ |
---|
533 | |
---|
534 | $bad_attvals = Array( |
---|
535 | '/.*/' => |
---|
536 | Array( |
---|
537 | '/.*/' => |
---|
538 | Array( |
---|
539 | Array( |
---|
540 | '/^([\'\"])\s*\S+\s*script\s*:*(.*)([\'\"])/si', |
---|
541 | //'/^([\'\"])\s*https*\s*:(.*)([\'\"])/si', -> doclinks notes |
---|
542 | '/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si', |
---|
543 | '/^([\'\"])\s*about\s*:(.*)([\'\"])/si' |
---|
544 | ), |
---|
545 | Array( |
---|
546 | '\\1oddjob:\\2\\1', |
---|
547 | //'\\1uucp:\\2\\1', -> doclinks notes |
---|
548 | '\\1amaretto:\\2\\1', |
---|
549 | '\\1round:\\2\\1' |
---|
550 | ) |
---|
551 | ), |
---|
552 | |
---|
553 | '/^style/i' => |
---|
554 | Array( |
---|
555 | Array( |
---|
556 | '/expression/i', |
---|
557 | '/behaviou*r/i', |
---|
558 | '/binding/i', |
---|
559 | '/include-source/i', |
---|
560 | '/url\s*\(\s*([\'\"]*)\s*https*:.*([\'\"]*)\s*\)/si', |
---|
561 | '/url\s*\(\s*([\'\"]*)\s*\S+\s*script:.*([\'\"]*)\s*\)/si' |
---|
562 | ), |
---|
563 | Array( |
---|
564 | 'idiocy', |
---|
565 | 'idiocy', |
---|
566 | 'idiocy', |
---|
567 | 'idiocy', |
---|
568 | 'url(\\1http://securityfocus.com/\\1)', |
---|
569 | 'url(\\1http://securityfocus.com/\\1)' |
---|
570 | ) |
---|
571 | ) |
---|
572 | ) |
---|
573 | ); |
---|
574 | |
---|
575 | $add_attr_to_tag = Array( |
---|
576 | '/^a$/i' => Array('target' => '"_new"') |
---|
577 | ); |
---|
578 | |
---|
579 | |
---|
580 | $trusted_body = sanitize($body, |
---|
581 | $tag_list, |
---|
582 | $rm_tags_with_content, |
---|
583 | $self_closing_tags, |
---|
584 | $force_tag_closing, |
---|
585 | $rm_attnames, |
---|
586 | $bad_attvals, |
---|
587 | $add_attr_to_tag |
---|
588 | ); |
---|
589 | |
---|
590 | return $trusted_body; |
---|
591 | } |
---|
592 | |
---|
593 | function decodeBody($body, $encoding, $charset=null) |
---|
594 | { |
---|
595 | /** |
---|
596 | * replace e-mail by anchor. |
---|
597 | */ |
---|
598 | // HTML Filter |
---|
599 | //$body = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=# onclick=\"javascript:new_message('new_by_message', '\\2@\\3')\">\\2@\\3</a>", $body); |
---|
600 | $body = str_replace("\r\n", "\n", $body); |
---|
601 | if ($encoding == 'quoted-printable') |
---|
602 | { |
---|
603 | |
---|
604 | for($i=0;$i<256;$i++) { |
---|
605 | $c1=dechex($i); |
---|
606 | if(strlen($c1)==1){$c1="0".$c1;} |
---|
607 | $c1="=".$c1; |
---|
608 | $myqprinta[]=$c1; |
---|
609 | $myqprintb[]=chr($i); |
---|
610 | } |
---|
611 | $body = str_replace($myqprinta,$myqprintb,($body)); |
---|
612 | $body = quoted_printable_decode($body); |
---|
613 | while (ereg("=\n", $body)) |
---|
614 | { |
---|
615 | $body = ereg_replace ("=\n", '', $body); |
---|
616 | } |
---|
617 | } |
---|
618 | else if ($encoding == 'base64') |
---|
619 | { |
---|
620 | $body = base64_decode($body); |
---|
621 | } |
---|
622 | /*else if ($encoding == '7bit') |
---|
623 | { |
---|
624 | $body = quoted_printable_decode($body); |
---|
625 | }*/ |
---|
626 | // All other encodings are returned raw. |
---|
627 | if (strtolower($charset) == "utf-8") |
---|
628 | return utf8_decode($body); |
---|
629 | else |
---|
630 | return $body; |
---|
631 | } |
---|
632 | |
---|
633 | function process_embedded_images($msg, $msgno, $body, $msg_folder) |
---|
634 | { |
---|
635 | if (count($msg->inline_id[$msgno]) > 0) |
---|
636 | { |
---|
637 | foreach ($msg->inline_id[$msgno] as $index => $cid) |
---|
638 | { |
---|
639 | $cid = eregi_replace("<", "", $cid); |
---|
640 | $cid = eregi_replace(">", "", $cid); |
---|
641 | $msg_part = $msg->pid[$msgno][$index]; |
---|
642 | //$body = eregi_replace("alt=\"\"", "", $body); |
---|
643 | $body = eregi_replace("<br/>", "", $body); |
---|
644 | $body = str_replace("src=\"cid:".$cid."\"", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
645 | $body = str_replace("src='cid:".$cid."'", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
646 | $body = str_replace("src=cid:".$cid, " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
647 | } |
---|
648 | } |
---|
649 | |
---|
650 | return $body; |
---|
651 | } |
---|
652 | |
---|
653 | function replace_special_characters($body) |
---|
654 | { |
---|
655 | // Suspected TAGS! |
---|
656 | /*$tag_list = Array( |
---|
657 | 'blink','object','meta', |
---|
658 | 'html','link','frame', |
---|
659 | 'iframe','layer','ilayer', |
---|
660 | 'plaintext','script','style','img', |
---|
661 | 'applet','embed','head', |
---|
662 | 'frameset','xml','xmp'); |
---|
663 | */ |
---|
664 | |
---|
665 | // Layout problem: Change html elements |
---|
666 | // with absolute position to relate position, CASE INSENSITIVE. |
---|
667 | $body = @eregi_replace("POSITION: ABSOLUTE;","",$body); |
---|
668 | |
---|
669 | $tag_list = Array('head','blink','object','frame', |
---|
670 | 'iframe','layer','ilayer','plaintext','script', |
---|
671 | 'applet','embed','frameset','xml','xmp','style'); |
---|
672 | |
---|
673 | $body = $this-> replace_links($body); |
---|
674 | $blocked_tags = array(); |
---|
675 | foreach($tag_list as $index => $tag) { |
---|
676 | $new_body = eregi_replace("<$tag", "<!--$tag", $body); |
---|
677 | if($body != $new_body) { |
---|
678 | $blocked_tags[] = $tag; |
---|
679 | } |
---|
680 | $body = eregi_replace("</$tag>", "</$tag-->", $new_body); |
---|
681 | } |
---|
682 | |
---|
683 | return "<span>".$body; |
---|
684 | } |
---|
685 | |
---|
686 | function replace_links($body) { |
---|
687 | // Search for links,then open the link in new window. |
---|
688 | //$body = @ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)', '<a href="\\0" title="'.$this->functions->getLang("Open in New Window").'">\\0</a>',$body); |
---|
689 | //Search for emails, then open a new message tab. |
---|
690 | //$body = @ereg_replace('[a-zA-Z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*', '<a title=\''.$this->functions->getLang("New Message").' -> \\0\'" onclick="Element(\'msg_number\').value=\'\\0\';new_message(\'new\',\'null\')" href="#">\\0</a>',$body); |
---|
691 | $matches = array(); |
---|
692 | // Verify exception. |
---|
693 | @preg_match("/<a href=\"notes:\/\/\//",$body,$matches); |
---|
694 | // It no has exception,then open the link in new window. |
---|
695 | if(!count($matches)){ |
---|
696 | $body = @eregi_replace("<a (.*) href=", "<a \\1 target='_blank' href=", $body); |
---|
697 | $body = @str_replace("<a href=", "<a target='_blank' href=", $body); |
---|
698 | $body = @eregi_replace("target=\"\"", "target='_blank'", $body); |
---|
699 | $body = @eregi_replace("target=''", "target='_blank'", $body); |
---|
700 | } |
---|
701 | return $body; |
---|
702 | } |
---|
703 | |
---|
704 | function get_signature($msg, $msg_number, $msg_folder) |
---|
705 | { |
---|
706 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
707 | { |
---|
708 | $file_type = strtolower($file_type); |
---|
709 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') |
---|
710 | { |
---|
711 | if ($file_type == 'application/x-pkcs7-signature') |
---|
712 | { |
---|
713 | $export_mail = new ExportEml(); |
---|
714 | $params['folder'] = $msg_folder; |
---|
715 | $params['msgs_to_export'] = $msg_number; |
---|
716 | $tempDir = ini_get("session.save_path"); |
---|
717 | $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; |
---|
718 | $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); |
---|
719 | if (file_exists($cert_file)) |
---|
720 | { |
---|
721 | $handle = fopen ($cert_file,"r"); |
---|
722 | $pemout = fread($handle,filesize($cert_file)); |
---|
723 | fclose($handle); |
---|
724 | $cert=openssl_x509_parse($pemout); |
---|
725 | $temp = "\\nSigned by: ".$cert[subject][CN]; |
---|
726 | $temp .= "\\nEmail Address: ".$cert[subject][emailAddress]; |
---|
727 | $temp .= "\\nCertificate issued by: ".$cert[issuer][CN]."\\n"; |
---|
728 | } |
---|
729 | /* Message verified */ |
---|
730 | if ($result === true) |
---|
731 | $sign = $temp; |
---|
732 | else |
---|
733 | $sign = "void"; |
---|
734 | } |
---|
735 | } |
---|
736 | } |
---|
737 | return $sign; |
---|
738 | } |
---|
739 | |
---|
740 | function get_thumbs($msg, $msg_number, $msg_folder) |
---|
741 | { |
---|
742 | $thumbs_array = array(); |
---|
743 | $i = 0; |
---|
744 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
745 | { |
---|
746 | $file_type = strtolower($file_type); |
---|
747 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') { |
---|
748 | if (($file_type == 'image/jpeg') || ($file_type == 'image/pjpeg') || ($file_type == 'image/gif') || ($file_type == 'image/png')) { |
---|
749 | $img = "<IMG id='".$msg_folder.";;".$msg_number.";;".$i.";;".$msg->pid[$msg_number][$index].";;".$msg->encoding[$msg_number][$index]."' style='border:2px solid #fde7bc;padding:5px' title='".$this->functions->getLang("Click here do view (+)")."'src=./inc/show_thumbs.php?file_type=".$file_type."&msg_num=".$msg_number."&msg_folder=".$msg_folder."&msg_part=".$msg->pid[$msg_number][$index].">"; |
---|
750 | $href = "<a onMouseDown='save_image(event,this)' href='#".$msg_folder.";;".$msg_number.";;".$i.";;".$msg->pid[$msg_number][$index].";;".$msg->encoding[$msg_number][$index]."' onClick=\"window.open('./inc/show_img.php?msg_num=".$msg_number."&msg_folder=".$msg_folder."&msg_part=".$msg->pid[$msg_number][$index]."','mywindow','width=700,height=600,scrollbars=yes');\">". $img ."</a>"; |
---|
751 | $thumbs_array[] = $href; |
---|
752 | } |
---|
753 | $i++; |
---|
754 | } |
---|
755 | } |
---|
756 | return $thumbs_array; |
---|
757 | } |
---|
758 | |
---|
759 | /*function delete_msg($params) |
---|
760 | { |
---|
761 | $folder = $params['folder']; |
---|
762 | $msgs_to_delete = explode(",",$params['msgs_to_delete']); |
---|
763 | |
---|
764 | $mbox_stream = $this->open_mbox($folder); |
---|
765 | |
---|
766 | foreach ($msgs_to_delete as $msg_number){ |
---|
767 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
768 | } |
---|
769 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
770 | return $params['msgs_to_delete']; |
---|
771 | }*/ |
---|
772 | |
---|
773 | // Novo |
---|
774 | function delete_msgs($params) |
---|
775 | { |
---|
776 | |
---|
777 | $folder = $params['folder']; |
---|
778 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
779 | $msgs_number = explode(",",$params['msgs_number']); |
---|
780 | $border_ID = $params['border_ID']; |
---|
781 | |
---|
782 | $return = array(); |
---|
783 | |
---|
784 | if ($params['get_previous_msg']) |
---|
785 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
786 | |
---|
787 | //$mbox_stream = $this->open_mbox($folder); |
---|
788 | $mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => imap_last_error()))); |
---|
789 | |
---|
790 | foreach ($msgs_number as $msg_number) |
---|
791 | { |
---|
792 | if (imap_delete($mbox_stream, $msg_number, FT_UID)); |
---|
793 | $return['msgs_number'][] = $msg_number; |
---|
794 | } |
---|
795 | |
---|
796 | $return['folder'] = $folder; |
---|
797 | $return['border_ID'] = $border_ID; |
---|
798 | |
---|
799 | if($mbox_stream) |
---|
800 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
801 | return $return; |
---|
802 | } |
---|
803 | |
---|
804 | |
---|
805 | function refresh($params) |
---|
806 | { |
---|
807 | include("class.imap_attachment.inc.php"); |
---|
808 | $imap_attachment = new imap_attachment(); |
---|
809 | $folder = $params['folder']; |
---|
810 | $msg_range_begin = $params['msg_range_begin']; |
---|
811 | $msg_range_end = $params['msg_range_end']; |
---|
812 | $msgs_existent = $params['msgs_existent']; |
---|
813 | $sort_box_type = $params['sort_box_type']; |
---|
814 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
815 | $msgs_in_the_server = array(); |
---|
816 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
817 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
818 | |
---|
819 | if(!count($sort_array_msg)) |
---|
820 | return array(); |
---|
821 | |
---|
822 | $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); |
---|
823 | $msgs_in_the_client = explode(",", $msgs_existent); |
---|
824 | |
---|
825 | |
---|
826 | for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) |
---|
827 | { |
---|
828 | $msgs_in_the_server[] = $sort_array_msg[$msg_range_begin-1]; |
---|
829 | } |
---|
830 | if ((count($msgs_in_the_server) < 1) && ($msg_range_begin != 0)) |
---|
831 | { |
---|
832 | $range = $msg_range_end - $msg_range_begin; |
---|
833 | $msg_range_begin = $msg_range_begin - $range; |
---|
834 | $msg_range_end = $msg_range_end - $range; |
---|
835 | for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) |
---|
836 | { |
---|
837 | $msgs_in_the_server[] = $sort_array_msg[$msg_range_begin-1]; |
---|
838 | } |
---|
839 | } |
---|
840 | |
---|
841 | $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); |
---|
842 | $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); |
---|
843 | |
---|
844 | $msgs_to_exec = array(); |
---|
845 | if ((count($msg_to_insert)) && ($msgs_existent)) |
---|
846 | { |
---|
847 | foreach($msg_to_insert as $index => $msg_number) |
---|
848 | { |
---|
849 | if ($msgs_in_the_server[$index+1]) |
---|
850 | { |
---|
851 | //$msgs_to_exec[$msg_number] = 'Inserir mensage numero ' . $msg_number . ' antes da ' . $msgs_in_the_server[$index+1]; |
---|
852 | $msgs_to_exec[$msg_number] = 'box.insertBefore(new_msg, Element("'.$msgs_in_the_server[$index+1].'"));'; |
---|
853 | } |
---|
854 | else |
---|
855 | { |
---|
856 | //$msgs_to_exec[$msg_number] = 'Inserir mensage numero ' . $msg_number . ' no final (append)'; |
---|
857 | $msgs_to_exec[$msg_number] = 'box.appendChild(new_msg);'; |
---|
858 | } |
---|
859 | } |
---|
860 | ksort($msgs_to_exec); |
---|
861 | } |
---|
862 | elseif(!$msgs_existent) |
---|
863 | { |
---|
864 | foreach($msgs_in_the_server as $index => $msg_number) |
---|
865 | { |
---|
866 | $msgs_to_exec[$msg_number] = 'box.appendChild(new_msg);'; |
---|
867 | } |
---|
868 | } |
---|
869 | |
---|
870 | $return = array(); |
---|
871 | $i = 0; |
---|
872 | foreach($msgs_to_exec as $msg_number => $command) |
---|
873 | { |
---|
874 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox , $msg_number), 80, 255); |
---|
875 | if (!is_object($header)) |
---|
876 | return false; |
---|
877 | |
---|
878 | $return[$i]['msg_number'] = $msg_number; |
---|
879 | $return[$i]['command'] = $command; |
---|
880 | |
---|
881 | $return[$i]['msg_folder'] = $folder; |
---|
882 | $return[$i]['Recent'] = $header->Recent; |
---|
883 | $return[$i]['Unseen'] = $header->Unseen; |
---|
884 | $return[$i]['Answered'] = $header->Answered; |
---|
885 | $return[$i]['Deleted'] = $header->Deleted; |
---|
886 | $return[$i]['Draft'] = $header->Draft; |
---|
887 | $return[$i]['Flagged'] = $header->Flagged; |
---|
888 | |
---|
889 | $date_msg = date("d/m/Y",$header->udate); |
---|
890 | if (date("d/m/Y") == $date_msg) |
---|
891 | $return[$i]['udate'] = date("H:i",$header->udate); |
---|
892 | else |
---|
893 | $return[$i]['udate'] = $date_msg; |
---|
894 | |
---|
895 | $from = $header->from; |
---|
896 | $return[$i]['from'] = array(); |
---|
897 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
898 | $return[$i]['from']['name'] = $tmp[0]->text; |
---|
899 | $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
900 | //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; |
---|
901 | if(!$return[$i]['from']['name']) |
---|
902 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
903 | |
---|
904 | /*$toaddress = imap_mime_header_decode($header->toaddress); |
---|
905 | $return[$i]['toaddress'] = ''; |
---|
906 | foreach ($toaddress as $tmp) |
---|
907 | $return[$i]['toaddress'] .= $tmp->text;*/ |
---|
908 | $to = $header->to; |
---|
909 | $return[$i]['to'] = array(); |
---|
910 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
911 | $return[$i]['to']['name'] = $tmp[0]->text; |
---|
912 | $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
913 | $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
914 | |
---|
915 | $return[$i]['subject'] = $this->decode_string($header->fetchsubject); |
---|
916 | |
---|
917 | $return[$i]['Size'] = $header->Size; |
---|
918 | $return[$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
919 | |
---|
920 | $return[$i]['attachment'] = array(); |
---|
921 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
922 | $i++; |
---|
923 | } |
---|
924 | $return['new_msgs'] = imap_num_recent($this->mbox); |
---|
925 | $return['msgs_to_delete'] = $msg_to_delete; |
---|
926 | if($this->mbox) |
---|
927 | imap_close($this->mbox); |
---|
928 | return $return; |
---|
929 | } |
---|
930 | |
---|
931 | function get_folders_list() |
---|
932 | { |
---|
933 | $mbox_stream = $this->open_mbox(); |
---|
934 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
935 | $folders_list = imap_getmailboxes($mbox_stream, $serverString, "*"); |
---|
936 | $tmp = array(); |
---|
937 | $result = array(); |
---|
938 | |
---|
939 | if (is_array($folders_list)) { |
---|
940 | reset($folders_list); |
---|
941 | |
---|
942 | $i = 0; |
---|
943 | while (list($key, $val) = each($folders_list)) { |
---|
944 | $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); |
---|
945 | $result[$i]['folder_unseen'] = $status->unseen; |
---|
946 | |
---|
947 | //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); |
---|
948 | $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); |
---|
949 | $folder_id = $tmp_folder_id[1]; |
---|
950 | $result[$i]['folder_id'] = $folder_id; |
---|
951 | |
---|
952 | $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); |
---|
953 | $result[$i]['folder_name'] = array_pop($tmp_folder_parent); |
---|
954 | $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; |
---|
955 | |
---|
956 | $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); |
---|
957 | $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; |
---|
958 | |
---|
959 | if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) |
---|
960 | $result[$i]['folder_hasChildren'] = 1; |
---|
961 | else |
---|
962 | $result[$i]['folder_hasChildren'] = 0; |
---|
963 | |
---|
964 | $i++; |
---|
965 | } |
---|
966 | } |
---|
967 | |
---|
968 | foreach ($result as $folder_info) |
---|
969 | { |
---|
970 | $array_tmp[] = $folder_info['folder_id']; |
---|
971 | } |
---|
972 | |
---|
973 | natcasesort($array_tmp); |
---|
974 | |
---|
975 | foreach ($array_tmp as $key => $folder_id) |
---|
976 | { |
---|
977 | $result2[] = $result[$key]; |
---|
978 | } |
---|
979 | |
---|
980 | return array_merge($result2, $this->get_quota()); |
---|
981 | } |
---|
982 | |
---|
983 | function create_mailbox($arr) |
---|
984 | { |
---|
985 | $namebox = $arr['newp']; |
---|
986 | $mbox_stream = $this->open_mbox(); |
---|
987 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
988 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); |
---|
989 | |
---|
990 | $result = "Ok"; |
---|
991 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
992 | { |
---|
993 | $result = implode("<br />\n", imap_errors()); |
---|
994 | } |
---|
995 | |
---|
996 | if($mbox_stream) |
---|
997 | imap_close($mbox_stream); |
---|
998 | |
---|
999 | return $result; |
---|
1000 | |
---|
1001 | } |
---|
1002 | |
---|
1003 | function create_extra_mailbox($arr) |
---|
1004 | { |
---|
1005 | $nameboxs = explode(";",$arr['nw_folders']); |
---|
1006 | $result = ""; |
---|
1007 | $mbox_stream = $this->open_mbox(); |
---|
1008 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
1009 | foreach($nameboxs as $key=>$tmp){ |
---|
1010 | if($tmp != ""){ |
---|
1011 | if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ |
---|
1012 | $result = implode("<br />\n", imap_errors()); |
---|
1013 | if($mbox_stream) |
---|
1014 | imap_close($mbox_stream); |
---|
1015 | return $result; |
---|
1016 | } |
---|
1017 | } |
---|
1018 | } |
---|
1019 | if($mbox_stream) |
---|
1020 | imap_close($mbox_stream); |
---|
1021 | return true; |
---|
1022 | } |
---|
1023 | |
---|
1024 | function delete_mailbox($arr) |
---|
1025 | { |
---|
1026 | $namebox = $arr['del_past']; |
---|
1027 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
1028 | $mbox_stream = $this->open_mbox(); |
---|
1029 | //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); |
---|
1030 | |
---|
1031 | $result = "Ok"; |
---|
1032 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
1033 | if(!imap_deletemailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
1034 | { |
---|
1035 | $result = implode("<br />\n", imap_errors()); |
---|
1036 | } |
---|
1037 | if($mbox_stream) |
---|
1038 | imap_close($mbox_stream); |
---|
1039 | return $result; |
---|
1040 | } |
---|
1041 | |
---|
1042 | function ren_mailbox($arr) |
---|
1043 | { |
---|
1044 | $namebox = $arr['current']; |
---|
1045 | $new_box = $arr['rename']; |
---|
1046 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
1047 | $mbox_stream = $this->open_mbox(); |
---|
1048 | //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); |
---|
1049 | |
---|
1050 | $result = "Ok"; |
---|
1051 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
1052 | $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); |
---|
1053 | |
---|
1054 | if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) |
---|
1055 | { |
---|
1056 | $result = imap_errors(); |
---|
1057 | } |
---|
1058 | if($mbox_stream) |
---|
1059 | imap_close($mbox_stream); |
---|
1060 | return $result; |
---|
1061 | |
---|
1062 | } |
---|
1063 | |
---|
1064 | function get_num_msgs($params) |
---|
1065 | { |
---|
1066 | $folder = $params['folder']; |
---|
1067 | if(!$this->mbox) { |
---|
1068 | $this->mbox = $this->open_mbox($folder); |
---|
1069 | if(!$this->mbox) |
---|
1070 | return imap_last_error(); |
---|
1071 | } |
---|
1072 | $num_msgs = imap_num_msg($this->mbox); |
---|
1073 | if($this->mbox) |
---|
1074 | imap_close($this->mbox); |
---|
1075 | |
---|
1076 | return $num_msgs; |
---|
1077 | } |
---|
1078 | |
---|
1079 | function send_mail($params) |
---|
1080 | { |
---|
1081 | include_once("class.phpmailer.php"); |
---|
1082 | $mail = new PHPMailer(); |
---|
1083 | include_once("class.db_functions.inc.php"); |
---|
1084 | $db = new db_functions(); |
---|
1085 | $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; |
---|
1086 | $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); |
---|
1087 | $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); |
---|
1088 | $ccoaddress = implode(',',$db->getAddrs(explode(',',$params['input_cco']))); |
---|
1089 | $subject = $params['input_subject']; |
---|
1090 | $msg_uid = $params['msg_id']; |
---|
1091 | $return_receipt = $params['input_return_receipt']; |
---|
1092 | $body = $params['body']; |
---|
1093 | //echo "<script language=\"javascript\">javascript:alert('".$body."');</script>"; |
---|
1094 | $attachments = $params['FILES']; |
---|
1095 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
1096 | |
---|
1097 | $folder =$params['folder']; |
---|
1098 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); |
---|
1099 | $folder_name = $params['folder_name']; |
---|
1100 | // Fix problem with cyrus delimiter changes. |
---|
1101 | // Dots in names: enabled/disabled. |
---|
1102 | $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); |
---|
1103 | $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); |
---|
1104 | // End Fix. |
---|
1105 | if ($folder != 'null'){ |
---|
1106 | $mail->SaveMessageInFolder = $folder; |
---|
1107 | } |
---|
1108 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
1109 | $mail->SMTPDebug = false; |
---|
1110 | |
---|
1111 | $mail->IsSMTP(); |
---|
1112 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
1113 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
1114 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
1115 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
1116 | if($fromaddress){ |
---|
1117 | $mail->Sender = $mail->From; |
---|
1118 | $mail->SenderName = $mail->FromName; |
---|
1119 | $mail->FromName = $fromaddress[0]; |
---|
1120 | $mail->From = $fromaddress[1]; |
---|
1121 | } |
---|
1122 | |
---|
1123 | $this->add_recipients("to", $toaddress, &$mail); |
---|
1124 | $this->add_recipients("cc", $ccaddress, &$mail); |
---|
1125 | $this->add_recipients("cco", $ccoaddress, &$mail); |
---|
1126 | $mail->Subject = $subject; |
---|
1127 | $mail->IsHTML(true); |
---|
1128 | $mail->Body = $params['body']; |
---|
1129 | |
---|
1130 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
1131 | // Build CID for embedded Images!!! |
---|
1132 | $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&msg_num=(.+)?&msg_part=(.+)?)"/isU'; |
---|
1133 | $cid_imgs = ''; |
---|
1134 | $name_cid_files = array(); |
---|
1135 | preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); |
---|
1136 | $cid_array = array(); |
---|
1137 | foreach($cid_imgs[4] as $j => $val){ |
---|
1138 | if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) |
---|
1139 | { |
---|
1140 | $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); |
---|
1141 | } |
---|
1142 | $cid = $cid_array[$cid_imgs[3][$j].$val]; |
---|
1143 | $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); |
---|
1144 | |
---|
1145 | if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? |
---|
1146 | { |
---|
1147 | $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); |
---|
1148 | $fileName = "image_".($j).".jpg"; |
---|
1149 | $fileCode = "base64"; |
---|
1150 | $fileType = "image/jpg"; |
---|
1151 | } |
---|
1152 | else |
---|
1153 | { |
---|
1154 | $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; |
---|
1155 | $file_description = unserialize(rawurldecode($attach_img)); |
---|
1156 | |
---|
1157 | foreach($file_description as $i => $descriptor){ |
---|
1158 | $file_description[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
1159 | } |
---|
1160 | $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); |
---|
1161 | $fileName = $file_description[2]; |
---|
1162 | $fileCode = $file_description[4]; |
---|
1163 | $fileType = $this->get_file_type($file_description[2]); |
---|
1164 | unset($forwarding_attachments[$cid_imgs[4][$j]-2]); |
---|
1165 | } |
---|
1166 | $tempDir = ini_get("session.save_path"); |
---|
1167 | $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; |
---|
1168 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
1169 | fputs($f,$fileContent); |
---|
1170 | fclose($f); |
---|
1171 | if ($fileContent) |
---|
1172 | $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); |
---|
1173 | //else |
---|
1174 | // return "Error loading image attachment content"; |
---|
1175 | |
---|
1176 | } |
---|
1177 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
1178 | // Build Uploading Attachments!!! |
---|
1179 | if (count($attachments)) |
---|
1180 | { |
---|
1181 | $total_uploaded_size = 0; |
---|
1182 | $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024; |
---|
1183 | foreach ($attachments as $attach) |
---|
1184 | { |
---|
1185 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name |
---|
1186 | $total_uploaded_size = $total_uploaded_size + $attach['size']; |
---|
1187 | } |
---|
1188 | if( $total_uploaded_size > $upload_max_filesize) |
---|
1189 | return 'false'; |
---|
1190 | } |
---|
1191 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
1192 | // Build Forwarding Attachments!!! |
---|
1193 | if (count($forwarding_attachments) > 0) |
---|
1194 | { |
---|
1195 | // Bug fixed for array_search function |
---|
1196 | if(count($name_cid_files) > 0) { |
---|
1197 | $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; |
---|
1198 | $name_cid_files[0] = null; |
---|
1199 | } |
---|
1200 | |
---|
1201 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
1202 | { |
---|
1203 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
1204 | $tmp = array_values($file_description); |
---|
1205 | foreach($file_description as $i => $descriptor){ |
---|
1206 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
1207 | } |
---|
1208 | $file_description = $tmp; |
---|
1209 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
1210 | $fileName = $file_description[2]; |
---|
1211 | if(!array_search(trim($fileName),$name_cid_files)) { |
---|
1212 | $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); |
---|
1213 | } |
---|
1214 | } |
---|
1215 | } |
---|
1216 | |
---|
1217 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
1218 | // Disposition-Notification-To |
---|
1219 | if ($return_receipt) |
---|
1220 | $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
1221 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
1222 | $sent = $mail->Send(); |
---|
1223 | if(!$sent) |
---|
1224 | { |
---|
1225 | return $mail->ErrorInfo; |
---|
1226 | } |
---|
1227 | else |
---|
1228 | { |
---|
1229 | if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") |
---|
1230 | { |
---|
1231 | $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
1232 | $userip = $_SESSION['phpgw_info']['expressomail']['user']['session_ip']; |
---|
1233 | $now = date("d/m/y H:i:s"); |
---|
1234 | $addrs = $toaddress.$ccaddress.$ccoaddress; |
---|
1235 | $sent = trim($sent); |
---|
1236 | error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); |
---|
1237 | } |
---|
1238 | return true; |
---|
1239 | } |
---|
1240 | } |
---|
1241 | |
---|
1242 | function add_recipients($recipient_type, $full_address, $mail) |
---|
1243 | { |
---|
1244 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
1245 | foreach ($parse_address as $val) |
---|
1246 | { |
---|
1247 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
1248 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
1249 | continue; |
---|
1250 | |
---|
1251 | if (empty($val->personal)) |
---|
1252 | { |
---|
1253 | switch($recipient_type) |
---|
1254 | { |
---|
1255 | case "to": |
---|
1256 | $mail->AddAddress($val->mailbox."@".$val->host); |
---|
1257 | break; |
---|
1258 | case "cc": |
---|
1259 | $mail->AddCC($val->mailbox."@".$val->host); |
---|
1260 | break; |
---|
1261 | case "cco": |
---|
1262 | $mail->AddBCC($val->mailbox."@".$val->host); |
---|
1263 | break; |
---|
1264 | } |
---|
1265 | } |
---|
1266 | else |
---|
1267 | { |
---|
1268 | switch($recipient_type) |
---|
1269 | { |
---|
1270 | case "to": |
---|
1271 | $mail->AddAddress($val->mailbox."@".$val->host, $val->personal); |
---|
1272 | break; |
---|
1273 | case "cc": |
---|
1274 | $mail->AddCC($val->mailbox."@".$val->host, $val->personal); |
---|
1275 | break; |
---|
1276 | case "cco": |
---|
1277 | $mail->AddBCC($val->mailbox."@".$val->host, $val->personal); |
---|
1278 | break; |
---|
1279 | } |
---|
1280 | } |
---|
1281 | } |
---|
1282 | return true; |
---|
1283 | } |
---|
1284 | |
---|
1285 | function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) |
---|
1286 | { |
---|
1287 | $mbox_stream = $this->open_mbox($msg_folder); |
---|
1288 | $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); |
---|
1289 | if($encoding == 'base64') |
---|
1290 | $fileContent = imap_base64($fileContent); |
---|
1291 | else if($encoding == 'quoted-printable') |
---|
1292 | $fileContent = quoted_printable_decode($fileContent); |
---|
1293 | return $fileContent; |
---|
1294 | } |
---|
1295 | |
---|
1296 | function del_last_caracter($string) |
---|
1297 | { |
---|
1298 | $string = substr($string,0,(strlen($string) - 1)); |
---|
1299 | return $string; |
---|
1300 | } |
---|
1301 | |
---|
1302 | function del_last_two_caracters($string) |
---|
1303 | { |
---|
1304 | $string = substr($string,0,(strlen($string) - 2)); |
---|
1305 | return $string; |
---|
1306 | } |
---|
1307 | |
---|
1308 | function imap_sortfrom($sort_box_reverse, $search_box_type) |
---|
1309 | { |
---|
1310 | $sortfrom = array(); |
---|
1311 | $sortfrom_uid = array(); |
---|
1312 | |
---|
1313 | $num_msgs = imap_num_msg($this->mbox); |
---|
1314 | for ($i=1; $i<=$num_msgs; $i++) |
---|
1315 | { |
---|
1316 | $header = imap_headerinfo($this->mbox, $i, 80, 255); |
---|
1317 | // List UNSEEN messages. |
---|
1318 | if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ |
---|
1319 | continue; |
---|
1320 | } |
---|
1321 | // List SEEN messages. |
---|
1322 | elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ |
---|
1323 | continue; |
---|
1324 | } |
---|
1325 | // List ANSWERED messages. |
---|
1326 | elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ |
---|
1327 | continue; |
---|
1328 | } |
---|
1329 | // List FLAGGED messages. |
---|
1330 | elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ |
---|
1331 | continue; |
---|
1332 | } |
---|
1333 | |
---|
1334 | if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) |
---|
1335 | $from = $header->to; |
---|
1336 | else |
---|
1337 | $from = $header->from; |
---|
1338 | |
---|
1339 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
1340 | |
---|
1341 | if ($tmp[0]->text != "") |
---|
1342 | $sortfrom[$i] = $tmp[0]->text; |
---|
1343 | else |
---|
1344 | $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
1345 | } |
---|
1346 | |
---|
1347 | natcasesort($sortfrom); |
---|
1348 | |
---|
1349 | foreach($sortfrom as $index => $header_msg) |
---|
1350 | { |
---|
1351 | $sortfrom_uid[] = imap_uid($this->mbox, $index); |
---|
1352 | } |
---|
1353 | |
---|
1354 | if ($sort_box_reverse) |
---|
1355 | $sortfrom_uid = array_reverse($sortfrom_uid); |
---|
1356 | |
---|
1357 | return $sortfrom_uid; |
---|
1358 | } |
---|
1359 | |
---|
1360 | function move_search_messages($params){ |
---|
1361 | $params['selected_messages'] = urldecode($params['selected_messages']); |
---|
1362 | $params['new_folder'] = urldecode($params['new_folder']); |
---|
1363 | $params['new_folder_name'] = urldecode($params['new_folder_name']); |
---|
1364 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
1365 | @reset($sel_msgs); |
---|
1366 | $sorted_msgs = array(); |
---|
1367 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
1368 | $sel_msg = explode(";", $sel_msg); |
---|
1369 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
1370 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
1371 | } |
---|
1372 | else { |
---|
1373 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
1374 | } |
---|
1375 | } |
---|
1376 | @ksort($sorted_msgs); |
---|
1377 | $last_return = false; |
---|
1378 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
1379 | $params['msgs_number'] = $msgs_number; |
---|
1380 | $params['folder'] = $folder; |
---|
1381 | if($params['new_folder'] && $folder != $params['new_folder']){ |
---|
1382 | $last_return = $this -> move_messages($params); |
---|
1383 | } |
---|
1384 | elseif(!$params['new_folder'] || $params['delete'] ){ |
---|
1385 | $last_return = $this -> delete_msgs($params); |
---|
1386 | $last_return['deleted'] = true; |
---|
1387 | } |
---|
1388 | } |
---|
1389 | return $last_return; |
---|
1390 | } |
---|
1391 | |
---|
1392 | function move_messages($params) |
---|
1393 | { |
---|
1394 | $folder = $params['folder']; |
---|
1395 | $mbox_stream = $this->open_mbox($folder); |
---|
1396 | $newmailbox = ($params['new_folder']); |
---|
1397 | $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); |
---|
1398 | $new_folder_name = $params['new_folder_name']; |
---|
1399 | $msgs_number = $params['msgs_number']; |
---|
1400 | $return = array('msgs_number' => $msgs_number, |
---|
1401 | 'folder' => $folder, |
---|
1402 | 'new_folder_name' => $new_folder_name, |
---|
1403 | 'border_ID' => $params['border_ID']); |
---|
1404 | |
---|
1405 | // Caso estejamos no box principal, não é necessário pegar a informação da mensagem anterior. |
---|
1406 | if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) |
---|
1407 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
1408 | |
---|
1409 | $mbox_stream = $this->open_mbox($folder); |
---|
1410 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
1411 | imap_expunge($mbox_stream); |
---|
1412 | if($mbox_stream) |
---|
1413 | imap_close($mbox_stream); |
---|
1414 | return $return; |
---|
1415 | }else { |
---|
1416 | if(strstr(imap_last_error(),'Over quota')) { |
---|
1417 | $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; |
---|
1418 | $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; |
---|
1419 | $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
1420 | $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
1421 | $mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => imap_last_error()))); |
---|
1422 | if(!$mbox) |
---|
1423 | return imap_last_error(); |
---|
1424 | $quota = imap_get_quotaroot($mbox_stream, "INBOX"); |
---|
1425 | if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { |
---|
1426 | if($mbox_stream) |
---|
1427 | imap_close($mbox_stream); |
---|
1428 | if($mbox) |
---|
1429 | imap_close($mbox); |
---|
1430 | return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; |
---|
1431 | } |
---|
1432 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
1433 | imap_expunge($mbox_stream); |
---|
1434 | if($mbox_stream) |
---|
1435 | imap_close($mbox_stream); |
---|
1436 | // return to original quota limit. |
---|
1437 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
1438 | if($mbox) |
---|
1439 | imap_close($mbox); |
---|
1440 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
1441 | } |
---|
1442 | return $return; |
---|
1443 | } |
---|
1444 | else { |
---|
1445 | if($mbox_stream) |
---|
1446 | imap_close($mbox_stream); |
---|
1447 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
1448 | if($mbox) |
---|
1449 | imap_close($mbox); |
---|
1450 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
1451 | } |
---|
1452 | return imap_last_error(); |
---|
1453 | } |
---|
1454 | |
---|
1455 | } |
---|
1456 | else { |
---|
1457 | if($mbox_stream) |
---|
1458 | imap_close($mbox_stream); |
---|
1459 | return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; |
---|
1460 | } |
---|
1461 | } |
---|
1462 | } |
---|
1463 | |
---|
1464 | function save_msg($params) |
---|
1465 | { |
---|
1466 | |
---|
1467 | include_once("class.phpmailer.php"); |
---|
1468 | $mail = new PHPMailer(); |
---|
1469 | include_once("class.db_functions.inc.php"); |
---|
1470 | $toaddress = $params['input_to']; |
---|
1471 | $ccaddress = $params['input_cc']; |
---|
1472 | $subject = $params['input_subject']; |
---|
1473 | $body = $params['body']; |
---|
1474 | $body = str_replace("%nbsp;"," ",$params['body']); |
---|
1475 | $body = preg_replace("/\n/"," ",$body); |
---|
1476 | $body = preg_replace("/\r/","",$body); |
---|
1477 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
1478 | $attachments = $params['FILES']; |
---|
1479 | $return_files = $params['FILES']; |
---|
1480 | |
---|
1481 | $folder = $params['folder']; |
---|
1482 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); |
---|
1483 | // Fix problem with cyrus delimiter changes. |
---|
1484 | // Dots in names: enabled/disabled. |
---|
1485 | $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); |
---|
1486 | $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); |
---|
1487 | // End Fix. |
---|
1488 | |
---|
1489 | $mail->SaveMessageInFolder = $folder; |
---|
1490 | $mail->SMTPDebug = false; |
---|
1491 | |
---|
1492 | $mail->IsSMTP(); |
---|
1493 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
1494 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
1495 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
1496 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
1497 | |
---|
1498 | $mail->Sender = $mail->From; |
---|
1499 | $mail->SenderName = $mail->FromName; |
---|
1500 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
1501 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
1502 | |
---|
1503 | $this->add_recipients("to", $toaddress, &$mail); |
---|
1504 | $this->add_recipients("cc", $ccaddress, &$mail); |
---|
1505 | $mail->Subject = $subject; |
---|
1506 | $mail->IsHTML(true); |
---|
1507 | $mail->Body = $body; |
---|
1508 | |
---|
1509 | |
---|
1510 | // Build Forwarding Attachments!!! |
---|
1511 | if (count($forwarding_attachments) > 0) |
---|
1512 | { |
---|
1513 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
1514 | { |
---|
1515 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
1516 | $tmp = array_values($file_description); |
---|
1517 | foreach($file_description as $i => $descriptor){ |
---|
1518 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
1519 | } |
---|
1520 | $file_description = $tmp; |
---|
1521 | |
---|
1522 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
1523 | $fileName = $file_description[2]; |
---|
1524 | |
---|
1525 | $file_description[5] = strlen($fileContent); //Size of file |
---|
1526 | $return_forward[] = $file_description; |
---|
1527 | |
---|
1528 | $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); |
---|
1529 | } |
---|
1530 | } |
---|
1531 | |
---|
1532 | if ((count($return_forward) > 0) && (count($return_files) > 0)) |
---|
1533 | $return_files = array_merge_recursive($return_forward,$return_files); |
---|
1534 | else |
---|
1535 | if (count($return_files) < 1) |
---|
1536 | $return_files = $return_forward; |
---|
1537 | |
---|
1538 | // Build Uploading Attachments!!! |
---|
1539 | if (count($attachments)) |
---|
1540 | foreach ($attachments as $attach) |
---|
1541 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name |
---|
1542 | |
---|
1543 | |
---|
1544 | |
---|
1545 | if(!empty($mail->AltBody)) |
---|
1546 | $mail->ContentType = "multipart/alternative"; |
---|
1547 | |
---|
1548 | $mail->error_count = 0; // reset errors |
---|
1549 | $mail->SetMessageType(); |
---|
1550 | $header = $mail->CreateHeader(); |
---|
1551 | $body = $mail->CreateBody(); |
---|
1552 | |
---|
1553 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
1554 | { |
---|
1555 | $imap_options = '/tls/novalidate-cert'; |
---|
1556 | } |
---|
1557 | else |
---|
1558 | { |
---|
1559 | $imap_options = '/notls/novalidate-cert'; |
---|
1560 | } |
---|
1561 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
1562 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
1563 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
1564 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
1565 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); |
---|
1566 | |
---|
1567 | $new_header = str_replace("\n", "\r\n", $header); |
---|
1568 | $new_body = str_replace("\n", "\r\n", $body); |
---|
1569 | |
---|
1570 | $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); |
---|
1571 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
1572 | $return['msg_no'] = $status->uidnext - 1; |
---|
1573 | $return['folder_id'] = $folder; |
---|
1574 | |
---|
1575 | if($mbox_stream) |
---|
1576 | imap_close($mbox_stream); |
---|
1577 | |
---|
1578 | foreach ($return_files as $index => $_attachment) { |
---|
1579 | if (array_key_exists("name",$_attachment)){ |
---|
1580 | unset($return_files[$index]); |
---|
1581 | $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; |
---|
1582 | } |
---|
1583 | else |
---|
1584 | { |
---|
1585 | unset($return_files[$index]); |
---|
1586 | $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; |
---|
1587 | } |
---|
1588 | } |
---|
1589 | |
---|
1590 | $return['files'] = serialize($return_files); |
---|
1591 | |
---|
1592 | if (!$return['append']) |
---|
1593 | $return['append'] = imap_last_error(); |
---|
1594 | |
---|
1595 | return $return; |
---|
1596 | } |
---|
1597 | |
---|
1598 | function set_messages_flag($params) |
---|
1599 | { |
---|
1600 | $folder = $params['folder']; |
---|
1601 | $msgs_to_set = $params['msgs_to_set']; |
---|
1602 | $flag = $params['flag']; |
---|
1603 | $return = array(); |
---|
1604 | $return["msgs_to_set"] = $msgs_to_set; |
---|
1605 | $return["flag"] = $flag; |
---|
1606 | |
---|
1607 | if(!$this->mbox) |
---|
1608 | $this->mbox = $this->open_mbox($folder); |
---|
1609 | |
---|
1610 | if ($flag == "unseen") |
---|
1611 | $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
1612 | elseif ($flag == "seen") |
---|
1613 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
1614 | elseif ($flag == "answered"){ |
---|
1615 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); |
---|
1616 | imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); |
---|
1617 | } |
---|
1618 | elseif ($flag == "forwarded") |
---|
1619 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); |
---|
1620 | elseif ($flag == "flagged") |
---|
1621 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
1622 | elseif ($flag == "unflagged") |
---|
1623 | $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
1624 | |
---|
1625 | if($this->mbox) |
---|
1626 | imap_close($this->mbox); |
---|
1627 | return $return; |
---|
1628 | } |
---|
1629 | |
---|
1630 | function get_file_type($file_name) |
---|
1631 | { |
---|
1632 | $file_name = strtolower($file_name); |
---|
1633 | $strFileType = strrev(substr(strrev($file_name),0,4)); |
---|
1634 | if ($strFileType == ".asf") |
---|
1635 | return "video/x-ms-asf"; |
---|
1636 | if ($strFileType == ".avi") |
---|
1637 | return "video/avi"; |
---|
1638 | if ($strFileType == ".doc") |
---|
1639 | return "application/msword"; |
---|
1640 | if ($strFileType == ".zip") |
---|
1641 | return "application/zip"; |
---|
1642 | if ($strFileType == ".xls") |
---|
1643 | return "application/vnd.ms-excel"; |
---|
1644 | if ($strFileType == ".gif") |
---|
1645 | return "image/gif"; |
---|
1646 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
1647 | return "image/jpeg"; |
---|
1648 | if ($strFileType == ".png") |
---|
1649 | return "image/png"; |
---|
1650 | if ($strFileType == ".wav") |
---|
1651 | return "audio/wav"; |
---|
1652 | if ($strFileType == ".mp3") |
---|
1653 | return "audio/mpeg3"; |
---|
1654 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
1655 | return "video/mpeg"; |
---|
1656 | if ($strFileType == ".rtf") |
---|
1657 | return "application/rtf"; |
---|
1658 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
1659 | return "text/html"; |
---|
1660 | if ($strFileType == ".xml") |
---|
1661 | return "text/xml"; |
---|
1662 | if ($strFileType == ".xsl") |
---|
1663 | return "text/xsl"; |
---|
1664 | if ($strFileType == ".css") |
---|
1665 | return "text/css"; |
---|
1666 | if ($strFileType == ".php") |
---|
1667 | return "text/php"; |
---|
1668 | if ($strFileType == ".asp") |
---|
1669 | return "text/asp"; |
---|
1670 | if ($strFileType == ".pdf") |
---|
1671 | return "application/pdf"; |
---|
1672 | if ($strFileType == ".txt") |
---|
1673 | return "text/plain"; |
---|
1674 | if ($strFileType == ".wmv") |
---|
1675 | return "video/x-ms-wmv"; |
---|
1676 | if ($strFileType == ".sxc") |
---|
1677 | return "application/vnd.sun.xml.calc"; |
---|
1678 | if ($strFileType == ".stc") |
---|
1679 | return "application/vnd.sun.xml.calc.template"; |
---|
1680 | if ($strFileType == ".sxd") |
---|
1681 | return "application/vnd.sun.xml.draw"; |
---|
1682 | if ($strFileType == ".std") |
---|
1683 | return "application/vnd.sun.xml.draw.template"; |
---|
1684 | if ($strFileType == ".sxi") |
---|
1685 | return "application/vnd.sun.xml.impress"; |
---|
1686 | if ($strFileType == ".sti") |
---|
1687 | return "application/vnd.sun.xml.impress.template"; |
---|
1688 | if ($strFileType == ".sxm") |
---|
1689 | return "application/vnd.sun.xml.math"; |
---|
1690 | if ($strFileType == ".sxw") |
---|
1691 | return "application/vnd.sun.xml.writer"; |
---|
1692 | if ($strFileType == ".sxq") |
---|
1693 | return "application/vnd.sun.xml.writer.global"; |
---|
1694 | if ($strFileType == ".stw") |
---|
1695 | return "application/vnd.sun.xml.writer.template"; |
---|
1696 | |
---|
1697 | |
---|
1698 | return "application/octet-stream"; |
---|
1699 | } |
---|
1700 | |
---|
1701 | function htmlspecialchars_encode($str) |
---|
1702 | { |
---|
1703 | /*// replace ' and " with htmlspecialchars */ |
---|
1704 | $str = ereg_replace('&', '&', $str); |
---|
1705 | // any ampersand & that ia already in a "&" should NOT be encoded |
---|
1706 | //$str = preg_replace("/&(?![:alnum:]*;)/", "&", $str); |
---|
1707 | $str = ereg_replace('"', '"', $str); |
---|
1708 | $str = ereg_replace('\'', ''', $str); |
---|
1709 | |
---|
1710 | $str = ereg_replace('<', '<', $str); |
---|
1711 | $str = ereg_replace('>', '>', $str); |
---|
1712 | // these { and } must be html encoded or else they conflict with the template system |
---|
1713 | $str = str_replace("{", '{', $str); |
---|
1714 | $str = str_replace("}", '}', $str); |
---|
1715 | return $str; |
---|
1716 | } |
---|
1717 | function htmlspecialchars_decode($str) |
---|
1718 | { |
---|
1719 | /*// replace ' and " with htmlspecialchars */ |
---|
1720 | $str = ereg_replace('&','&', $str); |
---|
1721 | // any ampersand & that ia already in a "&" should NOT be encoded |
---|
1722 | //$str = preg_replace("/&(?![:alnum:]*;)/", "&", $str); |
---|
1723 | $str = ereg_replace('"', '"', $str); |
---|
1724 | $str = ereg_replace(''', '\'', $str); |
---|
1725 | $str = ereg_replace('<','<', $str); |
---|
1726 | $str = ereg_replace('>', '>', $str); |
---|
1727 | // these { and } must be html encoded or else they conflict with the template system |
---|
1728 | $str = str_replace('{', "{", $str); |
---|
1729 | $str = str_replace( '}',"}", $str); |
---|
1730 | return $str; |
---|
1731 | } |
---|
1732 | |
---|
1733 | function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse){ |
---|
1734 | |
---|
1735 | if(!$this->mbox) |
---|
1736 | $this->mbox = $this->open_mbox($folder); |
---|
1737 | |
---|
1738 | switch($sort_box_type){ |
---|
1739 | case 'SORTFROM': |
---|
1740 | return $this->imap_sortfrom($sort_box_reverse, $search_box_type); |
---|
1741 | case 'SORTSUBJECT': |
---|
1742 | return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); |
---|
1743 | case 'SORTSIZE': |
---|
1744 | return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); |
---|
1745 | default: |
---|
1746 | return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); |
---|
1747 | } |
---|
1748 | } |
---|
1749 | |
---|
1750 | function get_info_next_msg($params) |
---|
1751 | { |
---|
1752 | $msg_number = $params['msg_number']; |
---|
1753 | $folder = $params['msg_folder']; |
---|
1754 | $sort_box_type = $params['sort_box_type']; |
---|
1755 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
1756 | $reuse_border = $params['reuse_border']; |
---|
1757 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
1758 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
1759 | $i = 0; |
---|
1760 | |
---|
1761 | while($sort_array_msg[$i] != $msg_number) |
---|
1762 | { |
---|
1763 | $i++; |
---|
1764 | } |
---|
1765 | |
---|
1766 | if ($i == (count($sort_array_msg)-1)) |
---|
1767 | { |
---|
1768 | $params['status'] = 'false'; |
---|
1769 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
1770 | return $params; |
---|
1771 | } |
---|
1772 | |
---|
1773 | $params = array(); |
---|
1774 | $params['msg_number'] = $sort_array_msg[($i+1)]; |
---|
1775 | $params['msg_folder'] = $folder; |
---|
1776 | |
---|
1777 | $return = $this->get_info_msg($params); |
---|
1778 | $return["reuse_border"] = $reuse_border; |
---|
1779 | return $return; |
---|
1780 | } |
---|
1781 | |
---|
1782 | function get_info_previous_msg($params) |
---|
1783 | { |
---|
1784 | $msg_number = $params['msgs_number']; |
---|
1785 | $folder = $params['folder']; |
---|
1786 | $sort_box_type = $params['sort_box_type']; |
---|
1787 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
1788 | $reuse_border = $params['reuse_border']; |
---|
1789 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
1790 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
1791 | $i = 0; |
---|
1792 | |
---|
1793 | while($sort_array_msg[$i] != $msg_number) |
---|
1794 | { |
---|
1795 | $i++; |
---|
1796 | } |
---|
1797 | |
---|
1798 | if ($i == 0){ |
---|
1799 | $params['status'] = 'false'; |
---|
1800 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
1801 | return $params; |
---|
1802 | } |
---|
1803 | |
---|
1804 | $params = array(); |
---|
1805 | $params['msg_number'] = $sort_array_msg[($i-1)]; |
---|
1806 | $params['msg_folder'] = $folder; |
---|
1807 | |
---|
1808 | $return = $this->get_info_msg($params); |
---|
1809 | $return["reuse_border"] = $reuse_border; |
---|
1810 | return $return; |
---|
1811 | } |
---|
1812 | |
---|
1813 | // This function updates the values: quota, paging and new messages menu. |
---|
1814 | function get_menu_values($params){ |
---|
1815 | $return_array = array(); |
---|
1816 | $return_array = $this->get_quota($params); |
---|
1817 | |
---|
1818 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
1819 | $return_array['num_msgs'] = imap_num_msg($mbox_stream); |
---|
1820 | if($mbox_stream) |
---|
1821 | imap_close($mbox_stream); |
---|
1822 | |
---|
1823 | return $return_array; |
---|
1824 | } |
---|
1825 | |
---|
1826 | function get_quota(){ |
---|
1827 | |
---|
1828 | if(!$this->mbox) |
---|
1829 | $this->mbox = $this->open_mbox(); |
---|
1830 | |
---|
1831 | $quota = imap_get_quotaroot($this->mbox, "INBOX"); |
---|
1832 | if($this->mbox) |
---|
1833 | imap_close($this->mbox); |
---|
1834 | |
---|
1835 | if (!$quota){ |
---|
1836 | return array( |
---|
1837 | 'quota_percent' => 0, |
---|
1838 | 'quota_used' => 0, |
---|
1839 | 'quota_limit' => 0 |
---|
1840 | ); |
---|
1841 | } |
---|
1842 | |
---|
1843 | if(count($quota) && $quota['limit']) { |
---|
1844 | $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; |
---|
1845 | $quota_used = (($quota['usage']/1024)* 100 + .5 )* .01; |
---|
1846 | if($quota_used >= $quota_limit) |
---|
1847 | $quota_used = $quota_limit; |
---|
1848 | $quotaPercent = ($quota_used / $quota_limit)*100; |
---|
1849 | $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; |
---|
1850 | |
---|
1851 | return array( |
---|
1852 | 'quota_percent' => floor($quotaPercent), |
---|
1853 | 'quota_used' => floor($quota_used), |
---|
1854 | 'quota_limit' => floor($quota_limit) |
---|
1855 | ); |
---|
1856 | } |
---|
1857 | else |
---|
1858 | return array(); |
---|
1859 | } |
---|
1860 | |
---|
1861 | function send_notification($params){ |
---|
1862 | require_once("class.phpmailer.php"); |
---|
1863 | $mail = new PHPMailer(); |
---|
1864 | |
---|
1865 | $toaddress = $params['notificationto']; |
---|
1866 | |
---|
1867 | $subject = 'Confirmação de leitura: ' . $params['subject']; |
---|
1868 | $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; |
---|
1869 | $body .= 'foi lida por: ' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . ' <' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '> em ' . date("d/m/Y H:i"); |
---|
1870 | $mail->SMTPDebug = false; |
---|
1871 | $mail->IsSMTP(); |
---|
1872 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
1873 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
1874 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
1875 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
1876 | $mail->AddAddress($toaddress); |
---|
1877 | $mail->Subject = $this->htmlspecialchars_decode($subject); |
---|
1878 | |
---|
1879 | $mail->IsHTML(true); |
---|
1880 | $mail->Body = $body; |
---|
1881 | |
---|
1882 | if(!$mail->Send()){ |
---|
1883 | return $mail->ErrorInfo; |
---|
1884 | } |
---|
1885 | else |
---|
1886 | return true; |
---|
1887 | } |
---|
1888 | |
---|
1889 | function empty_trash() |
---|
1890 | { |
---|
1891 | $folder = 'INBOX' . $this->imap_delimiter . 'Lixeira'; |
---|
1892 | $mbox_stream = $this->open_mbox($folder); |
---|
1893 | $return = imap_delete($mbox_stream,'1:*'); |
---|
1894 | if($mbox_stream) |
---|
1895 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
1896 | return $return; |
---|
1897 | } |
---|
1898 | |
---|
1899 | function search($params) |
---|
1900 | { |
---|
1901 | include("class.imap_attachment.inc.php"); |
---|
1902 | $imap_attachment = new imap_attachment(); |
---|
1903 | $criteria = $params['criteria']; |
---|
1904 | $return = array(); |
---|
1905 | $folders = $this->get_folders_list(); |
---|
1906 | |
---|
1907 | $j = 0; |
---|
1908 | foreach($folders as $folder) |
---|
1909 | { |
---|
1910 | $mbox_stream = $this->open_mbox($folder); |
---|
1911 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
1912 | |
---|
1913 | if ($messages == '') |
---|
1914 | continue; |
---|
1915 | |
---|
1916 | $i = 0; |
---|
1917 | $return[$j] = array(); |
---|
1918 | $return[$j]['folder_name'] = $folder['name']; |
---|
1919 | |
---|
1920 | foreach($messages as $msg_number) |
---|
1921 | { |
---|
1922 | $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $msg_number), 80, 255); |
---|
1923 | if (!is_object($header)) |
---|
1924 | return false; |
---|
1925 | |
---|
1926 | $return[$j][$i]['msg_folder'] = $folder['name']; |
---|
1927 | $return[$j][$i]['msg_number'] = $msg_number; |
---|
1928 | $return[$j][$i]['Recent'] = $header->Recent; |
---|
1929 | $return[$j][$i]['Unseen'] = $header->Unseen; |
---|
1930 | $return[$j][$i]['Answered'] = $header->Answered; |
---|
1931 | $return[$j][$i]['Deleted'] = $header->Deleted; |
---|
1932 | $return[$j][$i]['Draft'] = $header->Draft; |
---|
1933 | $return[$j][$i]['Flagged'] = $header->Flagged; |
---|
1934 | |
---|
1935 | $date_msg = date("d/m/Y",$header->udate); |
---|
1936 | if (date("d/m/Y") == $date_msg) |
---|
1937 | $return[$j][$i]['udate'] = date("H:i",$header->udate); |
---|
1938 | else |
---|
1939 | $return[$j][$i]['udate'] = $date_msg; |
---|
1940 | |
---|
1941 | $fromaddress = imap_mime_header_decode($header->fromaddress); |
---|
1942 | $return[$j][$i]['fromaddress'] = ''; |
---|
1943 | foreach ($fromaddress as $tmp) |
---|
1944 | $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); |
---|
1945 | |
---|
1946 | $from = $header->from; |
---|
1947 | $return[$j][$i]['from'] = array(); |
---|
1948 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
1949 | $return[$j][$i]['from']['name'] = $tmp[0]->text; |
---|
1950 | $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
1951 | $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; |
---|
1952 | |
---|
1953 | $to = $header->to; |
---|
1954 | $return[$j][$i]['to'] = array(); |
---|
1955 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
1956 | $return[$j][$i]['to']['name'] = $tmp[0]->text; |
---|
1957 | $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
1958 | $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
1959 | |
---|
1960 | $subject = imap_mime_header_decode($header->fetchsubject); |
---|
1961 | $return[$j][$i]['subject'] = ''; |
---|
1962 | foreach ($subject as $tmp) |
---|
1963 | $return[$j][$i]['subject'] .= $tmp->text; |
---|
1964 | |
---|
1965 | $return[$j][$i]['Size'] = $header->Size; |
---|
1966 | $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
1967 | |
---|
1968 | $return[$j][$i]['attachment'] = array(); |
---|
1969 | $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); |
---|
1970 | |
---|
1971 | $i++; |
---|
1972 | } |
---|
1973 | $j++; |
---|
1974 | if($mbox_stream) |
---|
1975 | imap_close($mbox_stream); |
---|
1976 | } |
---|
1977 | |
---|
1978 | return $return; |
---|
1979 | } |
---|
1980 | |
---|
1981 | function delete_and_show_previous_message($params) |
---|
1982 | { |
---|
1983 | $return = $this->get_info_previous_msg($params); |
---|
1984 | |
---|
1985 | $params_tmp1 = array(); |
---|
1986 | $params_tmp1['msgs_to_delete'] = $params['msg_number']; |
---|
1987 | $params_tmp1['folder'] = $params['msg_folder']; |
---|
1988 | $return_tmp1 = $this->delete_msg($params_tmp1); |
---|
1989 | |
---|
1990 | $return['msg_number_deleted'] = $return_tmp1; |
---|
1991 | |
---|
1992 | return $return; |
---|
1993 | } |
---|
1994 | |
---|
1995 | |
---|
1996 | function automatic_trash_cleanness($params) |
---|
1997 | { |
---|
1998 | $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); |
---|
1999 | $criteria = 'BEFORE "'.$before_date.'"'; |
---|
2000 | $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter."Lixeira"); |
---|
2001 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
2002 | if (is_array($messages)){ |
---|
2003 | foreach ($messages as $msg_number){ |
---|
2004 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
2005 | } |
---|
2006 | } |
---|
2007 | if($mbox_stream) |
---|
2008 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
2009 | return $messages; |
---|
2010 | } |
---|
2011 | // Fix the search problem with special characters!!!! |
---|
2012 | function remove_accents($string) { |
---|
2013 | return strtr($string, |
---|
2014 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
2015 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
2016 | } |
---|
2017 | |
---|
2018 | function search_msg($params = ''){ |
---|
2019 | $retorno = ""; |
---|
2020 | $mbox_stream = ""; |
---|
2021 | $search = explode(",",$params['condition']); |
---|
2022 | if($search){ |
---|
2023 | $search_criteria = ''; |
---|
2024 | foreach($search as $tmp) |
---|
2025 | { |
---|
2026 | $tmp1 = explode("##",$tmp); |
---|
2027 | $name_box = $tmp1[0]; |
---|
2028 | $criteria = explode("<=>",rawurldecode($tmp1[1])); |
---|
2029 | $criteria[1] = $this->remove_accents($criteria[1]); |
---|
2030 | |
---|
2031 | if(!is_resource($mbox_stream)) |
---|
2032 | $mbox_stream = $this->open_mbox(); |
---|
2033 | else |
---|
2034 | imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); |
---|
2035 | |
---|
2036 | if($criteria[0] == "ALL ") { |
---|
2037 | $all_criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
2038 | foreach($all_criterias as $criteria_fixed) |
---|
2039 | { |
---|
2040 | $filter = $criteria_fixed . ' "' . $criteria[1] . '"'; |
---|
2041 | $search_criteria = imap_search($mbox_stream, $filter, SE_UID); |
---|
2042 | |
---|
2043 | if($search_criteria && count($search_criteria) < 50) |
---|
2044 | { |
---|
2045 | foreach($search_criteria as $new_search){ |
---|
2046 | $m_token = trim("##".$name_box . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); |
---|
2047 | if(!@strstr($retorno,$m_token)) |
---|
2048 | $retorno .= $m_token; |
---|
2049 | } |
---|
2050 | } |
---|
2051 | else if(count($search_criteria) >= 50) |
---|
2052 | return "many results"; |
---|
2053 | } |
---|
2054 | } |
---|
2055 | else { |
---|
2056 | $filter = $criteria[0] . '"' . $criteria[1] . '"'; |
---|
2057 | $search_criteria = imap_search($mbox_stream, $filter, SE_UID); |
---|
2058 | |
---|
2059 | if($search_criteria) { |
---|
2060 | foreach($search_criteria as $new_search){ |
---|
2061 | $retorno .= trim("##".$name_box . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); |
---|
2062 | } |
---|
2063 | } |
---|
2064 | } |
---|
2065 | } |
---|
2066 | } |
---|
2067 | if($mbox_stream) |
---|
2068 | imap_close($mbox_stream); |
---|
2069 | |
---|
2070 | return $retorno ? $retorno : "none"; |
---|
2071 | } |
---|
2072 | |
---|
2073 | function get_msg($uid_msg,$name_box, $mbox_stream ) |
---|
2074 | { |
---|
2075 | $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); |
---|
2076 | $subject = $this->decode_string($header->fetchsubject); |
---|
2077 | $from = $header->from[0]->mailbox; |
---|
2078 | if($header->from[0]->personal != "") |
---|
2079 | $from = $header->from[0]->personal; |
---|
2080 | $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size); |
---|
2081 | return $ret_msg; |
---|
2082 | } |
---|
2083 | |
---|
2084 | function size_msg($size){ |
---|
2085 | $var = floor($size/1024); |
---|
2086 | if($var >= 1){ |
---|
2087 | return $var." kb"; |
---|
2088 | }else{ |
---|
2089 | return $size ." b"; |
---|
2090 | } |
---|
2091 | } |
---|
2092 | |
---|
2093 | function ob_array($the_object) |
---|
2094 | { |
---|
2095 | $the_array=array(); |
---|
2096 | if(!is_scalar($the_object)) |
---|
2097 | { |
---|
2098 | foreach($the_object as $id => $object) |
---|
2099 | { |
---|
2100 | if(is_scalar($object)) |
---|
2101 | { |
---|
2102 | $the_array[$id]=$object; |
---|
2103 | } |
---|
2104 | else |
---|
2105 | { |
---|
2106 | $the_array[$id]=$this->ob_array($object); |
---|
2107 | } |
---|
2108 | } |
---|
2109 | return $the_array; |
---|
2110 | } |
---|
2111 | else |
---|
2112 | { |
---|
2113 | return $the_object; |
---|
2114 | } |
---|
2115 | } |
---|
2116 | |
---|
2117 | function getacl() |
---|
2118 | { |
---|
2119 | $this->ldap = new ldap_functions(); |
---|
2120 | |
---|
2121 | $return = array(); |
---|
2122 | $mbox_stream = $this->open_mbox(); |
---|
2123 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
2124 | |
---|
2125 | $i = 0; |
---|
2126 | foreach ($mbox_acl as $user => $acl) |
---|
2127 | { |
---|
2128 | if ($user != $this->username) |
---|
2129 | { |
---|
2130 | $return[$i]['uid'] = $user; |
---|
2131 | $return[$i]['cn'] = $this->ldap->uid2cn($user); |
---|
2132 | } |
---|
2133 | $i++; |
---|
2134 | } |
---|
2135 | return $return; |
---|
2136 | } |
---|
2137 | |
---|
2138 | function setacl($params) |
---|
2139 | { |
---|
2140 | $old_users = $this->getacl(); |
---|
2141 | if (!count($old_users)) |
---|
2142 | $old_users = array(); |
---|
2143 | |
---|
2144 | $tmp_array = array(); |
---|
2145 | foreach ($old_users as $index => $user_info) |
---|
2146 | { |
---|
2147 | $tmp_array[$index] = $user_info['uid']; |
---|
2148 | } |
---|
2149 | $old_users = $tmp_array; |
---|
2150 | |
---|
2151 | $users = unserialize($params['users']); |
---|
2152 | if (!count($users)) |
---|
2153 | $users = array(); |
---|
2154 | |
---|
2155 | //$add_share = array_diff($users, $old_users); |
---|
2156 | $remove_share = array_diff($old_users, $users); |
---|
2157 | |
---|
2158 | $mbox_stream = $this->open_mbox(); |
---|
2159 | |
---|
2160 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
2161 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
2162 | |
---|
2163 | /*if (count($add_share)) |
---|
2164 | { |
---|
2165 | foreach ($add_share as $index=>$uid) |
---|
2166 | { |
---|
2167 | if (is_array($mailboxes_list)) |
---|
2168 | { |
---|
2169 | foreach ($mailboxes_list as $key => $val) |
---|
2170 | { |
---|
2171 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
2172 | imap_setacl ($mbox_stream, $folder, "$uid", "lrswipcda"); |
---|
2173 | } |
---|
2174 | } |
---|
2175 | } |
---|
2176 | }*/ |
---|
2177 | |
---|
2178 | if (count($remove_share)) |
---|
2179 | { |
---|
2180 | foreach ($remove_share as $index=>$uid) |
---|
2181 | { |
---|
2182 | if (is_array($mailboxes_list)) |
---|
2183 | { |
---|
2184 | foreach ($mailboxes_list as $key => $val) |
---|
2185 | { |
---|
2186 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
2187 | imap_setacl ($mbox_stream, $folder, "$uid", ""); |
---|
2188 | } |
---|
2189 | } |
---|
2190 | } |
---|
2191 | } |
---|
2192 | |
---|
2193 | return true; |
---|
2194 | } |
---|
2195 | |
---|
2196 | function getaclfromuser($params) |
---|
2197 | { |
---|
2198 | $useracl = $params['user']; |
---|
2199 | |
---|
2200 | $return = array(); |
---|
2201 | $return[$useracl] = 'false'; |
---|
2202 | $mbox_stream = $this->open_mbox(); |
---|
2203 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
2204 | |
---|
2205 | foreach ($mbox_acl as $user => $acl) |
---|
2206 | { |
---|
2207 | if (($user != $this->username) && ($user == $useracl)) |
---|
2208 | { |
---|
2209 | $return[$user] = $acl; |
---|
2210 | } |
---|
2211 | } |
---|
2212 | return $return; |
---|
2213 | } |
---|
2214 | |
---|
2215 | function getacltouser($user) |
---|
2216 | { |
---|
2217 | $return = array(); |
---|
2218 | $mbox_stream = $this->open_mbox(); |
---|
2219 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
2220 | return $mbox_acl[$this->username]; |
---|
2221 | } |
---|
2222 | |
---|
2223 | |
---|
2224 | function setaclfromuser($params) |
---|
2225 | { |
---|
2226 | $user = $params['user']; |
---|
2227 | $acl = $params['acl']; |
---|
2228 | |
---|
2229 | $mbox_stream = $this->open_mbox(); |
---|
2230 | |
---|
2231 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
2232 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
2233 | |
---|
2234 | if (is_array($mailboxes_list)) |
---|
2235 | { |
---|
2236 | foreach ($mailboxes_list as $key => $val) |
---|
2237 | { |
---|
2238 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
2239 | if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) |
---|
2240 | { |
---|
2241 | return imap_last_error(); |
---|
2242 | } |
---|
2243 | } |
---|
2244 | } |
---|
2245 | |
---|
2246 | return true; |
---|
2247 | } |
---|
2248 | |
---|
2249 | function download_attachment($msg,$msgno) |
---|
2250 | { |
---|
2251 | $array_parts_attachments = array(); |
---|
2252 | $array_parts_attachments['names'] = ''; |
---|
2253 | include("class.imap_attachment.inc.php"); |
---|
2254 | $imap_attachment = new imap_attachment(); |
---|
2255 | |
---|
2256 | if (count($msg->fname[$msgno]) > 0) |
---|
2257 | { |
---|
2258 | $i = 0; |
---|
2259 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
2260 | { |
---|
2261 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
2262 | $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($fname); |
---|
2263 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
2264 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
2265 | $array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
2266 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
2267 | $i++; |
---|
2268 | } |
---|
2269 | } |
---|
2270 | $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
2271 | return $array_parts_attachments; |
---|
2272 | } |
---|
2273 | |
---|
2274 | function spam($params) |
---|
2275 | { |
---|
2276 | $is_spam = $params['spam']; |
---|
2277 | $folder = $params['folder']; |
---|
2278 | $mbox_stream = $this->open_mbox($folder); |
---|
2279 | $msgs_number = explode(',',$params['msgs_number']); |
---|
2280 | |
---|
2281 | foreach($msgs_number as $msg_number) { |
---|
2282 | $header = imap_fetchheader($mbox_stream, imap_msgno($mbox_stream, $msg_number)); |
---|
2283 | $body = imap_body($mbox_stream, imap_msgno($mbox_stream, $msg_number)); |
---|
2284 | $msg = $header . $body; |
---|
2285 | $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
2286 | $username = $this->username; |
---|
2287 | strtok($email, '@'); |
---|
2288 | $domain = strtok('@'); |
---|
2289 | |
---|
2290 | //Encontrar a assinatura do dspam no cabecalho |
---|
2291 | $v = explode("\r\n", $header); |
---|
2292 | foreach ($v as $linha){ |
---|
2293 | if (eregi("^X-DSPAM-Signature", $linha)) { |
---|
2294 | |
---|
2295 | $args = explode(" ",$linha); |
---|
2296 | $signature = $args[1]; |
---|
2297 | } |
---|
2298 | } |
---|
2299 | |
---|
2300 | // feed dspam |
---|
2301 | switch($is_spam){ |
---|
2302 | case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; |
---|
2303 | case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; |
---|
2304 | } |
---|
2305 | $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); |
---|
2306 | $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); |
---|
2307 | system($cmd); |
---|
2308 | } |
---|
2309 | imap_close($mbox_stream); |
---|
2310 | return false; |
---|
2311 | } |
---|
2312 | } |
---|
2313 | ?> |
---|