Changeset 51 for trunk/expressoMail1_2/inc/class.imap_functions.inc.php
- Timestamp:
- 08/10/07 14:12:05 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r46 r51 39 39 function open_mbox($folder = False) 40 40 { 41 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 41 42 $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => imap_last_error()))); 42 43 return $this->mbox; … … 47 48 include("class.imap_attachment.inc.php"); 48 49 $imap_attachment = new imap_attachment(); 49 $folder =$params['folder']; 50 $folder =$params['folder']; 50 51 $msg_range_begin = $params['msg_range_begin']; 51 52 $msg_range_end = $params['msg_range_end']; 52 53 $sort_box_type = $params['sort_box_type']; 54 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 53 55 $sort_box_reverse = $params['sort_box_reverse']; 54 $ mbox_stream= $this->open_mbox($folder);56 $this->mbox = $this->open_mbox($folder); 55 57 56 58 switch($sort_box_type){ 57 59 case 'SORTFROM': 58 $sort_array_msg = $this->imap_sortfrom($ mbox_stream, $sort_box_reverse, $folder);60 $sort_array_msg = $this->imap_sortfrom($sort_box_reverse, $folder); 59 61 break; 60 62 case 'SORTSUBJECT': 61 $sort_array_msg = imap_sort($mbox_stream, SORTSUBJECT, $sort_box_reverse, SE_UID); 62 break; 63 case 'SORTARRIVAL': 64 $sort_array_msg = imap_sort($mbox_stream, SORTARRIVAL, $sort_box_reverse, SE_UID); 63 $sort_array_msg = imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 65 64 break; 66 65 case 'SORTSIZE': 67 $sort_array_msg = imap_sort($ mbox_stream, SORTSIZE, $sort_box_reverse, SE_UID);66 $sort_array_msg = imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 68 67 break; 69 case 'UNSEEN': 70 $sort_array_msg = imap_search($mbox_stream,"UNSEEN", SE_UID); // nao lidas 71 break; 72 case 'ANSWERED': 73 $sort_array_msg = imap_search($mbox_stream,"ANSWERED", SE_UID); // repondidas 74 break; 75 case 'SEEN': 76 $sort_array_msg = imap_search($mbox_stream,"SEEN", SE_UID); // lidas 77 break; 78 case 'FLAGGED': 79 $sort_array_msg = imap_search($mbox_stream,"FLAGGED", SE_UID); // importantes 80 break; 81 case 'ALL': 82 $sort_array_msg = imap_search($mbox_stream,SORTARRIVAL,$sort_box_reverse, SE_UID); // Todas 83 break; 68 default: 69 $sort_array_msg = imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 70 break; 84 71 } 85 72 … … 92 79 $msg_number = $sort_array_msg[$msg_range_begin-1]; 93 80 94 $header = @imap_headerinfo($ mbox_stream, imap_msgno($mbox_stream, $msg_number), 80, 255);81 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 95 82 if (!is_object($header)) 96 83 return false; … … 136 123 137 124 $return[$i]['attachment'] = array(); 138 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($ mbox_stream, $msg_number);125 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 139 126 $i++; 140 127 } 141 128 } 142 129 $return['num_msgs'] = $num_msgs; 130 143 131 return $return; 144 132 } … … 173 161 function get_info_msg($params) 174 162 { 175 include("class.imap_attachment.inc.php"); 176 $imap_attachment = new imap_attachment(); 177 163 $return = array(); 178 164 $msg_number = $params['msg_number']; 179 165 $msg_folder = $params['msg_folder']; 180 $mbox_stream = $this->open_mbox($msg_folder); 181 $return = array(); 182 $header = imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $msg_number), 80, 255); 183 $all_header = explode("\n", imap_fetchheader($mbox_stream, $msg_number, FT_UID)); 166 if(!$this->mbox) 167 $this->mbox = $this->open_mbox($msg_folder); 168 $header = imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 169 $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); 170 $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 171 172 $return['body'] = $return_get_body['body']; 173 $return['attachments'] = $return_get_body['attachments']; 174 $return['thumbs'] = $return_get_body['thumbs']; 175 184 176 foreach($all_header as $line) { 185 177 if (eregi("^Disposition-Notification-To", $line)) { … … 365 357 $return['Size'] = $header->Size; 366 358 $return['reply_toaddress'] = $header->reply_toaddress; 367 $return['body'] = $this->get_body_msg($msg_number, $msg_folder); 359 return $return; 360 } 361 362 function get_body_msg($msg_number, $msg_folder) 363 { 364 include_once("class.message_components.inc.php"); 365 $msg = &new message_components($this->mbox); 366 $msg->fetch_structure($msg_number); 367 $return = array(); 368 $return['attachments'] = $this-> download_attachment($msg,$msg_number); 368 369 if(!$this->has_cid) 369 $return['thumbs'] = $this->get_thumbs($msg_number, $msg_folder); 370 $return['attachments'] = $imap_attachment->download_attachment($mbox_stream, $msg_number); 371 imap_close($mbox_stream); 372 return $return; 373 } 374 375 function get_body_msg($msg_number, $msg_folder) 376 { 377 include_once("class.message_components.inc.php"); 378 $mbox_stream = $this -> open_mbox($msg_folder); 379 380 $msg =& new message_components($mbox_stream); 381 $msg->fetch_structure($msg_number); 382 370 $return['thumbs'] = $this->get_thumbs($msg,$msg_number,$msg_folder); 371 383 372 if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 384 373 { … … 388 377 if (strtolower($msg->structure[$msg_number]->subtype) == "plain") 389 378 { 390 $content .= nl2br($this->decodeBody((imap_body($ mbox_stream, $msg_number, FT_UID)), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]));379 $content .= nl2br($this->decodeBody((imap_body($this->mbox, $msg_number, FT_UID)), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0])); 391 380 } 392 381 else if (strtolower($msg->structure[$msg_number]->subtype) == "html") 393 382 { 394 $content .= $this->decodeBody(imap_body($ mbox_stream, $msg_number, FT_UID), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]);383 $content .= $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); 395 384 } 396 385 } … … 428 417 // if TXT file size > 100kb, then it will not expand. 429 418 if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { 430 $content .= nl2br(htmlentities($this->decodeBody(imap_fetchbody($ mbox_stream, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])));419 $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]))); 431 420 } 432 421 } … … 434 423 else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 307200) 435 424 { 436 $content .= $this->decodeBody(imap_fetchbody($ mbox_stream, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]);425 $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); 437 426 $show_only_html = true; 438 427 } … … 440 429 else if($file_type == "message/delivery-status"){ 441 430 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 442 $content .= nl2br($this->decodeBody(imap_fetchbody($ mbox_stream, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));431 $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); 443 432 444 433 } … … 447 436 include_once("class.imap_attachment.inc.php"); 448 437 $att = new imap_attachment(); 449 $attachments = $att -> get_attachment_info($ mbox_stream,$msg_number);438 $attachments = $att -> get_attachment_info($this->mbox,$msg_number); 450 439 if($attachments['number_attachments'] > 0) { 451 440 foreach($attachments ['attachment'] as $index => $attachment){ … … 454 443 strtolower($attachment['type']) == "plain" 455 444 ){ 456 $obj = imap_rfc822_parse_headers(imap_fetchbody($ mbox_stream, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]);445 $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); 457 446 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 458 447 $content .= "<br><table style='margin:2px;border:1px solid black;background:#EAEAEA'>"; … … 463 452 $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>"; 464 453 $ix_part = strtolower($attachment['type']) == "delivery-status" ? 1 : 0; 465 $content .= nl2br($this->decodeBody(imap_fetchbody($ mbox_stream, $msg_number, ($attachment['part_in_msg']+$ix_part).".1", FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]));454 $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])); 466 455 break; 467 456 } … … 472 461 if($file_type == "text/plain" && ($show_only_html && $msg_part == 1) || (!$show_only_html && $msg_part == 3)){ 473 462 if(strtolower($msg->structure[$msg_number]->subtype) == "mixed" && $msg_part == 1) 474 $content .= nl2br(imap_base64(imap_fetchbody($ mbox_stream, $msg_number, $msg_part, FT_UID)));463 $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); 475 464 else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") 476 $content .= nl2br(imap_fetchbody($ mbox_stream, $msg_number, $msg_part, FT_UID));465 $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); 477 466 } 478 467 } … … 480 469 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 481 470 $this->set_messages_flag($params); 482 imap_close($mbox_stream); 483 $content = $this->process_embedded_images($msg_number, $msg_folder, $content); 484 //$content = $this->htmlfilter($content); 471 $content = $this->process_embedded_images($msg,$msg_number,$content); 485 472 $content = $this->replace_special_characters($content); 486 return $content; 473 $return['body'] = $content; 474 return $return; 487 475 } 488 476 … … 645 633 } 646 634 647 function process_embedded_images($msgno, $msg_folder, $body) 648 { 649 include_once("class.message_components.inc.php"); 650 651 $mbox_stream = $this->open_mbox($msg_folder); 652 653 $msg =& new message_components($mbox_stream); 654 $msg->fetch_structure($msgno); 635 function process_embedded_images($msg, $msgno,$body) 636 { 655 637 656 638 if (count($msg->inline_id[$msgno]) > 0) … … 723 705 } 724 706 725 function get_thumbs($msg_number, $msg_folder) 726 { 727 include_once ("class.message_components.inc.php"); 728 729 $mbox_stream = $this->open_mbox($msg_folder); 730 731 $msg =& new message_components($mbox_stream); 732 $msg->fetch_structure($msg_number); 707 function get_thumbs($msg, $msg_number, $msg_folder) 708 { 733 709 $thumbs_array = array(); 734 710 $i = 0; … … 765 741 function delete_msgs($params) 766 742 { 743 767 744 $folder = $params['folder']; 745 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 768 746 $msgs_number = explode(",",$params['msgs_number']); 769 747 $border_ID = $params['border_ID']; … … 786 764 $return['border_ID'] = $border_ID; 787 765 788 imap_close($mbox_stream, CL_EXPUNGE); 766 if($mbox_stream) 767 imap_close($mbox_stream, CL_EXPUNGE); 789 768 return $return; 790 769 } … … 801 780 $msgs_existent = $params['msgs_existent']; 802 781 $sort_box_type = $params['sort_box_type']; 782 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 803 783 $sort_box_reverse = $params['sort_box_reverse']; 804 784 $msgs_in_the_server = array(); 805 785 $sort_array_msg = array(); 806 807 $mbox_stream = $this->open_mbox($folder); 808 $num_msgs = (imap_num_msg($mbox_stream) - imap_num_recent($mbox_stream)); 809 810 $msgs_in_the_client = explode(",", $msgs_existent); 786 $this->mbox = $this->open_mbox($folder); 811 787 812 788 switch($sort_box_type){ 813 789 case 'SORTFROM': 814 $sort_array_msg = $this->imap_sortfrom($ mbox_stream, $sort_box_reverse, $folder);790 $sort_array_msg = $this->imap_sortfrom($sort_box_reverse, $folder); 815 791 break; 816 792 case 'SORTSUBJECT': 817 $sort_array_msg = imap_sort($mbox_stream, SORTSUBJECT, $sort_box_reverse, SE_UID); 818 break; 819 case 'SORTARRIVAL': 820 $sort_array_msg = imap_sort($mbox_stream, SORTARRIVAL, $sort_box_reverse, SE_UID); 793 $sort_array_msg = imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 821 794 break; 822 795 case 'SORTSIZE': 823 $sort_array_msg = imap_sort($ mbox_stream, SORTSIZE, $sort_box_reverse, SE_UID);796 $sort_array_msg = imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 824 797 break; 825 case 'ANSWERED': 826 $sort_array_msg = imap_search($mbox_stream,"ANSWERED", SE_UID); // repondidas 827 break; 828 case 'SEEN': 829 $sort_array_msg = imap_search($mbox_stream,"SEEN", SE_UID); // lidas 830 break; 831 case 'FLAGGED': 832 $sort_array_msg = imap_search($mbox_stream,"FLAGGED", SE_UID); // importantes 833 break; 834 case 'ALL': 835 $sort_array_msg = imap_search($mbox_stream,SORTARRIVAL,$sort_box_reverse, SE_UID); // Todas 836 break; 837 } 798 default: 799 $sort_array_msg = imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 800 break; 801 } 802 803 if(!count($sort_array_msg)) 804 return array(); 805 806 $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); 807 $msgs_in_the_client = explode(",", $msgs_existent); 808 838 809 839 810 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) … … 892 863 foreach($msgs_to_exec as $msg_number => $command) 893 864 { 894 $header = @imap_headerinfo($ mbox_stream, imap_msgno($mbox_stream, $msg_number), 80, 255);865 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox , $msg_number), 80, 255); 895 866 if (!is_object($header)) 896 867 return false; … … 939 910 940 911 $return[$i]['attachment'] = array(); 941 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($ mbox_stream, $msg_number);912 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 942 913 $i++; 943 914 } 944 $return['new_msgs'] = imap_num_recent($mbox_stream); 945 imap_close($mbox_stream); 915 $return['new_msgs'] = imap_num_recent($this->mbox); 916 if($this->mbox) 917 imap_close($this->mbox); 946 918 return $return; 947 919 } … … 996 968 } 997 969 998 imap_close($mbox_stream); 999 return $result2; 970 return array_merge($result2, $this->get_quota()); 1000 971 } 1001 972 … … 1005 976 $mbox_stream = $this->open_mbox(); 1006 977 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 1007 //$new_folder = imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}INBOX.$namebox"));978 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); 1008 979 1009 980 $result = "Ok"; 1010 if(!imap_createmailbox($mbox_stream, imap_utf7_encode("{".$imap_server."}$namebox")))981 if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) 1011 982 { 1012 983 $result = implode("<br />\n", imap_errors()); 1013 984 } 1014 1015 imap_close($mbox_stream); 1016 985 986 if($mbox_stream) 987 imap_close($mbox_stream); 988 1017 989 return $result; 1018 990 … … 1029 1001 if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ 1030 1002 $result = implode("<br />\n", imap_errors()); 1031 imap_close($mbox_stream); 1003 if($mbox_stream) 1004 imap_close($mbox_stream); 1032 1005 return $result; 1033 1006 } 1034 1007 } 1035 1008 } 1036 imap_close($mbox_stream); 1009 if($mbox_stream) 1010 imap_close($mbox_stream); 1037 1011 return true; 1038 1012 } … … 1051 1025 $result = implode("<br />\n", imap_errors()); 1052 1026 } 1053 1054 imap_close($mbox_stream);1027 if($mbox_stream) 1028 imap_close($mbox_stream); 1055 1029 return $result; 1056 1030 } … … 1066 1040 $result = "Ok"; 1067 1041 $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); 1042 $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); 1043 1068 1044 if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) 1069 1045 { 1070 $result = im plode("<br />\n". imap_errors());1071 } 1072 1073 imap_close($mbox_stream);1046 $result = imap_errors(); 1047 } 1048 if($mbox_stream) 1049 imap_close($mbox_stream); 1074 1050 return $result; 1075 1051 … … 1085 1061 } 1086 1062 $num_msgs = imap_num_msg($this->mbox); 1087 imap_close($this->mbox); 1063 if($this->mbox) 1064 imap_close($this->mbox); 1088 1065 1089 1066 return $num_msgs; … … 1106 1083 $attachments = $params['FILES']; 1107 1084 $forwarding_attachments = $params['forwarding_attachments']; 1108 $folder = $params['folder']; 1085 $folder =$params['folder']; 1086 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 1109 1087 $folder_name = $params['folder_name']; 1110 1088 // Fix problem with cyrus delimiter changes. … … 1113 1091 $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 1114 1092 // End Fix. 1115 if ($folder != 'null'){ 1093 if ($folder != 'null'){ 1116 1094 $mail->SaveMessageInFolder = $folder; 1117 1095 } … … 1287 1265 } 1288 1266 1289 function get_preferences() 1290 { 1291 //print_r($_SESSION['phpgw_info']['expressomail']['user']['preferences']['expressoMail']); 1292 return $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; 1293 } 1294 1295 function imap_sortfrom($mbox_stream, $sort_box_reverse, $folder) 1267 function imap_sortfrom($sort_box_reverse, $folder) 1296 1268 { 1297 1269 $sortfrom = array(); 1298 1270 $sortfrom_uid = array(); 1299 1271 1300 $num_msgs = imap_num_msg($ mbox_stream);1272 $num_msgs = imap_num_msg($this->mbox); 1301 1273 for ($i=1; $i<=$num_msgs; $i++) 1302 1274 { 1303 $header = imap_headerinfo($ mbox_stream, $i, 80, 255);1275 $header = imap_headerinfo($this->mbox, $i, 80, 255); 1304 1276 if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 1305 1277 $from = $header->to; … … 1317 1289 foreach($sortfrom as $index => $header_msg) 1318 1290 { 1319 $sortfrom_uid[] = imap_uid($ mbox_stream, $index+1);1291 $sortfrom_uid[] = imap_uid($this->mbox, $index+1); 1320 1292 } 1321 1293 … … 1325 1297 return $sortfrom_uid; 1326 1298 } 1327 1299 1328 1300 function move_messages($params) 1329 1301 { 1330 1302 $folder = $params['folder']; 1331 1303 $mbox_stream = $this->open_mbox($folder); 1332 $newmailbox = $params['new_folder']; 1304 $newmailbox = ($params['new_folder']); 1305 $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); 1333 1306 $new_folder_name = $params['new_folder_name']; 1334 1307 $msgs_number = $params['msgs_number']; … … 1338 1311 'border_ID' => $params['border_ID']); 1339 1312 1340 // Caso estejamos no box principal, não é necessário pegar a sinformação da mensagem anterior.1341 if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') )1313 // Caso estejamos no box principal, não é necessário pegar a informação da mensagem anterior. 1314 if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) 1342 1315 $return['previous_msg'] = $this->get_info_previous_msg($params); 1343 1316 1344 1317 $mbox_stream = $this->open_mbox($folder); 1345 1318 if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 1346 1319 imap_expunge($mbox_stream); 1347 imap_close($mbox_stream); 1320 if($mbox_stream) 1321 imap_close($mbox_stream); 1348 1322 return $return; 1349 1323 }else { … … 1358 1332 $quota = imap_get_quotaroot($mbox_stream, "INBOX"); 1359 1333 if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { 1360 imap_close($mbox_stream); 1361 imap_close($mbox); 1334 if($mbox_stream) 1335 imap_close($mbox_stream); 1336 if($mbox) 1337 imap_close($mbox); 1362 1338 return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; 1363 1339 } 1364 1340 if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { 1365 1341 imap_expunge($mbox_stream); 1366 imap_close($mbox_stream); 1342 if($mbox_stream) 1343 imap_close($mbox_stream); 1367 1344 // return to original quota limit. 1368 1345 if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { 1369 imap_close($mbox); 1346 if($mbox) 1347 imap_close($mbox); 1370 1348 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1371 1349 } … … 1373 1351 } 1374 1352 else { 1375 imap_close($mbox_stream); 1353 if($mbox_stream) 1354 imap_close($mbox_stream); 1376 1355 if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { 1377 imap_close($mbox); 1356 if($mbox) 1357 imap_close($mbox); 1378 1358 return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; 1379 1359 } … … 1383 1363 } 1384 1364 else { 1385 imap_close($mbox_stream); 1386 return imap_last_error(); 1365 if($mbox_stream) 1366 imap_close($mbox_stream); 1367 return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; 1387 1368 } 1388 1369 } … … 1392 1373 { 1393 1374 $folder_id = $params['folder_id']; 1375 $folder_id = mb_convert_encoding($folder_id, "UTF7-IMAP", "UTF-8"); 1394 1376 $folder_name = $params['folder_name']; 1377 $folder_name = mb_convert_encoding($folder_name, "ISO-8859-1", "UTF-8"); 1395 1378 $border_id = $params['border_id']; 1396 1379 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; … … 1404 1387 $body = str_replace("%nbsp;"," ",$params['body']); 1405 1388 $body = preg_replace("/\n/","",$body); 1389 $body = preg_replace("/\r/","",$body); 1406 1390 1407 1391 $header = "From: " . $from . "\r\n" … … 1420 1404 $return['border_id'] = $border_id; 1421 1405 1422 imap_close($mbox_stream); 1406 if($mbox_stream) 1407 imap_close($mbox_stream); 1423 1408 1424 1409 if (!$return['append']) … … 1438 1423 $return["flag"] = $flag; 1439 1424 1440 $mbox_stream = $this->open_mbox($folder); 1425 if(!$this->mbox) 1426 $this->mbox = $this->open_mbox($folder); 1441 1427 1442 1428 if ($flag == "unseen") 1443 $return["status"] = imap_clearflag_full($ mbox_stream, $msgs_to_set, "\\Seen", ST_UID);1429 $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); 1444 1430 elseif ($flag == "seen") 1445 $return["status"] = imap_setflag_full($ mbox_stream, $msgs_to_set, "\\Seen", ST_UID);1431 $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); 1446 1432 elseif ($flag == "answered"){ 1447 $return["status"] = imap_setflag_full($ mbox_stream, $msgs_to_set, "\\Answered", ST_UID);1448 imap_clearflag_full($ mbox_stream, $msgs_to_set, "\\Draft", ST_UID);1433 $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); 1434 imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); 1449 1435 } 1450 1436 elseif ($flag == "forwarded") 1451 $return["status"] = imap_setflag_full($ mbox_stream, $msgs_to_set, "\\Answered \\Draft", ST_UID);1437 $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); 1452 1438 elseif ($flag == "flagged") 1453 $return["status"] = imap_setflag_full($ mbox_stream, $msgs_to_set, "\\Flagged", ST_UID);1439 $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); 1454 1440 elseif ($flag == "unflagged") 1455 $return["status"] = imap_clearflag_full($mbox_stream, $msgs_to_set, "\\Flagged", ST_UID); 1456 1457 imap_close($mbox_stream); 1441 $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); 1442 1443 if($this->mbox) 1444 imap_close($this->mbox); 1458 1445 return $return; 1459 1446 } … … 1569 1556 $reuse_border = $params['reuse_border']; 1570 1557 1571 $mbox_stream = $this->open_mbox($folder); 1558 if(!$this->mbox) 1559 $this->mbox = $this->open_mbox($folder); 1572 1560 1573 1561 switch($sort_box_type){ 1574 1562 case 'SORTFROM': 1575 $sort_array_msg = $this->imap_sortfrom($ mbox_stream, $sort_box_reverse, $folder);1563 $sort_array_msg = $this->imap_sortfrom($this->mbox , $sort_box_reverse, $folder); 1576 1564 break; 1577 1565 case 'SORTSUBJECT': 1578 $sort_array_msg = imap_sort($ mbox_stream, SORTSUBJECT, $sort_box_reverse, SE_UID);1566 $sort_array_msg = imap_sort($this->mbox , SORTSUBJECT, $sort_box_reverse, SE_UID); 1579 1567 break; 1580 1568 case 'SORTARRIVAL': 1581 $sort_array_msg = imap_sort($ mbox_stream, SORTARRIVAL, $sort_box_reverse, SE_UID);1569 $sort_array_msg = imap_sort($this->mbox , SORTARRIVAL, $sort_box_reverse, SE_UID); 1582 1570 break; 1583 1571 case 'SORTSIZE': 1584 $sort_array_msg = imap_sort($ mbox_stream, SORTSIZE, $sort_box_reverse, SE_UID);1572 $sort_array_msg = imap_sort($this->mbox , SORTSIZE, $sort_box_reverse, SE_UID); 1585 1573 break; 1586 1574 } … … 1603 1591 $params['msg_folder'] = $folder; 1604 1592 1605 $return = $this->get_info_msg($params); 1593 $return = $this->get_info_msg($params); 1606 1594 $return["reuse_border"] = $reuse_border; 1607 1595 return $return; … … 1610 1598 function get_info_previous_msg($params) 1611 1599 { 1612 //$msg_number = $params['msg_number'];1613 1600 $msg_number = $params['msgs_number']; 1614 //$folder = $params['msg_folder'];1615 1601 $folder = $params['folder']; 1616 1602 $sort_box_type = $params['sort_box_type']; … … 1618 1604 $reuse_border = $params['reuse_border']; 1619 1605 1620 $mbox_stream = $this->open_mbox($folder); 1606 if(!$this->mbox) 1607 $this->mbox = $this->open_mbox($folder); 1621 1608 1622 1609 switch($sort_box_type){ 1623 1610 case 'SORTFROM': 1624 $sort_array_msg = $this->imap_sortfrom($ mbox_stream, $sort_box_reverse, $folder);1611 $sort_array_msg = $this->imap_sortfrom($this->mbox, $sort_box_reverse, $folder); 1625 1612 break; 1626 1613 case 'SORTSUBJECT': 1627 $sort_array_msg = imap_sort($ mbox_stream, SORTSUBJECT, $sort_box_reverse, SE_UID);1614 $sort_array_msg = imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID); 1628 1615 break; 1629 1616 case 'SORTARRIVAL': 1630 $sort_array_msg = imap_sort($ mbox_stream, SORTARRIVAL, $sort_box_reverse, SE_UID);1617 $sort_array_msg = imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID); 1631 1618 break; 1632 1619 case 'SORTSIZE': 1633 $sort_array_msg = imap_sort($ mbox_stream, SORTSIZE, $sort_box_reverse, SE_UID);1620 $sort_array_msg = imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID); 1634 1621 break; 1635 1622 } … … 1654 1641 $return = $this->get_info_msg($params); 1655 1642 $return["reuse_border"] = $reuse_border; 1656 imap_close($mbox_stream);1657 1643 return $return; 1658 1644 } … … 1664 1650 1665 1651 $mbox_stream = $this->open_mbox($params['folder']); 1666 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 1667 imap_close($mbox_stream); 1668 //$return_array['num_msgs'] = $this->get_num_msgs($params['folder']); 1652 $return_array['num_msgs'] = imap_num_msg($mbox_stream); 1653 if($mbox_stream) 1654 imap_close($mbox_stream); 1655 1669 1656 return $return_array; 1670 1657 } … … 1672 1659 function get_quota(){ 1673 1660 1674 $mbox_stream = $this->open_mbox(); 1675 1676 $quota = imap_get_quotaroot($mbox_stream, "INBOX"); 1661 if(!$this->mbox) 1662 $this->mbox = $this->open_mbox(); 1663 1664 $quota = imap_get_quotaroot($this->mbox, "INBOX"); 1665 if($this->mbox) 1666 imap_close($this->mbox); 1667 1677 1668 if (!$quota){ 1678 1669 return array( … … 1731 1722 function empty_trash() 1732 1723 { 1733 $folder = 'INBOX' . $this->imap_delimiter . ' Trash';1724 $folder = 'INBOX' . $this->imap_delimiter . 'Lixeira'; 1734 1725 $mbox_stream = $this->open_mbox($folder); 1735 1726 $return = imap_delete($mbox_stream,'1:*'); 1736 imap_close($mbox_stream, CL_EXPUNGE); 1727 if($mbox_stream) 1728 imap_close($mbox_stream, CL_EXPUNGE); 1737 1729 return $return; 1738 1730 } … … 1813 1805 } 1814 1806 $j++; 1815 imap_close($mbox_stream); 1807 if($mbox_stream) 1808 imap_close($mbox_stream); 1816 1809 } 1817 1810 … … 1832 1825 return $return; 1833 1826 } 1834 1835 /* 1836 function movetotrash_and_show_previous_message($params) 1837 { 1838 $return = $this->get_info_previous_msg($params); 1839 1840 $params_tmp1 = array(); 1841 $params_tmp1['msgs_number'] = $params['msg_number']; 1842 $params_tmp1['folder'] = $params['msg_folder']; 1843 $params_tmp1['new_folder'] = 'INBOX'.$this->imap_delimiter.'Trash'; 1844 1845 $return_tmp1 = $this->move_messages($params_tmp1); 1846 1847 $return['msg_number_deleted'] = $return_tmp1; 1848 1849 return $return; 1850 } 1851 */ 1827 1852 1828 1853 1829 function automatic_trash_cleanness($params) … … 1855 1831 $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); 1856 1832 $criteria = 'BEFORE "'.$before_date.'"'; 1857 $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter." Trash");1833 $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter."Lixeira"); 1858 1834 $messages = imap_search($mbox_stream, $criteria, SE_UID); 1859 1835 if (is_array($messages)){ … … 1862 1838 } 1863 1839 } 1864 1865 imap_close($mbox_stream, CL_EXPUNGE);1840 if($mbox_stream) 1841 imap_close($mbox_stream, CL_EXPUNGE); 1866 1842 return $messages; 1867 1843 } … … 1908 1884 } 1909 1885 } 1910 imap_close($mbox_stream); 1886 if($mbox_stream) 1887 imap_close($mbox_stream); 1911 1888 } 1912 1889 } … … 2095 2072 return true; 2096 2073 } 2074 2075 function download_attachment($msg,$msgno) 2076 { 2077 $array_parts_attachments = array(); 2078 $array_parts_attachments['names'] = ''; 2079 include("class.imap_attachment.inc.php"); 2080 $imap_attachment = new imap_attachment(); 2081 2082 if (count($msg->fname[$msgno]) > 0) 2083 { 2084 $i = 0; 2085 foreach ($msg->fname[$msgno] as $index=>$fname) 2086 { 2087 $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; 2088 $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($fname); 2089 $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; 2090 $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; 2091 $array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; 2092 $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; 2093 $i++; 2094 } 2095 } 2096 $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); 2097 return $array_parts_attachments; 2098 } 2097 2099 } 2098 2100 ?>
Note: See TracChangeset
for help on using the changeset viewer.