Changeset 3389


Ignore:
Timestamp:
10/21/10 15:19:06 (14 years ago)
Author:
eduardoalex
Message:

Ticket #1210 - Corrigido erro da paginacao quando selecionado algum filtro

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php

    r3387 r3389  
    5050        } 
    5151        // BEGIN of functions. 
    52         function open_mbox($folder = False,$force_die=true) 
     52        function open_mbox($folder = False) 
    5353        { 
    5454                if (is_resource($this->mbox)) 
    5555                        return $this->mbox; 
    5656                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 
    57                                 if($force_die)  
    58                         $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())))); 
    59                 else  
    60                         $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password); 
     57                $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())))); 
    6158                return $this->mbox; 
    6259         } 
     
    9188                $sort_box_reverse = $params['sort_box_reverse']; 
    9289                $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 
    93                 $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 
     90 
     91                if(!$this->mbox || !is_resource($this->mbox)) 
     92                        $this->mbox = $this->open_mbox($folder); 
    9493 
    9594                $return = array(); 
    96                 $i = 0; 
    97                 $num_msgs = imap_num_msg($this->mbox); 
    98                 if(is_array($sort_array_msg)){ 
    99                         foreach($sort_array_msg as $msg_number => $value) 
    100                         { 
    101                                 $temp = $this->get_info_head_msg($msg_number); 
    102                                 $temp['msg_sample'] = $this->get_msg_sample($msg_number); 
    103                                 if(!$temp) 
     95                 
     96                if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") { 
     97                        $msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder,SA_ALL); 
     98 
     99 
     100                        $return['tot_unseen'] = $search_box_type == "SEEN" ? 0 : $msgs_info->unseen; 
     101 
     102                        $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 
     103 
     104                        $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages); 
     105 
     106                        $i = 0; 
     107                        if(is_array($sort_array_msg)){ 
     108                                foreach($sort_array_msg as $msg_number => $value) 
    104109                                { 
    105                                         return false; 
    106                                 } 
    107  
    108                                 $return[$i] = $temp; 
    109                                 $i++; 
    110                         } 
    111                 } 
    112                 $return['num_msgs'] = $num_msgs; 
    113  
     110                                        $temp = $this->get_info_head_msg($msg_number); 
     111                                        if(!$temp) 
     112                                                return false; 
     113 
     114                                        $return[$i] = $temp; 
     115                                        $i++; 
     116                                } 
     117                        } 
     118                        $return['num_msgs'] =  $num_msgs; 
     119                } 
     120                else { 
     121                        $num_msgs = imap_num_msg($this->mbox);   
     122                        $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$num_msgs); 
     123 
     124 
     125                        $return['tot_unseen'] = 0; 
     126                        $i = 0;          
     127 
     128                        if(is_array($sort_array_msg)){ 
     129                                foreach($sort_array_msg as $msg_number => $value) 
     130                                { 
     131                                        $temp = $this->get_info_head_msg($msg_number); 
     132                                        if(!$temp) 
     133                                                return false; 
     134                                 
     135                                        if($temp['Unseen'] == 'U' || $temp['Recent'] == 'N'){ 
     136                                                $return['tot_unseen']++; 
     137                                        } 
     138                                 
     139                                        if($i <= ($msg_range_end-$msg_range_begin)) 
     140                                                $return[$i] = $temp; 
     141                                        $i++; 
     142                                } 
     143                        } 
     144                        $return['num_msgs'] = count($sort_array_msg)+($msg_range_begin-1); 
     145 
     146                } 
    114147                return $return; 
    115148        } 
     
    724757 
    725758                $return = "";  
    726                 if( (!isset($this->preferences['preview_msg_subject']) || ($this->preferences['preview_msg_subject'] != "1")) &&   
    727                         (!isset($this->preferences['preview_msg_tip']    ) || ($this->preferences['preview_msg_tip']     != "1")) )  
     759                if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) &&   
     760                        (!isset($this->prefs['preview_msg_tip']    ) || ($this->prefs['preview_msg_tip']     != "1")) )  
    728761                {  
    729762                        $return['body'] = "";  
     
    31973230 
    31983231        function search_msg($params = ''){ 
    3199                 $retorno = ""; 
    3200                 $mbox_stream = ""; 
    3201                 if(strpos($params['condition'],"#")===false) { //local messages 
    3202                         $search=false; 
    3203                 } 
    3204                 else { 
    3205                         $search = explode(",",$params['condition']); 
    3206                 } 
    3207  
    3208                 if($search){ 
    3209                         $search_criteria = ''; 
    3210                         $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 
    3211                         foreach($search as $tmp) 
    3212                         { 
    3213                                 $tmp1 = explode("##",$tmp); 
    3214                                 $sum = 0; 
    3215                                 $name_box = $tmp1[0]; 
    3216                                 unset($filter); 
    3217                                 foreach($tmp1 as $index => $criteria) 
    3218                                 { 
    3219                                     if ($index != 0 && strlen($criteria) != 0) 
     3232            $mbox_stream = ""; 
     3233            if(strpos($params['condition'],"#")===false) { //local messages? It shouldn't be necessary, should it? FIXME 
     3234                    $search=false; 
     3235            } 
     3236            else { 
     3237                    $search = explode(",",$params['condition']); 
     3238            } 
     3239            $params['page'] = $params['page']*1; 
     3240 
     3241            if(is_array($search)){ 
     3242                $search = array_unique($search); // Remove duplicated folders 
     3243                $search_criteria = ''; 
     3244                $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 
     3245                foreach($search as $tmp) 
     3246                { 
     3247                    $tmp1 = explode("##",$tmp); 
     3248                    $sum = 0; 
     3249                    $name_box = $tmp1[0]; 
     3250                    unset($filter); 
     3251                    foreach($tmp1 as $index => $criteria) 
     3252                    { 
     3253                        if ($index != 0 && strlen($criteria) != 0) 
     3254                        { 
     3255                            $filter_array = explode("<=>",rawurldecode($criteria)); 
     3256                            $filter .= " ".$filter_array[0]; 
     3257                            if (strlen($filter_array[1]) != 0){ 
     3258                                if (trim($filter_array[0]) != 'BEFORE' && 
     3259                                    trim($filter_array[0]) != 'SINCE' && 
     3260                                    trim($filter_array[0]) != 'ON') 
     3261                                { 
     3262                                    $filter .= '"'.$filter_array[1].'"'; 
     3263                                } 
     3264                                else 
    32203265                                    { 
    3221                                         $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); 
    3222                                         $filter .= " ".$filter_array[0]; 
    3223                                         if (strlen($filter_array[1]) != 0){ 
    3224                                             if (trim($filter_array[0]) != 'BEFORE' && 
    3225                                                 trim($filter_array[0]) != 'SINCE' && 
    3226                                                 trim($filter_array[0]) != 'ON') 
    3227                                             { 
    3228                                                 // Remove accents from criteria, because method remove accents is broken. 
    3229                                                 $filter .= '"'.strtr($filter_array[1], 
    3230                                                     "áàâãäéèêëíìîïóòôõöúùûüçÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ", 
    3231                                                     "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC").'"'; 
    3232                                             } 
    3233                                             else { 
    3234                                                 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 
    3235                                             } 
    3236                                         } 
     3266                                        $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 
    32373267                                    } 
    3238                                 } 
    3239                                 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
    3240  
    3241                                 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 
    3242                                 if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') 
    3243                                 { 
    3244                                         $folder_name = explode($this->imap_delimiter,$name_box); 
    3245                                         $this->ldap = new ldap_functions(); 
    3246                                         if ($cn = $this->ldap->uid2cn($folder_name[1])) 
    3247                                         { 
    3248                                                 $folder_name[1] = $cn; 
    3249                                         } 
    3250                                         $folder_name = implode($this->imap_delimiter,$folder_name); 
    3251                                 } 
    3252                                 else 
    3253                                         $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
    3254  
    3255                                 if(!is_resource($mbox_stream)) 
    3256                                         $mbox_stream = $this->open_mbox($name_box); 
    3257                                 else 
    3258                                         imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 
    3259  
    3260                                 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 
    3261  
    3262                                         $all_criterias = array ("TO","SUBJECT","FROM","CC"); 
    3263  
    3264                                         foreach($all_criterias as $criteria_fixed) 
    3265                                         { 
    3266                                                 $_filter = $criteria_fixed . substr($filter,4); 
    3267  
    3268                                                 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 
    3269                                                 // Testa aqui 
    3270                                                 if($search_criteria) // && count($search_criteria) < $search_result_number) 
    3271                                                 { 
    3272                                                         foreach($search_criteria as $new_search){ 
    3273                                                                 if ($search_result_number != '65536' && $sum == $search_result_number) 
    3274                                                                 { 
    3275                                                                   return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 
    3276                                                                 } 
    3277  
    3278                                                                 $m_token = trim("##". mb_convert_encoding( $folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 
    3279                                                                 if(!@strstr($retorno,$m_token)) 
    3280                                                                 { 
    3281                                                                     $retorno .= $m_token; 
    3282                                                                     $sum++; 
    3283                                                                 } 
    3284                                                         } 
    3285                                                 } 
    3286                                         } 
    3287                                 } 
    3288                                 else { 
    3289                                         $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 
    3290                                         if( is_array( $search_criteria) ) 
    3291                                         { 
    3292                                                 foreach($search_criteria as $new_search) 
    3293                                                 { 
    3294                                                     if ($search_result_number != '65536' && $sum == $search_result_number) 
    3295                                                     { 
    3296                                                         return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 
    3297                                                     } 
    3298                                                     $retorno .= trim("##". mb_convert_encoding( $folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 
    3299                                                     $sum++; 
    3300                                                 } 
    3301                                         } 
    3302                                 } 
    3303  
    3304 //                                $acumulated_results += $sum; 
    3305 // 
    3306 //                                if ($search_result_number != '65536' && $acumulated_results >= $search_result_number) 
    3307 //                                { 
    3308 //                                    return "many results"; 
    3309 //                                } 
    3310                         } 
    3311                 } 
    3312                 if($mbox_stream) 
    3313                         imap_close($mbox_stream); 
    3314  
    3315                 if ($retorno){ 
    3316                     return $retorno; 
     3268                            } 
     3269                        } 
     3270                    } 
     3271                    $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
     3272                    $filter = $this->remove_accents($filter); 
     3273                    //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 
     3274                    if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') 
     3275                    { 
     3276                        $folder_name = explode($this->imap_delimiter,$name_box); 
     3277                        $this->ldap = new ldap_functions(); 
     3278                        if ($cn = $this->ldap->uid2cn($folder_name[1])) 
     3279                        { 
     3280                            $folder_name[1] = $cn; 
     3281                        } 
     3282                        $folder_name = implode($this->imap_delimiter,$folder_name); 
     3283                    } 
     3284                    else 
     3285                    { 
     3286                        $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 
     3287                    } 
     3288 
     3289                    if(!is_resource($mbox_stream)) 
     3290                    { 
     3291                        $mbox_stream = $this->open_mbox($name_box); 
     3292                    } 
     3293                    else 
     3294                        { 
     3295                            imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 
     3296                        } 
     3297 
     3298                    if (preg_match("/^.?\bALL\b/", $filter)) 
     3299                    { // Quick Search, note: this ALL isn't the same ALL from imap_search 
     3300 
     3301                        $all_criterias = array ("TO","SUBJECT","FROM","CC"); 
     3302                        foreach($all_criterias as $criteria_fixed) 
     3303                        { 
     3304                            $_filter = $criteria_fixed . substr($filter,4); 
     3305 
     3306                            $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 
     3307 
     3308                            if(is_array($search_criteria)) 
     3309                            { 
     3310                                foreach($search_criteria as $new_search) 
     3311                                { 
     3312                                    $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);  
     3313                                    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" );  
     3314                                    $elem['uid'] = $new_search;  
     3315                                    $retorno[] = $elem;  
     3316                                } 
     3317                            } 
     3318                        } 
     3319                    } 
     3320                    else { 
     3321                        $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 
     3322                        if( is_array( $search_criteria) ) 
     3323                        { 
     3324                            foreach($search_criteria as $new_search) 
     3325                            { 
     3326                                    $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);  
     3327                                    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" );  
     3328                                    $elem['uid'] = $new_search;  
     3329                                    $retorno[] = $elem; 
     3330                            } 
     3331                        } 
     3332                    } 
    33173333                } 
    3318                 else 
    3319                 { 
    3320                     return 'none'; 
    3321                 } 
    3322                 //return $retorno ? $retorno : "none"; 
    3323         } 
    3324  
    3325         function get_msg($uid_msg,$name_box, $mbox_stream ) 
     3334            } 
     3335            if($mbox_stream) 
     3336            { 
     3337                imap_close($mbox_stream); 
     3338            } 
     3339            $num_msgs = count($retorno); 
     3340 
     3341            /* Comparison functions, descendent is ascendent with parms inverted */ 
     3342            function SORTDATE($a, $b) { return ($a['udate'] < $b['udate']); } 
     3343            function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } 
     3344 
     3345            function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); } 
     3346            function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); } 
     3347 
     3348            function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); } 
     3349            function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); } 
     3350 
     3351            function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); } 
     3352            function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); } 
     3353 
     3354            function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); } 
     3355            function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } 
     3356 
     3357            usort($retorno, $params['sort_type']); 
     3358            $pageret = array_slice($retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); 
     3359            $arrayRetorno['num_msgs'] =  $num_msgs; 
     3360            $arrayRetorno['data'] =  $pageret; 
     3361 
     3362            if ($pageret) 
     3363            { 
     3364                return $arrayRetorno; 
     3365            } 
     3366            else 
     3367            { 
     3368                return 'none'; 
     3369            } 
     3370        } 
     3371 
     3372        function get_msg_detail($uid_msg,$name_box, $mbox_stream ) 
    33263373        { 
    33273374                $header = $this->get_header($uid_msg); 
    3328                 include_once("class.imap_attachment.inc.php"); 
     3375                require_once("class.imap_attachment.inc.php"); 
    33293376                $imap_attachment = new imap_attachment(); 
    33303377                $attachments =  $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); 
     
    33433390                if($header->from[0]->personal != "") 
    33443391                        $from = $header->from[0]->personal; 
    3345                 $ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) ."--". $flag; 
     3392                $ret_msg['from'] = $this->decode_string($from);  
     3393                $ret_msg['subject'] = $subject;  
     3394                $ret_msg['udate'] = $header ->udate;  
     3395                $ret_msg['size'] = $header->Size;  
     3396                $ret_msg['flag'] = $flag;  
    33463397                return $ret_msg; 
    33473398        } 
    3348  
    3349  
    3350         function size_msg($size){ 
    3351                 $var = floor($size/1024); 
    3352                 if($var >= 1){ 
    3353                         return $var." kb"; 
    3354                 }else{ 
    3355                         return $size ." b"; 
    3356                 } 
    3357         } 
    3358          
    33593399        function ob_array($the_object) 
    33603400        { 
Note: See TracChangeset for help on using the changeset viewer.