Changeset 828
- Timestamp:
- 05/11/09 11:34:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r708 r828 45 45 function open_mbox($folder = False) 46 46 { 47 if (is_resource($this->mbox)) 48 return $this->mbox; 47 49 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 48 50 $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); … … 77 79 $sort_box_reverse = $params['sort_box_reverse']; 78 80 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 79 $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse );81 $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 80 82 81 83 $return = array(); 82 84 $i = 0; 83 $num_msgs = (is_array($sort_array_msg) ? count($sort_array_msg) : 0); 84 if($num_msgs) { 85 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++) 86 { 87 $msg_number = $sort_array_msg[$msg_range_begin-1]; 85 $num_msgs = imap_num_msg($this->mbox); 86 if(is_array($sort_array_msg)){ 87 foreach($sort_array_msg as $msg_number => $value) 88 { 88 89 $temp = $this->get_info_head_msg($msg_number); 89 90 if(!$temp) 90 91 return false; 91 92 92 93 $return[$i] = $temp; 93 94 $i++; 94 95 } 95 96 } 96 $return['num_msgs'] = $num_msgs; 97 97 $return['num_msgs'] = $num_msgs; 98 98 99 return $return; 99 100 } 100 101 101 102 function get_info_head_msg($msg_number) { 102 103 $head_array = array(); 103 104 include_once("class.imap_attachment.inc.php"); 104 105 $imap_attachment = new imap_attachment(); 105 106 /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns 107 * atributos do cabeçalho. Como eu preciso do atributo Importance 108 * para saber se o email é importante ou não, uso abaixo a função 109 * imap_fetchheader e busco o atributo importance nela para passar 110 * para as funções ajax. Isso faz com que eu acesse o cabeçalho 111 * duas vezes e de duas formas diferentes, mas em contrapartida, eu 112 * não preciso reimplementar o método utilizando o fetchheader. 113 * Como as mensagens são renderizadas de X em X, não parece ter 114 * perda considerável de performance. 115 */ 106 107 /*Como eu preciso do atributo Importance para saber se o email é 108 * importante ou não, uso abaixo a função imap_fetchheader e busco 109 * o atributo importance nela. Isso faz com que eu acesse o cabeçalho 110 * duas vezes e de duas formas diferentes, mas em contrapartida, eu 111 * não preciso reimplementar o método utilizando o fetchheader. 112 * Como as mensagens são renderizadas em um número pequeno por vez, 113 * não parece ter perda considerável de performance. 114 */ 116 115 $flag = preg_match('/importance *: *(.*)\r/i', 117 imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number))118 ,$importance);116 imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)), 117 $importance); 119 118 $head_array['Importance'] = $flag==0?"Normal":$importance[1]; 120 119 121 120 122 121 $header = $this->get_header($msg_number); 123 124 122 if (!is_object($header)) 123 return false; 125 124 $head_array['Recent'] = $header->Recent; 126 125 $head_array['Unseen'] = $header->Unseen; … … 130 129 else { 131 130 $head_array['Answered'] = $header->Answered; 132 $head_array['Draft'] = $header->Draft; 131 $head_array['Draft'] = $header->Draft; 133 132 } 134 133 $head_array['Deleted'] = $header->Deleted; 135 134 $head_array['Flagged'] = $header->Flagged; 136 135 137 136 $head_array['msg_number'] = $msg_number; 138 //$ return[$i]['msg_folder'] = $folder;139 137 //$head_array['msg_folder'] = $folder; 138 140 139 $date_msg = gmdate("d/m/Y",$header->udate); 141 if ( date("d/m/Y") == $date_msg)140 if (gmdate("d/m/Y") == $date_msg) 142 141 $head_array['udate'] = gmdate("H:i",$header->udate); 143 142 else 144 143 $head_array['udate'] = $date_msg; 145 144 146 145 $head_array['aux_date'] = $date_msg; //Auxiliar apenas para mensagens locais. 147 146 148 147 $from = $header->from; 149 148 $head_array['from'] = array(); … … 161 160 $head_array['to']['name'] = $head_array['to']['email']; 162 161 $head_array['subject'] = $this->decode_string($header->fetchsubject); 163 162 164 163 $head_array['Size'] = $header->Size; 165 164 166 165 $head_array['attachment'] = array(); 167 166 $head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 168 167 169 168 return $head_array; 170 169 } 171 170 172 171 function decode_string($string) 173 172 { … … 337 336 imap_close($this->mbox); 338 337 $this->mbox=false; 339 340 341 338 array_push($return,serialize($msg_info)); 342 343 } 344 339 } 345 340 return $return; 346 341 } … … 361 356 } 362 357 363 $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); 358 $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); 359 364 360 $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 365 361 366 362 //Substituição de links em email para abrir no próprio expresso 367 363 $body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); 368 364 369 365 $return['body'] = $body; 370 366 $return['attachments'] = $return_get_body['attachments']; 371 367 $return['thumbs'] = $return_get_body['thumbs']; 372 368 $return['signature'] = $return_get_body['signature']; 373 374 foreach($all_header as $line) { 375 if (eregi("^Disposition-Notification-To", $line)) { 376 eregi("^([^:]*): (.*)", $line, &$arg); 377 $return['DispositionNotificationTo'] = $arg[2]; 378 } 379 } 369 370 $pattern = '/^[ \t]*Disposition-Notification-To(^:)*:(.+)*@(.+)*$/isUm'; 371 if (preg_match($pattern, $header_, $fields)) 372 { 373 preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches); 374 $return['DispositionNotificationTo'] = "<".$matches[0].">"; 375 } 376 380 377 $return['Recent'] = $header->Recent; 381 378 $return['Unseen'] = $header->Unseen; … … 598 595 $return['subject'] = $this->decode_string($header->fetchsubject); 599 596 $return['Size'] = $header->Size; 600 $return['reply_toaddress'] = $header->reply_toaddress; 601 597 $return['reply_toaddress'] = $header->reply_toaddress; 598 602 599 //All this is to help in local messages 603 600 $return['timestamp'] = $header->udate; 604 601 $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; 605 602 $return['reply_toaddress'] = $header->reply_toaddress; 606 603 607 604 return $return; 608 605 } … … 858 855 // HTML Filter 859 856 //$body = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=# onclick=\"javascript:new_message('new_by_message', '\\2@\\3')\">\\2@\\3</a>", $body); 860 $body = str_replace("\r\n", "\n", $body);857 //$body = str_replace("\r\n", "\n", $body); 861 858 if ($encoding == 'quoted-printable') 862 { 859 { 860 /* 863 861 864 862 for($i=0;$i<256;$i++) { … … 869 867 $myqprintb[]=chr($i); 870 868 } 869 */ 871 870 $body = str_replace($myqprinta,$myqprintb,($body)); 872 871 $body = quoted_printable_decode($body); … … 880 879 $body = base64_decode($body); 881 880 } 882 /*else if ($encoding == '7bit')881 else if ($encoding == '7bit') 883 882 { 884 883 $body = quoted_printable_decode($body); 885 } */884 } 886 885 // All other encodings are returned raw. 887 886 if (strtolower($charset) == "utf-8") … … 1082 1081 $msgs_in_the_server = array(); 1083 1082 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 1084 $ sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);1085 1086 if(!count($ sort_array_msg))1083 $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 1084 $msgs_in_the_server = array_keys($msgs_in_the_server); 1085 if(!count($msgs_in_the_server)) 1087 1086 return array(); 1088 1087 1089 $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); 1090 $msgs_in_the_client = explode(",", $msgs_existent); 1091 1092 1093 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) 1094 { 1095 $msgs_in_the_server[] = $sort_array_msg[$msg_range_begin-1]; 1096 } 1097 if ((count($msgs_in_the_server) < 1) && ($msg_range_begin != 0)) 1098 { 1099 $range = $msg_range_end - $msg_range_begin; 1100 $msg_range_begin = $msg_range_begin - $range; 1101 $msg_range_end = $msg_range_end - $range; 1102 for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) 1103 { 1104 $msgs_in_the_server[] = $sort_array_msg[$msg_range_begin-1]; 1105 } 1106 } 1107 1088 $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); 1089 $msgs_in_the_client = explode(",", $msgs_existent); 1090 1108 1091 $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); 1109 1092 $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); … … 1150 1133 */ 1151 1134 $flag = preg_match('/importance *: *(.*)\r/i', 1152 imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number))1135 @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 1153 1136 ,$importance); 1154 1137 $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; … … 1156 1139 $header = $this->get_header($msg_number); 1157 1140 if (!is_object($header)) 1158 return false;1159 1141 continue; 1142 1160 1143 $return[$i]['msg_number'] = $msg_number; 1161 1144 $return[$i]['command'] = $command; … … 1208 1191 if($this->mbox && is_resource($this->mbox)) 1209 1192 imap_close($this->mbox); 1193 1210 1194 return $return; 1211 1195 } … … 1392 1376 return "The server denied your request to send a mail, you cannot use this mail address."; 1393 1377 } 1394 1378 1395 1379 //new_message_to backs to mailto: pattern 1396 1380 $params['body'] = eregi_replace("<a href=\"javascript:new_message_to\('([^>]+)'\)\">[^>]+</a>","<a href='mailto:\\1'>\\1</a>",$params['body']); 1397 1381 1398 1382 $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); 1399 1383 $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); … … 1502 1486 if( $total_uploaded_size > $upload_max_filesize) 1503 1487 return $this->parse_error("message file too big"); 1504 } 1488 } 1505 1489 else if(($params['is_local_forward']=="1") && (count($local_attachments))) { //Caso seja forward de mensagens locais 1506 1490 1507 1491 $total_uploaded_size = 0; 1508 1492 $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024; … … 1517 1501 } 1518 1502 if( $total_uploaded_size > $upload_max_filesize) 1519 return 'false'; 1503 return 'false'; 1520 1504 } 1521 1505 //////////////////////////////////////////////////////////////////////////////////////////////////// … … 1628 1612 function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) 1629 1613 { 1630 $mbox_stream = $this->open_mbox( $msg_folder);1614 $mbox_stream = $this->open_mbox(utf8_decode(urldecode($msg_folder))); 1631 1615 $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); 1632 1616 if($encoding == 'base64') … … 1654 1638 } 1655 1639 1656 function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type )1640 function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd) 1657 1641 { 1658 1642 $sort = array(); 1659 $sort_uid = array(); 1660 1643 if ($offsetBegin > $offsetEnd) {$temp=$offsetEnd; $offsetEnd=$offsetBegin; $offsetBegin=$temp;} 1661 1644 $num_msgs = imap_num_msg($this->mbox); 1662 for ($i=1; $i<=$num_msgs; $i++) 1663 { 1664 $header = $this->get_header(imap_uid($this->mbox,$i)); 1645 if ($offsetEnd > $num_msgs) {$offsetEnd = $num_msgs;} 1646 if ($search_box_type == "" && $sort_box_type == "SORTARRIVAL") 1647 { 1648 // If I'm looking for any type of email doesn't need to see all imap box 1649 if ($sort_box_reverse) 1650 { 1651 $numBegin = $num_msgs - $offsetEnd; 1652 if ($numBegin < 0) $numBegin=0; 1653 $numEnd = $num_msgs - ($offsetBegin-1); 1654 } 1655 else 1656 { 1657 $numBegin = ($offsetBegin-1); 1658 $numEnd = $offsetEnd; 1659 } 1660 $slice_array = false; 1661 } 1662 else 1663 { 1664 // If I'm looking for a specific type of email I have to see entire imap box 1665 $numBegin = 0; 1666 $numEnd = $num_msgs; 1667 $slice_array = true; 1668 } 1669 for ($i=$numBegin+1; $i<=$numEnd; $i++) 1670 { 1671 $iuid = @imap_uid($this->mbox,$i); 1672 $header = $this->get_header($iuid); 1665 1673 // List UNSEEN messages. 1666 1674 if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ … … 1689 1697 1690 1698 if ($tmp[0]->text != "") 1691 $sort[$i ] = $tmp[0]->text;1699 $sort[$iuid] = $tmp[0]->text; 1692 1700 else 1693 $sort[$i ] = $from[0]->mailbox . "@" . $from[0]->host;1701 $sort[$iuid] = $from[0]->mailbox . "@" . $from[0]->host; 1694 1702 } 1695 1703 else if($sort_box_type=='SORTSUBJECT') { 1696 $sort[$i ] = $header->subject;1704 $sort[$iuid] = $header->subject; 1697 1705 } 1698 1706 else if($sort_box_type=='SORTSIZE') { 1699 $sort[$i ] = $header->Size;1707 $sort[$iuid] = $header->Size; 1700 1708 } 1701 1709 else { 1702 $sort[$i] = $header->udate; 1703 } 1704 1705 } 1706 1710 $sort[$iuid] = $header->udate; 1711 } 1712 1713 } 1707 1714 natcasesort($sort); 1708 1709 foreach($sort as $index => $header_msg) 1710 { 1711 $sort_uid[] = imap_uid($this->mbox, $index); 1712 } 1713 1715 1714 1716 if ($sort_box_reverse) 1715 $sort_uid = array_reverse($sort_uid); 1716 1717 return $sort_uid; 1718 1719 } 1720 1721 /** 1722 * Deprecated 1723 * 1724 * Replaced for the method messages_sort 1725 */ 1726 function imap_sortfrom($sort_box_reverse, $search_box_type) 1727 { 1728 $sortfrom = array(); 1729 $sortfrom_uid = array(); 1730 1731 $num_msgs = imap_num_msg($this->mbox); 1732 for ($i=1; $i<=$num_msgs; $i++) 1733 { 1734 $header = $this->get_header(imap_uid($this->mbox,$i)); 1735 // List UNSEEN messages. 1736 if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ 1737 continue; 1738 } 1739 // List SEEN messages. 1740 elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ 1741 continue; 1742 } 1743 // List ANSWERED messages. 1744 elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ 1745 continue; 1746 } 1747 // List FLAGGED messages. 1748 elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ 1749 continue; 1750 } 1751 1752 if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) 1753 $from = $header->to; 1754 else 1755 $from = $header->from; 1756 1757 $tmp = imap_mime_header_decode($from[0]->personal); 1758 1759 if ($tmp[0]->text != "") 1760 $sortfrom[$i] = $tmp[0]->text; 1761 else 1762 $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; 1763 } 1764 1765 natcasesort($sortfrom); 1766 1767 foreach($sortfrom as $index => $header_msg) 1768 { 1769 $sortfrom_uid[] = imap_uid($this->mbox, $index); 1770 } 1771 1772 if ($sort_box_reverse) 1773 $sortfrom_uid = array_reverse($sortfrom_uid); 1774 1775 return $sortfrom_uid; 1776 } 1777 1717 $sort = array_reverse($sort,true); 1718 1719 if ($slice_array) 1720 $sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true); 1721 return $sort; 1722 1723 } 1724 1778 1725 function move_search_messages($params){ 1779 1726 $params['selected_messages'] = urldecode($params['selected_messages']); … … 1850 1797 $return['new_folder_name'] = $cn; 1851 1798 } 1852 1799 1853 1800 // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. 1854 1801 if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) … … 2057 2004 $mail->ContentType = "multipart/alternative"; 2058 2005 2059 2060 2061 2062 $body = $mail->CreateBody(); 2063 2006 $mail->error_count = 0; // reset errors 2007 $mail->SetMessageType(); 2008 $header = $mail->CreateHeader(); 2009 $body = $mail->CreateBody(); 2010 2064 2011 if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 2065 2012 { … … 2083 2030 $return['msg_no'] = $status->uidnext - 1; 2084 2031 $return['folder_id'] = $folder; 2085 2032 2086 2033 if($mbox_stream) 2087 2034 imap_close($mbox_stream); 2088 2035 if (is_array($return_files)) 2089 foreach ($return_files as $index => $_attachment) {2090 if (array_key_exists("name",$_attachment)){2036 foreach ($return_files as $index => $_attachment) { 2037 if (array_key_exists("name",$_attachment)){ 2091 2038 unset($return_files[$index]); 2092 2039 $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; … … 2250 2197 } 2251 2198 2252 function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse ){2253 2254 if(!$this->mbox || !is_resource($this->mbox)) {2199 function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$offsetBegin = 0,$offsetEnd = 0) 2200 { 2201 if(!$this->mbox || !is_resource($this->mbox)) 2255 2202 $this->mbox = $this->open_mbox($folder); 2256 2257 } 2258 2259 return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type); 2260 /*switch($sort_box_type){ 2261 case 'SORTFROM': 2262 return $this->imap_sortfrom($sort_box_reverse, $search_box_type); 2263 case 'SORTSUBJECT': 2264 return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); 2265 case 'SORTSIZE': 2266 return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); 2267 default: 2268 return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); 2269 }*/ 2270 } 2203 2204 return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd); 2205 } 2271 2206 2272 2207 function get_info_next_msg($params) … … 2644 2579 function get_msg($uid_msg,$name_box, $mbox_stream ) 2645 2580 { 2646 $header = $this->get_header($uid_msg); 2647 $flag = $header->Unseen.$header->Recent.$header->Flagged.$header->Draft; 2581 $header = $this->get_header($uid_msg); 2582 include_once("class.imap_attachment.inc.php"); 2583 $imap_attachment = new imap_attachment(); 2584 $attachments = $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); 2585 $attachments = $attachments['number_attachments'] > 0?"T".$attachments['number_attachments']:""; 2586 $flag = $header->Unseen 2587 .$header->Recent 2588 .$header->Flagged 2589 .$header->Draft 2590 .$header->Answered 2591 .$header->Deleted 2592 .$attachments; 2593 2594 2648 2595 $subject = $this->decode_string($header->fetchsubject); 2649 2596 $from = $header->from[0]->mailbox; … … 2653 2600 return $ret_msg; 2654 2601 } 2655 2602 2656 2603 function size_msg($size){ 2657 2604 $var = floor($size/1024);
Note: See TracChangeset
for help on using the changeset viewer.