Have IMP_Search::createQuery() handle new subfolder searching
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 18 Nov 2010 23:54:07 +0000 (16:54 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 19 Nov 2010 20:10:48 +0000 (13:10 -0700)
imp/lib/Search.php
imp/lib/Views/ListMessages.php
imp/mailbox-mimp.php
imp/search-basic.php
imp/search.php

index 978fc7a..7206286 100644 (file)
@@ -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:
+     * <pre>
+     * 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.
+     * </pre>
      *
      * @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;
index c18d2a0..2ade2e7 100644 (file)
@@ -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 {
index 11d2780..fc72fc0 100644 (file)
@@ -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. */
index c2af2bc..58ad0d4 100644 (file)
@@ -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();
index 716bfa4..1d781c9 100644 (file)
@@ -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;
     }