Changeset 3843
- Timestamp:
- 03/01/11 15:15:19 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
r3831 r3843 101 101 { 102 102 // Free others requests 103 103 session_write_close(); 104 104 $folder = $params['folder']; 105 105 $msg_range_begin = $params['msg_range_begin']; … … 109 109 $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; 110 110 111 111 if(!$this->mbox || !is_resource($this->mbox)) 112 112 $this->mbox = $this->open_mbox($folder); 113 113 114 114 $return = array(); 115 //Para enviar o offset entre o timezone definido pelo usuário e GMT116 115 //Para enviar o offset entre o timezone definido pelo usuário e GMT 116 $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); 117 117 118 118 if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") { … … 397 397 } 398 398 else 399 return ("The import was executed successfully.");399 return $this->functions->getLang("The import was executed successfully."); 400 400 } 401 401 } … … 3394 3394 } 3395 3395 3396 function search_msg($params = ''){ 3397 $mbox_stream = ""; 3398 if(strpos($params['condition'],"#")===false) { //local messages? It shouldn't be necessary, should it? FIXME 3399 $search=false; 3400 } 3401 else { 3402 $search = explode(",",$params['condition']); 3396 function search_msg( $params = false ) 3397 { 3398 $mbox_stream = ""; 3399 3400 if(strpos($params['condition'],"#")===false) 3401 { //local messages 3402 $search=false; 3403 } 3404 else 3405 { 3406 $search = explode(",",$params['condition']); 3407 } 3408 3409 $params['page'] = $params['page'] * 1; 3410 3411 if( is_array($search) ) 3412 { 3413 $search = array_unique($search); // Remove duplicated folders 3414 $search_criteria = ''; 3415 $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 3416 foreach($search as $tmp) 3417 { 3418 $tmp1 = explode("##",$tmp); 3419 $sum = 0; 3420 $name_box = $tmp1[0]; 3421 unset($filter); 3422 foreach($tmp1 as $index => $criteria) 3423 { 3424 if ($index != 0 && strlen($criteria) != 0) 3425 { 3426 $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); 3427 $filter .= " ".$filter_array[0]; 3428 if (strlen($filter_array[1]) != 0) 3429 { 3430 if ( trim($filter_array[0]) != 'BEFORE' && 3431 trim($filter_array[0]) != 'SINCE' && 3432 trim($filter_array[0]) != 'ON') 3433 { 3434 $filter .= '"'.$filter_array[1].'"'; 3435 } 3436 else 3437 { 3438 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 3439 } 3440 } 3441 } 3442 } 3443 3444 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3445 $filter = $this->remove_accents($filter); 3446 3447 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 3448 if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') 3449 { 3450 $folder_name = explode($this->imap_delimiter,$name_box); 3451 $this->ldap = new ldap_functions(); 3452 3453 if ($cn = $this->ldap->uid2cn($folder_name[1])) 3454 { 3455 $folder_name[1] = $cn; 3456 } 3457 $folder_name = implode($this->imap_delimiter,$folder_name); 3458 } 3459 else 3460 $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3461 3462 if(!is_resource($mbox_stream)) 3463 $mbox_stream = $this->open_mbox($name_box); 3464 else 3465 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 3466 3467 if (preg_match("/^.?\bALL\b/", $filter)) 3468 { 3469 // Quick Search, note: this ALL isn't the same ALL from imap_search 3470 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 3471 3472 foreach($all_criterias as $criteria_fixed) 3473 { 3474 $_filter = $criteria_fixed . substr($filter,4); 3475 3476 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 3477 3478 if(is_array($search_criteria)) 3479 { 3480 foreach($search_criteria as $new_search) 3481 { 3482 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3483 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3484 $elem['uid'] = $new_search; 3485 $retorno[] = $elem; 3486 } 3487 } 3488 } 3489 } 3490 else 3491 { 3492 $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 3493 3494 if( is_array( $search_criteria) ) 3495 { 3496 foreach($search_criteria as $new_search) 3497 { 3498 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3499 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3500 $elem['uid'] = $new_search; 3501 $retorno[] = $elem; 3502 } 3503 } 3504 } 3505 } 3506 } 3507 3508 if($mbox_stream) 3509 { 3510 imap_close($mbox_stream); 3403 3511 } 3404 $params['page'] = $params['page']*1; 3405 3406 if(is_array($search)){ 3407 $search = array_unique($search); // Remove duplicated folders 3408 $search_criteria = ''; 3409 $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; 3410 foreach($search as $tmp) 3411 { 3412 $tmp1 = explode("##",$tmp); 3413 $sum = 0; 3414 $name_box = $tmp1[0]; 3415 unset($filter); 3416 foreach($tmp1 as $index => $criteria) 3417 { 3418 if ($index != 0 && strlen($criteria) != 0) 3419 { 3420 $filter_array = explode("<=>",rawurldecode($criteria)); 3421 $filter .= " ".$filter_array[0]; 3422 if (strlen($filter_array[1]) != 0){ 3423 if (trim($filter_array[0]) != 'BEFORE' && 3424 trim($filter_array[0]) != 'SINCE' && 3425 trim($filter_array[0]) != 'ON') 3426 { 3427 $filter .= '"'.$filter_array[1].'"'; 3428 } 3429 else 3430 { 3431 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 3432 } 3433 } 3434 } 3435 } 3436 $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3437 $filter = $this->remove_accents($filter); 3438 //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name 3439 if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') 3440 { 3441 $folder_name = explode($this->imap_delimiter,$name_box); 3442 $this->ldap = new ldap_functions(); 3443 if ($cn = $this->ldap->uid2cn($folder_name[1])) 3444 { 3445 $folder_name[1] = $cn; 3446 } 3447 $folder_name = implode($this->imap_delimiter,$folder_name); 3448 } 3449 else 3450 { 3451 $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); 3452 } 3453 3454 if(!is_resource($mbox_stream)) 3455 { 3456 $mbox_stream = $this->open_mbox($name_box); 3457 } 3458 else 3459 { 3460 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 3461 } 3462 3463 if (preg_match("/^.?\bALL\b/", $filter)) 3464 { // Quick Search, note: this ALL isn't the same ALL from imap_search 3465 3466 $all_criterias = array ("TO","SUBJECT","FROM","CC"); 3467 foreach($all_criterias as $criteria_fixed) 3468 { 3469 $_filter = $criteria_fixed . substr($filter,4); 3470 3471 $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); 3472 3473 if(is_array($search_criteria)) 3474 { 3475 foreach($search_criteria as $new_search) 3476 { 3477 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3478 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3479 $elem['uid'] = $new_search; 3480 $retorno[] = $elem; 3481 } 3482 } 3483 } 3484 } 3485 else { 3486 $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 3487 if( is_array( $search_criteria) ) 3488 { 3489 foreach($search_criteria as $new_search) 3490 { 3491 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3492 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3493 $elem['uid'] = $new_search; 3494 $retorno[] = $elem; 3495 } 3496 } 3497 } 3498 } 3499 } 3500 if($mbox_stream) 3501 { 3502 imap_close($mbox_stream); 3503 } 3512 3504 3513 $num_msgs = count($retorno); 3505 3514 3506 3515 /* Comparison functions, descendent is ascendent with parms inverted */ 3507 function SORTDATE($a, $b) 3516 function SORTDATE($a, $b){ return ($a['udate'] < $b['udate']); } 3508 3517 function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } 3509 3518 … … 3520 3529 function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } 3521 3530 3522 usort($retorno, $params['sort_type']); 3523 $pageret = array_slice($retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); 3524 $arrayRetorno['num_msgs'] = $num_msgs; 3525 $arrayRetorno['data'] = $pageret; 3526 3527 if ($pageret) 3528 { 3529 return $arrayRetorno; 3530 } 3531 else 3532 { 3533 return 'none'; 3534 } 3531 usort( $retorno, $params['sort_type']); 3532 $pageret = array_slice( $retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); 3533 3534 $arrayRetorno['num_msgs'] = $num_msgs; 3535 $arrayRetorno['data'] = $pageret; 3536 3537 error_log( '\nNumero de mensagens :'.$arrayRetorno['num_msgs'], 3, "/tmp/log" ); 3538 3539 if ($pageret) 3540 { 3541 return $arrayRetorno; 3542 } 3543 else 3544 { 3545 return 'none'; 3546 } 3535 3547 } 3536 3548 … … 3555 3567 if($header->from[0]->personal != "") 3556 3568 $from = $header->from[0]->personal; 3557 $ret_msg['from'] = $this->decode_string($from);3558 $ret_msg['subject'] 3559 $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset());3560 $ret_msg['size'] = $header->Size;3561 $ret_msg['flag'] = $flag;3569 $ret_msg['from'] = $this->decode_string($from); 3570 $ret_msg['subject'] = $subject; 3571 $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); 3572 $ret_msg['size'] = $header->Size; 3573 $ret_msg['flag'] = $flag; 3562 3574 return $ret_msg; 3563 3575 } … … 3938 3950 $sources = explode("#@#@#@",$params['source']); 3939 3951 $timestamps = explode("#@#@#@",$params['timestamp']); 3940 foreach($sources as $index=>$src) { 3941 if($src!=""){ 3942 $source = $this->treat_base64_from_post($src); 3943 $insert = $this->insert_email($source,$dest_folder,$timestamps[$index]); 3944 } 3945 } 3952 foreach($sources as $index=>$src) 3953 { 3954 if($src!="") 3955 { 3956 $source = $this->treat_base64_from_post($src); 3957 $insert = $this->insert_email($source,$dest_folder,$timestamps[$index]); 3958 } 3959 } 3960 3961 error_log( print_r($insert, true), 3, "/tmp/log" ); 3962 3946 3963 return $insert; 3947 3964 }
Note: See TracChangeset
for help on using the changeset viewer.