Store the thread algorithm used in the session.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 26 Nov 2009 01:12:40 +0000 (18:12 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Nov 2009 06:33:09 +0000 (23:33 -0700)
Explicitly state REFERENCES as the desired first choice thread algorithm

imp/config/servers.php.dist
imp/lib/Auth.php
imp/lib/Mailbox.php

index d16900d..5f461b5 100644 (file)
  *            (i.e. it is selected per default). Otherwise the first entry
  *            in the list is selected.
  *
+ * thread: (string) Set the preferred thread sort algorithm. This algorithm
+ *         must be supported by the remote server. By default, IMP attempts
+ *         to use REFERENCES sorting and, if this is not available, it will
+ *         fall back to ORDEREDSUBJECT sorting done on the local server.
+ *
  *
  * $Id$
  */
index d3dd584..6f33859 100644 (file)
@@ -81,6 +81,14 @@ class IMP_Auth
             throw new Horde_Auth_Exception($e->getMessage());
         }
 
+        /* Set the IMAP threading algorithm. */
+        $ptr = $GLOBALS['imp_imap']->loadServerConfig($credentials['server']);
+        if (strcasecmp($ptr['protocol'], 'imap') == 0) {
+            $_SESSION['imp']['imap']['thread'] = in_array(isset($ptr['thread']) ? strtoupper($ptr['thread']) : 'REFERENCES', $GLOBALS['imp_imap']->ob()->queryCapability('THREAD'))
+                ? 'REFERENCES'
+                : 'ORDEREDSUBJECT';
+        }
+
         return false;
     }
 
index 93e3789..1d43bf2 100644 (file)
@@ -667,22 +667,9 @@ class IMP_Mailbox
     {
         if (is_null($this->_threadob)) {
             try {
-                $this->_threadob = $GLOBALS['imp_imap']->ob()->thread($this->_mailbox);
-                $ref_errcode = null;
+                $this->_threadob = $GLOBALS['imp_imap']->ob()->thread($this->_mailbox, array('criteria' => $_SESSION['imp']['imap']['thread']));
             } catch (Horde_Imap_Client_Exception $e) {
-                $error = $e;
-                $ref_errcode = $e->getCode();
-            }
-
-            if ($ref_errcode == Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT) {
-                try {
-                    $this->_threadob = $GLOBALS['imp_imap']->ob()->thread($this->_mailbox, array('criteria' => Horde_Imap_Client::THREAD_ORDEREDSUBJECT));
-                } catch (Horde_Imap_Client_Exception $e) {
-                    $GLOBALS['notification']->push(_("Server does not support thread sorting."), 'horde.error');
-                    return new Horde_Imap_Client_Thread(array(), 'uid');
-                }
-            } elseif (!is_null($ref_errcode)) {
-                $GLOBALS['notification']->push($error, 'horde.error');
+                $GLOBALS['notification']->push($e, 'horde.error');
                 return new Horde_Imap_Client_Thread(array(), 'uid');
             }
         }