/** * Determines the sequence number of the first message to display, based * on the user's preferences. * * @param integer $total The total number of messages in the mailbox. * * @return integer The sequence number in the sorted mailbox. */ public function mailboxStart($total) { switch ($GLOBALS['prefs']->getValue('mailbox_start')) { case IMP::MAILBOX_START_FIRSTPAGE: return 1; case IMP::MAILBOX_START_LASTPAGE: return $total; case IMP::MAILBOX_START_FIRSTUNSEEN: if (!$this->_mailbox->access_sort) { return 1; } $sortpref = $this->_mailbox->getSort(); /* Optimization: if sorting by sequence then first unseen * information is returned via a SELECT/EXAMINE call. */ if ($sortpref->sortby == Horde_Imap_Client::SORT_SEQUENCE) { try { $res = $this->_mailbox->imp_imap->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN | Horde_Imap_Client::STATUS_MESSAGES); if (!is_null($res['firstunseen'])) { return $sortpref->sortdir ? $res['messages'] - $res['firstunseen'] + 1 : $res['firstunseen']; } } catch (IMP_Imap_Exception $e) { } return 1; } $unseen_msgs = $this->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_MIN, array('sort' => array(Horde_Imap_Client::SORT_DATE), 'uids' => true)); return empty($unseen_msgs['min']) ? 1 : $this->getArrayIndex($unseen_msgs['min']) + 1; case IMP::MAILBOX_START_LASTUNSEEN: if (!$this->_mailbox->access_sort) { return 1; } $unseen_msgs = $this->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_MAX, array('sort' => array(Horde_Imap_Client::SORT_DATE), 'uids' => true)); return empty($unseen_msgs['max']) ? 1 : $this->getArrayIndex($unseen_msgs['max']) + 1; } }