Ignore:
Timestamp:
02/06/09 16:53:27 (15 years ago)
Author:
niltonneto
Message:

Revisão 670 revertida para versionar 1.233 em TAGS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.imap_functions.inc.php

    r670 r673  
    1010                'get_range_msgs'                                => True, 
    1111                'get_info_msg'                                  => True, 
    12                 'get_info_msgs'                                 => True, 
    1312                'get_folders_list'                              => True, 
    1413                'import_msgs'                                   => True 
     
    7170        function get_range_msgs2($params) 
    7271        { 
     72                include("class.imap_attachment.inc.php"); 
     73                $imap_attachment = new imap_attachment(); 
    7374                $folder = $params['folder']; 
    7475                $msg_range_begin = $params['msg_range_begin']; 
     
    8485                if($num_msgs) {  
    8586                        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]; 
    88                                 $temp = $this->get_info_head_msg($msg_number); 
    89                                 if(!$temp) 
    90                                         return false; 
    91          
    92                                 $return[$i] = $temp; 
    93                                 $i++; 
    94                         } 
    95                 } 
    96                 $return['num_msgs'] = $num_msgs;                 
    97                  
    98                 return $return; 
    99         } 
    100          
    101         function get_info_head_msg($msg_number) { 
    102                 $head_array = array(); 
    103                 include_once("class.imap_attachment.inc.php"); 
    104                 $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                 */ 
    116                 $flag = preg_match('/importance *: *(.*)\r/i', 
     87                { 
     88                        $msg_number = $sort_array_msg[$msg_range_begin-1]; 
     89 
     90                        /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns 
     91                        * atributos do cabeçalho. Como eu preciso do atributo Importance  
     92                        * para saber se o email é importante ou não, uso abaixo a função 
     93                        * imap_fetchheader e busco o atributo importance nela para passar 
     94                        * para as funções ajax. Isso faz com que eu acesse o cabeçalho 
     95                        * duas vezes e de duas formas diferentes, mas em contrapartida, eu 
     96                        * não preciso reimplementar o método utilizando o fetchheader. 
     97                        * Como as mensagens são renderizadas em um número pequeno por vez, 
     98                        * não parece ter perda considerável de performance. 
     99                        */ 
     100                        $flag = preg_match('/importance *: *(.*)\r/i', 
    117101                                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    118102                                        ,$importance);           
    119                 $head_array['Importance'] = $flag==0?"Normal":$importance[1]; 
    120  
    121                  
    122                 $header = $this->get_header($msg_number); 
     103                        $return[$i]['Importance'] = $flag==0?"":$importance[1]; 
     104                         
     105                         
     106                        $header = $this->get_header($msg_number); 
    123107                        if (!is_object($header)) 
    124                                 return false; 
    125                 $head_array['Recent'] = $header->Recent; 
    126                 $head_array['Unseen'] = $header->Unseen; 
    127                 if($header->Answered =='A' && $header->Draft == 'X'){ 
    128                         $head_array['Forwarded'] = 'F'; 
    129                 } 
    130                 else { 
    131                         $head_array['Answered'] = $header->Answered; 
    132                         $head_array['Draft']    = $header->Draft;        
    133                 } 
    134                 $head_array['Deleted'] = $header->Deleted; 
    135                 $head_array['Flagged'] = $header->Flagged; 
    136                  
    137                 $head_array['msg_number'] = $msg_number; 
    138                 //$return[$i]['msg_folder'] = $folder; 
    139                  
    140                 $date_msg = date("d/m/Y",$header->udate); 
    141                 if (date("d/m/Y") == $date_msg) 
    142                         $head_array['udate'] = date("H:i",$header->udate); 
    143                 else 
    144                         $head_array['udate'] = $date_msg; 
    145                  
    146                 $head_array['aux_date'] = $date_msg; //Auxiliar apenas para mensagens locais. 
    147                  
    148                 $from = $header->from; 
    149                 $head_array['from'] = array(); 
    150                 $tmp = imap_mime_header_decode($from[0]->personal); 
    151                 $head_array['from']['name'] = $this->decode_string($tmp[0]->text); 
    152                 $head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; 
    153                 if(!$head_array['from']['name']) 
    154                         $head_array['from']['name'] = $head_array['from']['email']; 
    155                 $to = $header->to; 
    156                 $head_array['to'] = array(); 
    157                 $tmp = imap_mime_header_decode($to[0]->personal); 
    158                 $head_array['to']['name'] = $this->decode_string($this->decode_string($tmp[0]->text)); 
    159                 $head_array['to']['email'] = $this->decode_string($to[0]->mailbox) . "@" . $to[0]->host; 
    160                 if(!$head_array['to']['name']) 
    161                         $head_array['to']['name'] = $head_array['to']['email']; 
    162                 $head_array['subject'] = $this->decode_string($header->fetchsubject); 
    163                  
    164                 $head_array['Size'] = $header->Size; 
    165                  
    166                 $head_array['attachment'] = array(); 
    167                 $head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 
    168                  
    169                 return $head_array; 
     108                                return false;                    
     109                         
     110                        $return[$i]['Recent'] = $header->Recent; 
     111                        $return[$i]['Unseen'] = $header->Unseen; 
     112                        if($header->Answered =='A' && $header->Draft == 'X'){ 
     113                                $return[$i]['Forwarded'] = 'F'; 
     114                        } 
     115                        else { 
     116                                $return[$i]['Answered'] = $header->Answered; 
     117                                $return[$i]['Draft']    = $header->Draft;        
     118                        } 
     119                        $return[$i]['Deleted'] = $header->Deleted; 
     120                        $return[$i]['Flagged'] = $header->Flagged; 
     121                         
     122                        $return[$i]['msg_number'] = $msg_number; 
     123                        //$return[$i]['msg_folder'] = $folder; 
     124                         
     125                        $date_msg = gmdate("d/m/Y",$header->udate); 
     126                        if (gmdate("d/m/Y") == $date_msg) 
     127                                $return[$i]['udate'] = gmdate("H:i",$header->udate); 
     128                        else 
     129                                $return[$i]['udate'] = $date_msg; 
     130                         
     131                        $from = $header->from; 
     132                        $return[$i]['from'] = array(); 
     133                        $tmp = imap_mime_header_decode($from[0]->personal); 
     134                        $return[$i]['from']['name'] = $this->decode_string($tmp[0]->text); 
     135                        $return[$i]['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; 
     136                        if(!$return[$i]['from']['name']) 
     137                                $return[$i]['from']['name'] = $return[$i]['from']['email']; 
     138                        $to = $header->to; 
     139                        $return[$i]['to'] = array(); 
     140                        $tmp = imap_mime_header_decode($to[0]->personal); 
     141                        $return[$i]['to']['name'] = $this->decode_string($this->decode_string($tmp[0]->text)); 
     142                        $return[$i]['to']['email'] = $this->decode_string($to[0]->mailbox) . "@" . $to[0]->host; 
     143                        if(!$return[$i]['to']['name']) 
     144                                $return[$i]['to']['name'] = $return[$i]['to']['email']; 
     145                        $return[$i]['subject'] = $this->decode_string($header->fetchsubject); 
     146 
     147                        $return[$i]['Size'] = $header->Size; 
     148                         
     149                        $return[$i]['attachment'] = array(); 
     150                        $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number);                       
     151                        $i++; 
     152                } 
     153                } 
     154                $return['num_msgs'] = $num_msgs;                 
     155                 
     156                return $return; 
    170157        } 
    171158         
     
    310297        } 
    311298 
    312 /** 
    313          *  
    314          * @return  
    315          * @param $params Object 
    316          */ 
    317         function get_info_msgs($params) { 
    318                 include_once("class.exporteml.inc.php"); 
    319                 $return = array(); 
    320                 $new_params = array(); 
    321                 $attach_params = array(); 
    322                 $new_params["msg_folder"]=$params["folder"]; 
    323                 $attach_params["folder"] = $params["folder"]; 
    324                 $msgs = explode(",",$params["msgs_number"]); 
    325                 $exporteml = new ExportEml(); 
    326                 foreach($msgs as $msg_number) { 
    327                         $new_params["msg_number"] = $msg_number; 
    328                         //ini_set("display_errors","1"); 
    329                         $msg_info = $this->get_info_msg($new_params); 
    330  
    331                         $this->mbox = $this->open_mbox($params['folder']); //Não sei porque, mas se não abrir de novo a caixa dá erro. 
    332                         $msg_info['header'] = $this->get_info_head_msg($msg_number); 
    333  
    334                         $attach_params["num_msg"] = $msg_number; 
    335                         $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); 
    336                         $msg_info['url_export_file'] = $exporteml->export_to_archive($msg_number,$params["folder"]); 
    337                         imap_close($this->mbox); 
    338                         $this->mbox=false; 
    339  
    340  
    341                         array_push($return,serialize($msg_info)); 
    342  
    343                 } 
    344  
    345                 return $return; 
    346         } 
    347  
    348299        function get_info_msg($params) 
    349300        { 
     
    366317                //Substituição de links em email para abrir no próprio expresso 
    367318                $body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); 
    368                  
     319                         
    369320                $return['body']                 = $body; 
    370321                $return['attachments']  = $return_get_body['attachments']; 
     
    599550                $return['Size'] = $header->Size; 
    600551                $return['reply_toaddress'] = $header->reply_toaddress;           
    601  
    602                 //All this is to help in local messages 
    603                 $return['timestamp'] = $header->udate; 
    604                 $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; 
    605                 $return['reply_toaddress'] = $header->reply_toaddress; 
    606                  
    607552                return $return; 
    608553        } 
     
    10721017        function refresh($params) 
    10731018        { 
    1074                 include_once("class.imap_attachment.inc.php"); 
     1019                include("class.imap_attachment.inc.php"); 
    10751020                $imap_attachment = new imap_attachment();                
    10761021                $folder = $params['folder']; 
     
    11521097                                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    11531098                                        ,$importance);           
    1154                         $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; 
     1099                        $return[$i]['Importance'] = $flag==0?"":$importance[1]; 
    11551100                         
    11561101                        $header = $this->get_header($msg_number); 
     
    14031348                $attachments = $params['FILES']; 
    14041349                $forwarding_attachments = $params['forwarding_attachments']; 
    1405                 $local_attachments = $params['local_attachments']; 
    14061350                  
    14071351                $folder =$params['folder']; 
     
    14871431//////////////////////////////////////////////////////////////////////////////////////////////////// 
    14881432                //      Build Uploading Attachments!!! 
    1489                 if ((count($attachments)) && ($params['is_local_forward']!="1")) //Caso seja forward normal... 
     1433                if (count($attachments)) 
    14901434                { 
    14911435                        $total_uploaded_size = 0; 
     
    14991443                                return $this->parse_error("message file too big");                       
    15001444                }                        
    1501                 else if(($params['is_local_forward']=="1") && (count($local_attachments))) { //Caso seja forward de mensagens locais 
    1502                          
    1503                         $total_uploaded_size = 0; 
    1504                         $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024;                         
    1505                         foreach($local_attachments as $local_attachment) { 
    1506                                 $file_description = unserialize(rawurldecode($local_attachment)); 
    1507                                 $tmp = array_values($file_description); 
    1508                                 foreach($file_description as $i => $descriptor){                                 
    1509                                         $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    1510                                 } 
    1511                                 $mail->AddAttachment($_FILES[$tmp[1]]['tmp_name'], $tmp[2], "base64", $this->get_file_type($tmp[2]));  // optional name 
    1512                                 $total_uploaded_size = $total_uploaded_size + $_FILES[$tmp[1]]['size']; 
    1513                         } 
    1514                         if( $total_uploaded_size > $upload_max_filesize) 
    1515                                 return 'false';  
    1516                 } 
    15171445//////////////////////////////////////////////////////////////////////////////////////////////////// 
    15181446                //      Build Forwarding Attachments!!! 
     
    16751603                                continue; 
    16761604                        } 
    1677                                                  
    1678                          
     1605                                                                         
    16791606                        if($sort_box_type=='SORTFROM') { 
    16801607                                if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email'])                              
     
    17161643        } 
    17171644         
    1718         /** 
    1719          * Deprecated 
    1720          *  
    1721          * Replaced for the method messages_sort 
    1722          */ 
    1723         function imap_sortfrom($sort_box_reverse, $search_box_type) 
    1724         { 
    1725                 $sortfrom = array(); 
    1726                 $sortfrom_uid = array(); 
    1727                  
    1728                 $num_msgs = imap_num_msg($this->mbox); 
    1729                 for ($i=1; $i<=$num_msgs; $i++) 
    1730                 { 
    1731                         $header = $this->get_header(imap_uid($this->mbox,$i)); 
    1732                         // List UNSEEN messages. 
    1733                         if($search_box_type == "UNSEEN" &&  (!trim($header->Recent) && !trim($header->Unseen))){ 
    1734                                 continue; 
    1735                         } 
    1736                         // List SEEN messages. 
    1737                         elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ 
    1738                                 continue; 
    1739                         } 
    1740                         // List ANSWERED messages.                       
    1741                         elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ 
    1742                                 continue;                                
    1743                         } 
    1744                         // List FLAGGED messages.                        
    1745                         elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ 
    1746                                 continue; 
    1747                         } 
    1748                                                  
    1749                         if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email'])                              
    1750                                 $from = $header->to; 
    1751                         else 
    1752                                 $from = $header->from; 
    1753                          
    1754                         $tmp = imap_mime_header_decode($from[0]->personal);                      
    1755                          
    1756                         if ($tmp[0]->text != "") 
    1757                                 $sortfrom[$i] = $tmp[0]->text; 
    1758                         else 
    1759                                 $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; 
    1760                 } 
    1761                  
    1762                 natcasesort($sortfrom); 
    1763                  
    1764                 foreach($sortfrom as $index => $header_msg) 
    1765                 {        
    1766                         $sortfrom_uid[] = imap_uid($this->mbox, $index); 
    1767                 } 
    1768                  
    1769                 if ($sort_box_reverse) 
    1770                         $sortfrom_uid = array_reverse($sortfrom_uid); 
    1771                  
    1772                 return $sortfrom_uid; 
    1773         } 
    1774  
    17751645        function move_search_messages($params){          
    17761646                $params['selected_messages'] = urldecode($params['selected_messages']);  
     
    20831953                if($mbox_stream) 
    20841954                        imap_close($mbox_stream); 
    2085                                  
     1955                if (is_array($return_files))               
    20861956                foreach ($return_files as $index => $_attachment) { 
    20871957                        if (array_key_exists("name",$_attachment)){ 
     
    20971967                 
    20981968                $return['files'] = serialize($return_files); 
     1969                $return["subject"] = $subject; 
    20991970                                 
    21001971                if (!$return['append']) 
     
    21362007                                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    21372008                                        ,$importance);           
    2138                                 if(strtolower($importance[1])=="high") { 
     2009                                if(strtolower($importance[1])=="high" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { 
    21392010                                        $flag_importance=true; 
    21402011                                } 
     
    21522023                        } 
    21532024 
    2154                         if($flag_importance) { 
     2025                        if($flag_importance && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { 
    21552026                                $return["status"] = false; 
    21562027                                $return["msg"] = $this->functions->getLang("At least one of selected message cant be marked as normal"); 
     
    24412312        function search($params) 
    24422313        { 
    2443                 include_once("class.imap_attachment.inc.php"); 
     2314                include("class.imap_attachment.inc.php"); 
    24442315                $imap_attachment = new imap_attachment();                                
    24452316                $criteria = $params['criteria']; 
     
    25612432                $retorno = ""; 
    25622433                $mbox_stream = ""; 
    2563                 if(strpos($params['condition'],"#")===false) { //local messages 
    2564                         $search=false; 
    2565                 } 
    2566                 else { 
    2567                         $search = explode(",",$params['condition']);                     
    2568                 } 
    2569  
     2434                $search = explode(",",$params['condition']); 
    25702435                if($search){ 
    25712436                        $search_criteria = ''; 
    2572                         foreach($search as $tmp){ 
     2437                        foreach($search as $tmp) 
     2438                        { 
    25732439                                $tmp1 = explode("##",$tmp); 
    25742440                                $name_box = $tmp1[0]; 
     
    28272693                $array_parts_attachments = array();              
    28282694                $array_parts_attachments['names'] = ''; 
    2829                 include_once("class.imap_attachment.inc.php"); 
     2695                include("class.imap_attachment.inc.php"); 
    28302696                $imap_attachment = new imap_attachment();                
    28312697                 
     
    28942760                $header->udate +=  $pdate['zone']*(-60); 
    28952761                 
    2896                 if($header->Flagged!="F") { 
     2762                if($header->Flagged != "F" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { 
    28972763                        $flag = preg_match('/importance *: *(.*)\r/i', 
    28982764                                                imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
Note: See TracChangeset for help on using the changeset viewer.