* 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;
$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;
/* 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 {
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. */
}
/* 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();
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');
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');
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;
}