Ticket #8936: Simplified date sorting UI in IMP
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 26 Mar 2010 23:10:52 +0000 (17:10 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 26 Mar 2010 23:11:36 +0000 (17:11 -0600)
13 files changed:
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/js/DimpBase.js
imp/lib/Block/Newmail.php
imp/lib/IMP.php
imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php
imp/lib/Mailbox.php
imp/lib/Search.php
imp/mailbox-mimp.php
imp/mailbox.php
imp/rss.php
imp/templates/dimp/javascript_defs_dimp.php
imp/templates/mimp/mailbox/mailbox.html

index 90387de..3ae89d8 100644 (file)
@@ -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,
index 31e6d1a..749552b 100644 (file)
@@ -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
index d027b87..37336c3 100644 (file)
@@ -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')
index 78d6522..58392ab 100644 (file)
@@ -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 = '<table cellspacing="0" width="100%">';
         if (empty($ids)) {
index b9c2f69..bae99c4 100644 (file)
@@ -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:
      * <pre>
-     * 'by'  - (integer) Sort type (Horde_Imap_Client constant)
-     * 'dir' - (integer) Sort direction
+     * 'by'  - (integer) Sort type.
+     * 'dir' - (integer) Sort direction.
      * </pre>
      */
-    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;
     }
 
index 9dac350..6aeb2ff 100644 (file)
@@ -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()
index 5ec6c9f..88f26fd 100644 (file)
@@ -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) {}
index 628d225..f9d7af9 100644 (file)
@@ -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) {
index f3f3671..78b39e6 100644 (file)
@@ -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)
index 2463f67..4aaac81 100644 (file)
@@ -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'] = '<span class="toggleSort">[' . 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']) . ']</span>';
-    unset($headers[$extra]);
-
     /* Determine which of Subject/Thread to emphasize. */
     if (!IMP::threadSortAvailable($imp_mbox['mailbox'])) {
         unset($headers[Horde_Imap_Client::SORT_THREAD]);
index 71a69d6..5e75e57 100644 (file)
@@ -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']);
index c94aa84..82d6922 100644 (file)
@@ -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"),
index 0356fc8..076f85d 100644 (file)
@@ -11,7 +11,7 @@
 <if:checkbox>
     <th></th>
 </if:checkbox>
-    <th><tag:hdr_arrival /></th>
+    <th></th>
     <th><tag:hdr_from /></th>
     <th><tag:hdr_subject /><if:hdr_subject_minor> <small>[<tag:hdr_subject_minor />]</small></if:hdr_subject_minor></th>
    </tr>