- Timestamp:
- 09/18/08 17:08:34 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r432 r449 7 7 { 8 8 var $public_functions = array 9 ( 9 ( 10 10 'get_range_msgs' => True, 11 11 'get_info_msg' => True, … … 26 26 $this->imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 27 27 $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; 28 $this->functions = new functions(); 28 $this->functions = new functions(); 29 29 $this->has_cid = false; 30 30 31 31 if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 32 32 { … … 53 53 $msg_range_begin = $params['msg_range_begin']; 54 54 $msg_range_end = $params['msg_range_end']; 55 $sort_box_type = $params['sort_box_type']; 55 $sort_box_type = $params['sort_box_type']; 56 56 $sort_box_reverse = $params['sort_box_reverse']; 57 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 58 $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 59 60 60 $return = array(); 61 61 $i = 0; 62 62 $num_msgs = (is_array($sort_array_msg) ? count($sort_array_msg) : 0); 63 if($num_msgs) { 63 if($num_msgs) { 64 64 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++) 65 65 { … … 68 68 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 69 69 if (!is_object($header)) 70 return false; 71 70 return false; 71 72 72 $return[$i]['Recent'] = $header->Recent; 73 73 $return[$i]['Unseen'] = $header->Unseen; … … 77 77 else { 78 78 $return[$i]['Answered'] = $header->Answered; 79 $return[$i]['Draft'] = $header->Draft; 79 $return[$i]['Draft'] = $header->Draft; 80 80 } 81 81 $return[$i]['Deleted'] = $header->Deleted; 82 82 $return[$i]['Flagged'] = $header->Flagged; 83 83 84 84 $return[$i]['msg_number'] = $msg_number; 85 85 //$return[$i]['msg_folder'] = $folder; 86 86 87 87 $date_msg = date("d/m/Y",$header->udate); 88 88 if (date("d/m/Y") == $date_msg) … … 90 90 else 91 91 $return[$i]['udate'] = $date_msg; 92 92 93 93 $from = $header->from; 94 94 $return[$i]['from'] = array(); … … 108 108 109 109 $return[$i]['Size'] = $header->Size; 110 110 111 111 $return[$i]['attachment'] = array(); 112 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 112 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 113 113 $i++; 114 114 } 115 115 } 116 $return['num_msgs'] = $num_msgs; 117 116 $return['num_msgs'] = $num_msgs; 117 118 118 return $return; 119 119 } 120 120 121 121 function decode_string($string) 122 { 122 { 123 123 if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) 124 124 { … … 145 145 return $this->htmlspecialchars_encode($string); 146 146 } 147 147 148 148 function get_info_msg($params) 149 149 { … … 151 151 $msg_number = $params['msg_number']; 152 152 $msg_folder = $params['msg_folder']; 153 153 154 154 if(!$this->mbox || !is_resource($this->mbox)) 155 $this->mbox = $this->open_mbox($msg_folder); 156 157 158 //if(!$this->mbox) 159 // $this->mbox = $this->open_mbox($msg_folder); 160 155 $this->mbox = $this->open_mbox($msg_folder); 156 161 157 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 162 158 if (!$header) { … … 166 162 $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); 167 163 $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 168 164 169 165 $return['body'] = $return_get_body['body']; 170 166 $return['attachments'] = $return_get_body['attachments']; 171 167 $return['thumbs'] = $return_get_body['thumbs']; 172 168 $return['signature'] = $return_get_body['signature']; 173 169 174 170 foreach($all_header as $line) { 175 171 if (eregi("^Disposition-Notification-To", $line)) { … … 180 176 $return['Recent'] = $header->Recent; 181 177 $return['Unseen'] = $header->Unseen; 182 $return['Deleted'] = $header->Deleted; 178 $return['Deleted'] = $header->Deleted; 183 179 $return['Flagged'] = $header->Flagged; 184 180 … … 188 184 else { 189 185 $return['Answered'] = $header->Answered; 190 $return['Draft'] = $header->Draft; 186 $return['Draft'] = $header->Draft; 191 187 } 192 188 193 189 $return['msg_number'] = $msg_number; 194 190 $return['msg_folder'] = $msg_folder; 195 191 196 192 $date_msg = date("d/m/Y",$header->udate); 197 193 if (date("d/m/Y") == $date_msg) … … 199 195 else 200 196 $return['udate'] = $date_msg; 201 202 $return['msg_day'] = $date_msg; 197 198 $return['msg_day'] = $date_msg; 203 199 $return['msg_hour'] = date("H:i",$header->udate); 204 200 205 201 if (date("d/m/Y") == $date_msg) //no dia 206 202 { 207 203 $return['fulldate'] = date("d/m/Y H:i",$header->udate); 208 204 $return['smalldate'] = date("H:i",$header->udate); 209 205 210 206 $timestamp_now = strtotime("now"); 211 207 $timestamp_msg_time = $header->udate; 212 208 $timestamp_diff = $timestamp_now - $timestamp_msg_time; 213 209 214 210 if (gmdate("H",$timestamp_diff) > 0) 215 211 { … … 233 229 $return['smalldate'] = date("d/m/Y",$header->udate); 234 230 } 235 231 236 232 $from = $header->from; 237 233 $return['from'] = array(); … … 248 244 else 249 245 $return['from']['full'] = $return['from']['email']; 250 246 251 247 // Sender attribute 252 248 $sender = $header->sender; … … 300 296 { 301 297 $return['toaddress2'] = "<Empty>"; 302 } 303 298 } 299 304 300 $cc = $header->cc; 305 301 $return['cc'] = ""; … … 329 325 { 330 326 $return['cc'] = ""; 331 } 327 } 328 329 ## 330 # @AUTHOR Rodrigo Souza dos Santos 331 # @DATE 2008/09/12 332 # @BRIEF Adding the BCC field. 333 ## 334 $bcc = $header->bcc; 335 $return['bcc'] = ""; 336 if (!empty($bcc)) 337 { 338 foreach ($bcc as $tmp_bcc) 339 { 340 if (!empty($tmp_bcc->personal)) 341 { 342 $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); 343 $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; 344 $return['bcc'] .= " "; 345 $return['bcc'] .= "<"; 346 $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; 347 $return['bcc'] .= ">"; 348 $return['bcc'] .= ", "; 349 } 350 else 351 { 352 $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; 353 $return['bcc'] .= ", "; 354 } 355 } 356 $return['bcc'] = $this->del_last_two_caracters($return['bcc']); 357 } 358 else 359 { 360 $return['bcc'] = ""; 361 } 332 362 333 363 $reply_to = $header->reply_to; … … 361 391 $return['Size'] = $header->Size; 362 392 $return['reply_toaddress'] = $header->reply_toaddress; 363 393 364 394 return $return; 365 395 } 366 396 367 397 function get_body_msg($msg_number, $msg_folder) 368 398 { … … 371 401 $msg->fetch_structure($msg_number); 372 402 $return = array(); 373 $return['attachments'] = $this-> download_attachment($msg,$msg_number); 403 $return['attachments'] = $this-> download_attachment($msg,$msg_number); 374 404 if(!$this->has_cid) 375 405 { 376 406 $return['thumbs'] = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); 377 407 $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 378 } 379 408 } 409 380 410 if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 381 411 { 382 412 $attachment = array(); //No attachments 383 413 384 414 $content = ''; 385 415 if (strtolower($msg->structure[$msg_number]->subtype) == "plain") … … 392 422 } 393 423 } 394 else 424 else 395 425 { //Complicated message, multiple parts 396 426 $html_body = ''; … … 398 428 $has_multipart = true; 399 429 $this->has_cid = false; 400 430 401 431 if (strtolower($msg->structure[$msg_number]->subtype) == "related") 402 432 $this->has_cid = true; 403 433 404 434 if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") 405 435 { … … 409 439 $file_type = strtolower($msg->file_type[$msg_number][$values]); 410 440 if($file_type == "text/html") 411 $show_only_html = true;441 $show_only_html = true; 412 442 } 413 443 } … … 417 447 foreach($msg->pid[$msg_number] as $values => $msg_part) 418 448 { 419 449 420 450 $file_type = strtolower($msg->file_type[$msg_number][$values]); 421 451 if($file_type == "message/rfc822") 422 452 $has_multipart = false; 423 453 424 454 if($file_type == "multipart/alternative") 425 455 $has_multipart = false; 426 427 if(($file_type == "text/plain" 456 457 if(($file_type == "text/plain" 428 458 || $file_type == "text/html") 429 459 && $file_type != 'attachment') … … 433 463 // if TXT file size > 100kb, then it will not expand. 434 464 if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 435 $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]))); 465 $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]))); 436 466 } 437 467 } 438 468 // if HTML attachment file size > 300kb, then it will not expand. 439 else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 307200 0)469 else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 307200) 440 470 { 441 471 $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); … … 445 475 else if($file_type == "message/delivery-status"){ 446 476 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 447 $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 477 $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 448 478 449 479 } 450 480 else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ 451 481 452 482 include_once("class.imap_attachment.inc.php"); 453 483 $att = new imap_attachment(); 454 484 $attachments = $att -> get_attachment_info($this->mbox,$msg_number); 455 if($attachments['number_attachments'] > 0) { 485 if($attachments['number_attachments'] > 0) { 456 486 foreach($attachments ['attachment'] as $index => $attachment){ 457 487 if(strtolower($attachment['type']) == "delivery-status" || 458 strtolower($attachment['type']) == "rfc822" || 488 strtolower($attachment['type']) == "rfc822" || 459 489 strtolower($attachment['type']) == "rfc822-headers" || 460 490 strtolower($attachment['type']) == "plain" 461 491 ){ 462 $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); 463 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 492 $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); 493 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 464 494 $content .= "<br><table style='margin:2px;border:1px solid black;background:#EAEAEA'>"; 465 495 $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; … … 467 497 $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; 468 498 $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; 469 $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>"; 499 $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>"; 470 500 $ix_part = strtolower($attachment['type']) == "delivery-status" ? 1 : 0; 471 $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])); 472 break; 501 $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])); 502 break; 473 503 } 474 504 } … … 480 510 $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); 481 511 else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") 482 $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 483 } 484 } 512 $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 513 } 514 } 485 515 // Force message with flag Seen (imap_fetchbody not works correctly) 486 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 516 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 487 517 $this->set_messages_flag($params); 488 518 $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); … … 491 521 return $return; 492 522 } 493 523 494 524 function htmlfilter($body) 495 525 { 496 526 require_once('htmlfilter.inc'); 497 527 498 528 $tag_list = Array( 499 529 false, … … 568 598 '\\1round:\\2\\1' 569 599 ) 570 ), 571 600 ), 601 572 602 '/^style/i' => 573 603 Array( … … 595 625 '/^a$/i' => Array('target' => '"_new"') 596 626 ); 597 598 627 628 599 629 $trusted_body = sanitize($body, 600 630 $tag_list, … … 606 636 $add_attr_to_tag 607 637 ); 608 638 609 639 return $trusted_body; 610 640 } 611 641 612 642 function decodeBody($body, $encoding, $charset=null) 613 643 { … … 620 650 if ($encoding == 'quoted-printable') 621 651 { 622 652 623 653 for($i=0;$i<256;$i++) { 624 654 $c1=dechex($i); … … 627 657 $myqprinta[]=$c1; 628 658 $myqprintb[]=chr($i); 629 } 659 } 630 660 $body = str_replace($myqprinta,$myqprintb,($body)); 631 661 $body = quoted_printable_decode($body); 632 while (ereg("=\n", $body)) 662 while (ereg("=\n", $body)) 633 663 { 634 664 $body = ereg_replace ("=\n", '', $body); 635 665 } 636 666 } 637 else if ($encoding == 'base64') 667 else if ($encoding == 'base64') 638 668 { 639 669 $body = base64_decode($body); 640 670 } 641 /*else if ($encoding == '7bit') 671 /*else if ($encoding == '7bit') 642 672 { 643 $body = quoted_printable_decode($body); 673 $body = quoted_printable_decode($body); 644 674 }*/ 645 675 // All other encodings are returned raw. … … 649 679 return $body; 650 680 } 651 681 652 682 function process_embedded_images($msg, $msgno, $body, $msg_folder) 653 683 { … … 666 696 } 667 697 } 668 698 669 699 return $body; 670 700 } 671 701 672 702 function replace_special_characters($body) 673 703 { 674 704 // Suspected TAGS! 675 /*$tag_list = Array( 705 /*$tag_list = Array( 676 706 'blink','object','meta', 677 707 'html','link','frame', … … 682 712 */ 683 713 684 // Layout problem: Change html elements 685 // with absolute position to relate position, CASE INSENSITIVE. 714 // Layout problem: Change html elements 715 // with absolute position to relate position, CASE INSENSITIVE. 686 716 $body = @eregi_replace("POSITION: ABSOLUTE;","",$body); 687 717 … … 691 721 692 722 $body = $this-> replace_links($body); 693 $blocked_tags = array(); 723 $blocked_tags = array(); 694 724 foreach($tag_list as $index => $tag) { 695 725 $new_body = eregi_replace("<$tag", "<!--$tag", $body); … … 703 733 } 704 734 705 function replace_links($body) { 706 // Search for links,then open the link in new window. 707 //$body = @ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)', '<a href="\\0" title="'.$this->functions->getLang("Open in New Window").'">\\0</a>',$body); 708 //Search for emails, then open a new message tab. 709 //$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); 710 //$matches = array(); 735 function replace_links($body) { 736 $matches = array(); 711 737 // Verify exception. 712 //@preg_match("/<a href=\"notes:\/\/\//",$body,$matches);738 @preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 713 739 // It no has exception,then open the link in new window. 714 /*if(!count($matches)){ 715 $body = @eregi_replace("<a (.*) href=", "<a \\1 target='_blank' href=", $body); 716 $body = @str_replace("<a href=", "<a target='_blank' href=", $body); 717 $body = @eregi_replace("target=\"\"", "target='_blank'", $body); 718 $body = @eregi_replace("target=''", "target='_blank'", $body); 719 }*/ 720 $body = preg_replace('/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\/\w.\-~&=?%;@+]*))/i', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $body); 721 return $body; 740 if(count($matches)) 741 return $body; 742 743 $pattern = '/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; 744 $replacement = '<a href="http$3://$4$5" target="_blank">$1</a>'; 745 return preg_replace($pattern, $replacement, $body); 746 747 // Original 748 //return preg_replace('/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\/\w.\-~&=?%;@+]*))/i', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $body); 722 749 } 723 750 724 751 function get_signature($msg, $msg_number, $msg_folder) 725 { 752 { 726 753 foreach ($msg->file_type[$msg_number] as $index => $file_type) 727 754 { 728 755 $file_type = strtolower($file_type); 729 if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 730 { 731 if ($file_type == 'application/x-pkcs7-signature') 756 if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 757 { 758 if ($file_type == 'application/x-pkcs7-signature') 732 759 { 733 760 $export_mail = new ExportEml(); … … 735 762 $params['msgs_to_export'] = $msg_number; 736 763 $tempDir = ini_get("session.save_path"); 737 $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 764 $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 738 765 $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); 739 766 if (file_exists($cert_file)) … … 755 782 } 756 783 } 757 return $sign; 784 return $sign; 758 785 } 759 786 … … 776 803 return $thumbs_array; 777 804 } 778 805 779 806 /*function delete_msg($params) 780 807 { 781 808 $folder = $params['folder']; 782 809 $msgs_to_delete = explode(",",$params['msgs_to_delete']); 783 810 784 811 $mbox_stream = $this->open_mbox($folder); 785 812 786 813 foreach ($msgs_to_delete as $msg_number){ 787 814 imap_delete($mbox_stream, $msg_number, FT_UID); … … 794 821 function delete_msgs($params) 795 822 { 796 823 797 824 $folder = $params['folder']; 798 825 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 799 826 $msgs_number = explode(",",$params['msgs_number']); 800 827 $border_ID = $params['border_ID']; 801 828 802 829 $return = array(); 803 804 if ($params['get_previous_msg']) 830 831 if ($params['get_previous_msg']){ 805 832 $return['previous_msg'] = $this->get_info_previous_msg($params); 833 // Fix problem in unserialize function JS. 834 $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); 835 } 806 836 807 837 //$mbox_stream = $this->open_mbox($folder); 808 838 $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()))); 809 839 810 840 foreach ($msgs_number as $msg_number) 811 841 { … … 813 843 $return['msgs_number'][] = $msg_number; 814 844 } 815 845 816 846 $return['folder'] = $folder; 817 847 $return['border_ID'] = $border_ID; 818 848 819 849 if($mbox_stream) 820 850 imap_close($mbox_stream, CL_EXPUNGE); … … 822 852 } 823 853 824 854 825 855 function refresh($params) 826 856 { 827 857 include("class.imap_attachment.inc.php"); 828 $imap_attachment = new imap_attachment(); 858 $imap_attachment = new imap_attachment(); 829 859 $folder = $params['folder']; 830 860 $msg_range_begin = $params['msg_range_begin']; 831 861 $msg_range_end = $params['msg_range_end']; 832 862 $msgs_existent = $params['msgs_existent']; 833 $sort_box_type = $params['sort_box_type']; 863 $sort_box_type = $params['sort_box_type']; 834 864 $sort_box_reverse = $params['sort_box_reverse']; 835 865 $msgs_in_the_server = array(); … … 839 869 if(!count($sort_array_msg)) 840 870 return array(); 841 871 842 872 $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); 843 873 $msgs_in_the_client = explode(",", $msgs_existent); 844 874 845 875 846 876 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) 847 877 { … … 858 888 } 859 889 } 860 890 861 891 $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); 862 892 $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 863 893 864 894 $msgs_to_exec = array(); 865 895 if ((count($msg_to_insert)) && ($msgs_existent)) … … 887 917 } 888 918 } 889 919 890 920 $return = array(); 891 921 $i = 0; … … 895 925 if (!is_object($header)) 896 926 return false; 897 927 898 928 $return[$i]['msg_number'] = $msg_number; 899 929 $return[$i]['command'] = $command; 900 930 901 931 $return[$i]['msg_folder'] = $folder; 902 932 $return[$i]['Recent'] = $header->Recent; … … 912 942 else 913 943 $return[$i]['udate'] = $date_msg; 914 944 915 945 $from = $header->from; 916 946 $return[$i]['from'] = array(); … … 918 948 $return[$i]['from']['name'] = $tmp[0]->text; 919 949 $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 920 //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 950 //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 921 951 if(!$return[$i]['from']['name']) 922 952 $return[$i]['from']['name'] = $return[$i]['from']['email']; 923 953 924 954 /*$toaddress = imap_mime_header_decode($header->toaddress); 925 955 $return[$i]['toaddress'] = ''; … … 932 962 $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 933 963 $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 934 964 935 965 $return[$i]['subject'] = $this->decode_string($header->fetchsubject); 936 966 937 967 $return[$i]['Size'] = $header->Size; 938 968 $return[$i]['reply_toaddress'] = $header->reply_toaddress; 939 969 940 970 $return[$i]['attachment'] = array(); 941 971 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); … … 949 979 } 950 980 951 function get_folders_list( )952 { 953 $mbox_stream = $this->open_mbox(); 981 function get_folders_list($params = null) 982 { 983 $mbox_stream = $this->open_mbox(); 954 984 $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; 955 985 $folders_list = imap_getmailboxes($mbox_stream, $serverString, "*"); 956 986 $tmp = array(); 957 987 $result = array(); 958 988 959 989 if (is_array($folders_list)) { 960 990 reset($folders_list); 961 991 $this->ldap = new ldap_functions(); 962 992 963 993 $i = 0; 964 994 while (list($key, $val) = each($folders_list)) { 965 995 $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 966 996 $result[$i]['folder_unseen'] = $status->unseen; 967 997 968 998 //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 969 999 $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); 970 1000 $folder_id = $tmp_folder_id[1]; 971 1001 $result[$i]['folder_id'] = $folder_id; 972 1002 973 1003 $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 974 1004 $result[$i]['folder_name'] = array_pop($tmp_folder_parent); … … 979 1009 } 980 1010 } 981 1011 982 1012 $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 983 1013 $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 984 1014 985 1015 if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 986 1016 $result[$i]['folder_hasChildren'] = 1; … … 988 1018 $result[$i]['folder_hasChildren'] = 0; 989 1019 990 $i++; 1020 $i++; 991 1021 } 992 1022 } 993 1023 994 1024 foreach ($result as $folder_info) 995 1025 { 996 1026 $array_tmp[] = $folder_info['folder_id']; 997 1027 } 998 1028 999 1029 natcasesort($array_tmp); 1000 1030 1001 1031 foreach ($array_tmp as $key => $folder_id) 1002 1032 { 1003 1033 $result2[] = $result[$key]; 1004 1034 } 1005 1006 if($mbox_stream && is_resource($mbox_stream)){ 1007 imap_close($mbox_stream); 1008 } 1009 1010 return array_merge($result2); 1011 } 1012 1035 1036 $current_folder = "INBOX"; 1037 if($params && $params['folder']) 1038 $current_folder = $params['folder']; 1039 return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); 1040 } 1041 1013 1042 function create_mailbox($arr) 1014 1043 { … … 1017 1046 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1018 1047 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); 1019 1048 1020 1049 $result = "Ok"; 1021 1050 if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) 1022 1051 { 1023 1052 $result = implode("<br />\n", imap_errors()); 1024 } 1025 1053 } 1054 1026 1055 if($mbox_stream) 1027 1056 imap_close($mbox_stream); 1028 1057 1029 1058 return $result; 1030 1031 } 1032 1059 1060 } 1061 1033 1062 function create_extra_mailbox($arr) 1034 1063 { … … 1037 1066 $mbox_stream = $this->open_mbox(); 1038 1067 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1039 foreach($nameboxs as $key=>$tmp){ 1068 foreach($nameboxs as $key=>$tmp){ 1040 1069 if($tmp != ""){ 1041 1070 if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ 1042 1071 $result = implode("<br />\n", imap_errors()); 1043 1072 if($mbox_stream) 1044 imap_close($mbox_stream); 1073 imap_close($mbox_stream); 1045 1074 return $result; 1046 1075 } … … 1051 1080 return true; 1052 1081 } 1053 1082 1054 1083 function delete_mailbox($arr) 1055 1084 { … … 1058 1087 $mbox_stream = $this->open_mbox(); 1059 1088 //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); 1060 1089 1061 1090 $result = "Ok"; 1062 1091 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); … … 1069 1098 return $result; 1070 1099 } 1071 1100 1072 1101 function ren_mailbox($arr) 1073 1102 { … … 1077 1106 $mbox_stream = $this->open_mbox(); 1078 1107 //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); 1079 1108 1080 1109 $result = "Ok"; 1081 1110 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 1082 1111 $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); 1083 1112 1084 1113 if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) 1085 1114 { 1086 $result = imap_errors(); 1115 $result = imap_errors(); 1087 1116 } 1088 1117 if($mbox_stream) 1089 1118 imap_close($mbox_stream); 1090 1119 return $result; 1091 1092 } 1093 1120 1121 } 1122 1094 1123 function get_num_msgs($params) 1095 1124 { … … 1099 1128 if(!$this->mbox || !is_resource($this->mbox)) 1100 1129 return imap_last_error(); 1101 } 1130 } 1102 1131 $num_msgs = imap_num_msg($this->mbox); 1103 1132 if($this->mbox && is_resource($this->mbox)) 1104 1133 imap_close($this->mbox); 1105 1134 1106 1135 return $num_msgs; 1107 1136 } 1108 1137 1109 1138 function send_mail($params) 1110 1139 { … … 1114 1143 $db = new db_functions(); 1115 1144 $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; 1145 ## 1146 # @AUTHOR Rodrigo Souza dos Santos 1147 # @DATE 2008/09/17 1148 # @BRIEF Checks if the user has permission to send an email with the email address used. 1149 ## 1150 if ( is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email']) ) 1151 { 1152 $deny = true; 1153 foreach( $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val ) 1154 if ( array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1] ) 1155 $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); 1156 1157 if ( $deny ) 1158 return "The server denied your request to send a mail, you cannot use this mail address."; 1159 } 1116 1160 $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); 1117 1161 $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); … … 1124 1168 $attachments = $params['FILES']; 1125 1169 $forwarding_attachments = $params['forwarding_attachments']; 1126 1170 1127 1171 $folder =$params['folder']; 1128 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1129 $folder_name = $params['folder_name']; 1172 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1173 $folder_name = $params['folder_name']; 1130 1174 // Fix problem with cyrus delimiter changes. 1131 // Dots in names: enabled/disabled. 1175 // Dots in names: enabled/disabled. 1132 1176 $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 1133 1177 $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 1134 1178 // End Fix. 1135 if ($folder != 'null'){ 1179 if ($folder != 'null'){ 1136 1180 $mail->SaveMessageInFolder = $folder; 1137 1181 } 1138 1182 //////////////////////////////////////////////////////////////////////////////////////////////////// 1139 1183 $mail->SMTPDebug = false; 1140 1184 1141 1185 $mail->IsSMTP(); 1142 1186 $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; … … 1150 1194 $mail->From = $fromaddress[1]; 1151 1195 } 1152 1196 1153 1197 $this->add_recipients("to", $toaddress, &$mail); 1154 1198 $this->add_recipients("cc", $ccaddress, &$mail); … … 1160 1204 //////////////////////////////////////////////////////////////////////////////////////////////////// 1161 1205 // Build CID for embedded Images!!! 1162 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?& amp;msg_num=(.+)?&msg_part=(.+)?)"/isU';1206 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 1163 1207 $cid_imgs = ''; 1164 1208 $name_cid_files = array(); 1165 1209 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 1166 1210 $cid_array = array(); 1167 foreach($cid_imgs[ 4] as $j => $val){1168 if ( !array_key_exists($cid_imgs[ 3][$j].$val, $cid_array) )1211 foreach($cid_imgs[6] as $j => $val){ 1212 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 1169 1213 { 1170 $cid_array[$cid_imgs[ 3][$j].$val] = base_convert(microtime(), 10, 36);1214 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 1171 1215 } 1172 $cid = $cid_array[$cid_imgs[ 3][$j].$val];1216 $cid = $cid_array[$cid_imgs[4][$j].$val]; 1173 1217 $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 1174 1175 if ($msg_uid != $cid_imgs[ 3][$j]) // The image isn't in the same mail?1218 1219 if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 1176 1220 { 1177 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[ 3][$j], $cid_imgs[4][$j], 'base64');1221 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 1178 1222 $fileName = "image_".($j).".jpg"; 1179 1223 $fileCode = "base64"; … … 1182 1226 else 1183 1227 { 1184 $attach_img = $forwarding_attachments[$cid_imgs[ 4][$j]-2];1228 $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 1185 1229 $file_description = unserialize(rawurldecode($attach_img)); 1186 1230 1187 foreach($file_description as $i => $descriptor){ 1231 foreach($file_description as $i => $descriptor){ 1188 1232 $file_description[$i] = eregi_replace('\'*\'','',$descriptor); 1189 1233 } … … 1192 1236 $fileCode = $file_description[4]; 1193 1237 $fileType = $this->get_file_type($file_description[2]); 1194 unset($forwarding_attachments[$cid_imgs[ 4][$j]-2]);1238 unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 1195 1239 } 1196 1240 $tempDir = ini_get("session.save_path"); 1197 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1241 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1198 1242 $f = fopen($tempDir.'/'.$file,"w"); 1199 1243 fputs($f,$fileContent); … … 1202 1246 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 1203 1247 //else 1204 // return "Error loading image attachment content"; 1248 // return "Error loading image attachment content"; 1205 1249 1206 1250 } … … 1217 1261 } 1218 1262 if( $total_uploaded_size > $upload_max_filesize) 1219 return 'false'; 1220 } 1263 return 'false'; 1264 } 1221 1265 //////////////////////////////////////////////////////////////////////////////////////////////////// 1222 1266 // Build Forwarding Attachments!!! … … 1227 1271 $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; 1228 1272 $name_cid_files[0] = null; 1229 } 1230 1273 } 1274 1231 1275 foreach($forwarding_attachments as $forwarding_attachment) 1232 1276 { 1233 1277 $file_description = unserialize(rawurldecode($forwarding_attachment)); 1234 1278 $tmp = array_values($file_description); 1235 foreach($file_description as $i => $descriptor){ 1279 foreach($file_description as $i => $descriptor){ 1236 1280 $tmp[$i] = eregi_replace('\'*\'','',$descriptor); 1237 1281 } 1238 $file_description = $tmp; 1282 $file_description = $tmp; 1239 1283 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 1240 1284 $fileName = $file_description[2]; … … 1257 1301 else 1258 1302 { 1259 if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 1303 if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 1260 1304 { 1261 1305 $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; … … 1263 1307 $now = date("d/m/y H:i:s"); 1264 1308 $addrs = $toaddress.$ccaddress.$ccoaddress; 1265 $sent = trim($sent); 1309 $sent = trim($sent); 1266 1310 error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); 1267 1311 } … … 1277 1321 function add_recipients($recipient_type, $full_address, $mail) 1278 1322 { 1279 $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 1280 foreach ($parse_address as $val) 1323 $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 1324 foreach ($parse_address as $val) 1281 1325 { 1282 1326 //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; 1283 1327 if ($val->mailbox == "INVALID_ADDRESS") 1284 1328 continue; 1285 1329 1286 1330 if (empty($val->personal)) 1287 1331 { … … 1317 1361 return true; 1318 1362 } 1319 1363 1320 1364 function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) 1321 1365 { 1322 $mbox_stream = $this->open_mbox($msg_folder); 1323 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 1366 $mbox_stream = $this->open_mbox($msg_folder); 1367 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 1324 1368 if($encoding == 'base64') 1325 $fileContent = imap_base64($fileContent); 1369 # The function imap_base64 adds a new line 1370 # at ASCII text, with CRLF line terminators. 1371 # So is being exchanged for base64_decode. 1372 # 1373 #$fileContent = imap_base64($fileContent); 1374 $fileContent = base64_decode($fileContent); 1326 1375 else if($encoding == 'quoted-printable') 1327 $fileContent = quoted_printable_decode($fileContent); 1376 $fileContent = quoted_printable_decode($fileContent); 1328 1377 return $fileContent; 1329 1378 } 1330 1379 1331 1380 function del_last_caracter($string) 1332 1381 { 1333 1382 $string = substr($string,0,(strlen($string) - 1)); 1334 return $string; 1335 } 1336 1383 return $string; 1384 } 1385 1337 1386 function del_last_two_caracters($string) 1338 1387 { 1339 1388 $string = substr($string,0,(strlen($string) - 2)); 1340 return $string; 1341 } 1342 1389 return $string; 1390 } 1391 1343 1392 function imap_sortfrom($sort_box_reverse, $search_box_type) 1344 1393 { 1345 1394 $sortfrom = array(); 1346 1395 $sortfrom_uid = array(); 1347 1396 1348 1397 $num_msgs = imap_num_msg($this->mbox); 1349 1398 for ($i=1; $i<=$num_msgs; $i++) … … 1358 1407 continue; 1359 1408 } 1360 // List ANSWERED messages. 1409 // List ANSWERED messages. 1361 1410 elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ 1362 continue; 1363 } 1364 // List FLAGGED messages. 1411 continue; 1412 } 1413 // List FLAGGED messages. 1365 1414 elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ 1366 1415 continue; 1367 1416 } 1368 1369 if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 1417 1418 if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 1370 1419 $from = $header->to; 1371 1420 else 1372 1421 $from = $header->from; 1373 1374 $tmp = imap_mime_header_decode($from[0]->personal); 1375 1422 1423 $tmp = imap_mime_header_decode($from[0]->personal); 1424 1376 1425 if ($tmp[0]->text != "") 1377 1426 $sortfrom[$i] = $tmp[0]->text; … … 1379 1428 $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; 1380 1429 } 1381 1430 1382 1431 natcasesort($sortfrom); 1383 1432 1384 1433 foreach($sortfrom as $index => $header_msg) 1385 { 1434 { 1386 1435 $sortfrom_uid[] = imap_uid($this->mbox, $index); 1387 1436 } 1388 1437 1389 1438 if ($sort_box_reverse) 1390 1439 $sortfrom_uid = array_reverse($sortfrom_uid); 1391 1440 1392 1441 return $sortfrom_uid; 1393 1442 } 1394 1443 1395 function move_search_messages($params){ 1396 $params['selected_messages'] = urldecode($params['selected_messages']); 1444 function move_search_messages($params){ 1445 $params['selected_messages'] = urldecode($params['selected_messages']); 1397 1446 $params['new_folder'] = urldecode($params['new_folder']); 1398 1447 $params['new_folder_name'] = urldecode($params['new_folder_name']); 1399 1448 $sel_msgs = explode(",", $params['selected_messages']); 1400 @reset($sel_msgs); 1449 @reset($sel_msgs); 1401 1450 $sorted_msgs = array(); 1402 1451 foreach($sel_msgs as $idx => $sel_msg) { … … 1404 1453 if(array_key_exists($sel_msg[0], $sorted_msgs)){ 1405 1454 $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; 1406 } 1455 } 1407 1456 else { 1408 1457 $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; … … 1410 1459 } 1411 1460 @ksort($sorted_msgs); 1412 $last_return = false; 1413 foreach($sorted_msgs as $folder => $msgs_number) { 1461 $last_return = false; 1462 foreach($sorted_msgs as $folder => $msgs_number) { 1414 1463 $params['msgs_number'] = $msgs_number; 1415 $params['folder'] = $folder; 1464 $params['folder'] = $folder; 1416 1465 if($params['new_folder'] && $folder != $params['new_folder']){ 1417 $last_return = $this -> move_messages($params); 1466 $last_return = $this -> move_messages($params); 1418 1467 } 1419 1468 elseif(!$params['new_folder'] || $params['delete'] ){ … … 1424 1473 return $last_return; 1425 1474 } 1426 1475 1427 1476 function move_messages($params) 1428 1477 { 1429 $folder = $params['folder']; 1430 $mbox_stream = $this->open_mbox($folder); 1478 $folder = $params['folder']; 1479 $mbox_stream = $this->open_mbox($folder); 1431 1480 $newmailbox = ($params['new_folder']); 1432 1481 $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); … … 1438 1487 'border_ID' => $params['border_ID'], 1439 1488 'status' => true); //Status foi adicionado para validar as permissoes ACL 1440 1489 1441 1490 //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas 1442 1491 if (substr($folder,0,4) == 'user'){ … … 1467 1516 $return['new_folder_name'] = $cn; 1468 1517 } 1469 1470 // Caso estejamos no box principal, n ï¿œo ï¿œ necessï¿œrio pegar a informaᅵᅵo da mensagem anterior.1518 1519 // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. 1471 1520 if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 1521 { 1472 1522 $return['previous_msg'] = $this->get_info_previous_msg($params); 1473 1474 $mbox_stream = $this->open_mbox($folder); 1523 // Fix problem in unserialize function JS. 1524 $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); 1525 } 1526 1527 $mbox_stream = $this->open_mbox($folder); 1475 1528 if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 1476 1529 imap_expunge($mbox_stream); … … 1479 1532 return $return; 1480 1533 }else { 1481 if(strstr(imap_last_error(),'Over quota')) { 1534 if(strstr(imap_last_error(),'Over quota')) { 1482 1535 $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; 1483 $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 1484 $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 1536 $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 1537 $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 1485 1538 $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1486 1539 $mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => imap_last_error()))); 1487 1540 if(!$mbox) 1488 1541 return imap_last_error(); 1489 $quota = imap_get_quotaroot($mbox_stream, "INBOX"); 1542 $quota = imap_get_quotaroot($mbox_stream, "INBOX"); 1490 1543 if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { 1491 1544 if($mbox_stream) 1492 1545 imap_close($mbox_stream); 1493 if($mbox) 1546 if($mbox) 1494 1547 imap_close($mbox); 1495 return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 1548 return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 1496 1549 } 1497 1550 if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { … … 1503 1556 if($mbox) 1504 1557 imap_close($mbox); 1505 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1558 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1506 1559 } 1507 return $return; 1560 return $return; 1508 1561 } 1509 1562 else { … … 1513 1566 if($mbox) 1514 1567 imap_close($mbox); 1515 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1568 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1516 1569 } 1517 return imap_last_error(); 1518 } 1519 1570 return imap_last_error(); 1571 } 1572 1520 1573 } 1521 1574 else { … … 1524 1577 return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; 1525 1578 } 1526 } 1527 } 1528 1579 } 1580 } 1581 1529 1582 function save_msg($params) 1530 1583 { 1531 1584 1532 1585 include_once("class.phpmailer.php"); 1533 1586 $mail = new PHPMailer(); … … 1544 1597 $attachments = $params['FILES']; 1545 1598 $return_files = $params['FILES']; 1546 1599 1547 1600 $folder = $params['folder']; 1548 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1601 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1549 1602 // Fix problem with cyrus delimiter changes. 1550 // Dots in names: enabled/disabled. 1603 // Dots in names: enabled/disabled. 1551 1604 $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 1552 1605 $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 1553 1606 // End Fix. 1554 1607 1555 1608 $mail->SaveMessageInFolder = $folder; 1556 1609 $mail->SMTPDebug = false; 1557 1610 1558 1611 $mail->IsSMTP(); 1559 1612 $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; … … 1561 1614 $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 1562 1615 $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 1563 1616 1564 1617 $mail->Sender = $mail->From; 1565 1618 $mail->SenderName = $mail->FromName; 1566 1619 $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 1567 1620 $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 1568 1621 1569 1622 $this->add_recipients("to", $toaddress, &$mail); 1570 1623 $this->add_recipients("cc", $ccaddress, &$mail); … … 1572 1625 $mail->IsHTML(true); 1573 1626 $mail->Body = $body; 1574 1627 1575 1628 // Build CID for embedded Images!!! 1576 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?& amp;msg_num=(.+)?&msg_part=(.+)?)"/isU';1629 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 1577 1630 $cid_imgs = ''; 1578 1631 $name_cid_files = array(); 1579 1632 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 1580 1633 $cid_array = array(); 1581 foreach($cid_imgs[ 4] as $j => $val){1582 if ( !array_key_exists($cid_imgs[ 3][$j].$val, $cid_array) )1634 foreach($cid_imgs[6] as $j => $val){ 1635 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 1583 1636 { 1584 $cid_array[$cid_imgs[ 3][$j].$val] = base_convert(microtime(), 10, 36);1637 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 1585 1638 } 1586 $cid = $cid_array[$cid_imgs[ 3][$j].$val];1639 $cid = $cid_array[$cid_imgs[4][$j].$val]; 1587 1640 $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 1588 1589 if ($msg_uid != $cid_imgs[ 3][$j]) // The image isn't in the same mail?1641 1642 if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? 1590 1643 { 1591 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 1644 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 1645 //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) 1592 1646 $fileName = "image_".($j).".jpg"; 1593 1647 $fileCode = "base64"; 1594 1648 $fileType = "image/jpg"; 1649 $file_attached[0] = $cid_imgs[2][$j]; 1650 $file_attached[1] = $cid_imgs[4][$j]; 1651 $file_attached[2] = $fileName; 1652 $file_attached[3] = $cid_imgs[6][$j]; 1653 $file_attached[4] = 'base64'; 1654 $file_attached[5] = strlen($fileContent); //Size of file 1655 $return_forward[] = $file_attached; 1595 1656 } 1596 1657 else 1597 1658 { 1598 $attach_img = $forwarding_attachments[$cid_imgs[ 4][$j]-2];1659 $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; 1599 1660 $file_description = unserialize(rawurldecode($attach_img)); 1600 foreach($file_description as $i => $descriptor){ 1661 foreach($file_description as $i => $descriptor){ 1601 1662 $file_description[$i] = eregi_replace('\'*\'','',$descriptor); 1602 1663 } … … 1605 1666 $fileCode = $file_description[4]; 1606 1667 $fileType = $this->get_file_type($file_description[2]); 1607 unset($forwarding_attachments[$cid_imgs[ 4][$j]-2]);1668 unset($forwarding_attachments[$cid_imgs[6][$j]-2]); 1608 1669 if (!empty($file_description)) 1609 1670 { … … 1613 1674 } 1614 1675 $tempDir = ini_get("session.save_path"); 1615 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1676 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1616 1677 $f = fopen($tempDir.'/'.$file,"w"); 1617 1678 fputs($f,$fileContent); … … 1620 1681 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 1621 1682 //else 1622 // return "Error loading image attachment content"; 1623 1624 } 1625 1626 // Build Forwarding Attachments!!! 1683 // return "Error loading image attachment content"; 1684 1685 } 1686 1687 // Build Forwarding Attachments!!! 1627 1688 if (count($forwarding_attachments) > 0) 1628 1689 { … … 1631 1692 $file_description = unserialize(rawurldecode($forwarding_attachment)); 1632 1693 $tmp = array_values($file_description); 1633 foreach($file_description as $i => $descriptor){ 1694 foreach($file_description as $i => $descriptor){ 1634 1695 $tmp[$i] = eregi_replace('\'*\'','',$descriptor); 1635 1696 } 1636 1697 $file_description = $tmp; 1637 1698 1638 1699 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 1639 1700 $fileName = $file_description[2]; 1640 1701 1641 1702 $file_description[5] = strlen($fileContent); //Size of file 1642 1703 $return_forward[] = $file_description; 1643 1704 1644 1705 $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 1645 1706 } 1646 1707 } 1647 1708 1648 1709 if ((count($return_forward) > 0) && (count($return_files) > 0)) 1649 1710 $return_files = array_merge_recursive($return_forward,$return_files); … … 1651 1712 if (count($return_files) < 1) 1652 1713 $return_files = $return_forward; 1653 1714 1654 1715 // Build Uploading Attachments!!! 1655 1716 if (count($attachments)) 1656 1717 foreach ($attachments as $attach) 1657 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name 1658 1659 1660 1718 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name 1719 1720 1721 1661 1722 if(!empty($mail->AltBody)) 1662 1723 $mail->ContentType = "multipart/alternative"; … … 1666 1727 $header = $mail->CreateHeader(); 1667 1728 $body = $mail->CreateBody(); 1668 1729 1669 1730 if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 1670 1731 { … … 1680 1741 $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 1681 1742 $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); 1682 1743 1683 1744 $new_header = str_replace("\n", "\r\n", $header); 1684 1745 $new_body = str_replace("\n", "\r\n", $body); 1685 1746 1686 1747 $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 1687 1748 $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 1688 1749 $return['msg_no'] = $status->uidnext - 1; 1689 1750 $return['folder_id'] = $folder; 1690 1751 1691 1752 if($mbox_stream) 1692 1753 imap_close($mbox_stream); 1693 1754 1694 1755 foreach ($return_files as $index => $_attachment) { 1695 1756 if (array_key_exists("name",$_attachment)){ … … 1703 1764 } 1704 1765 } 1705 1766 1706 1767 $return['files'] = serialize($return_files); 1707 1768 1708 1769 if (!$return['append']) 1709 1770 $return['append'] = imap_last_error(); 1710 1771 1711 1772 return $return; 1712 1773 } 1713 1774 1714 1775 function set_messages_flag($params) 1715 1776 { … … 1720 1781 $return["msgs_to_set"] = $msgs_to_set; 1721 1782 $return["flag"] = $flag; 1722 1783 1723 1784 if(!$this->mbox && !is_resource($this->mbox)) 1724 1785 $this->mbox = $this->open_mbox($folder); 1725 1786 1726 1787 if ($flag == "unseen") 1727 1788 $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); … … 1738 1799 elseif ($flag == "unflagged") 1739 1800 $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); 1740 1801 1741 1802 if($this->mbox && is_resource($this->mbox)) 1742 1803 imap_close($this->mbox); 1743 1804 return $return; 1744 1805 } 1745 1806 1746 1807 function get_file_type($file_name) 1747 1808 { 1748 1809 $file_name = strtolower($file_name); 1749 1810 $strFileType = strrev(substr(strrev($file_name),0,4)); 1750 if ($strFileType == ".asf") 1811 if ($strFileType == ".asf") 1751 1812 return "video/x-ms-asf"; 1752 1813 if ($strFileType == ".avi") … … 1774 1835 if ($strFileType == ".htm" || $strFileType == "html") 1775 1836 return "text/html"; 1776 if ($strFileType == ".xml") 1837 if ($strFileType == ".xml") 1777 1838 return "text/xml"; 1778 if ($strFileType == ".xsl") 1839 if ($strFileType == ".xsl") 1779 1840 return "text/xsl"; 1780 if ($strFileType == ".css") 1841 if ($strFileType == ".css") 1781 1842 return "text/css"; 1782 if ($strFileType == ".php") 1843 if ($strFileType == ".php") 1783 1844 return "text/php"; 1784 if ($strFileType == ".asp") 1845 if ($strFileType == ".asp") 1785 1846 return "text/asp"; 1786 1847 if ($strFileType == ".pdf") … … 1810 1871 if ($strFileType == ".stw") 1811 1872 return "application/vnd.sun.xml.writer.template"; 1812 1813 1814 return "application/octet-stream"; 1815 } 1816 1873 1874 1875 return "application/octet-stream"; 1876 } 1877 1817 1878 function htmlspecialchars_encode($str) 1818 1879 { 1819 /*// replace ' and " with htmlspecialchars */ 1820 $str = ereg_replace('&', '&', $str); 1821 // any ampersand & that ia already in a "&" should NOT be encoded 1822 //$str = preg_replace("/&(?![:alnum:]*;)/", "&", $str); 1823 $str = ereg_replace('"', '"', $str); 1824 $str = ereg_replace('\'', ''', $str); 1825 1826 $str = ereg_replace('<', '<', $str); 1827 $str = ereg_replace('>', '>', $str); 1828 // these { and } must be html encoded or else they conflict with the template system 1829 $str = str_replace("{", '{', $str); 1830 $str = str_replace("}", '}', $str); 1831 return $str; 1880 return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); 1832 1881 } 1833 1882 function htmlspecialchars_decode($str) 1834 1883 { 1835 /*// replace ' and " with htmlspecialchars */ 1836 $str = ereg_replace('&','&', $str); 1837 // any ampersand & that ia already in a "&" should NOT be encoded 1838 //$str = preg_replace("/&(?![:alnum:]*;)/", "&", $str); 1839 $str = ereg_replace('"', '"', $str); 1840 $str = ereg_replace(''', '\'', $str); 1841 $str = ereg_replace('<','<', $str); 1842 $str = ereg_replace('>', '>', $str); 1843 // these { and } must be html encoded or else they conflict with the template system 1844 $str = str_replace('{', "{", $str); 1845 $str = str_replace( '}',"}", $str); 1846 return $str; 1847 } 1848 1884 return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); 1885 } 1886 1849 1887 function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse){ 1850 1888 1851 1889 if(!$this->mbox || !is_resource($this->mbox)){ 1852 1890 $this->mbox = $this->open_mbox($folder); 1891 1853 1892 } 1854 1893 1855 1894 switch($sort_box_type){ 1856 1895 case 'SORTFROM': 1857 return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 1896 return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 1858 1897 case 'SORTSUBJECT': 1859 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 1898 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 1860 1899 case 'SORTSIZE': 1861 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 1900 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 1862 1901 default: 1863 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 1864 } 1865 } 1866 1902 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 1903 } 1904 } 1905 1867 1906 function get_info_next_msg($params) 1868 1907 { … … 1873 1912 $reuse_border = $params['reuse_border']; 1874 1913 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 1875 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 1876 1914 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 1915 1877 1916 $success = false; 1878 1917 if (is_array($sort_array_msg)) … … 1893 1932 return $params; 1894 1933 } 1895 1934 1896 1935 $params = array(); 1897 1936 $params['msg_number'] = $sort_array_msg[($i+1)]; 1898 1937 $params['msg_folder'] = $folder; 1899 1900 $return = $this->get_info_msg($params); 1938 1939 $return = $this->get_info_msg($params); 1901 1940 $return["reuse_border"] = $reuse_border; 1902 1941 return $return; … … 1912 1951 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 1913 1952 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 1914 1953 1915 1954 $success = false; 1916 1955 if (is_array($sort_array_msg)) … … 1930 1969 return $params; 1931 1970 } 1932 1971 1933 1972 $params = array(); 1934 1973 $params['msg_number'] = $sort_array_msg[($i-1)]; 1935 1974 $params['msg_folder'] = $folder; 1936 1975 1937 1976 $return = $this->get_info_msg($params); 1938 1977 $return["reuse_border"] = $reuse_border; 1939 1978 return $return; 1940 1979 } 1941 1980 1942 1981 // This function updates the values: quota, paging and new messages menu. 1943 1982 function get_menu_values($params){ 1944 1983 $return_array = array(); 1945 1984 $return_array = $this->get_quota($params); 1946 1985 1947 1986 $mbox_stream = $this->open_mbox($params['folder']); 1948 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 1987 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 1949 1988 if($mbox_stream) 1950 1989 imap_close($mbox_stream); 1951 1952 return $return_array; 1953 } 1954 1990 1991 return $return_array; 1992 } 1993 1955 1994 function get_quota($params){ 1956 $folder_id = $params['folder_id']; 1957 if(!$this->mbox || !is_resource($this->mbox)) 1995 // folder_id = user/{uid} for shared folders 1996 if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ 1997 $array_folder = explode($this->imap_delimiter,$params['folder_id']); 1998 $folder_id = "user".$this->imap_delimiter.$array_folder[1]; 1999 } 2000 // folder_id = INBOX for inbox folders 2001 else 2002 $folder_id = "INBOX"; 2003 2004 if(!$this->mbox) 1958 2005 $this->mbox = $this->open_mbox(); 1959 2006 … … 1961 2008 if($this->mbox && is_resource($this->mbox)) 1962 2009 imap_close($this->mbox); 1963 2010 1964 2011 if (!$quota){ 1965 2012 return array( … … 1969 2016 ); 1970 2017 } 1971 2018 1972 2019 if(count($quota) && $quota['limit']) { 1973 2020 $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; … … 1984 2031 ); 1985 2032 } 1986 else 2033 else 1987 2034 return array(); 1988 2035 } 1989 2036 1990 2037 function send_notification($params){ 1991 2038 require_once("class.phpmailer.php"); 1992 2039 $mail = new PHPMailer(); 1993 2040 1994 2041 $toaddress = $params['notificationto']; 1995 1996 $subject = ' Leitura confirmada da mensagem: ' . $params['subject'];2042 2043 $subject = 'Confirmação de leitura: ' . $params['subject']; 1997 2044 $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; 1998 2045 $body .= 'foi lida por: ' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . ' <' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '> em ' . date("d/m/Y H:i"); … … 2008 2055 $mail->IsHTML(true); 2009 2056 $mail->Body = $body; 2010 2057 2011 2058 if(!$mail->Send()){ 2012 2059 return $mail->ErrorInfo; … … 2015 2062 return true; 2016 2063 } 2017 2064 2018 2065 function empty_trash() 2019 2066 { 2020 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 2067 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 2021 2068 $mbox_stream = $this->open_mbox($folder); 2022 2069 $return = imap_delete($mbox_stream,'1:*'); … … 2025 2072 return $return; 2026 2073 } 2027 2074 2028 2075 function search($params) 2029 2076 { 2030 2077 include("class.imap_attachment.inc.php"); 2031 $imap_attachment = new imap_attachment(); 2078 $imap_attachment = new imap_attachment(); 2032 2079 $criteria = $params['criteria']; 2033 2080 $return = array(); 2034 2081 $folders = $this->get_folders_list(); 2035 2082 2036 2083 $j = 0; 2037 2084 foreach($folders as $folder) … … 2039 2086 $mbox_stream = $this->open_mbox($folder); 2040 2087 $messages = imap_search($mbox_stream, $criteria, SE_UID); 2041 2088 2042 2089 if ($messages == '') 2043 2090 continue; 2044 2091 2045 2092 $i = 0; 2046 2093 $return[$j] = array(); 2047 2094 $return[$j]['folder_name'] = $folder['name']; 2048 2095 2049 2096 foreach($messages as $msg_number) 2050 2097 { … … 2052 2099 if (!is_object($header)) 2053 2100 return false; 2054 2101 2055 2102 $return[$j][$i]['msg_folder'] = $folder['name']; 2056 2103 $return[$j][$i]['msg_number'] = $msg_number; … … 2061 2108 $return[$j][$i]['Draft'] = $header->Draft; 2062 2109 $return[$j][$i]['Flagged'] = $header->Flagged; 2063 2110 2064 2111 $date_msg = date("d/m/Y",$header->udate); 2065 2112 if (date("d/m/Y") == $date_msg) … … 2067 2114 else 2068 2115 $return[$j][$i]['udate'] = $date_msg; 2069 2116 2070 2117 $fromaddress = imap_mime_header_decode($header->fromaddress); 2071 2118 $return[$j][$i]['fromaddress'] = ''; 2072 2119 foreach ($fromaddress as $tmp) 2073 2120 $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); 2074 2121 2075 2122 $from = $header->from; 2076 2123 $return[$j][$i]['from'] = array(); … … 2078 2125 $return[$j][$i]['from']['name'] = $tmp[0]->text; 2079 2126 $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 2080 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 2127 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 2081 2128 2082 2129 $to = $header->to; … … 2085 2132 $return[$j][$i]['to']['name'] = $tmp[0]->text; 2086 2133 $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 2087 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 2134 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 2088 2135 2089 2136 $subject = imap_mime_header_decode($header->fetchsubject); … … 2094 2141 $return[$j][$i]['Size'] = $header->Size; 2095 2142 $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; 2096 2143 2097 2144 $return[$j][$i]['attachment'] = array(); 2098 2145 $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); 2099 2146 2100 2147 $i++; 2101 2148 } … … 2104 2151 imap_close($mbox_stream); 2105 2152 } 2106 2153 2107 2154 return $return; 2108 2155 } 2109 2156 2110 2157 function delete_and_show_previous_message($params) 2111 2158 { 2112 2159 $return = $this->get_info_previous_msg($params); 2113 2160 2114 2161 $params_tmp1 = array(); 2115 2162 $params_tmp1['msgs_to_delete'] = $params['msg_number']; 2116 2163 $params_tmp1['folder'] = $params['msg_folder']; 2117 2164 $return_tmp1 = $this->delete_msg($params_tmp1); 2118 2165 2119 2166 $return['msg_number_deleted'] = $return_tmp1; 2120 2167 2121 2168 return $return; 2122 2169 } 2123 2124 2170 2171 2125 2172 function automatic_trash_cleanness($params) 2126 2173 { … … 2140 2187 // Fix the search problem with special characters!!!! 2141 2188 function remove_accents($string) { 2142 return strtr($string, 2143 "? ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ",2189 return strtr($string, 2190 "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", 2144 2191 "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 2145 2192 } … … 2165 2212 $filter .= '"'.$filter_array[1].'"'; 2166 2213 } 2167 } 2168 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 2214 } 2215 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 2169 2216 $filter = $this->remove_accents($filter); 2170 2217 $folder_name = explode($this->imap_delimiter,$name_box); … … 2177 2224 } 2178 2225 $folder_name = implode($this->imap_delimiter,$folder_name); 2179 2226 2180 2227 if(!is_resource($mbox_stream)) 2181 2228 $mbox_stream = $this->open_mbox($name_box); 2182 2229 else 2183 2230 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 2184 2185 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 2186 2231 2232 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 2233 2187 2234 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 2188 2235 foreach($all_criterias as $criteria_fixed) 2189 2236 { 2190 2237 $_filter = $criteria_fixed . substr($filter,4); 2191 2238 2192 2239 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 2193 2240 2194 2241 if($search_criteria && count($search_criteria) < 50) 2195 2242 { 2196 2243 foreach($search_criteria as $new_search){ 2197 $m_token = trim("##".mb_convert_encoding( $ folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n");2244 $m_token = trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 2198 2245 if(!@strstr($retorno,$m_token)) 2199 2246 $retorno .= $m_token; 2200 2247 } 2201 } 2202 else if(count($search_criteria) >= 50) 2203 return "many results"; 2248 } 2249 else if(count($search_criteria) >= 50) 2250 return "many results"; 2204 2251 } 2205 2252 } … … 2209 2256 { 2210 2257 foreach($search_criteria as $new_search) 2211 $retorno .= trim("##".mb_convert_encoding( $ folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n");2258 $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 2212 2259 } 2213 2260 } … … 2215 2262 } 2216 2263 if($mbox_stream) 2217 imap_close($mbox_stream); 2218 2264 imap_close($mbox_stream); 2265 2219 2266 return $retorno ? $retorno : "none"; 2220 2267 } 2221 2268 2222 2269 function get_msg($uid_msg,$name_box, $mbox_stream ) 2223 2270 { 2224 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); 2271 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); 2225 2272 $subject = $this->decode_string($header->fetchsubject); 2226 2273 $from = $header->from[0]->mailbox; 2227 2274 if($header->from[0]->personal != "") 2228 2275 $from = $header->from[0]->personal; 2229 $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) . "--". $header->Unseen;2230 return $ret_msg; 2231 } 2232 2276 $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size); 2277 return $ret_msg; 2278 } 2279 2233 2280 function size_msg($size){ 2234 2281 $var = floor($size/1024); 2235 2282 if($var >= 1){ 2236 return $var." kb"; 2283 return $var." kb"; 2237 2284 }else{ 2238 return $size ." b"; 2285 return $size ." b"; 2239 2286 } 2240 2287 } … … 2263 2310 } 2264 2311 } 2265 2312 2266 2313 function getacl() 2267 2314 { 2268 2315 $this->ldap = new ldap_functions(); 2269 2316 2270 2317 $return = array(); 2271 $mbox_stream = $this->open_mbox(); 2318 $mbox_stream = $this->open_mbox(); 2272 2319 $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 2273 2320 2274 2321 $i = 0; 2275 2322 foreach ($mbox_acl as $user => $acl) … … 2284 2331 return $return; 2285 2332 } 2286 2333 2287 2334 function setacl($params) 2288 2335 { … … 2290 2337 if (!count($old_users)) 2291 2338 $old_users = array(); 2292 2339 2293 2340 $tmp_array = array(); 2294 2341 foreach ($old_users as $index => $user_info) … … 2297 2344 } 2298 2345 $old_users = $tmp_array; 2299 2346 2300 2347 $users = unserialize($params['users']); 2301 2348 if (!count($users)) 2302 2349 $users = array(); 2303 2350 2304 2351 //$add_share = array_diff($users, $old_users); 2305 2352 $remove_share = array_diff($old_users, $users); … … 2324 2371 } 2325 2372 }*/ 2326 2373 2327 2374 if (count($remove_share)) 2328 2375 { … … 2337 2384 } 2338 2385 } 2339 } 2340 } 2341 2386 } 2387 } 2388 2342 2389 return true; 2343 2390 } 2344 2391 2345 2392 function getaclfromuser($params) 2346 2393 { 2347 2394 $useracl = $params['user']; 2348 2395 2349 2396 $return = array(); 2350 2397 $return[$useracl] = 'false'; 2351 $mbox_stream = $this->open_mbox(); 2398 $mbox_stream = $this->open_mbox(); 2352 2399 $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 2353 2400 2354 2401 foreach ($mbox_acl as $user => $acl) 2355 2402 { … … 2370 2417 //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo 2371 2418 if(substr($user,0,4) != 'user') 2372 2419 $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 2373 2420 else 2374 2421 $mbox_acl = imap_getacl($mbox_stream, $user); 2375 2422 return $mbox_acl[$this->username]; 2376 2423 } 2377 2424 2378 2425 2379 2426 function setaclfromuser($params) … … 2381 2428 $user = $params['user']; 2382 2429 $acl = $params['acl']; 2383 2430 2384 2431 $mbox_stream = $this->open_mbox(); 2385 2432 … … 2391 2438 foreach ($mailboxes_list as $key => $val) 2392 2439 { 2393 $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); 2440 $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); 2441 $folder = str_replace("&-", "&", $folder); 2394 2442 if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) 2395 2443 { 2396 return imap_last_error(); 2397 } 2398 } 2399 } 2400 2401 return true; 2402 } 2403 2444 $return = imap_last_error(); 2445 } 2446 } 2447 } 2448 if (isset($return)) 2449 return $return; 2450 else 2451 return true; 2452 } 2453 2404 2454 function download_attachment($msg,$msgno) 2405 2455 { 2406 $array_parts_attachments = array(); 2456 $array_parts_attachments = array(); 2407 2457 $array_parts_attachments['names'] = ''; 2408 2458 include("class.imap_attachment.inc.php"); 2409 $imap_attachment = new imap_attachment(); 2410 2459 $imap_attachment = new imap_attachment(); 2460 2411 2461 if (count($msg->fname[$msgno]) > 0) 2412 2462 { … … 2425 2475 $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); 2426 2476 return $array_parts_attachments; 2427 } 2477 } 2428 2478 2429 2479 function spam($params) … … 2439 2489 $msg = $header . $body; 2440 2490 $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; 2441 //$tmp_file = $tmp_dir . "msg." . $email . '.'. $msg_number . time(); 2442 // maybe we can get it faster with regex, don't know how :'( 2443 $signature = trim(substr($header, strpos($header, 'X-DSPAM-Signature:') + 18)); 2491 $username = $this->username; 2444 2492 strtok($email, '@'); 2445 2493 $domain = strtok('@'); 2446 2494 2495 //Encontrar a assinatura do dspam no cabecalho 2496 $v = explode("\r\n", $header); 2497 foreach ($v as $linha){ 2498 if (eregi("^X-DSPAM-Signature", $linha)) { 2499 2500 $args = explode(" ",$linha); 2501 $signature = $args[1]; 2502 } 2503 } 2504 2447 2505 // feed dspam 2448 if ($is_spam) 2449 $cmd = str_replace( 2450 array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'), 2451 array($email, $this->username, $domain, $signature), $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] 2452 ); 2453 else 2454 $cmd = str_replace( 2455 array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'), 2456 array($email, $this->username, $domain, $signature), $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] 2457 ); 2458 2506 switch($is_spam){ 2507 case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; 2508 case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; 2509 } 2510 $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); 2511 $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); 2459 2512 system($cmd); 2460 2461 2513 } 2462 2514 imap_close($mbox_stream);
Note: See TracChangeset
for help on using the changeset viewer.