'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'),
);
$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(
$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'))
);
}
// 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
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.
opts.offset = 0;
}
+ opts.initial = 1;
+
this._fetchBuffer(opts);
},
//
// 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.
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;
* @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)
{
* @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)
{
}
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();
} 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
}
/**
+ * 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
/**
* Returns a list of messages for use with ViewPort.
*
- * @var array $args TODO (applyfilter)
+ * @var array $args TODO (applyfilter, initial)
*
* @return array TODO
*/
$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;
+ }
}
}
}
$result->rownum = $rownum;
+ } else {
+ $slice_start = $args['slice_start'];
+ $slice_end = $args['slice_end'];
}
$slice_start = max(1, $slice_start);