From: Michael M Slusarz Date: Wed, 10 Nov 2010 20:21:12 +0000 (-0700) Subject: Queries need to be built for each mailbox X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=43f1fffd5c839e3a18e90b40cfcf17fa2f5c7802;p=horde.git Queries need to be built for each mailbox Right now, it is impossible to do an advanced search query - in other words, a query that involves more than an IMAP query statement. Creating queries by mailbox allows advanced queries to be performed. For example, a query element can independently run a query, get the list of indices that match, and then put this result into the master IMAP server query with a UID sequence search. --- diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 71f4db923..92d14a21e 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -95,25 +95,22 @@ class IMP_Search implements ArrayAccess, Iterator, Serializable $mbox = ''; $sorted = new IMP_Indices(); - $query = $this[$id]->query; - if (!$query) { + if (!($query_list = $this[$id]->query)) { return $sorted; } - /* Prepare the search query. */ - if (!empty($ob)) { - $query->andSearch(array($ob)); - } - /* How do we want to sort results? */ $sortpref = IMP::getSort(null, true); if ($sortpref['by'] == Horde_Imap_Client::SORT_THREAD) { $sortpref['by'] = $GLOBALS['prefs']->getValue('sortdate'); } - foreach ($this[$id]->mboxes as $val) { - $results = $this->imapSearch($val, $query, array('reverse' => $sortpref['dir'], 'sort' => array($sortpref['by']))); - $sorted->add($val, $results['sort']); + foreach ($query_list as $mbox => $query) { + if (!empty($ob)) { + $query->andSearch(array($ob)); + } + $results = $this->imapSearch($mbox, $query, array('reverse' => $sortpref['dir'], 'sort' => array($sortpref['by']))); + $sorted->add($mbox, $results['sort']); } return $sorted; diff --git a/imp/lib/Search/Element.php b/imp/lib/Search/Element.php index 2c4694bb0..3e7244f0c 100644 --- a/imp/lib/Search/Element.php +++ b/imp/lib/Search/Element.php @@ -34,9 +34,13 @@ abstract class IMP_Search_Element implements Serializable /** * Adds the current query item to the query object. * - * @param Horde_Imap_Client_Search_Query The query object. + * @param string $mbox The mailbox to create + * the query for. + * @param Horde_Imap_Client_Search_Query $queryob The query object. + * + * @return Horde_Imap_Client_Search_Query The altered query object. */ - abstract public function createQuery($queryob); + abstract public function createQuery($mbox, $queryob); /** * Return search query text representation. diff --git a/imp/lib/Search/Element/Bulk.php b/imp/lib/Search/Element/Bulk.php index b51d7eb46..8c579a893 100644 --- a/imp/lib/Search/Element/Bulk.php +++ b/imp/lib/Search/Element/Bulk.php @@ -31,7 +31,7 @@ class IMP_Search_Element_Bulk extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $queryob->headerText('precedence', 'bulk', $this->_data); diff --git a/imp/lib/Search/Element/Date.php b/imp/lib/Search/Element/Date.php index ab3b0e00f..7b78b65a0 100644 --- a/imp/lib/Search/Element/Date.php +++ b/imp/lib/Search/Element/Date.php @@ -42,7 +42,7 @@ class IMP_Search_Element_Date extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $date = new DateTime($this->_data->d); $queryob->dateSearch($date, ($this->_data->t == self::DATE_ON) ? Horde_Imap_Client_Search_Query::DATE_ON : (($this->_data->t == self::DATE_BEFORE) ? Horde_Imap_Client_Search_Query::DATE_BEFORE : Horde_Imap_Client_Search_Query::DATE_SINCE)); diff --git a/imp/lib/Search/Element/Flag.php b/imp/lib/Search/Element/Flag.php index 0be7a427e..3d102fa6e 100644 --- a/imp/lib/Search/Element/Flag.php +++ b/imp/lib/Search/Element/Flag.php @@ -41,7 +41,7 @@ class IMP_Search_Element_Flag extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $queryob->flag($this->_data->f, $this->_data->s); diff --git a/imp/lib/Search/Element/Header.php b/imp/lib/Search/Element/Header.php index e796b2934..4b0406459 100644 --- a/imp/lib/Search/Element/Header.php +++ b/imp/lib/Search/Element/Header.php @@ -35,7 +35,7 @@ class IMP_Search_Element_Header extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $queryob->headerText($this->_data->h, $this->_data->t, $this->_data->n); diff --git a/imp/lib/Search/Element/Mailinglist.php b/imp/lib/Search/Element/Mailinglist.php index e58f343b2..1cbf9ab9a 100644 --- a/imp/lib/Search/Element/Mailinglist.php +++ b/imp/lib/Search/Element/Mailinglist.php @@ -30,7 +30,7 @@ class IMP_Search_Element_Mailinglist extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $queryob->headerText('list-id', '', $this->_data); diff --git a/imp/lib/Search/Element/Or.php b/imp/lib/Search/Element/Or.php index 3ded706ac..ecbc73894 100644 --- a/imp/lib/Search/Element/Or.php +++ b/imp/lib/Search/Element/Or.php @@ -16,7 +16,7 @@ class IMP_Search_Element_Or extends IMP_Search_Element { /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $ob = new Horde_Imap_Client_Search_Query(); $ob->orSearch(array($queryob)); diff --git a/imp/lib/Search/Element/Personal.php b/imp/lib/Search/Element/Personal.php index ba0c6c966..6a26742ea 100644 --- a/imp/lib/Search/Element/Personal.php +++ b/imp/lib/Search/Element/Personal.php @@ -30,7 +30,7 @@ class IMP_Search_Element_Personal extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $and_ob = new Horde_Imap_Client_Search_Query(); $identity = $GLOBALS['injector']->getInstance('IMP_Identity'); diff --git a/imp/lib/Search/Element/Recipient.php b/imp/lib/Search/Element/Recipient.php index 219a089fa..a5977ce84 100644 --- a/imp/lib/Search/Element/Recipient.php +++ b/imp/lib/Search/Element/Recipient.php @@ -32,7 +32,7 @@ class IMP_Search_Element_Recipient extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $and_ob = new Horde_Imap_Client_Search_Query(); diff --git a/imp/lib/Search/Element/Size.php b/imp/lib/Search/Element/Size.php index 9023dfa8e..1ede15317 100644 --- a/imp/lib/Search/Element/Size.php +++ b/imp/lib/Search/Element/Size.php @@ -39,7 +39,7 @@ class IMP_Search_Element_Size extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $queryob->size($this->_data->s, $this->_data->l); diff --git a/imp/lib/Search/Element/Text.php b/imp/lib/Search/Element/Text.php index d93ad6328..a32fdc45b 100644 --- a/imp/lib/Search/Element/Text.php +++ b/imp/lib/Search/Element/Text.php @@ -36,7 +36,7 @@ class IMP_Search_Element_Text extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { $queryob->text($this->_data->t, $this->_data->b, $this->_data->n); diff --git a/imp/lib/Search/Element/Within.php b/imp/lib/Search/Element/Within.php index 2986eb3f5..b86d03d55 100644 --- a/imp/lib/Search/Element/Within.php +++ b/imp/lib/Search/Element/Within.php @@ -45,7 +45,7 @@ class IMP_Search_Element_Within extends IMP_Search_Element /** */ - public function createQuery($queryob) + public function createQuery($mbox, $queryob) { /* Limited to day granularity because that is the technical * limit for IMAP servers without 'WITHIN' extension. */ diff --git a/imp/lib/Search/Query.php b/imp/lib/Search/Query.php index 3f4f12c33..606a810d3 100644 --- a/imp/lib/Search/Query.php +++ b/imp/lib/Search/Query.php @@ -116,7 +116,9 @@ class IMP_Search_Query implements Serializable * 'label' - (string) The query label. * 'mboxes' - (array) The list of mailboxes to query. * 'mid' - (string) The query ID with the search mailbox prefix. - * 'query' - (Horde_Imap_Client_Search_Query) The IMAP query object. + * 'query' - (array) The list of IMAP queries that comprise this search. + * Keys are mailbox names, values are + * Horde_Imap_Client_Search_Query objects. * 'querytext' - (string) The textual representation of the query. * * @@ -151,11 +153,17 @@ class IMP_Search_Query implements Serializable return IMP_Search::MBOX_PREFIX . $this->_id; case 'query': - $query = new Horde_Imap_Client_Search_Query(); - foreach ($this->_criteria as $elt) { - $query = $elt->createQuery($query); + $qout = array(); + + foreach ($this->_mboxes as $mbox) { + $query = new Horde_Imap_Client_Search_Query(); + foreach ($this->_criteria as $elt) { + $query = $elt->createQuery($mbox, $query); + } + $qout[$mbox] = $query; } - return $query; + + return $qout; case 'querytext': $text = array(_("Search"));