From: Michael M Slusarz Date: Mon, 27 Jul 2009 23:43:16 +0000 (-0600) Subject: DIMP now honors the mailbox_start preference X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=440b7d713281cb240060d754a31bae71484de823;p=horde.git DIMP now honors the mailbox_start preference --- diff --git a/imp/ajax.php b/imp/ajax.php index 8c16c9c2e..06063d0c1 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -70,6 +70,7 @@ function _getListMessages($mbox, $change) 'applyfilter' => Horde_Util::getPost('applyfilter'), 'cached' => Horde_Util::getPost('cached'), 'cacheid' => Horde_Util::getPost('cacheid'), + 'initial' => Horde_Util::getPost('initial'), 'mbox' => $mbox, 'rangeslice' => Horde_Util::getPost('rangeslice'), 'qsearch' => Horde_Util::getPost('qsearch'), @@ -77,6 +78,14 @@ function _getListMessages($mbox, $change) ); $search = Horde_Util::getPost('search'); + + if (!empty($search) || $args['initial']) { + $args += array( + 'search_before' => intval(Horde_Util::getPost('search_before')), + 'search_after' => intval(Horde_Util::getPost('search_after')) + ); + } + if (empty($search)) { list($slice_start, $slice_end) = explode(':', Horde_Util::getPost('slice'), 2); $args += array( @@ -88,8 +97,6 @@ function _getListMessages($mbox, $change) $args += array( 'search_uid' => $search->imapuid, 'search_view' => $search->view, - 'search_before' => intval(Horde_Util::getPost('search_before')), - 'search_after' => intval(Horde_Util::getPost('search_after')) ); } diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index ad1c190cd..031dc97ed 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -1288,19 +1288,19 @@ $_prefs['fetchmail_login'] = array( // Display Options preferences -// which page to start on when opening mailbox +// Where to start when opening mailbox? $_prefs['mailbox_start'] = array( 'value' => IMP::MAILBOX_START_FIRSTUNSEEN, 'locked' => false, 'shared' => false, 'type' => 'enum', 'enum' => array( - IMP::MAILBOX_START_FIRSTUNSEEN => _("Page with the First (oldest) Unseen Message"), - IMP::MAILBOX_START_LASTUNSEEN => _("Page with the Last (newest) Unseen Message"), - IMP::MAILBOX_START_FIRSTPAGE => _("First Mailbox Page"), - IMP::MAILBOX_START_LASTPAGE => _("Last Mailbox Page") + IMP::MAILBOX_START_FIRSTUNSEEN => _("First (oldest) Unseen Message"), + IMP::MAILBOX_START_LASTUNSEEN => _("Last (newest) Unseen Message"), + IMP::MAILBOX_START_FIRSTPAGE => _("First Page"), + IMP::MAILBOX_START_LASTPAGE => _("Last Page") ), - 'desc' => _("When opening a new mailbox for the first time, which page do you want to start on?"), + 'desc' => _("When opening a mailbox for the first time, where do you want to start?"), 'help' => 'prefs-mailbox_start'); // default sorting column diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 6c44fc9ab..29a9f9444 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] DIMP now honors the 'mailbox_start' preference. [mms] Logins now handled by Horde login handler. [mms] When generating and sending compressed ZIP data, use server-side temp streams to minimize memory usage. diff --git a/imp/js/src/ViewPort.js b/imp/js/src/ViewPort.js index 381176d9e..9efa2471a 100644 --- a/imp/js/src/ViewPort.js +++ b/imp/js/src/ViewPort.js @@ -192,6 +192,8 @@ var ViewPort = Class.create({ opts.offset = 0; } + opts.initial = 1; + this._fetchBuffer(opts); }, @@ -407,6 +409,7 @@ var ViewPort = Class.create({ // // OPTIONAL: // background: (boolean) Do fetch in background + // initial: (boolean) Is this the initial access to this view? // nearing: (string) TODO [only used w/offset] // params: (object) Parameters to add to outgoing URL // view: (string) The view to retrieve. Defaults to current view. @@ -432,17 +435,25 @@ var ViewPort = Class.create({ params.update({ request_id: r_id }); // Determine if we are querying via offset or a search query - if (opts.search) { - type = 'search'; - value = opts.search; + if (opts.search || opts.initial) { + /* If this is an initial request, 'type' will be set correctly + * further down in the code. */ + if (opts.search) { + type = 'search'; + value = opts.search; + params.set('search', Object.toJSON(value)); + } else { + params.set('initial', 1); + } tmp = this._lookbehind(); params.update({ - search: Object.toJSON(value), search_after: this.bufferSize() - tmp, search_before: tmp }); - } else { + } + + if (!opts.search) { type = 'rownum'; value = opts.offset + 1; diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index 83a6eb879..4e2890109 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -369,7 +369,8 @@ class IMP_Mailbox * @param integer $results A Horde_Imap_Client::SORT_RESULTS_* constant * that indicates the desired return type. * - * @return mixed Whatever is requested in $results. + * @return mixed Whatever is requested in $results. NOTE: Returns + * sequence numbers instead of UIDs. */ public function unseenMessages($results) { @@ -383,7 +384,8 @@ class IMP_Mailbox * @param integer $results A Horde_Imap_Client::SORT_RESULTS_* constant * that indicates the desired return type. * - * @return mixed Whatever is requested in $results. + * @return mixed Whatever is requested in $results. NOTE: Returns + * sequence numbers instead of UIDs. */ protected function _msgFlagSearch($type, $results) { @@ -413,7 +415,7 @@ class IMP_Mailbox } try { - $res = $GLOBALS['imp_imap']->ob->search($this->_mailbox, $criteria, array('results' => array($results))); + $res = $GLOBALS['imp_imap']->ob->search($this->_mailbox, $criteria, array('results' => array($results), 'sequence' => true)); return $count ? $res['count'] : $res; } catch (Horde_Imap_Client_Exception $e) { return $count ? 0 : array(); @@ -526,48 +528,9 @@ class IMP_Mailbox } elseif ($this->_searchmbox) { $page = 1; } else { - $page_uid = null; - $startpage = $GLOBALS['prefs']->getValue('mailbox_start'); - - switch ($GLOBALS['prefs']->getValue('mailbox_start')) { - case IMP::MAILBOX_START_FIRSTPAGE: - $page = 1; - break; - - case IMP::MAILBOX_START_LASTPAGE: - $page = $ret['pagecount']; - break; - - case IMP::MAILBOX_START_FIRSTUNSEEN: - $sortpref = IMP::getSort($this->_mailbox); - - /* Optimization: if sorting by arrival then first - * unseen information is returned via a - * SELECT/EXAMINE call. */ - if ($sortpref['by'] == Horde_Imap_Client::SORT_ARRIVAL) { - try { - $res = $GLOBALS['imp_imap']->ob->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN); - $page_uid = is_null($res['firstunseen']) ? null : $this->_sorted[$res['firstunseen'] - 1]; - } catch (Horde_Imap_Client_Exception $e) {} - } else { - $unseen_msgs = $this->unseenMessages(Horde_Imap_Client::SORT_RESULTS_MIN); - $page_uid = $unseen_msgs['min']; - } - break; - - case IMP::MAILBOX_START_LASTUNSEEN: - $unseen_msgs = $this->unseenMessages(Horde_Imap_Client::SORT_RESULTS_MAX); - $page_uid = $unseen_msgs['max']; - break; - } + $page = ceil($this->mailboxStart($ret['msgcount']) / $page_size); } } - - if (empty($page)) { - $page = is_null($page_uid) - ? 1 - : ceil((array_search($page_uid, $this->_sorted) + 1) / $page_size); - } } /* Make sure we're not past the end or before the beginning, and @@ -612,6 +575,52 @@ class IMP_Mailbox } /** + * 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 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: + $sortpref = IMP::getSort($this->_mailbox); + + /* Optimization: if sorting by arrival then first unseen + * information is returned via a SELECT/EXAMINE call. */ + if ($sortpref['by'] == Horde_Imap_Client::SORT_ARRIVAL) { + try { + $res = $GLOBALS['imp_imap']->ob->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN); + if (!is_null($res['firstunseen'])) { + return $res['firstunseen']; + } + } catch (Horde_Imap_Client_Exception $e) {} + + return 1; + } + + $unseen_msgs = $this->unseenMessages(Horde_Imap_Client::SORT_RESULTS_MIN); + return empty($unseen_msgs['min']) + ? 1 + : $unseen_msgs['min']; + + case IMP::MAILBOX_START_LASTUNSEEN: + $unseen_msgs = $this->unseenMessages(Horde_Imap_Client::SORT_RESULTS_MAX); + return empty($unseen_msgs['max']) + ? 1 + : $unseen_msgs['max']; + } + } + + /** * Updates the message array index. * * @param integer $data If $type is 'offset', the number of messages to diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index a9b895028..099535b02 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -15,7 +15,7 @@ class IMP_Views_ListMessages /** * Returns a list of messages for use with ViewPort. * - * @var array $args TODO (applyfilter) + * @var array $args TODO (applyfilter, initial) * * @return array TODO */ @@ -64,17 +64,22 @@ class IMP_Views_ListMessages $result->label = $label; $result->cacheid = $imp_mailbox->getCacheID(); + /* If this is the initial request for a mailbox, figure out the + * starting location based on user's preferences. */ + $rownum = $args['initial'] + ? intval($imp_mailbox->mailboxStart($msgcount)) + : null; + /* Determine the row slice to process. */ - if (isset($args['slice_start'])) { - $slice_start = $args['slice_start']; - $slice_end = $args['slice_end']; - } else { - $rownum = 1; - foreach (array_keys($sorted_list['s'], $args['search_uid']) as $val) { - if (empty($sorted_list['m'][$val]) || - ($sorted_list['m'][$val] == $args['search_mbox'])) { - $rownum = $val; - break; + if (isset($args['search_uid']) || !is_null($rownum)) { + if (is_null($rownum)) { + $rownum = 1; + foreach (array_keys($sorted_list['s'], $args['search_uid']) as $val) { + if (empty($sorted_list['m'][$val]) || + ($sorted_list['m'][$val] == $args['search_mbox'])) { + $rownum = $val; + break; + } } } @@ -87,6 +92,9 @@ class IMP_Views_ListMessages } $result->rownum = $rownum; + } else { + $slice_start = $args['slice_start']; + $slice_end = $args['slice_end']; } $slice_start = max(1, $slice_start);