Changeset 1614 for trunk/expressoMail1_2/inc/class.imap_functions.inc.php
- Timestamp:
- 11/10/09 16:01:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r1608 r1614 2956 2956 2957 2957 function search_msg($params = ''){ 2958 $retorno = ""; 2959 $mbox_stream = ""; 2960 if(strpos($params['condition'],"#")===false) { //local messages 2961 $search=false; 2962 } 2963 else { 2964 $search = explode(",",$params['condition']); 2965 } 2966 2967 if($search){ 2968 $search_criteria = ''; 2969 $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 2970 $acumulated_results = 0; 2971 foreach($search as $tmp) 2972 { 2973 $tmp1 = explode("##",$tmp); 2974 $name_box = $tmp1[0]; 2975 unset($filter); 2976 foreach($tmp1 as $index => $criteria) 2977 { 2978 if ($index != 0 && strlen($criteria) != 0) 2979 { 2980 $filter_array = explode("<=>",rawurldecode($criteria)); 2981 $filter .= " ".$filter_array[0]; 2982 $filter .= '"'.$filter_array[1].'"'; 2983 } 2984 } 2985 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 2986 $filter = $this->remove_accents($filter); 2987 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 2988 $folder_name = explode($this->imap_delimiter,$name_box); 2989 if (is_numeric($folder_name[1])) { 2990 $this->ldap = new ldap_functions(); 2991 if ($cn = $this->ldap->uid2cn($folder_name[1])) { 2992 $folder_name[1] = $cn; 2993 } 2994 } 2995 $folder_name = implode($this->imap_delimiter,$folder_name); 2996 2997 if(!is_resource($mbox_stream)) 2998 $mbox_stream = $this->open_mbox($name_box); 2999 else 3000 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 3001 3002 $sum = 0; 3003 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 3004 3005 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 3006 foreach($all_criterias as $criteria_fixed) 3007 { 3008 $_filter = $criteria_fixed . substr($filter,4); 3009 3010 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 3011 3012 if($search_criteria) //&& count($search_criteria) < 50) 3013 { 3014 foreach($search_criteria as $new_search){ 3015 $m_token = trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 3016 if(!@strstr($retorno,$m_token)) 3017 { 3018 $retorno .= $m_token; 3019 $sum += 1; 3020 } 3021 } 3022 } 3023 } 3024 } 3025 else { 3026 $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 3027 if( is_array( $search_criteria) ) 2958 $retorno = ""; 2959 $mbox_stream = ""; 2960 if(strpos($params['condition'],"#")===false) { //local messages 2961 $search=false; 2962 } 2963 else { 2964 $search = explode(",",$params['condition']); 2965 } 2966 2967 if($search){ 2968 $search_criteria = ''; 2969 $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 2970 foreach($search as $tmp) 2971 { 2972 $tmp1 = explode("##",$tmp); 2973 $sum = 0; 2974 $name_box = $tmp1[0]; 2975 unset($filter); 2976 foreach($tmp1 as $index => $criteria) 2977 { 2978 if ($index != 0 && strlen($criteria) != 0) 2979 { 2980 $filter_array = explode("<=>",rawurldecode($criteria)); 2981 $filter .= " ".$filter_array[0]; 2982 $filter .= '"'.$filter_array[1].'"'; 2983 } 2984 } 2985 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 2986 $filter = $this->remove_accents($filter); 2987 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 2988 $folder_name = explode($this->imap_delimiter,$name_box); 2989 if (is_numeric($folder_name[1])) 2990 { 2991 $this->ldap = new ldap_functions(); 2992 if ($cn = $this->ldap->uid2cn($folder_name[1])) 2993 { 2994 $folder_name[1] = $cn; 2995 } 2996 } 2997 $folder_name = implode($this->imap_delimiter,$folder_name); 2998 2999 if(!is_resource($mbox_stream)) 3000 { 3001 $mbox_stream = $this->open_mbox($name_box); 3002 } 3003 else 3004 { 3005 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 3006 } 3007 3008 if (preg_match("/^.?\bALL\b/", $filter)) 3009 { // Quick Search, note: this ALL isn't the same ALL from imap_search 3010 3011 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 3012 foreach($all_criterias as $criteria_fixed) 3013 { 3014 $_filter = $criteria_fixed . substr($filter,4); 3015 3016 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 3017 3018 if($search_criteria) //&& count($search_criteria) < 50) 3019 { 3020 foreach($search_criteria as $new_search) 3021 { 3022 if ($search_result_number != '65536' && $sum == $search_result_number) 3028 3023 { 3029 foreach($search_criteria as $new_search) 3030 $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 3024 return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 3031 3025 } 3032 $sum += count($search_criteria); 3033 } 3034 3035 $acumulated_results += $sum; 3036 3037 if ($search_result_number != '65536' && $acumulated_results >= $search_result_number) 3026 3027 $m_token = trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 3028 if(!@strstr($retorno,$m_token)) 3029 { 3030 $retorno .= $m_token; 3031 $sum ++; 3032 } 3033 } 3034 } 3035 } 3036 } 3037 else { 3038 $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 3039 if( is_array( $search_criteria) ) 3040 { 3041 foreach($search_criteria as $new_search) 3042 { 3043 if ($search_result_number != '65536' && $sum == $search_result_number) 3038 3044 { 3039 return "many results";3045 return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 3040 3046 } 3041 } 3042 } 3043 if($mbox_stream) 3044 imap_close($mbox_stream); 3045 3046 return $retorno ? $retorno : "none"; 3047 $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); 3048 $sum++; 3049 } 3050 } 3051 } 3052 } 3053 } 3054 if($mbox_stream) 3055 { 3056 imap_close($mbox_stream); 3057 } 3058 3059 if ($retorno) 3060 { 3061 return $retorno; 3062 } 3063 else 3064 { 3065 return 'none'; 3066 } 3047 3067 } 3048 3068
Note: See TracChangeset
for help on using the changeset viewer.