From: Michael M Slusarz Date: Thu, 22 Oct 2009 20:18:07 +0000 (-0600) Subject: Support SORT=DISPLAY extension X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d3e5b4f90d1693f0b240a0105f4bfe0baf987974;p=horde.git Support SORT=DISPLAY extension --- diff --git a/framework/Imap_Client/lib/Horde/Imap/Client.php b/framework/Imap_Client/lib/Horde/Imap/Client.php index ec7301d7f..e2f8ba239 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client.php @@ -108,6 +108,9 @@ class Horde_Imap_Client /* SORT_THREAD provided for completeness - it is not a valid sort criteria * for search() (use thread() instead). */ const SORT_THREAD = 9; + /* Sort criteria defined in draft-ietf-morg-sortdisplay-02 */ + const SORT_DISPLAYFROM = 10; + const SORT_DISPLAYTO = 11; const SORT_RESULTS_COUNT = 1; const SORT_RESULTS_MATCH = 2; diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Base.php b/framework/Imap_Client/lib/Horde/Imap/Client/Base.php index 5c4bbcf0b..f314c051c 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Base.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Base.php @@ -1254,6 +1254,10 @@ abstract class Horde_Imap_Client_Base * Horde_Imap_Client::SORT_SIZE * Horde_Imap_Client::SORT_SUBJECT * Horde_Imap_Client::SORT_TO + * [On servers that support SORT=DISPLAY, these criteria are also + * available:] + * Horde_Imap_Client::SORT_DISPLAYFROM + * Horde_Imap_Client::SORT_DISPLAYTO * * Additionally, any sort criteria can be sorted in reverse order * (instead of the default ascending order) by adding a diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php b/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php index 5ac8432a9..e89ecb892 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php @@ -772,13 +772,15 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base { // Already guaranteed to be logged in here. - /* If more than 1 sort criteria given, or if SORT_REVERSE is given - * as a sort criteria, or search query uses IMAP4 criteria, use the - * Socket client instead. */ + /* If more than 1 sort criteria given, or if SORT_REVERSE, + * SORT_DISPLAYFROM, or SORT_DISPLAYTO is given as a sort criteria, or + * search query uses IMAP4 criteria, use the Socket client instead. */ if ($options['_query']['imap4'] || (!empty($options['sort']) && ((count($options['sort']) > 1) || - in_array(Horde_Imap_Client::SORT_REVERSE, $options['sort'])))) { + in_array(Horde_Imap_Client::SORT_REVERSE, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYFROM, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYTO, $options['sort'])))) { return $this->_getSocket()->search($this->_selected, $query, $options); } diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Cclient/Pop3.php b/framework/Imap_Client/lib/Horde/Imap/Client/Cclient/Pop3.php index b03fac040..338d15918 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Cclient/Pop3.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Cclient/Pop3.php @@ -237,13 +237,15 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient // POP 3 supports c-client search criteria only. $search_query = $query->build(); - /* If more than 1 sort criteria given, or if SORT_REVERSE is given - * as a sort criteria, or search query uses IMAP4 criteria, use the - * Socket client instead. */ + /* If more than 1 sort criteria given, or if SORT_REVERSE, + * SORT_DISPLAYFROM, or SORT_DISPLAYTO is given as a sort criteria, + * or search query uses IMAP4 criteria, fail. */ if ($search_query['imap4'] || (!empty($options['sort']) && ((count($options['sort']) > 1) || - in_array(Horde_Imap_Client::SORT_REVERSE, $options['sort'])))) { + in_array(Horde_Imap_Client::SORT_REVERSE, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYFROM, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYTO, $options['sort'])))) { throw new Horde_Imap_Client_Exception('Unsupported search criteria on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED); } diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php b/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php index 53bfd1b00..724f779f1 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php @@ -34,6 +34,8 @@ * RFC 5267 - ESORT * RFC 5464 - METADATA * + * draft-ietf-morg-sortdisplay-02 - SORT=DISPLAY + * * [NO RFC] - XIMAPPROXY * + Requires imapproxy v1.2.7-rc1 or later * + See http://lists.andrew.cmu.edu/pipermail/imapproxy-info/2008-October/000771.html and @@ -1506,6 +1508,8 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base Horde_Imap_Client::SORT_ARRIVAL => 'ARRIVAL', Horde_Imap_Client::SORT_CC => 'CC', Horde_Imap_Client::SORT_DATE => 'DATE', + Horde_Imap_Client::SORT_DISPLAYFROM => 'DISPLAYFROM', + Horde_Imap_Client::SORT_DISPLAYTO => 'DISPLAYTO', Horde_Imap_Client::SORT_FROM => 'FROM', Horde_Imap_Client::SORT_REVERSE => 'REVERSE', Horde_Imap_Client::SORT_SIZE => 'SIZE', @@ -1532,6 +1536,13 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base if (count(array_intersect($options['sort'], array_keys($sort_criteria))) === 0) { $options['sort'] = array(Horde_Imap_Client::SORT_ARRIVAL); } + + /* Make sure server supports DISPLAYFROM & DISPLAYTO. */ + if ((in_array(Horde_Imap_Client::SORT_DISPLAYFROM, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYTO, $options['sort'])) && + (!is_array($server_sort) || !in_array('DISPLAY', $server_sort))) { + $server_sort = false; + } } if ($server_sort) { @@ -1736,6 +1747,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base $slices = array(); foreach ($slices_list as $slice_start => $slice) { + $display_sort = false; $sorted = array(); if ($reverse) { @@ -1758,21 +1770,31 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base asort($sorted, SORT_NUMERIC); break; + case Horde_Imap_Client::SORT_DISPLAYFROM: + case Horde_Imap_Client::SORT_DISPLAYTO: + $display_sort = true; + // Fallthrough + case Horde_Imap_Client::SORT_CC: case Horde_Imap_Client::SORT_FROM: case Horde_Imap_Client::SORT_TO: if ($val == Horde_Imap_Client::SORT_CC) { $field = 'cc'; - } elseif ($val = Horde_Imap_Client::SORT_FROM) { + } elseif (in_array($val, array(Horde_Imap_Client::SORT_DISPLAYFROM, Horde_Imap_Client::SORT_FROM))) { $field = 'from'; } else { $field = 'to'; } foreach ($slice as $num) { - $sorted[$num] = empty($fetch_res[$num]['envelope'][$field]) - ? null - : $fetch_res[$num]['envelope'][$field][0]['mailbox']; + if (empty($fetch_res[$num]['envelope'][$field])) { + $sorted[$num] = null; + } else { + $tmp = ($display_sort && !empty($fetch_res[$num]['envelope'][$field][0]['personal'])) + ? 'personal' + : 'mailbox'; + $sorted[$num] = $fetch_res[$num]['envelope'][$field][0][$tmp]; + } } asort($sorted, SORT_LOCALE_STRING); break; diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php b/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php index 0f7ccac93..cefdddb7e 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php @@ -648,7 +648,10 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base // Only support a single query: an ALL search sorted by arrival. if (($options['_query']['query'] != 'ALL') || (!empty($options['sort']) && - ((count($options['sort']) > 1) || (reset($options['sort']) != Horde_Imap_Client::SORT_ARRIVAL)))) { + ((count($options['sort']) > 1) || + in_array(Horde_Imap_Client::SORT_ARRIVAL, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYFROM, $options['sort']) || + in_array(Horde_Imap_Client::SORT_DISPLAYTO, $options['sort'])))) { throw new Horde_Imap_Client_Exception('Server search not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED); } diff --git a/framework/Imap_Client/package.xml b/framework/Imap_Client/package.xml index 6382b995a..851a237d5 100644 --- a/framework/Imap_Client/package.xml +++ b/framework/Imap_Client/package.xml @@ -31,9 +31,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Added search and thread (message list) caching. -* Added PHP socket based POP3 driver. -* Initial release + * Support SORT=DISPLAY extension. + * Added search and thread (message list) caching. + * Added PHP socket based POP3 driver. + * Initial release