- Timestamp:
- 09/16/08 15:21:54 (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r426 r432 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 155 $this->mbox = $this->open_mbox($msg_folder); 156 157 158 //if(!$this->mbox) 159 // $this->mbox = $this->open_mbox($msg_folder); 160 157 161 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 158 162 if (!$header) { … … 162 166 $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); 163 167 $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 164 168 165 169 $return['body'] = $return_get_body['body']; 166 170 $return['attachments'] = $return_get_body['attachments']; 167 171 $return['thumbs'] = $return_get_body['thumbs']; 168 172 $return['signature'] = $return_get_body['signature']; 169 173 170 174 foreach($all_header as $line) { 171 175 if (eregi("^Disposition-Notification-To", $line)) { … … 176 180 $return['Recent'] = $header->Recent; 177 181 $return['Unseen'] = $header->Unseen; 178 $return['Deleted'] = $header->Deleted; 182 $return['Deleted'] = $header->Deleted; 179 183 $return['Flagged'] = $header->Flagged; 180 184 … … 184 188 else { 185 189 $return['Answered'] = $header->Answered; 186 $return['Draft'] = $header->Draft; 190 $return['Draft'] = $header->Draft; 187 191 } 188 192 189 193 $return['msg_number'] = $msg_number; 190 194 $return['msg_folder'] = $msg_folder; 191 195 192 196 $date_msg = date("d/m/Y",$header->udate); 193 197 if (date("d/m/Y") == $date_msg) … … 195 199 else 196 200 $return['udate'] = $date_msg; 197 198 $return['msg_day'] = $date_msg; 201 202 $return['msg_day'] = $date_msg; 199 203 $return['msg_hour'] = date("H:i",$header->udate); 200 204 201 205 if (date("d/m/Y") == $date_msg) //no dia 202 206 { 203 207 $return['fulldate'] = date("d/m/Y H:i",$header->udate); 204 208 $return['smalldate'] = date("H:i",$header->udate); 205 209 206 210 $timestamp_now = strtotime("now"); 207 211 $timestamp_msg_time = $header->udate; 208 212 $timestamp_diff = $timestamp_now - $timestamp_msg_time; 209 213 210 214 if (gmdate("H",$timestamp_diff) > 0) 211 215 { … … 229 233 $return['smalldate'] = date("d/m/Y",$header->udate); 230 234 } 231 235 232 236 $from = $header->from; 233 237 $return['from'] = array(); … … 244 248 else 245 249 $return['from']['full'] = $return['from']['email']; 246 250 247 251 // Sender attribute 248 252 $sender = $header->sender; … … 296 300 { 297 301 $return['toaddress2'] = "<Empty>"; 298 } 299 302 } 303 300 304 $cc = $header->cc; 301 305 $return['cc'] = ""; … … 325 329 { 326 330 $return['cc'] = ""; 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 } 331 } 362 332 363 333 $reply_to = $header->reply_to; … … 391 361 $return['Size'] = $header->Size; 392 362 $return['reply_toaddress'] = $header->reply_toaddress; 393 363 394 364 return $return; 395 365 } 396 366 397 367 function get_body_msg($msg_number, $msg_folder) 398 368 { … … 401 371 $msg->fetch_structure($msg_number); 402 372 $return = array(); 403 $return['attachments'] = $this-> download_attachment($msg,$msg_number); 373 $return['attachments'] = $this-> download_attachment($msg,$msg_number); 404 374 if(!$this->has_cid) 405 375 { 406 376 $return['thumbs'] = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); 407 377 $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 408 } 409 378 } 379 410 380 if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 411 381 { 412 382 $attachment = array(); //No attachments 413 383 414 384 $content = ''; 415 385 if (strtolower($msg->structure[$msg_number]->subtype) == "plain") … … 422 392 } 423 393 } 424 else 394 else 425 395 { //Complicated message, multiple parts 426 396 $html_body = ''; … … 428 398 $has_multipart = true; 429 399 $this->has_cid = false; 430 400 431 401 if (strtolower($msg->structure[$msg_number]->subtype) == "related") 432 402 $this->has_cid = true; 433 403 434 404 if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") 435 $show_only_html = true; 405 { 406 $show_only_html = false; 407 foreach($msg->pid[$msg_number] as $values => $msg_part) 408 { 409 $file_type = strtolower($msg->file_type[$msg_number][$values]); 410 if($file_type == "text/html") 411 $show_only_html = true; 412 } 413 } 436 414 else 437 415 $show_only_html = false; … … 439 417 foreach($msg->pid[$msg_number] as $values => $msg_part) 440 418 { 441 419 442 420 $file_type = strtolower($msg->file_type[$msg_number][$values]); 443 421 if($file_type == "message/rfc822") 444 422 $has_multipart = false; 445 423 446 424 if($file_type == "multipart/alternative") 447 425 $has_multipart = false; 448 449 if(($file_type == "text/plain" 426 427 if(($file_type == "text/plain" 450 428 || $file_type == "text/html") 451 429 && $file_type != 'attachment') … … 455 433 // if TXT file size > 100kb, then it will not expand. 456 434 if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 457 $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]))); 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]))); 458 436 } 459 437 } 460 438 // if HTML attachment file size > 300kb, then it will not expand. 461 else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 307200 )439 else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 3072000) 462 440 { 463 441 $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); … … 467 445 else if($file_type == "message/delivery-status"){ 468 446 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 469 $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 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])); 470 448 471 449 } 472 450 else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ 473 451 474 452 include_once("class.imap_attachment.inc.php"); 475 453 $att = new imap_attachment(); 476 454 $attachments = $att -> get_attachment_info($this->mbox,$msg_number); 477 if($attachments['number_attachments'] > 0) { 455 if($attachments['number_attachments'] > 0) { 478 456 foreach($attachments ['attachment'] as $index => $attachment){ 479 457 if(strtolower($attachment['type']) == "delivery-status" || 480 strtolower($attachment['type']) == "rfc822" || 458 strtolower($attachment['type']) == "rfc822" || 481 459 strtolower($attachment['type']) == "rfc822-headers" || 482 460 strtolower($attachment['type']) == "plain" 483 461 ){ 484 $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); 485 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 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'>"; 486 464 $content .= "<br><table style='margin:2px;border:1px solid black;background:#EAEAEA'>"; 487 465 $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; … … 489 467 $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; 490 468 $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; 491 $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>"; 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>"; 492 470 $ix_part = strtolower($attachment['type']) == "delivery-status" ? 1 : 0; 493 $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])); 494 break; 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; 495 473 } 496 474 } … … 502 480 $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); 503 481 else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") 504 $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 505 } 506 } 482 $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 483 } 484 } 507 485 // Force message with flag Seen (imap_fetchbody not works correctly) 508 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 486 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 509 487 $this->set_messages_flag($params); 510 488 $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); … … 513 491 return $return; 514 492 } 515 493 516 494 function htmlfilter($body) 517 495 { 518 496 require_once('htmlfilter.inc'); 519 497 520 498 $tag_list = Array( 521 499 false, … … 590 568 '\\1round:\\2\\1' 591 569 ) 592 ), 593 570 ), 571 594 572 '/^style/i' => 595 573 Array( … … 617 595 '/^a$/i' => Array('target' => '"_new"') 618 596 ); 619 620 597 598 621 599 $trusted_body = sanitize($body, 622 600 $tag_list, … … 628 606 $add_attr_to_tag 629 607 ); 630 608 631 609 return $trusted_body; 632 610 } 633 611 634 612 function decodeBody($body, $encoding, $charset=null) 635 613 { … … 642 620 if ($encoding == 'quoted-printable') 643 621 { 644 622 645 623 for($i=0;$i<256;$i++) { 646 624 $c1=dechex($i); … … 649 627 $myqprinta[]=$c1; 650 628 $myqprintb[]=chr($i); 651 } 629 } 652 630 $body = str_replace($myqprinta,$myqprintb,($body)); 653 631 $body = quoted_printable_decode($body); 654 while (ereg("=\n", $body)) 632 while (ereg("=\n", $body)) 655 633 { 656 634 $body = ereg_replace ("=\n", '', $body); 657 635 } 658 636 } 659 else if ($encoding == 'base64') 637 else if ($encoding == 'base64') 660 638 { 661 639 $body = base64_decode($body); 662 640 } 663 /*else if ($encoding == '7bit') 641 /*else if ($encoding == '7bit') 664 642 { 665 $body = quoted_printable_decode($body); 643 $body = quoted_printable_decode($body); 666 644 }*/ 667 645 // All other encodings are returned raw. … … 671 649 return $body; 672 650 } 673 651 674 652 function process_embedded_images($msg, $msgno, $body, $msg_folder) 675 653 { … … 688 666 } 689 667 } 690 668 691 669 return $body; 692 670 } 693 671 694 672 function replace_special_characters($body) 695 673 { 696 674 // Suspected TAGS! 697 /*$tag_list = Array( 675 /*$tag_list = Array( 698 676 'blink','object','meta', 699 677 'html','link','frame', … … 704 682 */ 705 683 706 // Layout problem: Change html elements 707 // with absolute position to relate position, CASE INSENSITIVE. 684 // Layout problem: Change html elements 685 // with absolute position to relate position, CASE INSENSITIVE. 708 686 $body = @eregi_replace("POSITION: ABSOLUTE;","",$body); 709 687 … … 713 691 714 692 $body = $this-> replace_links($body); 715 $blocked_tags = array(); 693 $blocked_tags = array(); 716 694 foreach($tag_list as $index => $tag) { 717 695 $new_body = eregi_replace("<$tag", "<!--$tag", $body); … … 725 703 } 726 704 727 function replace_links($body) { 728 $matches = array(); 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(); 729 711 // Verify exception. 730 @preg_match("/<a href=\"notes:\/\/\//",$body,$matches);712 //@preg_match("/<a href=\"notes:\/\/\//",$body,$matches); 731 713 // It no has exception,then open the link in new window. 732 if(count($matches)) 733 return $body; 734 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); 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; 735 722 } 736 723 737 724 function get_signature($msg, $msg_number, $msg_folder) 738 { 725 { 739 726 foreach ($msg->file_type[$msg_number] as $index => $file_type) 740 727 { 741 728 $file_type = strtolower($file_type); 742 if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 743 { 744 if ($file_type == 'application/x-pkcs7-signature') 729 if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') 730 { 731 if ($file_type == 'application/x-pkcs7-signature') 745 732 { 746 733 $export_mail = new ExportEml(); … … 748 735 $params['msgs_to_export'] = $msg_number; 749 736 $tempDir = ini_get("session.save_path"); 750 $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 737 $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 751 738 $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); 752 739 if (file_exists($cert_file)) … … 768 755 } 769 756 } 770 return $sign; 757 return $sign; 771 758 } 772 759 … … 789 776 return $thumbs_array; 790 777 } 791 778 792 779 /*function delete_msg($params) 793 780 { 794 781 $folder = $params['folder']; 795 782 $msgs_to_delete = explode(",",$params['msgs_to_delete']); 796 783 797 784 $mbox_stream = $this->open_mbox($folder); 798 785 799 786 foreach ($msgs_to_delete as $msg_number){ 800 787 imap_delete($mbox_stream, $msg_number, FT_UID); … … 807 794 function delete_msgs($params) 808 795 { 809 796 810 797 $folder = $params['folder']; 811 798 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 812 799 $msgs_number = explode(",",$params['msgs_number']); 813 800 $border_ID = $params['border_ID']; 814 801 815 802 $return = array(); 816 817 if ($params['get_previous_msg']) {803 804 if ($params['get_previous_msg']) 818 805 $return['previous_msg'] = $this->get_info_previous_msg($params); 819 // Fix problem in unserialize function JS.820 $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']);821 }822 806 823 807 //$mbox_stream = $this->open_mbox($folder); 824 808 $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()))); 825 809 826 810 foreach ($msgs_number as $msg_number) 827 811 { … … 829 813 $return['msgs_number'][] = $msg_number; 830 814 } 831 815 832 816 $return['folder'] = $folder; 833 817 $return['border_ID'] = $border_ID; 834 818 835 819 if($mbox_stream) 836 820 imap_close($mbox_stream, CL_EXPUNGE); … … 838 822 } 839 823 840 824 841 825 function refresh($params) 842 826 { 843 827 include("class.imap_attachment.inc.php"); 844 $imap_attachment = new imap_attachment(); 828 $imap_attachment = new imap_attachment(); 845 829 $folder = $params['folder']; 846 830 $msg_range_begin = $params['msg_range_begin']; 847 831 $msg_range_end = $params['msg_range_end']; 848 832 $msgs_existent = $params['msgs_existent']; 849 $sort_box_type = $params['sort_box_type']; 833 $sort_box_type = $params['sort_box_type']; 850 834 $sort_box_reverse = $params['sort_box_reverse']; 851 835 $msgs_in_the_server = array(); … … 855 839 if(!count($sort_array_msg)) 856 840 return array(); 857 841 858 842 $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); 859 843 $msgs_in_the_client = explode(",", $msgs_existent); 860 844 861 845 862 846 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) 863 847 { … … 874 858 } 875 859 } 876 860 877 861 $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); 878 862 $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 879 863 880 864 $msgs_to_exec = array(); 881 865 if ((count($msg_to_insert)) && ($msgs_existent)) … … 903 887 } 904 888 } 905 889 906 890 $return = array(); 907 891 $i = 0; … … 911 895 if (!is_object($header)) 912 896 return false; 913 897 914 898 $return[$i]['msg_number'] = $msg_number; 915 899 $return[$i]['command'] = $command; 916 900 917 901 $return[$i]['msg_folder'] = $folder; 918 902 $return[$i]['Recent'] = $header->Recent; … … 928 912 else 929 913 $return[$i]['udate'] = $date_msg; 930 914 931 915 $from = $header->from; 932 916 $return[$i]['from'] = array(); … … 934 918 $return[$i]['from']['name'] = $tmp[0]->text; 935 919 $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 936 //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 920 //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 937 921 if(!$return[$i]['from']['name']) 938 922 $return[$i]['from']['name'] = $return[$i]['from']['email']; 939 923 940 924 /*$toaddress = imap_mime_header_decode($header->toaddress); 941 925 $return[$i]['toaddress'] = ''; … … 948 932 $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 949 933 $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 950 934 951 935 $return[$i]['subject'] = $this->decode_string($header->fetchsubject); 952 936 953 937 $return[$i]['Size'] = $header->Size; 954 938 $return[$i]['reply_toaddress'] = $header->reply_toaddress; 955 939 956 940 $return[$i]['attachment'] = array(); 957 941 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); … … 965 949 } 966 950 967 function get_folders_list( $params = null)968 { 969 $mbox_stream = $this->open_mbox(); 951 function get_folders_list() 952 { 953 $mbox_stream = $this->open_mbox(); 970 954 $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; 971 955 $folders_list = imap_getmailboxes($mbox_stream, $serverString, "*"); 972 956 $tmp = array(); 973 957 $result = array(); 974 958 975 959 if (is_array($folders_list)) { 976 960 reset($folders_list); 977 $ ldap = new ldap_functions();978 961 $this->ldap = new ldap_functions(); 962 979 963 $i = 0; 980 964 while (list($key, $val) = each($folders_list)) { 981 965 $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 982 966 $result[$i]['folder_unseen'] = $status->unseen; 983 967 984 968 //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 985 969 $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); 986 970 $folder_id = $tmp_folder_id[1]; 987 971 $result[$i]['folder_id'] = $folder_id; 988 972 989 973 $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 990 974 $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 991 975 $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 992 976 if (is_numeric($result[$i]['folder_name'])) { 993 if ($cn = $ ldap->uid2cn($result[$i]['folder_name'])){977 if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])){ 994 978 $result[$i]['folder_name'] = $cn; 995 979 } 996 980 } 997 981 998 982 $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 999 983 $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 1000 984 1001 985 if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 1002 986 $result[$i]['folder_hasChildren'] = 1; … … 1004 988 $result[$i]['folder_hasChildren'] = 0; 1005 989 1006 $i++; 990 $i++; 1007 991 } 1008 992 } 1009 993 1010 994 foreach ($result as $folder_info) 1011 995 { 1012 996 $array_tmp[] = $folder_info['folder_id']; 1013 997 } 1014 998 1015 999 natcasesort($array_tmp); 1016 1000 1017 1001 foreach ($array_tmp as $key => $folder_id) 1018 1002 { 1019 1003 $result2[] = $result[$key]; 1020 1004 } 1021 1022 $current_folder = "INBOX"; 1023 if($params && $params['folder']) 1024 $current_folder = $params['folder']; 1025 return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); 1026 } 1027 1005 1006 if($mbox_stream && is_resource($mbox_stream)){ 1007 imap_close($mbox_stream); 1008 } 1009 1010 return array_merge($result2); 1011 } 1012 1028 1013 function create_mailbox($arr) 1029 1014 { … … 1032 1017 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1033 1018 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); 1034 1019 1035 1020 $result = "Ok"; 1036 1021 if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) 1037 1022 { 1038 1023 $result = implode("<br />\n", imap_errors()); 1039 } 1040 1024 } 1025 1041 1026 if($mbox_stream) 1042 1027 imap_close($mbox_stream); 1043 1028 1044 1029 return $result; 1045 1046 } 1047 1030 1031 } 1032 1048 1033 function create_extra_mailbox($arr) 1049 1034 { … … 1052 1037 $mbox_stream = $this->open_mbox(); 1053 1038 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1054 foreach($nameboxs as $key=>$tmp){ 1039 foreach($nameboxs as $key=>$tmp){ 1055 1040 if($tmp != ""){ 1056 1041 if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ 1057 1042 $result = implode("<br />\n", imap_errors()); 1058 1043 if($mbox_stream) 1059 imap_close($mbox_stream); 1044 imap_close($mbox_stream); 1060 1045 return $result; 1061 1046 } … … 1066 1051 return true; 1067 1052 } 1068 1053 1069 1054 function delete_mailbox($arr) 1070 1055 { … … 1073 1058 $mbox_stream = $this->open_mbox(); 1074 1059 //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); 1075 1060 1076 1061 $result = "Ok"; 1077 1062 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); … … 1084 1069 return $result; 1085 1070 } 1086 1071 1087 1072 function ren_mailbox($arr) 1088 1073 { … … 1092 1077 $mbox_stream = $this->open_mbox(); 1093 1078 //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); 1094 1079 1095 1080 $result = "Ok"; 1096 1081 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 1097 1082 $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); 1098 1083 1099 1084 if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) 1100 1085 { 1101 $result = imap_errors(); 1086 $result = imap_errors(); 1102 1087 } 1103 1088 if($mbox_stream) 1104 1089 imap_close($mbox_stream); 1105 1090 return $result; 1106 1107 } 1108 1091 1092 } 1093 1109 1094 function get_num_msgs($params) 1110 1095 { … … 1114 1099 if(!$this->mbox || !is_resource($this->mbox)) 1115 1100 return imap_last_error(); 1116 } 1101 } 1117 1102 $num_msgs = imap_num_msg($this->mbox); 1118 if($this->mbox ||is_resource($this->mbox))1103 if($this->mbox && is_resource($this->mbox)) 1119 1104 imap_close($this->mbox); 1120 1105 1121 1106 return $num_msgs; 1122 1107 } 1123 1108 1124 1109 function send_mail($params) 1125 1110 { … … 1139 1124 $attachments = $params['FILES']; 1140 1125 $forwarding_attachments = $params['forwarding_attachments']; 1141 1126 1142 1127 $folder =$params['folder']; 1143 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1144 $folder_name = $params['folder_name']; 1128 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1129 $folder_name = $params['folder_name']; 1145 1130 // Fix problem with cyrus delimiter changes. 1146 // Dots in names: enabled/disabled. 1131 // Dots in names: enabled/disabled. 1147 1132 $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 1148 1133 $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 1149 1134 // End Fix. 1150 if ($folder != 'null'){ 1135 if ($folder != 'null'){ 1151 1136 $mail->SaveMessageInFolder = $folder; 1152 1137 } 1153 1138 //////////////////////////////////////////////////////////////////////////////////////////////////// 1154 1139 $mail->SMTPDebug = false; 1155 1140 1156 1141 $mail->IsSMTP(); 1157 1142 $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; … … 1165 1150 $mail->From = $fromaddress[1]; 1166 1151 } 1167 1152 1168 1153 $this->add_recipients("to", $toaddress, &$mail); 1169 1154 $this->add_recipients("cc", $ccaddress, &$mail); … … 1175 1160 //////////////////////////////////////////////////////////////////////////////////////////////////// 1176 1161 // Build CID for embedded Images!!! 1177 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?& (amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';1162 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&msg_num=(.+)?&msg_part=(.+)?)"/isU'; 1178 1163 $cid_imgs = ''; 1179 1164 $name_cid_files = array(); 1180 1165 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 1181 1166 $cid_array = array(); 1182 foreach($cid_imgs[ 6] as $j => $val){1183 if ( !array_key_exists($cid_imgs[ 4][$j].$val, $cid_array) )1167 foreach($cid_imgs[4] as $j => $val){ 1168 if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 1184 1169 { 1185 $cid_array[$cid_imgs[ 4][$j].$val] = base_convert(microtime(), 10, 36);1170 $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 1186 1171 } 1187 $cid = $cid_array[$cid_imgs[ 4][$j].$val];1172 $cid = $cid_array[$cid_imgs[3][$j].$val]; 1188 1173 $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 1189 1190 if ($msg_uid != $cid_imgs[ 4][$j]) // The image isn't in the same mail?1174 1175 if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 1191 1176 { 1192 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[ 4][$j], $cid_imgs[6][$j], 'base64');1177 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 1193 1178 $fileName = "image_".($j).".jpg"; 1194 1179 $fileCode = "base64"; … … 1197 1182 else 1198 1183 { 1199 $attach_img = $forwarding_attachments[$cid_imgs[ 6][$j]-2];1184 $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 1200 1185 $file_description = unserialize(rawurldecode($attach_img)); 1201 1186 1202 foreach($file_description as $i => $descriptor){ 1187 foreach($file_description as $i => $descriptor){ 1203 1188 $file_description[$i] = eregi_replace('\'*\'','',$descriptor); 1204 1189 } … … 1207 1192 $fileCode = $file_description[4]; 1208 1193 $fileType = $this->get_file_type($file_description[2]); 1209 unset($forwarding_attachments[$cid_imgs[ 6][$j]-2]);1194 unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 1210 1195 } 1211 1196 $tempDir = ini_get("session.save_path"); 1212 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1197 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1213 1198 $f = fopen($tempDir.'/'.$file,"w"); 1214 1199 fputs($f,$fileContent); … … 1217 1202 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 1218 1203 //else 1219 // return "Error loading image attachment content"; 1204 // return "Error loading image attachment content"; 1220 1205 1221 1206 } … … 1232 1217 } 1233 1218 if( $total_uploaded_size > $upload_max_filesize) 1234 return 'false'; 1235 } 1219 return 'false'; 1220 } 1236 1221 //////////////////////////////////////////////////////////////////////////////////////////////////// 1237 1222 // Build Forwarding Attachments!!! … … 1242 1227 $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; 1243 1228 $name_cid_files[0] = null; 1244 } 1245 1229 } 1230 1246 1231 foreach($forwarding_attachments as $forwarding_attachment) 1247 1232 { 1248 1233 $file_description = unserialize(rawurldecode($forwarding_attachment)); 1249 1234 $tmp = array_values($file_description); 1250 foreach($file_description as $i => $descriptor){ 1235 foreach($file_description as $i => $descriptor){ 1251 1236 $tmp[$i] = eregi_replace('\'*\'','',$descriptor); 1252 1237 } 1253 $file_description = $tmp; 1238 $file_description = $tmp; 1254 1239 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 1255 1240 $fileName = $file_description[2]; … … 1272 1257 else 1273 1258 { 1274 if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 1259 if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 1275 1260 { 1276 1261 $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; … … 1278 1263 $now = date("d/m/y H:i:s"); 1279 1264 $addrs = $toaddress.$ccaddress.$ccoaddress; 1280 $sent = trim($sent); 1265 $sent = trim($sent); 1281 1266 error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); 1282 1267 } 1283 1268 if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) 1284 1269 { 1285 1286 1270 $contacts = new dynamic_contacts(); 1271 $contacts->add_dynamic_contacts($toaddress.$ccaddress.$ccoaddress); 1287 1272 } 1288 1273 return true; … … 1292 1277 function add_recipients($recipient_type, $full_address, $mail) 1293 1278 { 1294 $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 1295 foreach ($parse_address as $val) 1279 $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 1280 foreach ($parse_address as $val) 1296 1281 { 1297 1282 //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; 1298 1283 if ($val->mailbox == "INVALID_ADDRESS") 1299 1284 continue; 1300 1285 1301 1286 if (empty($val->personal)) 1302 1287 { … … 1332 1317 return true; 1333 1318 } 1334 1319 1335 1320 function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) 1336 1321 { 1337 $mbox_stream = $this->open_mbox($msg_folder); 1338 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 1322 $mbox_stream = $this->open_mbox($msg_folder); 1323 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 1339 1324 if($encoding == 'base64') 1340 # The function imap_base64 adds a new line 1341 # at ASCII text, with CRLF line terminators. 1342 # So is being exchanged for base64_decode. 1343 # 1344 #$fileContent = imap_base64($fileContent); 1345 $fileContent = base64_decode($fileContent); 1325 $fileContent = imap_base64($fileContent); 1346 1326 else if($encoding == 'quoted-printable') 1347 $fileContent = quoted_printable_decode($fileContent); 1327 $fileContent = quoted_printable_decode($fileContent); 1348 1328 return $fileContent; 1349 1329 } 1350 1330 1351 1331 function del_last_caracter($string) 1352 1332 { 1353 1333 $string = substr($string,0,(strlen($string) - 1)); 1354 return $string; 1355 } 1356 1334 return $string; 1335 } 1336 1357 1337 function del_last_two_caracters($string) 1358 1338 { 1359 1339 $string = substr($string,0,(strlen($string) - 2)); 1360 return $string; 1361 } 1362 1340 return $string; 1341 } 1342 1363 1343 function imap_sortfrom($sort_box_reverse, $search_box_type) 1364 1344 { 1365 1345 $sortfrom = array(); 1366 1346 $sortfrom_uid = array(); 1367 1347 1368 1348 $num_msgs = imap_num_msg($this->mbox); 1369 1349 for ($i=1; $i<=$num_msgs; $i++) … … 1378 1358 continue; 1379 1359 } 1380 // List ANSWERED messages. 1360 // List ANSWERED messages. 1381 1361 elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ 1382 continue; 1383 } 1384 // List FLAGGED messages. 1362 continue; 1363 } 1364 // List FLAGGED messages. 1385 1365 elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ 1386 1366 continue; 1387 1367 } 1388 1389 if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 1368 1369 if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 1390 1370 $from = $header->to; 1391 1371 else 1392 1372 $from = $header->from; 1393 1394 $tmp = imap_mime_header_decode($from[0]->personal); 1395 1373 1374 $tmp = imap_mime_header_decode($from[0]->personal); 1375 1396 1376 if ($tmp[0]->text != "") 1397 1377 $sortfrom[$i] = $tmp[0]->text; … … 1399 1379 $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; 1400 1380 } 1401 1381 1402 1382 natcasesort($sortfrom); 1403 1383 1404 1384 foreach($sortfrom as $index => $header_msg) 1405 { 1385 { 1406 1386 $sortfrom_uid[] = imap_uid($this->mbox, $index); 1407 1387 } 1408 1388 1409 1389 if ($sort_box_reverse) 1410 1390 $sortfrom_uid = array_reverse($sortfrom_uid); 1411 1391 1412 1392 return $sortfrom_uid; 1413 1393 } 1414 1394 1415 function move_search_messages($params){ 1416 $params['selected_messages'] = urldecode($params['selected_messages']); 1395 function move_search_messages($params){ 1396 $params['selected_messages'] = urldecode($params['selected_messages']); 1417 1397 $params['new_folder'] = urldecode($params['new_folder']); 1418 1398 $params['new_folder_name'] = urldecode($params['new_folder_name']); 1419 1399 $sel_msgs = explode(",", $params['selected_messages']); 1420 @reset($sel_msgs); 1400 @reset($sel_msgs); 1421 1401 $sorted_msgs = array(); 1422 1402 foreach($sel_msgs as $idx => $sel_msg) { … … 1424 1404 if(array_key_exists($sel_msg[0], $sorted_msgs)){ 1425 1405 $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; 1426 } 1406 } 1427 1407 else { 1428 1408 $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; … … 1430 1410 } 1431 1411 @ksort($sorted_msgs); 1432 $last_return = false; 1433 foreach($sorted_msgs as $folder => $msgs_number) { 1412 $last_return = false; 1413 foreach($sorted_msgs as $folder => $msgs_number) { 1434 1414 $params['msgs_number'] = $msgs_number; 1435 $params['folder'] = $folder; 1415 $params['folder'] = $folder; 1436 1416 if($params['new_folder'] && $folder != $params['new_folder']){ 1437 $last_return = $this -> move_messages($params); 1417 $last_return = $this -> move_messages($params); 1438 1418 } 1439 1419 elseif(!$params['new_folder'] || $params['delete'] ){ … … 1444 1424 return $last_return; 1445 1425 } 1446 1426 1447 1427 function move_messages($params) 1448 1428 { 1449 $folder = $params['folder']; 1450 $mbox_stream = $this->open_mbox($folder); 1429 $folder = $params['folder']; 1430 $mbox_stream = $this->open_mbox($folder); 1451 1431 $newmailbox = ($params['new_folder']); 1452 1432 $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); … … 1458 1438 'border_ID' => $params['border_ID'], 1459 1439 'status' => true); //Status foi adicionado para validar as permissoes ACL 1460 1440 1461 1441 //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas 1462 1442 if (substr($folder,0,4) == 'user'){ … … 1478 1458 } 1479 1459 } 1480 1481 // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. 1460 //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name 1461 if (substr($new_folder_name,0,4) == 'user'){ 1462 $this->ldap = new ldap_functions(); 1463 $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); 1464 $return['new_folder_name'] = array_pop($tmp_folder_name); 1465 if (is_numeric($return['new_folder_name'])) 1466 if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) 1467 $return['new_folder_name'] = $cn; 1468 } 1469 1470 // Caso estejamos no box principal, nï¿œo ï¿œ necessï¿œrio pegar a informaᅵᅵo da mensagem anterior. 1482 1471 if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 1483 {1484 1472 $return['previous_msg'] = $this->get_info_previous_msg($params); 1485 // Fix problem in unserialize function JS. 1486 $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); 1487 } 1488 1489 $mbox_stream = $this->open_mbox($folder); 1473 1474 $mbox_stream = $this->open_mbox($folder); 1490 1475 if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 1491 1476 imap_expunge($mbox_stream); … … 1494 1479 return $return; 1495 1480 }else { 1496 if(strstr(imap_last_error(),'Over quota')) { 1481 if(strstr(imap_last_error(),'Over quota')) { 1497 1482 $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; 1498 $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 1499 $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 1483 $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; 1484 $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 1500 1485 $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1501 1486 $mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => imap_last_error()))); 1502 1487 if(!$mbox) 1503 1488 return imap_last_error(); 1504 $quota = imap_get_quotaroot($mbox_stream, "INBOX"); 1489 $quota = imap_get_quotaroot($mbox_stream, "INBOX"); 1505 1490 if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { 1506 1491 if($mbox_stream) 1507 1492 imap_close($mbox_stream); 1508 if($mbox) 1493 if($mbox) 1509 1494 imap_close($mbox); 1510 return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 1495 return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 1511 1496 } 1512 1497 if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { … … 1518 1503 if($mbox) 1519 1504 imap_close($mbox); 1520 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1505 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1521 1506 } 1522 return $return; 1507 return $return; 1523 1508 } 1524 1509 else { … … 1528 1513 if($mbox) 1529 1514 imap_close($mbox); 1530 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1515 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1531 1516 } 1532 return imap_last_error(); 1533 } 1534 1517 return imap_last_error(); 1518 } 1519 1535 1520 } 1536 1521 else { … … 1539 1524 return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; 1540 1525 } 1541 } 1542 } 1543 1526 } 1527 } 1528 1544 1529 function save_msg($params) 1545 1530 { 1546 1531 1547 1532 include_once("class.phpmailer.php"); 1548 1533 $mail = new PHPMailer(); … … 1559 1544 $attachments = $params['FILES']; 1560 1545 $return_files = $params['FILES']; 1561 1546 1562 1547 $folder = $params['folder']; 1563 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1548 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1564 1549 // Fix problem with cyrus delimiter changes. 1565 // Dots in names: enabled/disabled. 1550 // Dots in names: enabled/disabled. 1566 1551 $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 1567 1552 $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 1568 1553 // End Fix. 1569 1554 1570 1555 $mail->SaveMessageInFolder = $folder; 1571 1556 $mail->SMTPDebug = false; 1572 1557 1573 1558 $mail->IsSMTP(); 1574 1559 $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; … … 1576 1561 $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 1577 1562 $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 1578 1563 1579 1564 $mail->Sender = $mail->From; 1580 1565 $mail->SenderName = $mail->FromName; 1581 1566 $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 1582 1567 $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 1583 1568 1584 1569 $this->add_recipients("to", $toaddress, &$mail); 1585 1570 $this->add_recipients("cc", $ccaddress, &$mail); … … 1587 1572 $mail->IsHTML(true); 1588 1573 $mail->Body = $body; 1589 1574 1590 1575 // Build CID for embedded Images!!! 1591 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?& (amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';1576 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&msg_num=(.+)?&msg_part=(.+)?)"/isU'; 1592 1577 $cid_imgs = ''; 1593 1578 $name_cid_files = array(); 1594 1579 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 1595 1580 $cid_array = array(); 1596 foreach($cid_imgs[ 6] as $j => $val){1597 if ( !array_key_exists($cid_imgs[ 4][$j].$val, $cid_array) )1581 foreach($cid_imgs[4] as $j => $val){ 1582 if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 1598 1583 { 1599 $cid_array[$cid_imgs[ 4][$j].$val] = base_convert(microtime(), 10, 36);1584 $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 1600 1585 } 1601 $cid = $cid_array[$cid_imgs[ 4][$j].$val];1586 $cid = $cid_array[$cid_imgs[3][$j].$val]; 1602 1587 $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 1603 1604 if ($msg_uid != $cid_imgs[ 4][$j]) // The image isn't in the same mail?1588 1589 if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 1605 1590 { 1606 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 1607 //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) 1591 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 1608 1592 $fileName = "image_".($j).".jpg"; 1609 1593 $fileCode = "base64"; 1610 1594 $fileType = "image/jpg"; 1611 $file_attached[0] = $cid_imgs[2][$j];1612 $file_attached[1] = $cid_imgs[4][$j];1613 $file_attached[2] = $fileName;1614 $file_attached[3] = $cid_imgs[6][$j];1615 $file_attached[4] = 'base64';1616 $file_attached[5] = strlen($fileContent); //Size of file1617 $return_forward[] = $file_attached;1618 1595 } 1619 1596 else 1620 1597 { 1621 $attach_img = $forwarding_attachments[$cid_imgs[ 6][$j]-2];1598 $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 1622 1599 $file_description = unserialize(rawurldecode($attach_img)); 1623 foreach($file_description as $i => $descriptor){ 1600 foreach($file_description as $i => $descriptor){ 1624 1601 $file_description[$i] = eregi_replace('\'*\'','',$descriptor); 1625 1602 } … … 1628 1605 $fileCode = $file_description[4]; 1629 1606 $fileType = $this->get_file_type($file_description[2]); 1630 unset($forwarding_attachments[$cid_imgs[ 6][$j]-2]);1607 unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 1631 1608 if (!empty($file_description)) 1632 1609 { … … 1636 1613 } 1637 1614 $tempDir = ini_get("session.save_path"); 1638 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1615 $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; 1639 1616 $f = fopen($tempDir.'/'.$file,"w"); 1640 1617 fputs($f,$fileContent); … … 1643 1620 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 1644 1621 //else 1645 // return "Error loading image attachment content"; 1646 1647 } 1648 1649 // Build Forwarding Attachments!!! 1622 // return "Error loading image attachment content"; 1623 1624 } 1625 1626 // Build Forwarding Attachments!!! 1650 1627 if (count($forwarding_attachments) > 0) 1651 1628 { … … 1654 1631 $file_description = unserialize(rawurldecode($forwarding_attachment)); 1655 1632 $tmp = array_values($file_description); 1656 foreach($file_description as $i => $descriptor){ 1633 foreach($file_description as $i => $descriptor){ 1657 1634 $tmp[$i] = eregi_replace('\'*\'','',$descriptor); 1658 1635 } 1659 1636 $file_description = $tmp; 1660 1637 1661 1638 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 1662 1639 $fileName = $file_description[2]; 1663 1640 1664 1641 $file_description[5] = strlen($fileContent); //Size of file 1665 1642 $return_forward[] = $file_description; 1666 1643 1667 1644 $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 1668 1645 } 1669 1646 } 1670 1647 1671 1648 if ((count($return_forward) > 0) && (count($return_files) > 0)) 1672 1649 $return_files = array_merge_recursive($return_forward,$return_files); … … 1674 1651 if (count($return_files) < 1) 1675 1652 $return_files = $return_forward; 1676 1653 1677 1654 // Build Uploading Attachments!!! 1678 1655 if (count($attachments)) 1679 1656 foreach ($attachments as $attach) 1680 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name 1681 1682 1683 1657 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name 1658 1659 1660 1684 1661 if(!empty($mail->AltBody)) 1685 1662 $mail->ContentType = "multipart/alternative"; … … 1689 1666 $header = $mail->CreateHeader(); 1690 1667 $body = $mail->CreateBody(); 1691 1668 1692 1669 if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 1693 1670 { … … 1703 1680 $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 1704 1681 $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); 1705 1682 1706 1683 $new_header = str_replace("\n", "\r\n", $header); 1707 1684 $new_body = str_replace("\n", "\r\n", $body); 1708 1685 1709 1686 $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 1710 1687 $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 1711 1688 $return['msg_no'] = $status->uidnext - 1; 1712 1689 $return['folder_id'] = $folder; 1713 1690 1714 1691 if($mbox_stream) 1715 1692 imap_close($mbox_stream); 1716 1693 1717 1694 foreach ($return_files as $index => $_attachment) { 1718 1695 if (array_key_exists("name",$_attachment)){ … … 1726 1703 } 1727 1704 } 1728 1705 1729 1706 $return['files'] = serialize($return_files); 1730 1707 1731 1708 if (!$return['append']) 1732 1709 $return['append'] = imap_last_error(); 1733 1710 1734 1711 return $return; 1735 1712 } 1736 1713 1737 1714 function set_messages_flag($params) 1738 1715 { … … 1743 1720 $return["msgs_to_set"] = $msgs_to_set; 1744 1721 $return["flag"] = $flag; 1745 1722 1746 1723 if(!$this->mbox && !is_resource($this->mbox)) 1747 1724 $this->mbox = $this->open_mbox($folder); 1748 1725 1749 1726 if ($flag == "unseen") 1750 1727 $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); … … 1761 1738 elseif ($flag == "unflagged") 1762 1739 $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); 1763 1740 1764 1741 if($this->mbox && is_resource($this->mbox)) 1765 1742 imap_close($this->mbox); 1766 1743 return $return; 1767 1744 } 1768 1745 1769 1746 function get_file_type($file_name) 1770 1747 { 1771 1748 $file_name = strtolower($file_name); 1772 1749 $strFileType = strrev(substr(strrev($file_name),0,4)); 1773 if ($strFileType == ".asf") 1750 if ($strFileType == ".asf") 1774 1751 return "video/x-ms-asf"; 1775 1752 if ($strFileType == ".avi") … … 1797 1774 if ($strFileType == ".htm" || $strFileType == "html") 1798 1775 return "text/html"; 1799 if ($strFileType == ".xml") 1776 if ($strFileType == ".xml") 1800 1777 return "text/xml"; 1801 if ($strFileType == ".xsl") 1778 if ($strFileType == ".xsl") 1802 1779 return "text/xsl"; 1803 if ($strFileType == ".css") 1780 if ($strFileType == ".css") 1804 1781 return "text/css"; 1805 if ($strFileType == ".php") 1782 if ($strFileType == ".php") 1806 1783 return "text/php"; 1807 if ($strFileType == ".asp") 1784 if ($strFileType == ".asp") 1808 1785 return "text/asp"; 1809 1786 if ($strFileType == ".pdf") … … 1833 1810 if ($strFileType == ".stw") 1834 1811 return "application/vnd.sun.xml.writer.template"; 1835 1836 1837 return "application/octet-stream"; 1838 } 1839 1812 1813 1814 return "application/octet-stream"; 1815 } 1816 1840 1817 function htmlspecialchars_encode($str) 1841 1818 { 1842 return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); 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; 1843 1832 } 1844 1833 function htmlspecialchars_decode($str) 1845 1834 { 1846 return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); 1847 } 1848 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 1849 1849 function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse){ 1850 1850 1851 1851 if(!$this->mbox || !is_resource($this->mbox)){ 1852 1852 $this->mbox = $this->open_mbox($folder); 1853 1853 } 1854 1854 1855 switch($sort_box_type){ 1855 1856 case 'SORTFROM': 1856 return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 1857 return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 1857 1858 case 'SORTSUBJECT': 1858 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 1859 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 1859 1860 case 'SORTSIZE': 1860 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 1861 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 1861 1862 default: 1862 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 1863 } 1864 } 1865 1863 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 1864 } 1865 } 1866 1866 1867 function get_info_next_msg($params) 1867 1868 { … … 1872 1873 $reuse_border = $params['reuse_border']; 1873 1874 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 1874 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 1875 1875 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 1876 1876 1877 $success = false; 1877 1878 if (is_array($sort_array_msg)) … … 1892 1893 return $params; 1893 1894 } 1894 1895 1895 1896 $params = array(); 1896 1897 $params['msg_number'] = $sort_array_msg[($i+1)]; 1897 1898 $params['msg_folder'] = $folder; 1898 1899 $return = $this->get_info_msg($params); 1899 1900 $return = $this->get_info_msg($params); 1900 1901 $return["reuse_border"] = $reuse_border; 1901 1902 return $return; … … 1911 1912 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 1912 1913 $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); 1913 1914 1914 1915 $success = false; 1915 1916 if (is_array($sort_array_msg)) … … 1929 1930 return $params; 1930 1931 } 1931 1932 1932 1933 $params = array(); 1933 1934 $params['msg_number'] = $sort_array_msg[($i-1)]; 1934 1935 $params['msg_folder'] = $folder; 1935 1936 1936 1937 $return = $this->get_info_msg($params); 1937 1938 $return["reuse_border"] = $reuse_border; 1938 1939 return $return; 1939 1940 } 1940 1941 1941 1942 // This function updates the values: quota, paging and new messages menu. 1942 1943 function get_menu_values($params){ 1943 1944 $return_array = array(); 1944 1945 $return_array = $this->get_quota($params); 1945 1946 1946 1947 $mbox_stream = $this->open_mbox($params['folder']); 1947 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 1948 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 1948 1949 if($mbox_stream) 1949 1950 imap_close($mbox_stream); 1950 1951 return $return_array; 1952 } 1953 1951 1952 return $return_array; 1953 } 1954 1954 1955 function get_quota($params){ 1955 // folder_id = user/{uid} for shared folders 1956 if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ 1957 $array_folder = explode($this->imap_delimiter,$params['folder_id']); 1958 $folder_id = "user".$this->imap_delimiter.$array_folder[1]; 1959 } 1960 // folder_id = INBOX for inbox folders 1961 else 1962 $folder_id = "INBOX"; 1963 1956 $folder_id = $params['folder_id']; 1964 1957 if(!$this->mbox || !is_resource($this->mbox)) 1965 1958 $this->mbox = $this->open_mbox(); … … 1968 1961 if($this->mbox && is_resource($this->mbox)) 1969 1962 imap_close($this->mbox); 1970 1963 1971 1964 if (!$quota){ 1972 1965 return array( … … 1976 1969 ); 1977 1970 } 1978 1971 1979 1972 if(count($quota) && $quota['limit']) { 1980 1973 $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; … … 1991 1984 ); 1992 1985 } 1993 else 1986 else 1994 1987 return array(); 1995 1988 } 1996 1989 1997 1990 function send_notification($params){ 1998 1991 require_once("class.phpmailer.php"); 1999 1992 $mail = new PHPMailer(); 2000 1993 2001 1994 $toaddress = $params['notificationto']; 2002 2003 $subject = ' Confirmaᅵᅵo de leitura: ' . $params['subject'];1995 1996 $subject = 'Leitura confirmada da mensagem: ' . $params['subject']; 2004 1997 $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; 2005 1998 $body .= 'foi lida por: ' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . ' <' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '> em ' . date("d/m/Y H:i"); … … 2015 2008 $mail->IsHTML(true); 2016 2009 $mail->Body = $body; 2017 2010 2018 2011 if(!$mail->Send()){ 2019 2012 return $mail->ErrorInfo; … … 2022 2015 return true; 2023 2016 } 2024 2017 2025 2018 function empty_trash() 2026 2019 { 2027 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 2020 $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 2028 2021 $mbox_stream = $this->open_mbox($folder); 2029 2022 $return = imap_delete($mbox_stream,'1:*'); … … 2032 2025 return $return; 2033 2026 } 2034 2027 2035 2028 function search($params) 2036 2029 { 2037 2030 include("class.imap_attachment.inc.php"); 2038 $imap_attachment = new imap_attachment(); 2031 $imap_attachment = new imap_attachment(); 2039 2032 $criteria = $params['criteria']; 2040 2033 $return = array(); 2041 2034 $folders = $this->get_folders_list(); 2042 2035 2043 2036 $j = 0; 2044 2037 foreach($folders as $folder) … … 2046 2039 $mbox_stream = $this->open_mbox($folder); 2047 2040 $messages = imap_search($mbox_stream, $criteria, SE_UID); 2048 2041 2049 2042 if ($messages == '') 2050 2043 continue; 2051 2044 2052 2045 $i = 0; 2053 2046 $return[$j] = array(); 2054 2047 $return[$j]['folder_name'] = $folder['name']; 2055 2048 2056 2049 foreach($messages as $msg_number) 2057 2050 { … … 2059 2052 if (!is_object($header)) 2060 2053 return false; 2061 2054 2062 2055 $return[$j][$i]['msg_folder'] = $folder['name']; 2063 2056 $return[$j][$i]['msg_number'] = $msg_number; … … 2068 2061 $return[$j][$i]['Draft'] = $header->Draft; 2069 2062 $return[$j][$i]['Flagged'] = $header->Flagged; 2070 2063 2071 2064 $date_msg = date("d/m/Y",$header->udate); 2072 2065 if (date("d/m/Y") == $date_msg) … … 2074 2067 else 2075 2068 $return[$j][$i]['udate'] = $date_msg; 2076 2069 2077 2070 $fromaddress = imap_mime_header_decode($header->fromaddress); 2078 2071 $return[$j][$i]['fromaddress'] = ''; 2079 2072 foreach ($fromaddress as $tmp) 2080 2073 $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); 2081 2074 2082 2075 $from = $header->from; 2083 2076 $return[$j][$i]['from'] = array(); … … 2085 2078 $return[$j][$i]['from']['name'] = $tmp[0]->text; 2086 2079 $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 2087 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 2080 $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; 2088 2081 2089 2082 $to = $header->to; … … 2092 2085 $return[$j][$i]['to']['name'] = $tmp[0]->text; 2093 2086 $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 2094 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 2087 $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 2095 2088 2096 2089 $subject = imap_mime_header_decode($header->fetchsubject); … … 2101 2094 $return[$j][$i]['Size'] = $header->Size; 2102 2095 $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; 2103 2096 2104 2097 $return[$j][$i]['attachment'] = array(); 2105 2098 $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); 2106 2099 2107 2100 $i++; 2108 2101 } … … 2111 2104 imap_close($mbox_stream); 2112 2105 } 2113 2106 2114 2107 return $return; 2115 2108 } 2116 2109 2117 2110 function delete_and_show_previous_message($params) 2118 2111 { 2119 2112 $return = $this->get_info_previous_msg($params); 2120 2113 2121 2114 $params_tmp1 = array(); 2122 2115 $params_tmp1['msgs_to_delete'] = $params['msg_number']; 2123 2116 $params_tmp1['folder'] = $params['msg_folder']; 2124 2117 $return_tmp1 = $this->delete_msg($params_tmp1); 2125 2118 2126 2119 $return['msg_number_deleted'] = $return_tmp1; 2127 2120 2128 2121 return $return; 2129 2122 } 2130 2131 2123 2124 2132 2125 function automatic_trash_cleanness($params) 2133 2126 { … … 2147 2140 // Fix the search problem with special characters!!!! 2148 2141 function remove_accents($string) { 2149 return strtr($string, 2150 "?ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ", 2142 return strtr($string, 2143 "?ï¿œ??ï¿œ?ï¿œ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ?ᅵᅵᅵᅵ", 2151 2144 "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 2152 2145 } 2153 2146 2154 2147 function search_msg($params = ''){ 2148 $this->ldap = new ldap_functions(); 2155 2149 $retorno = ""; 2156 2150 $mbox_stream = ""; … … 2171 2165 $filter .= '"'.$filter_array[1].'"'; 2172 2166 } 2173 } 2174 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 2167 } 2168 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 2175 2169 $filter = $this->remove_accents($filter); 2176 2170 $folder_name = explode($this->imap_delimiter,$name_box); 2171 if (is_numeric($folder_name[1])) 2172 { 2173 if ($cn = $this->ldap->uid2cn($folder_name[1])) 2174 { 2175 $folder_name[1] = $cn; 2176 } 2177 } 2178 $folder_name = implode($this->imap_delimiter,$folder_name); 2179 2177 2180 if(!is_resource($mbox_stream)) 2178 2181 $mbox_stream = $this->open_mbox($name_box); 2179 2182 else 2180 2183 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 2181 2182 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 2183 2184 2185 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 2186 2184 2187 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 2185 2188 foreach($all_criterias as $criteria_fixed) 2186 2189 { 2187 2190 $_filter = $criteria_fixed . substr($filter,4); 2188 2191 2189 2192 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 2190 2193 2191 2194 if($search_criteria && count($search_criteria) < 50) 2192 2195 { 2193 2196 foreach($search_criteria as $new_search){ 2194 $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");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"); 2195 2198 if(!@strstr($retorno,$m_token)) 2196 2199 $retorno .= $m_token; 2197 2200 } 2198 } 2199 else if(count($search_criteria) >= 50) 2200 return "many results"; 2201 } 2202 else if(count($search_criteria) >= 50) 2203 return "many results"; 2201 2204 } 2202 2205 } … … 2206 2209 { 2207 2210 foreach($search_criteria as $new_search) 2208 $retorno .= trim("##".mb_convert_encoding( $ name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n");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"); 2209 2212 } 2210 2213 } … … 2212 2215 } 2213 2216 if($mbox_stream) 2214 imap_close($mbox_stream); 2215 2217 imap_close($mbox_stream); 2218 2216 2219 return $retorno ? $retorno : "none"; 2217 2220 } 2218 2221 2219 2222 function get_msg($uid_msg,$name_box, $mbox_stream ) 2220 2223 { 2221 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); 2224 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255); 2222 2225 $subject = $this->decode_string($header->fetchsubject); 2223 2226 $from = $header->from[0]->mailbox; 2224 2227 if($header->from[0]->personal != "") 2225 2228 $from = $header->from[0]->personal; 2226 $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) ;2227 return $ret_msg; 2228 } 2229 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 2230 2233 function size_msg($size){ 2231 2234 $var = floor($size/1024); 2232 2235 if($var >= 1){ 2233 return $var." kb"; 2236 return $var." kb"; 2234 2237 }else{ 2235 return $size ." b"; 2238 return $size ." b"; 2236 2239 } 2237 2240 } … … 2260 2263 } 2261 2264 } 2262 2265 2263 2266 function getacl() 2264 2267 { 2265 2268 $this->ldap = new ldap_functions(); 2266 2269 2267 2270 $return = array(); 2268 $mbox_stream = $this->open_mbox(); 2271 $mbox_stream = $this->open_mbox(); 2269 2272 $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 2270 2273 2271 2274 $i = 0; 2272 2275 foreach ($mbox_acl as $user => $acl) … … 2281 2284 return $return; 2282 2285 } 2283 2286 2284 2287 function setacl($params) 2285 2288 { … … 2287 2290 if (!count($old_users)) 2288 2291 $old_users = array(); 2289 2292 2290 2293 $tmp_array = array(); 2291 2294 foreach ($old_users as $index => $user_info) … … 2294 2297 } 2295 2298 $old_users = $tmp_array; 2296 2299 2297 2300 $users = unserialize($params['users']); 2298 2301 if (!count($users)) 2299 2302 $users = array(); 2300 2303 2301 2304 //$add_share = array_diff($users, $old_users); 2302 2305 $remove_share = array_diff($old_users, $users); … … 2321 2324 } 2322 2325 }*/ 2323 2326 2324 2327 if (count($remove_share)) 2325 2328 { … … 2334 2337 } 2335 2338 } 2336 } 2337 } 2338 2339 } 2340 } 2341 2339 2342 return true; 2340 2343 } 2341 2344 2342 2345 function getaclfromuser($params) 2343 2346 { 2344 2347 $useracl = $params['user']; 2345 2348 2346 2349 $return = array(); 2347 2350 $return[$useracl] = 'false'; 2348 $mbox_stream = $this->open_mbox(); 2351 $mbox_stream = $this->open_mbox(); 2349 2352 $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); 2350 2353 2351 2354 foreach ($mbox_acl as $user => $acl) 2352 2355 { … … 2367 2370 //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo 2368 2371 if(substr($user,0,4) != 'user') 2369 $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user);2372 $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); 2370 2373 else 2371 2374 $mbox_acl = imap_getacl($mbox_stream, $user); 2372 2375 return $mbox_acl[$this->username]; 2373 2376 } 2374 2377 2375 2378 2376 2379 function setaclfromuser($params) … … 2378 2381 $user = $params['user']; 2379 2382 $acl = $params['acl']; 2380 2383 2381 2384 $mbox_stream = $this->open_mbox(); 2382 2385 … … 2388 2391 foreach ($mailboxes_list as $key => $val) 2389 2392 { 2390 $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); 2391 $folder = str_replace("&-", "&", $folder); 2393 $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); 2392 2394 if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) 2393 2395 { 2394 $return = imap_last_error(); 2395 } 2396 } 2397 } 2398 if (isset($return)) 2399 return $return; 2400 else 2401 return true; 2402 } 2403 2396 return imap_last_error(); 2397 } 2398 } 2399 } 2400 2401 return true; 2402 } 2403 2404 2404 function download_attachment($msg,$msgno) 2405 2405 { 2406 $array_parts_attachments = array(); 2406 $array_parts_attachments = array(); 2407 2407 $array_parts_attachments['names'] = ''; 2408 2408 include("class.imap_attachment.inc.php"); 2409 $imap_attachment = new imap_attachment(); 2410 2409 $imap_attachment = new imap_attachment(); 2410 2411 2411 if (count($msg->fname[$msgno]) > 0) 2412 2412 { … … 2425 2425 $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); 2426 2426 return $array_parts_attachments; 2427 } 2427 } 2428 2428 2429 2429 function spam($params) … … 2439 2439 $msg = $header . $body; 2440 2440 $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; 2441 $username = $this->username; 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)); 2442 2444 strtok($email, '@'); 2443 2445 $domain = strtok('@'); 2444 2446 2445 //Encontrar a assinatura do dspam no cabecalho2446 $v = explode("\r\n", $header);2447 foreach ($v as $linha){2448 if (eregi("^X-DSPAM-Signature", $linha)) {2449 2450 $args = explode(" ",$linha);2451 $signature = $args[1];2452 }2453 }2454 2455 2447 // feed dspam 2456 switch($is_spam){ 2457 case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; 2458 case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; 2459 } 2460 $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); 2461 $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); 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 2462 2459 system($cmd); 2460 2463 2461 } 2464 2462 imap_close($mbox_stream); -
trunk/phpgwapi/inc/functions.inc.php
r411 r432 22 22 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 23 23 \**************************************************************************/ 24 25 24 25 26 26 /***************************************************************************\ 27 27 * If running in PHP3, then force admin to upgrade * … … 38 38 39 39 include(PHPGW_API_INC.'/common_functions.inc.php'); 40 40 41 41 /*! 42 42 @function lang … … 53 53 $vars = array($m1,$m2,$m3,$m4,$m5,$m6,$m7,$m8,$m9,$m10); 54 54 } 55 // Get the translation from Lang File, if the database is down.56 if(!$GLOBALS['phpgw']->translation){57 $fn = PHPGW_SERVER_ROOT.'/phpgwapi/setup/phpgw_'.$GLOBALS['_SERVER']['HTTP_ACCEPT_LANGUAGE'].'.lang';58 if (file_exists($fn)){59 $fp = fopen($fn,'r');60 while ($data = fgets($fp,16000)){61 list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1));62 $GLOBALS['phpgw_info']['phpgwapi']['lang'][$message_id] = $content;63 }64 fclose($fp);65 }66 $return = str_replace('%1',$vars[0],$GLOBALS['phpgw_info']['phpgwapi']['lang'][$key]);67 return $return;68 }69 55 $value = $GLOBALS['phpgw']->translation->translate("$key",$vars); 70 56 return $value; … … 94 80 * Multi-Domain support * 95 81 \****************************************************************************/ 96 82 97 83 /* make them fix their header */ 98 84 if (!isset($GLOBALS['phpgw_domain'])) … … 162 148 } 163 149 $GLOBALS['phpgw']->db->Halt_On_Error = 'no'; 164 /* jakjr: ExpressoLivre: We do not count the config table. */165 if (!166 150 $GLOBALS['phpgw']->db->connect( 167 151 $GLOBALS['phpgw_info']['server']['db_name'], … … 171 155 $GLOBALS['phpgw_info']['server']['db_pass'], 172 156 $GLOBALS['phpgw_info']['server']['db_type'] 173 ) )174 //@$GLOBALS['phpgw']->db->query("SELECT COUNT(config_name) FROM phpgw_config");175 //if(!@$GLOBALS['phpgw']->db->next_record())176 { 177 157 ); 158 @$GLOBALS['phpgw']->db->query("SELECT COUNT(config_name) FROM phpgw_config"); 159 if(!@$GLOBALS['phpgw']->db->next_record()) 160 { 161 $setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/'); 178 162 /* BEGIN - CELEPAR - jakjr - 05/06/2006 */ 179 /* $setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/'); */180 163 /*echo '<center><b>Fatal Error:</b> It appears that you have not created the database tables for ' 181 164 .'eGroupWare. Click <a href="' . $setup_dir . '">here</a> to run setup.</center>';*/ 182 echo '<center><b>'.lang("ExpressoLivre is unavailable at this moment. Code %1<br>Please, try later.","001").'</b></center>'; 165 echo '<center><b>ExpressoLivre indisponível no momento. Códgio 001<br>' . 166 'Tente mais tarde.</b></center>'; 183 167 /* END - CELEPAR - jakjr - 05/06/2006 */ 184 168 exit; … … 188 172 /* Fill phpgw_info["server"] array */ 189 173 // An Attempt to speed things up using cache premise 190 /* jakjr: ExpressoLivre does not use cache. */191 /*192 174 $GLOBALS['phpgw']->db->query("select config_value from phpgw_config WHERE config_app='phpgwapi' and config_name='cache_phpgw_info'",__LINE__,__FILE__); 193 175 if ($GLOBALS['phpgw']->db->num_rows()) … … 195 177 $GLOBALS['phpgw']->db->next_record(); 196 178 $GLOBALS['phpgw_info']['server']['cache_phpgw_info'] = stripslashes($GLOBALS['phpgw']->db->f('config_value')); 197 }*/ 198 199 /* jakjr: ExpressoLivre does not use cache. */ 200 /* 179 } 180 201 181 $cache_query = "select content from phpgw_app_sessions where" 202 182 ." sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config'"; … … 204 184 $GLOBALS['phpgw']->db->query($cache_query,__LINE__,__FILE__); 205 185 $server_info_cache = $GLOBALS['phpgw']->db->num_rows(); 206 */ 207 /* 186 208 187 if(@$GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $server_info_cache) 209 188 { … … 212 191 } 213 192 else 214 { */215 $GLOBALS['phpgw']->db->query(" SELECT* from phpgw_config WHERE config_app='phpgwapi'",__LINE__,__FILE__);193 { 194 $GLOBALS['phpgw']->db->query("select * from phpgw_config WHERE config_app='phpgwapi'",__LINE__,__FILE__); 216 195 while ($GLOBALS['phpgw']->db->next_record()) 217 196 { … … 219 198 } 220 199 221 /*222 200 if(@isset($GLOBALS['phpgw_info']['server']['cache_phpgw_info'])) 223 201 { … … 230 208 . "'0','0','phpgwapi','config','".addslashes(serialize($GLOBALS['phpgw_info']['server']))."')"; 231 209 $GLOBALS['phpgw']->db->query($cache_query,__LINE__,__FILE__); 232 } */233 //}210 } 211 } 234 212 unset($cache_query); 235 213 unset($server_info_cache); … … 476 454 } 477 455 $GLOBALS['phpgw']->applications->read_installed_apps(); // to get translated app-titles 478 456 479 457 /*************************************************************************\ 480 458 * Load the header unless the developer turns it off *
Note: See TracChangeset
for help on using the changeset viewer.