From 484cfc41b7859e98972e9886dfb8073a9efb8b5c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 22 Oct 2009 14:16:43 -0600 Subject: [PATCH] Use display name sorting, if possible, for to/from sorts. --- imp/docs/CHANGES | 1 + imp/docs/RFCS | 2 ++ imp/lib/Mailbox.php | 2 +- imp/lib/Search.php | 45 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 9b16363b6..004b95b83 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Sort by display name for to/from fields if supported on IMAP server. [mms] Add ability to quickly filter by flags in DIMP. [mms] Add ability to select sent-mail mailbox when composing in DIMP. [mms] Add ability to save drafts in MIMP. diff --git a/imp/docs/RFCS b/imp/docs/RFCS index 82967da0c..06a476380 100644 --- a/imp/docs/RFCS +++ b/imp/docs/RFCS @@ -44,6 +44,8 @@ RFC 5267 ESORT RFC 5464 METADATA RFC 5550 Lemonade Profile (specifically [2.8] - $Forwarded flag) +draft-ietf-morg-sortdisplay-02 SORT=DISPLAY + POP3 ==== diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index 995a777ac..43017d1fb 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -340,7 +340,7 @@ class IMP_Mailbox $query->flag('\\deleted', false); } try { - $res = $GLOBALS['imp_imap']->ob()->search($this->_mailbox, $query, array('sort' => array($sortpref['by']), 'reverse' => (bool)$sortpref['dir'])); + $res = $GLOBALS['imp_search']->imapSearch($this->_mailbox, $query, array('sort' => array($sortpref['by']), 'reverse' => (bool)$sortpref['dir'])); $this->_sorted = $res['sort']; } catch (Horde_Imap_Client_Exception $e) { $this->_sorted = array(); diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 6e325cf4c..1fb9dfb54 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -275,7 +275,7 @@ class IMP_Search } foreach ($search['f'] as $val) { - $results = $GLOBALS['imp_imap']->ob()->search($val, $query, array('reverse' => $sortpref['dir'], 'sort' => array($sortpref['by']))); + $results = $this->imapSearch($val, $query, array('reverse' => $sortpref['dir'], 'sort' => array($sortpref['by']))); foreach ($results['sort'] as $val2) { $sorted[] = $val2 . IMP::IDX_SEP . $val; } @@ -301,7 +301,7 @@ class IMP_Search $sortdir = null) { try { - $results = $GLOBALS['imp_imap']->ob()->search($mailbox, $query, array('reverse' => $sortdir, 'sort' => array($sortby))); + $results = $this->imapSearch($mailbox, $query, array('reverse' => $sortdir, 'sort' => array($sortby))); return $results['sort']; } catch (Horde_Imap_Client_Exception $e) { return array(); @@ -309,6 +309,47 @@ class IMP_Search } /** + * Performs the IMAP search query on the server. Use this function, + * instead of directly calling Horde_Imap_Client's search() function, + * because certain configuration parameters may need to be dynamically + * altered. + * + * @param string $mailbox The mailbox to search. + * @param object $query The search query object + * (Horde_Imap_Client_Search_Query). + * @param array $opts Additional search options. + * + * @return array Search results. + */ + public function imapSearch($mailbox, $query, $opts = array()) + { + /* If doing a from/to search, use display sorting if possible. + * Although there is a fallback to a PHP-based display sort, for + * performance reasons only do a display sort if it is supported + * on the server. */ + if (($_SESSION['imp']['protocol'] == 'imap') && + isset($opts['sort']) && + (in_array(Horde_Imap_Client::SORT_FROM, $opts['sort']) || + in_array(Horde_Imap_Client::SORT_TO, $opts['sort']))) { + $sort_cap = $GLOBALS['imp_imap']->ob()->queryCapability('SORT'); + print_r($sort_cap); + if (is_array($sort_cap) && in_array('DISPLAY', $sort_cap)) { + $pos = array_search(Horde_Imap_Client::SORT_FROM, $opts['sort']); + if ($pos !== false) { + $opts['sort'][$pos] = Horde_Imap_Client::SORT_DISPLAYFROM; + } + + $pos = array_search(Horde_Imap_Client::SORT_TO, $opts['sort']); + if ($pos !== false) { + $opts['sort'][$pos] = Horde_Imap_Client::SORT_DISPLAYTO; + } + } + } + + return $GLOBALS['imp_imap']->ob()->search($mailbox, $query, $opts); + } + + /** * Creates the IMAP search query in the IMP session. * * @param object $query The search query object -- 2.11.0