/**
  * Return messages thread.
  * If threaded index doesn't exist or is invalid, will be updated.
  *
  * @param string  $mailbox     Folder name
  * @param string  $sort_field  Sorting column
  * @param string  $sort_order  Sorting order (ASC|DESC)
  *
  * @return array Messages threaded index
  */
 function get_thread($mailbox)
 {
     if (empty($this->icache[$mailbox])) {
         $this->icache[$mailbox] = array();
     }
     // Seek in internal cache
     if (array_key_exists('thread', $this->icache[$mailbox])) {
         return $this->icache[$mailbox]['thread']['object'];
     }
     // Get thread from DB (if DB wasn't already queried)
     if (empty($this->icache[$mailbox]['thread_queried'])) {
         $index = $this->get_thread_row($mailbox);
         // set the flag that DB was already queried for thread
         // this way we'll be able to skip one SELECT, when
         // get_thread() is called more than once or after clear()
         $this->icache[$mailbox]['thread_queried'] = true;
     }
     // Entry exist, check cache status
     if (!empty($index)) {
         $exists = true;
         $is_valid = $this->validate($mailbox, $index, $exists);
         if (!$is_valid) {
             $index = null;
         }
     }
     // Index not found or not valid, get index from IMAP server
     if ($index === null) {
         // Get mailbox data (UIDVALIDITY, counters, etc.) for status check
         $mbox_data = $this->imap->folder_data($mailbox);
         if ($mbox_data['EXISTS']) {
             // get all threads (default sort order)
             $threads = $this->imap->fetch_threads($mailbox, true);
         } else {
             $threads = new rcube_result_thread($mailbox, '* THREAD');
         }
         $index['object'] = $threads;
         // insert/update
         $this->add_thread_row($mailbox, $threads, $mbox_data, $exists);
     }
     $this->icache[$mailbox]['thread'] = $index;
     return $index['object'];
 }
Пример #2
0
 /**
  * Return messages thread.
  * If threaded index doesn't exist or is invalid, will be updated.
  *
  * @param string  $mailbox     Folder name
  * @param string  $sort_field  Sorting column
  * @param string  $sort_order  Sorting order (ASC|DESC)
  *
  * @return array Messages threaded index
  */
 function get_thread($mailbox)
 {
     if (empty($this->icache[$mailbox])) {
         $this->icache[$mailbox] = array();
     }
     // Seek in internal cache
     if (array_key_exists('thread', $this->icache[$mailbox])) {
         return array($this->icache[$mailbox]['thread']['tree'], $this->icache[$mailbox]['thread']['depth'], $this->icache[$mailbox]['thread']['children']);
     }
     // Get thread from DB (if DB wasn't already queried)
     if (empty($this->icache[$mailbox]['thread_queried'])) {
         $index = $this->get_thread_row($mailbox);
         // set the flag that DB was already queried for thread
         // this way we'll be able to skip one SELECT, when
         // get_thread() is called more than once or after clear()
         $this->icache[$mailbox]['thread_queried'] = true;
     }
     $data = null;
     // Entry exist, check cache status
     if (!empty($index)) {
         $exists = true;
         $is_valid = $this->validate($mailbox, $index, $exists);
         if (!$is_valid) {
             $index = null;
         }
     }
     // Index not found or not valid, get index from IMAP server
     if ($index === null) {
         // Get mailbox data (UIDVALIDITY, counters, etc.) for status check
         $mbox_data = $this->imap->mailbox_data($mailbox);
         if ($mbox_data['EXISTS']) {
             // get all threads (default sort order)
             list($thread_tree, $msg_depth, $has_children) = $this->imap->fetch_threads($mailbox, true);
         }
         $index = array('tree' => !empty($thread_tree) ? $thread_tree : array(), 'depth' => !empty($msg_depth) ? $msg_depth : array(), 'children' => !empty($has_children) ? $has_children : array());
         // insert/update
         $this->add_thread_row($mailbox, $index, $mbox_data, $exists);
     }
     $this->icache[$mailbox]['thread'] = $index;
     return array($index['tree'], $index['depth'], $index['children']);
 }