From 7149a1c85edd0220ff68743e46f6cfa480bb663f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 18 Nov 2010 16:54:07 -0700 Subject: [PATCH] Have IMP_Search::createQuery() handle new subfolder searching --- imp/lib/Search.php | 40 ++++++++++++++++++++++++---------------- imp/lib/Views/ListMessages.php | 12 +++++------- imp/mailbox-mimp.php | 7 +++---- imp/search-basic.php | 12 +++++------- imp/search.php | 32 ++++++++++++++------------------ 5 files changed, 51 insertions(+), 52 deletions(-) diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 978fc7a27..720628695 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -193,36 +193,43 @@ class IMP_Search implements ArrayAccess, Iterator, Serializable * Creates the IMAP search query in the IMP session. * * @param array $criteria The search criteria array. - * @param array $mboxes The list of mailboxes to search. - * @param string $label The label to use for the search results. - * @param integer $type Query type. - * @param string $id Use as the mailbox ID. + * @param array $opts Additional options: + *
+     * id - (string) Use as the mailbox ID.
+     * label - (string) The label to use for the search results.
+     * mboxes - (array) The list of mailboxes to directly search.
+     * subfolders - (array) The list of mailboxes to do subfolder searches on.
+     * type - (integer) Query type.
+     * 
* * @return IMP_Search_Query Returns the query object. * @throws InvalidArgumentException */ - public function createQuery($criteria, $mboxes = array(), $label = null, - $type = self::CREATE_QUERY, $id = null) + public function createQuery($criteria, array $opts = array()) { - if (!is_null($id)) { - $id = $this->_strip($id); - } + $opts = array_merge(array( + 'id' => null, + 'label' => null, + 'mboxes' => array(), + 'subfolders' => array(), + 'type' => self::CREATE_QUERY + ), $opts); - switch ($type) { + switch ($opts['type']) { case self::CREATE_FILTER: $cname = 'IMP_Search_Filter'; break; case self::CREATE_QUERY: $cname = 'IMP_Search_Query'; - if (empty($mboxes)) { + if (empty($opts['mboxes']) && empty($opts['subfolders'])) { throw new InvalidArgumentException('Search query requires at least one mailbox.'); } break; case self::CREATE_VFOLDER: $cname = 'IMP_Search_Vfolder'; - if (empty($mboxes)) { + if (empty($opts['mboxes']) && empty($opts['subfolders'])) { throw new InvalidArgumentException('Search query requires at least one mailbox.'); } break; @@ -230,12 +237,13 @@ class IMP_Search implements ArrayAccess, Iterator, Serializable $ob = new $cname(array_filter(array( 'add' => $criteria, - 'id' => $id, - 'label' => $label, - 'mboxes' => $mboxes + 'id' => $this->_strip($opts['id']), + 'label' => $opts['label'], + 'mboxes' => $opts['mboxes'], + 'subfolders' => $opts['subfolders'] ))); - switch ($type) { + switch ($opts['type']) { case self::CREATE_FILTER: /* This will overwrite previous value, if it exists. */ $this->_search['filters'][$ob->id] = $ob; diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index c18d2a0e6..2ade2e72a 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -81,13 +81,11 @@ class IMP_Views_ListMessages /* Store the search in the session. */ if ($is_search) { $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); - $imp_search->createQuery( - $c_list, - array($args['qsearchmbox']), - null, - IMP_Search::CREATE_QUERY, - $mbox - ); + $imp_search->createQuery($c_list, array( + 'id' => $mbox, + 'mboxes' => array($args['qsearchmbox']), + 'type' => IMP_Search::CREATE_QUERY + )); } } } else { diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index 11d2780a9..fc72fc0c5 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -112,10 +112,9 @@ case 's': case 'rs': if (!empty($vars->search) && ($session->get('imp', 'protocol') == 'imap')) { /* Create the search query and reset the global mailbox variable. */ - $q_ob = $imp_search->createQuery( - array(new IMP_Search_Element_Text($vars->search, false)), - array(IMP::$mailbox) - ); + $q_ob = $imp_search->createQuery(array(new IMP_Search_Element_Text($vars->search, false)), array( + 'mboxes' => array(IMP::$mailbox) + )); IMP::setCurrentMailboxInfo(strval($q_ob)); /* Need to re-calculate these values. */ diff --git a/imp/search-basic.php b/imp/search-basic.php index c2af2bcfe..58ad0d422 100644 --- a/imp/search-basic.php +++ b/imp/search-basic.php @@ -76,13 +76,11 @@ if ($vars->search_basic_mbox) { } /* Store the search in the session. */ - $q_ob = $imp_search->createQuery( - $c_list, - array($vars->search_basic_mbox), - null, - IMP_Search::CREATE_QUERY, - IMP_Search::BASIC_SEARCH - ); + $q_ob = $imp_search->createQuery($c_list, array( + 'id' => IMP_Search::BASIC_SEARCH, + 'mboxes' => array($vars->search_basic_mbox), + 'type' => IMP_Search::CREATE_QUERY + )); /* Redirect to the mailbox screen. */ Horde::url('mailbox.php', true)->add('mailbox', strval($q_ob))->redirect(); diff --git a/imp/search.php b/imp/search.php index 716bfa4c8..1d781c928 100644 --- a/imp/search.php +++ b/imp/search.php @@ -270,13 +270,11 @@ if ($vars->criteria_form) { switch ($vars->search_type) { case 'filter': - $q_ob = $imp_search->createQuery( - $c_list, - array(), - $vars->search_label, - IMP_Search::CREATE_FILTER, - IMP::formMbox($vars->edit_query_filter, false) - ); + $q_ob = $imp_search->createQuery($c_list, array( + 'id' => IMP::formMbox($vars->edit_query_filter, false), + 'label' => $vars->search_label, + 'type' => IMP_Search::CREATE_FILTER + )); if ($vars->edit_query_filter) { $notification->push(sprintf(_("Filter \"%s\" edited successfully."), $vars->search_label), 'horde.success'); @@ -288,13 +286,12 @@ if ($vars->criteria_form) { break; case 'vfolder': - $q_ob = $imp_search->createQuery( - $c_list, - $vars->folder_list, - $vars->search_label, - IMP_Search::CREATE_VFOLDER, - IMP::formMbox($vars->edit_query_vfolder, false) - ); + $q_ob = $imp_search->createQuery($c_list, array( + 'id' => IMP::formMbox($vars->edit_query_vfolder, false), + 'label' => $vars->search_label, + 'mboxes' => Horde_Serialize::unserialize($vars->folders_form, Horde_Serialize::JSON), + 'type' => IMP_Search::CREATE_VFOLDER + )); if ($vars->edit_query_vfolder) { $notification->push(sprintf(_("Virtual Folder \"%s\" edited successfully."), $vars->search_label), 'horde.success'); @@ -306,10 +303,9 @@ if ($vars->criteria_form) { break; default: - $q_ob = $imp_search->createQuery( - $c_list, - $vars->folder_list - ); + $q_ob = $imp_search->createQuery($c_list, array( + 'mboxes' => Horde_Serialize::unserialize($vars->folders_form, Horde_Serialize::JSON) + )); $redirect_target = 'mailbox'; break; } -- 2.11.0