Ignore:
Timestamp:
02/06/09 15:34:17 (15 years ago)
Author:
eduardoalex
Message:

Ticket #413

File:
1 edited

Legend:

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

    r660 r670  
    1010                'get_range_msgs'                                => True, 
    1111                'get_info_msg'                                  => True, 
     12                'get_info_msgs'                                 => True, 
    1213                'get_folders_list'                              => True, 
    1314                'import_msgs'                                   => True 
     
    7071        function get_range_msgs2($params) 
    7172        { 
    72                 include("class.imap_attachment.inc.php"); 
    73                 $imap_attachment = new imap_attachment(); 
    7473                $folder = $params['folder']; 
    7574                $msg_range_begin = $params['msg_range_begin']; 
     
    8584                if($num_msgs) {  
    8685                        for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++) 
    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', 
     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', 
    101117                                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    102118                                        ,$importance);           
    103                         $return[$i]['Importance'] = $flag==0?"":$importance[1]; 
    104                          
    105                          
    106                         $header = $this->get_header($msg_number); 
     119                $head_array['Importance'] = $flag==0?"Normal":$importance[1]; 
     120 
     121                 
     122                $header = $this->get_header($msg_number); 
    107123                        if (!is_object($header)) 
    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; 
     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; 
    157170        } 
    158171         
     
    297310        } 
    298311 
     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 
    299348        function get_info_msg($params) 
    300349        { 
     
    317366                //Substituição de links em email para abrir no próprio expresso 
    318367                $body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); 
    319                          
     368                 
    320369                $return['body']                 = $body; 
    321370                $return['attachments']  = $return_get_body['attachments']; 
     
    550599                $return['Size'] = $header->Size; 
    551600                $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                 
    552607                return $return; 
    553608        } 
     
    10171072        function refresh($params) 
    10181073        { 
    1019                 include("class.imap_attachment.inc.php"); 
     1074                include_once("class.imap_attachment.inc.php"); 
    10201075                $imap_attachment = new imap_attachment();                
    10211076                $folder = $params['folder']; 
     
    10971152                                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 
    10981153                                        ,$importance);           
    1099                         $return[$i]['Importance'] = $flag==0?"":$importance[1]; 
     1154                        $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; 
    11001155                         
    11011156                        $header = $this->get_header($msg_number); 
     
    13481403                $attachments = $params['FILES']; 
    13491404                $forwarding_attachments = $params['forwarding_attachments']; 
     1405                $local_attachments = $params['local_attachments']; 
    13501406                  
    13511407                $folder =$params['folder']; 
     
    14311487//////////////////////////////////////////////////////////////////////////////////////////////////// 
    14321488                //      Build Uploading Attachments!!! 
    1433                 if (count($attachments)) 
     1489                if ((count($attachments)) && ($params['is_local_forward']!="1")) //Caso seja forward normal... 
    14341490                { 
    14351491                        $total_uploaded_size = 0; 
     
    14431499                                return $this->parse_error("message file too big");                       
    14441500                }                        
     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                } 
    14451517//////////////////////////////////////////////////////////////////////////////////////////////////// 
    14461518                //      Build Forwarding Attachments!!! 
     
    23692441        function search($params) 
    23702442        { 
    2371                 include("class.imap_attachment.inc.php"); 
     2443                include_once("class.imap_attachment.inc.php"); 
    23722444                $imap_attachment = new imap_attachment();                                
    23732445                $criteria = $params['criteria']; 
     
    24892561                $retorno = ""; 
    24902562                $mbox_stream = ""; 
    2491                 $search = explode(",",$params['condition']); 
     2563                if(strpos($params['condition'],"#")===false) { //local messages 
     2564                        $search=false; 
     2565                } 
     2566                else { 
     2567                        $search = explode(",",$params['condition']);                     
     2568                } 
     2569 
    24922570                if($search){ 
    24932571                        $search_criteria = ''; 
    2494                         foreach($search as $tmp) 
    2495                         { 
     2572                        foreach($search as $tmp){ 
    24962573                                $tmp1 = explode("##",$tmp); 
    24972574                                $name_box = $tmp1[0]; 
     
    27502827                $array_parts_attachments = array();              
    27512828                $array_parts_attachments['names'] = ''; 
    2752                 include("class.imap_attachment.inc.php"); 
     2829                include_once("class.imap_attachment.inc.php"); 
    27532830                $imap_attachment = new imap_attachment();                
    27542831                 
Note: See TracChangeset for help on using the changeset viewer.