Changeset 601 in subversion
- Timestamp:
- Jun 5, 2007 9:17:03 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-vnext/program/include/rcube_imap.inc
r597 r601 492 492 493 493 494 /** 495 * Public method for listing headers 496 * convert mailbox name with root dir first 497 * 498 * @param string Mailbox/folder name 499 * @param number Current page to list 500 * @param string Header field to sort by 501 * @param string Sort order [ASC|DESC] 502 * @return array Indexed array with message header objects 503 * @access public 504 */ 505 function list_headers($mbox_name='', $page=NULL, $sort_field=NULL, $sort_order=NULL) 506 { 507 $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; 508 return $this->_list_headers($mailbox, $page, $sort_field, $sort_order); 509 } 510 511 512 /** 513 * Private method for listing message headers 494 /** 495 * Public method for listing headers 496 * convert mailbox name with root dir first 497 * 498 * @param string Mailbox/folder name 499 * @param number Current page to list 500 * @param string Header field to sort by 501 * @param string Sort order [ASC|DESC] 502 * @return array Indexed array with message header objects 503 * @access public 504 */ 505 function list_headers($mbox_name='', $page=NULL, $sort_field=NULL, $sort_order=NULL) 506 { 507 $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; 508 return $this->_list_headers($mailbox, $page, $sort_field, $sort_order); 509 } 510 511 512 /** 513 * Private method for listing message headers 514 * 515 * @access private 516 * @see rcube_imap::list_headers 517 */ 518 function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE) 519 { 520 if (!strlen($mailbox)) { 521 return array(); 522 } 523 // use saved message set 524 if ($this->search_set && $mailbox == $this->mailbox) { 525 return $this->_list_header_set($mailbox, $this->search_set, $page, $sort_field, $sort_order); 526 } 527 if (is_null($sort_field) === FALSE) { 528 $this->sort_field = $sort_field; 529 } 530 if (is_null($sort_order) === FALSE) { 531 $this->sort_order = strtoupper($sort_order); 532 } 533 534 $max = $this->_messagecount($mailbox); 535 $start_msg = ($this->list_page-1) * $this->page_size; 536 537 list($begin, $end) = $this->_get_message_range($max, $page); 538 539 // mailbox is empty 540 if ($begin >= $end) { 541 return array(); 542 } 543 544 $headers_sorted = FALSE; 545 $cache_key = $mailbox.'.msg'; 546 $cache_status = $this->check_cache_status($mailbox, $cache_key); 547 548 // cache is OK, we can get all messages from local cache 549 if ($cache_status>0) { 550 $a_msg_headers = $this->get_message_cache($cache_key, $start_msg, $start_msg+$this->page_size, $this->sort_field, $this->sort_order); 551 $headers_sorted = TRUE; 552 } 553 // cache is dirty, sync it 554 elseif ($this->caching_enabled && $cache_status==-1 && !$recursive) { 555 $this->sync_header_index($mailbox); 556 return $this->_list_headers($mailbox, $page, $this->sort_field, $this->sort_order, TRUE); 557 } 558 else { 559 // retrieve headers from IMAP 560 if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) { 561 $msgs = $msg_index[$begin]; 562 for ($i=$begin+1; $i < $end; $i++) { 563 $msgs = $msgs.','.$msg_index[$i]; 564 } 565 } 566 else { 567 $msgs = sprintf("%d:%d", $begin+1, $end); 568 569 $i = 0; 570 for ($msg_seqnum = $begin; $msg_seqnum <= $end; $msg_seqnum++) { 571 $msg_index[$i++] = $msg_seqnum; 572 } 573 } 574 575 // use this class for message sorting 576 $sorter = new rcube_header_sorter(); 577 $sorter->set_sequence_numbers($msg_index); 578 579 // fetch reuested headers from server 580 $a_msg_headers = array(); 581 $deleted_count = $this->_fetch_headers($mailbox, $msgs, $a_msg_headers, $cache_key); 582 583 // delete cached messages with a higher index than $max+1 584 // Changed $max to $max+1 to fix this bug : #1484295 585 $this->clear_message_cache($cache_key, $max + 1); 586 587 588 // kick child process to sync cache 589 // ... 590 591 } 592 593 594 // return empty array if no messages found 595 if (!is_array($a_msg_headers) || empty($a_msg_headers)) { 596 return array(); 597 } 598 599 // if not already sorted 600 if (!$headers_sorted) { 601 $sorter->sort_headers($a_msg_headers); 602 603 if ($this->sort_order == 'DESC') { 604 $a_msg_headers = array_reverse($a_msg_headers); 605 } 606 } 607 return array_values($a_msg_headers); 608 } 609 610 611 612 /** 613 * Public method for listing a specific set of headers 614 * convert mailbox name with root dir first 615 * 616 * @param string Mailbox/folder name 617 * @param array List of message ids to list 618 * @param number Current page to list 619 * @param string Header field to sort by 620 * @param string Sort order [ASC|DESC] 621 * @return array Indexed array with message header objects 622 * @access public 623 */ 624 function list_header_set($mbox_name='', $msgs, $page=NULL, $sort_field=NULL, $sort_order=NULL) 625 { 626 $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; 627 return $this->_list_header_set($mailbox, $msgs, $page, $sort_field, $sort_order); 628 } 629 630 631 /** 632 * Private method for listing a set of message headers 514 633 * 515 634 * @access private 516 * @see rcube_imap::list_headers 517 */ 518 function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE) 519 { 520 if (!strlen($mailbox)) 635 * @see rcube_imap::list_header_set 636 */ 637 function _list_header_set($mailbox, $msgs, $page=NULL, $sort_field=NULL, $sort_order=NULL) 638 { 639 // also accept a comma-separated list of message ids 640 if (is_string($msgs)) 641 $msgs = split(',', $msgs); 642 643 if (!strlen($mailbox) || empty($msgs)) 521 644 return array(); 522 523 // use saved message set524 if ($this->search_set && $mailbox == $this->mailbox)525 return $this->_list_header_set($mailbox, $this->search_set, $page, $sort_field, $sort_order);526 645 527 646 if ($sort_field!=NULL) … … 530 649 $this->sort_order = strtoupper($sort_order); 531 650 532 $max = $this->_messagecount($mailbox);533 $start_msg = ($this->list_page-1) * $this->page_size;534 535 list($begin, $end) = $this->_get_message_range($max, $page);536 537 // mailbox is empty538 if ($begin >= $end)539 return array();540 541 $headers_sorted = FALSE;542 $cache_key = $mailbox.'.msg';543 $cache_status = $this->check_cache_status($mailbox, $cache_key);544 545 // cache is OK, we can get all messages from local cache546 if ($cache_status>0)547 {548 $a_msg_headers = $this->get_message_cache($cache_key, $start_msg, $start_msg+$this->page_size, $this->sort_field, $this->sort_order);549 $headers_sorted = TRUE;550 }551 // cache is dirty, sync it552 else if ($this->caching_enabled && $cache_status==-1 && !$recursive)553 {554 $this->sync_header_index($mailbox);555 return $this->_list_headers($mailbox, $page, $this->sort_field, $this->sort_order, TRUE);556 }557 else558 {559 // retrieve headers from IMAP560 if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')))561 {562 $msgs = $msg_index[$begin];563 for ($i=$begin+1; $i < $end; $i++)564 $msgs = $msgs.','.$msg_index[$i];565 }566 else567 {568 $msgs = sprintf("%d:%d", $begin+1, $end);569 570 $i = 0;571 for ($msg_seqnum = $begin; $msg_seqnum <= $end; $msg_seqnum++)572 $msg_index[$i++] = $msg_seqnum;573 }574 575 // use this class for message sorting576 $sorter = new rcube_header_sorter();577 $sorter->set_sequence_numbers($msg_index);578 579 // fetch reuested headers from server580 $a_msg_headers = array();581 $deleted_count = $this->_fetch_headers($mailbox, $msgs, $a_msg_headers, $cache_key);582 583 // delete cached messages with a higher index than $max+1584 // Changed $max to $max+1 to fix this bug : #1484295585 $this->clear_message_cache($cache_key, $max + 1);586 587 588 // kick child process to sync cache589 // ...590 591 }592 593 594 // return empty array if no messages found595 if (!is_array($a_msg_headers) || empty($a_msg_headers))596 return array();597 598 599 // if not already sorted600 if (!$headers_sorted)601 {602 $sorter->sort_headers($a_msg_headers);603 604 if ($this->sort_order == 'DESC')605 $a_msg_headers = array_reverse($a_msg_headers);606 }607 608 return array_values($a_msg_headers);609 }610 611 612 613 /**614 * Public method for listing a specific set of headers615 * convert mailbox name with root dir first616 *617 * @param string Mailbox/folder name618 * @param array List of message ids to list619 * @param number Current page to list620 * @param string Header field to sort by621 * @param string Sort order [ASC|DESC]622 * @return array Indexed array with message header objects623 * @access public624 */625 function list_header_set($mbox_name='', $msgs, $page=NULL, $sort_field=NULL, $sort_order=NULL)626 {627 $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox;628 return $this->_list_header_set($mailbox, $msgs, $page, $sort_field, $sort_order);629 }630 631 632 /**633 * Private method for listing a set of message headers634 *635 * @access private636 * @see rcube_imap::list_header_set637 */638 function _list_header_set($mailbox, $msgs, $page=NULL, $sort_field=NULL, $sort_order=NULL)639 {640 // also accept a comma-separated list of message ids641 if (is_string($msgs))642 $msgs = split(',', $msgs);643 644 if (!strlen($mailbox) || empty($msgs))645 return array();646 647 if ($sort_field!=NULL)648 $this->sort_field = $sort_field;649 if ($sort_order!=NULL)650 $this->sort_order = strtoupper($sort_order);651 652 651 $max = count($msgs); 653 652 $start_msg = ($this->list_page-1) * $this->page_size; … … 669 668 670 669 671 /** 672 * Helper function to get first and last index of the requested set 673 * 674 * @param number message count 675 * @param mixed page number to show, or string 'all' 676 * @return array array with two values: first index, last index 677 * @access private 678 */ 679 function _get_message_range($max, $page) 680 { 681 $start_msg = ($this->list_page-1) * $this->page_size; 682 683 if ($page=='all') 684 { 685 $begin = 0; 686 $end = $max; 687 } 688 else if ($this->sort_order=='DESC') 689 { 690 $begin = $max - $this->page_size - $start_msg; 691 $end = $max - $start_msg; 692 } 693 else 694 { 695 $begin = $start_msg; 696 $end = $start_msg + $this->page_size; 697 } 698 699 if ($begin < 0) $begin = 0; 700 if ($end < 0) $end = $max; 701 if ($end > $max) $end = $max; 702 703 return array($begin, $end); 670 /** 671 * Helper function to get first and last index of the requested set 672 * 673 * @param number message count 674 * @param mixed page number to show, or string 'all' 675 * @return array array with two values: first index, last index 676 * @access private 677 */ 678 function _get_message_range($max, $page) 679 { 680 $start_msg = ($this->list_page-1) * $this->page_size; 681 682 if ($page=='all') { 683 $begin = 0; 684 $end = $max; 685 } 686 elseif ($this->sort_order=='DESC') { 687 $begin = $max - $this->page_size - $start_msg; 688 $end = $max - $start_msg; 689 } 690 else { 691 $begin = $start_msg; 692 $end = $start_msg + $this->page_size; 693 } 694 695 if ($begin < 0) { 696 $begin = 0; 697 } 698 if ($end < 0) { 699 $end = $max; 700 } 701 if ($end > $max) { 702 $end = $max; 703 } 704 return array($begin, $end); 704 705 } 705 706
Note: See TracChangeset
for help on using the changeset viewer.
