$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();
}
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;
}
$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();
}
/**
+ * 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