/* 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;
* 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
* </pre>
* Additionally, any sort criteria can be sorted in reverse order
* (instead of the default ascending order) by adding a
{
// 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);
}
// 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);
}
* 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
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',
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) {
$slices = array();
foreach ($slices_list as $slice_start => $slice) {
+ $display_sort = false;
$sorted = array();
if ($reverse) {
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;
// 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);
}
<api>alpha</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Added search and thread (message list) caching.
-* Added PHP socket based POP3 driver.
-* Initial release
+ <notes>* Support SORT=DISPLAY extension.
+ * Added search and thread (message list) caching.
+ * Added PHP socket based POP3 driver.
+ * Initial release
</notes>
<contents>
<dir name="/">