Changeset 3803
- Timestamp:
- 02/22/11 18:14:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
r3798 r3803 3383 3383 3384 3384 function search_msg($params = ''){ 3385 $retorno = ""; 3386 $mbox_stream = ""; 3387 if(strpos($params['condition'],"#")===false) { //local messages 3388 $search=false; 3389 } 3390 else { 3391 $search = explode(",",$params['condition']); 3392 } 3393 3394 $offsetToGMT = $this->functions->CalculateDateOffset(); 3395 3396 if($search){ 3397 $search_criteria = ''; 3398 $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 3399 foreach($search as $tmp) 3400 { 3401 $tmp1 = explode("##",$tmp); 3402 $sum = 0; 3403 $name_box = $tmp1[0]; 3404 unset($filter); 3405 foreach($tmp1 as $index => $criteria) 3406 { 3407 if ($index != 0 && strlen($criteria) != 0) 3385 $mbox_stream = ""; 3386 if(strpos($params['condition'],"#")===false) { //local messages? It shouldn't be necessary, should it? FIXME 3387 $search=false; 3388 } 3389 else { 3390 $search = explode(",",$params['condition']); 3391 } 3392 $params['page'] = $params['page']*1; 3393 3394 if(is_array($search)){ 3395 $search = array_unique($search); // Remove duplicated folders 3396 $search_criteria = ''; 3397 $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 3398 foreach($search as $tmp) 3399 { 3400 $tmp1 = explode("##",$tmp); 3401 $sum = 0; 3402 $name_box = $tmp1[0]; 3403 unset($filter); 3404 foreach($tmp1 as $index => $criteria) 3405 { 3406 if ($index != 0 && strlen($criteria) != 0) 3407 { 3408 $filter_array = explode("<=>",rawurldecode($criteria)); 3409 $filter .= " ".$filter_array[0]; 3410 if (strlen($filter_array[1]) != 0){ 3411 if (trim($filter_array[0]) != 'BEFORE' && 3412 trim($filter_array[0]) != 'SINCE' && 3413 trim($filter_array[0]) != 'ON') 3414 { 3415 $filter .= '"'.$filter_array[1].'"'; 3416 } 3417 else 3408 3418 { 3409 $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); 3410 $filter .= " ".$filter_array[0]; 3411 if (strlen($filter_array[1]) != 0){ 3412 if (trim($filter_array[0]) != 'BEFORE' && 3413 trim($filter_array[0]) != 'SINCE' && 3414 trim($filter_array[0]) != 'ON') 3415 { 3416 // Remove accents from criteria, because method remove accents is broken. 3417 $a = 'áàâãäéèêëíìîïóòôõöúùûüçÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ'; 3418 $b = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC'; 3419 $filter .= '"'.strtr($filter_array[1], $a, $b).'"'; 3420 } 3421 else { 3422 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 3423 } 3424 } 3419 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 3425 3420 } 3426 } 3427 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3428 3429 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 3430 if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') 3431 { 3432 $folder_name = explode($this->imap_delimiter,$name_box); 3433 $this->ldap = new ldap_functions(); 3434 if ($cn = $this->ldap->uid2cn($folder_name[1])) 3435 { 3436 $folder_name[1] = $cn; 3437 } 3438 $folder_name = implode($this->imap_delimiter,$folder_name); 3439 } 3440 else 3441 $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3442 3443 if(!is_resource($mbox_stream)) 3444 $mbox_stream = $this->open_mbox($name_box); 3445 else 3446 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 3447 3448 if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search 3449 3450 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 3451 3452 foreach($all_criterias as $criteria_fixed) 3453 { 3454 $_filter = $criteria_fixed . substr($filter,4); 3455 3456 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 3457 // Testa aqui 3458 if($search_criteria) // && count($search_criteria) < $search_result_number) 3459 { 3460 foreach($search_criteria as $new_search){ 3461 if ($search_result_number != '65536' && $sum == $search_result_number) 3421 } 3422 } 3423 } 3424 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3425 $filter = $this->remove_accents($filter); 3426 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 3427 if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') 3428 { 3429 $folder_name = explode($this->imap_delimiter,$name_box); 3430 $this->ldap = new ldap_functions(); 3431 if ($cn = $this->ldap->uid2cn($folder_name[1])) 3432 { 3433 $folder_name[1] = $cn; 3434 } 3435 $folder_name = implode($this->imap_delimiter,$folder_name); 3436 } 3437 else 3438 { 3439 $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3440 } 3441 3442 if(!is_resource($mbox_stream)) 3443 { 3444 $mbox_stream = $this->open_mbox($name_box); 3445 } 3446 else 3447 { 3448 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 3449 } 3450 3451 if (preg_match("/^.?\bALL\b/", $filter)) 3452 { // Quick Search, note: this ALL isn't the same ALL from imap_search 3453 3454 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 3455 foreach($all_criterias as $criteria_fixed) 3456 { 3457 $_filter = $criteria_fixed . substr($filter,4); 3458 3459 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 3460 3461 if(is_array($search_criteria)) 3462 { 3463 foreach($search_criteria as $new_search) 3462 3464 { 3463 return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 3464 } 3465 3466 $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"); 3467 if(!@strstr($retorno,$m_token)) 3468 { 3469 $retorno .= $m_token; 3470 $sum++; 3471 } 3472 } 3473 } 3474 } 3475 } 3476 else { 3477 $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 3478 if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) 3479 { 3480 if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false)) 3481 { 3482 $num_msgs = imap_num_msg($mbox_stream); 3483 $flagged_msgs = array(); 3484 for ($i=$num_msgs; $i>0; $i--) 3485 { 3486 $iuid = @imap_uid($this->mbox,$i); 3487 $header = $this->get_header($iuid); 3488 if(trim($header->Flagged)) 3489 { 3490 $flagged_msgs[$i] = $iuid; 3491 } 3492 } 3493 if((count($flagged_msgs) >0) && (strpos($filter,"UNFLAGGED") === false)) 3494 { 3495 $arry_diff = array_diff($flagged_msgs,$search_criteria); 3496 foreach($arry_diff as $msg) 3497 { 3498 $search_criteria[] = $msg; 3499 } 3500 } 3501 else if((count($flagged_msgs) >0) && (is_array($search_criteria)) && (!strpos($filter,"UNFLAGGED") === false)) 3502 { 3503 $search_criteria = array_diff($search_criteria,$flagged_msgs); 3504 } 3505 } 3506 } 3507 if( is_array( $search_criteria) ) 3508 { 3509 foreach($search_criteria as $new_search) 3510 { 3511 if ($search_result_number != '65536' && $sum == $search_result_number) 3512 { 3513 return $retorno ? $sum . "=sumResults=" . $retorno : "none"; 3514 } 3515 $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"); 3516 $sum++; 3517 } 3518 } 3519 } 3520 3521 // $acumulated_results += $sum; 3522 // 3523 // if ($search_result_number != '65536' && $acumulated_results >= $search_result_number) 3524 // { 3525 // return "many results"; 3526 // } 3527 } 3528 } 3529 if($mbox_stream) 3530 imap_close($mbox_stream); 3531 3532 if ($retorno){ 3533 return $retorno; 3465 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3466 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3467 $elem['uid'] = $new_search; 3468 $retorno[] = $elem; 3469 } 3470 } 3471 } 3472 } 3473 else { 3474 $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 3475 if( is_array( $search_criteria) ) 3476 { 3477 foreach($search_criteria as $new_search) 3478 { 3479 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3480 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3481 $elem['uid'] = $new_search; 3482 $retorno[] = $elem; 3483 } 3484 } 3485 } 3534 3486 } 3535 else 3536 { 3537 return 'none'; 3538 } 3539 //return $retorno ? $retorno : "none"; 3540 } 3541 3542 function get_msg($uid_msg,$name_box, $mbox_stream ) 3487 } 3488 if($mbox_stream) 3489 { 3490 imap_close($mbox_stream); 3491 } 3492 $num_msgs = count($retorno); 3493 3494 /* Comparison functions, descendent is ascendent with parms inverted */ 3495 function SORTDATE($a, $b) { return ($a['udate'] < $b['udate']); } 3496 function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } 3497 3498 function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); } 3499 function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); } 3500 3501 function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); } 3502 function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); } 3503 3504 function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); } 3505 function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); } 3506 3507 function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); } 3508 function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } 3509 3510 usort($retorno, $params['sort_type']); 3511 $pageret = array_slice($retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); 3512 $arrayRetorno['num_msgs'] = $num_msgs; 3513 $arrayRetorno['data'] = $pageret; 3514 3515 if ($pageret) 3516 { 3517 return $arrayRetorno; 3518 } 3519 else 3520 { 3521 return 'none'; 3522 } 3523 } 3524 3525 function get_msg_detail($uid_msg,$name_box, $mbox_stream ) 3543 3526 { 3544 3527 $header = $this->get_header($uid_msg); 3545 include_once("class.imap_attachment.inc.php");3528 require_once("class.imap_attachment.inc.php"); 3546 3529 $imap_attachment = new imap_attachment(); 3547 3530 $attachments = $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); … … 3560 3543 if($header->from[0]->personal != "") 3561 3544 $from = $header->from[0]->personal; 3562 $ret_msg = $this->decode_string($from) . "--" . htmlentities(rawurlencode($subject)) . "--". gmdate("d/m/Y",$header ->udate + $this->functions->CalculateDateOffset())."--". $this->size_msg($header->Size) ."--". $flag; 3545 $ret_msg['from'] = $this->decode_string($from); 3546 $ret_msg['subject'] = $subject; 3547 $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); 3548 $ret_msg['size'] = $header->Size; 3549 $ret_msg['flag'] = $flag; 3563 3550 return $ret_msg; 3564 3551 } … … 3810 3797 if (!is_object($header)) 3811 3798 return false; 3799 // Prepare udate from mailDate (DateTime arrived with TZ) for fixing summertime problem. 3800 $pdate = date_parse($header->MailDate); 3801 $header->udate += $pdate['zone']*(-60); 3812 3802 3813 3803 if($header->Flagged != "F" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { … … 3855 3845 } 3856 3846 3857 function show_decript($params,$dec=0){ 3858 3847 function show_decript($params){ 3859 3848 $source = $params['source']; 3860 3849 //error_log("source: $source\nversao: " . PHP_VERSION, 3, '/tmp/teste.log'); 3861 3862 if ($dec == 0) 3863 { 3864 $source = str_replace(" ", "+", $source,$i); 3865 if (version_compare(PHP_VERSION, '5.2.0', '>=')){ 3866 if(!$source = base64_decode($source,true)) 3867 return "error ".$source."Espaços ".$i; 3868 3869 } 3870 else { 3871 if(!$source = base64_decode($source)) 3872 return "error ".$source."Espaços ".$i; 3873 } 3850 $source = str_replace(" ", "+", $source,$i); 3851 3852 if (version_compare(PHP_VERSION, '5.2.0', '>=')){ 3853 if(!$source = base64_decode($source,true)) 3854 return "error ".$source."Espaços ".$i; 3855 3874 3856 } 3857 else { 3858 if(!$source = base64_decode($source)) 3859 return "error ".$source."Espaços ".$i; 3860 } 3861 3875 3862 $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); 3876 3863
Note: See TracChangeset
for help on using the changeset viewer.