From: Michael M Slusarz Date: Fri, 26 Mar 2010 23:10:52 +0000 (-0600) Subject: Ticket #8936: Simplified date sorting UI in IMP X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=763bc2f73ce446d7c42ff21c2fdff51b27cbb807;p=horde.git Ticket #8936: Simplified date sorting UI in IMP --- diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index 90387de60..3ae89d810 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -1300,13 +1300,16 @@ $_prefs['mailbox_start'] = array( // default sorting column $_prefs['sortby'] = array( - 'value' => Horde_Imap_Client::SORT_ARRIVAL, + // Sort by sequence by default. It is the fastest sort as it is the only + // sort that can be done without parsing message headers. It sorts + // messages by the order they arrived within the mailbox. + 'value' => Horde_Imap_Client::SORT_SEQUENCE, 'locked' => false, 'shared' => false, 'type' => 'enum', 'enum' => array( - Horde_Imap_Client::SORT_ARRIVAL => _("Arrival Time"), - Horde_Imap_Client::SORT_DATE => _("Message Date"), + Horde_Imap_Client::SORT_SEQUENCE => _("NONE"), + IMP::IMAP_SORT_DATE => _("Date"), Horde_Imap_Client::SORT_FROM => _("From Address"), Horde_Imap_Client::SORT_TO => _("To Address"), Horde_Imap_Client::SORT_SUBJECT => _("Subject"), @@ -1335,6 +1338,23 @@ $_prefs['sortpref'] = array( 'shared' => false, 'type' => 'implicit'); +// default sorting criteria for the date column +$_prefs['sortdate'] = array( + // Use internal IMAP date by default - this is generally the date that a + // message was first received on the IMAP server and is maintained even + // if the message moves between mailboxes. + 'value' => Horde_Imap_Client::SORT_ARRIVAL, + // Locked by default + 'locked' => true, + 'shared' => false, + 'type' => 'enum', + 'enum' => array( + Horde_Imap_Client::SORT_ARRIVAL => _("Arrival time on server"), + Horde_Imap_Client::SORT_DATE => _("Date in message headers") + ), + 'desc' => _("Criteria to use when sorting by date:") +); + // mailbox constraints $_prefs['max_msgs'] = array( 'value' => 30, diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 31e6d1afa..749552b8a 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Simplified date sorting display (Ticket #8936). [mms] Properly redirect messages pursuant to RFC 5322 [3.6.6]. [mms] Add redirect message capability to DIMP. [mms] Add ability to add attachments to composed messages for advanced mobile diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index d027b870c..37336c312 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -1030,9 +1030,8 @@ var DimpBase = { setSortColumns: function(sortby) { - var tmp, + var hdr, tmp, ptr = DIMP.conf.sort, - togglesort = [], m = $('msglistHeader'); if (Object.isUndefined(sortby)) { @@ -1050,6 +1049,7 @@ var DimpBase = { m.down('.msgFrom').update(ptr.get('from').e).insert(ptr.get('to').e); m.down('.msgSize').update(ptr.get('size').e); + m.down('.msgDate').update(ptr.get('date').e); } /* Toggle between From/To header. */ @@ -1064,28 +1064,18 @@ var DimpBase = { tmp = m.down('.msgSubject'); if (this.isSearch() || this.viewport.getMetaData('nothread')) { - togglesort.push({ l: 'subject', t: tmp }); + hdr = { l: 'subject', t: tmp }; } else if (sortby == ptr.get('thread').v) { - togglesort.push({ l: 'thread', s: 'subject', t: tmp }); + hdr = { l: 'thread', s: 'subject', t: tmp }; } else { - togglesort.push({ l: 'subject', s: 'thread', t: tmp }); + hdr = { l: 'subject', s: 'thread', t: tmp }; } - /* Toggle between Date/Arrival header. */ - tmp = m.down('.msgDate'); - if (sortby == ptr.get('arrival').v) { - togglesort.push({ l: 'arrival', s: 'date', t: tmp }); - } else { - togglesort.push({ l: 'date', s: 'arrival', t: tmp }); + hdr.t.update().update(ptr.get(hdr.l).e.removeClassName('smallSort').update(ptr.get(hdr.l).t)); + if (hdr.s) { + hdr.t.insert(ptr.get(hdr.s).e.addClassName('smallSort').update('[' + ptr.get(hdr.s).t + ']')); } - togglesort.each(function(hdr) { - hdr.t.update().update(ptr.get(hdr.l).e.removeClassName('smallSort').update(ptr.get(hdr.l).t)); - if (hdr.s) { - hdr.t.insert(ptr.get(hdr.s).e.addClassName('smallSort').update('[' + ptr.get(hdr.s).t + ']')); - } - }); - ptr.find(function(s) { return (sortby == s.value.v) ? s.value.e.up().addClassName(this.viewport.getMetaData('sortdir') ? 'sortup' : 'sortdown') diff --git a/imp/lib/Block/Newmail.php b/imp/lib/Block/Newmail.php index 78d652201..58392ab3e 100644 --- a/imp/lib/Block/Newmail.php +++ b/imp/lib/Block/Newmail.php @@ -22,7 +22,7 @@ class IMP_Block_Newmail extends Horde_Block $query = new Horde_Imap_Client_Search_Query(); $query->flag('\\seen', false); - $ids = $GLOBALS['imp_search']->runSearchQuery($query, 'INBOX', Horde_Imap_Client::SORT_ARRIVAL, 1); + $ids = $GLOBALS['imp_search']->runSearchQuery($query, 'INBOX', Horde_Imap_Client::SORT_SEQUENCE, 1); $html = ''; if (empty($ids)) { diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index b9c2f69fc..bae99c4c9 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -38,6 +38,9 @@ class IMP const PREF_NO_FOLDER = 'nofolder\0'; const PREF_VTRASH = 'vtrash\0'; + /* Sorting constants. */ + const IMAP_SORT_DATE = 100; + /* Storage place for an altered version of the current URL. */ static public $newUrl = null; @@ -863,16 +866,17 @@ class IMP /** * Return the sorting preference for the current mailbox. * - * @param string $mbox The mailbox to use (defaults to current mailbox - * in the session). + * @param string $mbox The mailbox to use (defaults to current + * mailbox in the session). + * @param boolean $convert Convert 'by' to a Horde_Imap_Client constant? * * @return array An array with the following keys: *
-     * 'by'  - (integer) Sort type (Horde_Imap_Client constant)
-     * 'dir' - (integer) Sort direction
+     * 'by'  - (integer) Sort type.
+     * 'dir' - (integer) Sort direction.
      * 
*/ - static public function getSort($mbox = null) + static public function getSort($mbox = null, $convert = false) { if (is_null($mbox)) { $mbox = $GLOBALS['imp_mbox']['mailbox']; @@ -893,18 +897,18 @@ class IMP 'dir' => isset($entry['d']) ? $entry['d'] : $GLOBALS['prefs']->getValue('sortdir'), ); - /* Restrict POP3 sorting to arrival only. Although possible to + /* Restrict POP3 sorting to sequence only. Although possible to * abstract other sorting methods, all other methods require a * download of all messages, which is too much overhead.*/ if ($_SESSION['imp']['protocol'] == 'pop') { - $ob['by'] = Horde_Imap_Client::SORT_ARRIVAL; + $ob['by'] = Horde_Imap_Client::SORT_SEQUENCE; return $ob; } /* Can't do threaded searches in search mailboxes. */ if (!self::threadSortAvailable($mbox) && ($ob['by'] == Horde_Imap_Client::SORT_THREAD)) { - $ob['by'] = Horde_Imap_Client::SORT_DATE; + $ob['by'] = IMP::IMAP_SORT_DATE; } if (self::isSpecialFolder($mbox)) { @@ -917,6 +921,10 @@ class IMP $ob['by'] = Horde_Imap_Client::SORT_FROM; } + if ($convert && ($ob['by'] == IMP::IMAP_SORT_DATE)) { + $ob['by'] = $GLOBALS['prefs']->getValue('sortdate'); + } + return $ob; } diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index 9dac35004..6aeb2ffda 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -24,32 +24,16 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT */ public function execute() { + $this->_upgradeForwardPrefs(); $this->_upgradeSortPrefs(); $this->_upgradeVirtualFolders(); } /** - * Check for old, non-existent sort values. See Bug #7296. + * Upgrade to the new forward preferences. */ - protected function _upgradeSortPrefs() + protected function upgradeForwardPrefs() { - $sortby = $GLOBALS['prefs']->getValue('sortby'); - if ($sortby > 10) { - $GLOBALS['prefs']->setValue('sortby', Horde_Imap_Client::SORT_ARRIVAL); - } - - $update = false; - $sortpref = @unserialize($GLOBALS['prefs']->getValue('sortpref')); - foreach ($sortpref as $key => $val) { - if ($val['b'] > 10) { - $sortpref[$key]['b'] = Horde_Imap_Client::SORT_ARRIVAL; - $update = true; - } - } - if ($update) { - $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref)); - } - switch ($GLOBALS['prefs']->getValue('forward_default')) { case 'forward_attachments': $GLOBALS['prefs']->setValue('forward_default', 'both'); @@ -77,6 +61,55 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT } /** + * Check for old, non-existent sort values. See Bug #7296. + */ + protected function _upgradeSortPrefs() + { + $update = false; + $sortpref = @unserialize($GLOBALS['prefs']->getValue('sortpref')); + foreach ($sortpref as $key => $val) { + $sb = $this->_newSortbyValue($val['b']); + if (!is_null($sb)) { + $sortpref[$key]['b'] = $sb; + $update = true; + } + } + + if ($update) { + $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref)); + } + + $sb = $this->_newSortbyValue($GLOBALS['prefs']->getValue('sortby')); + if (!is_null($sb)) { + $GLOBALS['prefs']->setValue('sortby', $sb); + } + } + + /** + * Get the new sortby pref value. + * + * @param integer $sortby The old value. + * + * @return integer Null if no change or else the converted sort value. + */ + protected function _newSortbyValue($sortby) + { + switch ($sortby) { + case 1: // SORTARRIVAL + /* Sortarrival was the same thing as sequence sort in IMP 4. */ + return Horde_Imap_Client::SORT_SEQUENCE; + + case 2: // SORTDATE + return IMP::IMAP_SORT_DATE; + + case 161: // SORTTHREAD + return Horde_Imap_Client::SORT_THREAD; + } + + return null; + } + + /** * Upgrade IMP 4 style virtual folders. */ protected function _upgradeVirtualFolders() diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index 5ec6c9f55..88f26fdf8 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -333,7 +333,8 @@ class IMP_Mailbox $GLOBALS['notification']->push(_("Mailbox listing failed") . ': ' . $e->getMessage(), 'horde.error'); } } else { - $sortpref = IMP::getSort($this->_mailbox); + $sortpref = IMP::getSort($this->_mailbox, true); + $sortpref['by'] = 1; if ($sortpref['by'] == Horde_Imap_Client::SORT_THREAD) { $this->_threadob = null; @@ -608,9 +609,9 @@ class IMP_Mailbox case IMP::MAILBOX_START_FIRSTUNSEEN: $sortpref = IMP::getSort($this->_mailbox); - /* Optimization: if sorting by arrival then first unseen + /* Optimization: if sorting by sequence then first unseen * information is returned via a SELECT/EXAMINE call. */ - if ($sortpref['by'] == Horde_Imap_Client::SORT_ARRIVAL) { + if ($sortpref['by'] == Horde_Imap_Client::SORT_SEQUENCE) { try { $res = $GLOBALS['imp_imap']->ob()->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN); if (!is_null($res['firstunseen'])) { @@ -821,7 +822,7 @@ class IMP_Mailbox public function getCacheID() { if (!$this->_searchmbox) { - $sortpref = IMP::getSort($this->_mailbox); + $sortpref = IMP::getSort($this->_mailbox, true); try { return $GLOBALS['imp_imap']->ob()->getCacheId($this->_mailbox, array($sortpref['by'], $sortpref['dir'])); } catch (Horde_Imap_Client_Exception $e) {} diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 628d225a2..f9d7af92f 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -267,9 +267,9 @@ class IMP_Search } /* How do we want to sort results? */ - $sortpref = IMP::getSort(); + $sortpref = IMP::getSort(null, true); if ($sortpref['by'] == Horde_Imap_Client::SORT_THREAD) { - $sortpref['by'] = Horde_Imap_Client::SORT_DATE; + $sortpref['by'] = $GLOBALS['prefs']->getValue('sortdate'); } foreach ($search['f'] as $val) { diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index f3f367144..78b39e655 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -215,7 +215,6 @@ if (!$readonly && /* Create header links. */ $hdr_list = array( - 'hdr_arrival' => array('#', Horde_Imap_Client::SORT_ARRIVAL), 'hdr_from' => array(_("From"), Horde_Imap_Client::SORT_FROM), 'hdr_subject' => array(_("Subject"), Horde_Imap_Client::SORT_SUBJECT), 'hdr_thread' => array(_("Thread"), Horde_Imap_Client::SORT_THREAD) diff --git a/imp/mailbox.php b/imp/mailbox.php index 2463f6724..4aaac8100 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -568,12 +568,7 @@ if ($pageOb['msgcount']) { $sortImg = ($sortpref['dir']) ? 'za.png' : 'az.png'; $sortText = ($sortpref['dir']) ? '\/' : '/\\'; $headers = array( - Horde_Imap_Client::SORT_ARRIVAL => array( - 'stext' => _("Sort by Arrival"), - 'text' => _("Arrival"), - 'width' => '14%' - ), - Horde_Imap_Client::SORT_DATE => array( + IMP::IMAP_SORT_DATE => array( 'stext' => _("Sort by Date"), 'text' => _("Dat_e"), 'width' => '14%' @@ -613,17 +608,6 @@ if ($pageOb['msgcount']) { unset($headers[Horde_Imap_Client::SORT_TO]); } - /* Determine which of Date/Arrival to emphasize. */ - if ($sortpref['by'] == Horde_Imap_Client::SORT_ARRIVAL) { - $extra = Horde_Imap_Client::SORT_DATE; - $standard = Horde_Imap_Client::SORT_ARRIVAL; - } else { - $extra = Horde_Imap_Client::SORT_ARRIVAL; - $standard = Horde_Imap_Client::SORT_DATE; - } - $headers[$standard]['extra'] = '[' . Horde::widget($mailbox_imp_url->copy()->add(array('sortby' => $extra, 'actionID' => 'change_sort', 'mailbox_token' => $mailbox_token)), $headers[$extra]['stext'], 'widget', null, null, $headers[$extra]['text']) . ']'; - unset($headers[$extra]); - /* Determine which of Subject/Thread to emphasize. */ if (!IMP::threadSortAvailable($imp_mbox['mailbox'])) { unset($headers[Horde_Imap_Client::SORT_THREAD]); diff --git a/imp/rss.php b/imp/rss.php index 71a69d64c..5e75e57ba 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -53,7 +53,7 @@ $query = new Horde_Imap_Client_Search_Query(); if ($new_mail) { $query->flag('\\seen', false); } -$ids = $imp_search->runSearchQuery($query, $mailbox, Horde_Imap_Client::SORT_DATE, 1); +$ids = $imp_search->runSearchQuery($query, $mailbox, Horde_Imap_Client::SORT_ARRIVAL, 1); if (!empty($ids)) { $imp_ui = new IMP_Ui_Mailbox($imp_mbox['mailbox']); diff --git a/imp/templates/dimp/javascript_defs_dimp.php b/imp/templates/dimp/javascript_defs_dimp.php index c94aa841c..82d692251 100644 --- a/imp/templates/dimp/javascript_defs_dimp.php +++ b/imp/templates/dimp/javascript_defs_dimp.php @@ -92,11 +92,7 @@ $code['conf'] = array_filter(array( ), 'date' => array( 't' => _("Date"), - 'v' => Horde_Imap_Client::SORT_DATE - ), - 'arrival' => array( - 't' => _("Arrival"), - 'v' => Horde_Imap_Client::SORT_ARRIVAL + 'v' => IMP::IMAP_SORT_DATE ), 'size' => array( 't' => _("Size"), diff --git a/imp/templates/mimp/mailbox/mailbox.html b/imp/templates/mimp/mailbox/mailbox.html index 0356fc83a..076f85da7 100644 --- a/imp/templates/mimp/mailbox/mailbox.html +++ b/imp/templates/mimp/mailbox/mailbox.html @@ -11,7 +11,7 @@ - +
[]