protected function _buildMailbox()
{
$cacheid = $this->_mailbox->cacheid;
if (!is_null($this->_sorted) && $this->_cacheid == $cacheid) {
return;
}
$this->changed = true;
$this->_cacheid = $cacheid;
$this->_sorted = array();
$query_ob = $this->_buildMailboxQuery();
$sortpref = $this->_mailbox->getSort(true);
$thread_sort = $sortpref->sortby == Horde_Imap_Client::SORT_THREAD;
if ($this->_mailbox->access_search && $this->_mailbox->hideDeletedMsgs()) {
$delete_query = new Horde_Imap_Client_Search_Query();
$delete_query->flag(Horde_Imap_Client::FLAG_DELETED, false);
if (is_null($query_ob)) {
$query_ob = array(strval($this->_mailbox) => $delete_query);
} else {
foreach ($query_ob as $val) {
$val->andSearch($delete_query);
}
}
}
if (is_null($query_ob)) {
$query_ob = array(strval($this->_mailbox) => null);
}
if ($thread_sort) {
$this->_thread = $this->_threadui = array();
}
foreach ($query_ob as $mbox => $val) {
$mbox_ob = IMP_Mailbox::get($mbox);
if ($thread_sort) {
$this->_getThread($mbox, $val ? array('search' => $val) : array());
$sorted = $this->_thread[$mbox]->messageList()->ids;
if ($sortpref->sortdir) {
$sorted = array_reverse($sorted);
}
} else {
try {
$res = $mbox_ob->imp_imap->search($mbox, $val, array('sort' => array($sortpref->sortby)));
} catch (IMP_Imap_Exception $e) {
switch ($e->getCode()) {
case Horde_Imap_Client_Exception::MAILBOX_NOOPEN:
if ($this->_mailbox->search) {
/* Ignore non-existent mailboxes when in a search
* mailbox. */
continue 2;
}
}
throw $e;
}
if ($sortpref->sortdir) {
$res['match']->reverse();
}
$sorted = $res['match']->ids;
}
$this->_sorted = array_merge($this->_sorted, $this->_buildMailboxProcess($mbox_ob, $sorted));
}
}