* Copyright 1999-2004 Jon Parise * Copyright 2002-2004 Michael Slusarz * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * URL Parameters: * --------------- * 'mailbox' -- If exists, don't show the folder selection list; use the * passed in mailbox value instead. */ /* Utility functions. */ /** * Generates the HTML for a day selection widget. * * @access public * * @param string $name The name of the widget. * @param optional integer $default The value to select by default. * Range: 1-31 * @param optional string $params Any additional parameters to * include in the tag. * * @return string The HTML ' : '>'; $html .= $day . ''; } return $html . "\n"; } /** * Generates the HTML for a month selection widget. * * @access public * * @param string $name The name of the widget. * @param optional integer $default The value to select by default. * @param optional string $params Any additional parameters to * include in the tag. * * @return string The HTML ' : '>'; $html .= strftime('%B', mktime(0, 0, 0, $month, 1)) . ''; } return $html . "\n"; } /** * Generates the HTML for a year selection widget. * * @access public * * @param integer $name The name of the widget. * @param integer $years The number of years to include. * If (+): future years * If (-): past years * @param optional string $default The timestamp to select by default. * @param optional string $params Any additional parameters to * include in the tag. * * @return string The HTML ' : '>'; $html .= $year . ''; } return $html . "\n"; } /* Defines used to determine what kind of field query we are dealing * with. */ define('IMP_SEARCH_HEADER', 1); define('IMP_SEARCH_BODY', 2); define('IMP_SEARCH_DATE', 3); /* Defines used to identify the flag input. */ define('IMP_SEARCH_FLAG_SEEN', 1); define('IMP_SEARCH_FLAG_ANSWERED', 2); define('IMP_SEARCH_FLAG_FLAGGED', 3); define('IMP_SEARCH_FLAG_DELETED', 4); /* The base search fields. */ $fields = array( 'from' => array( 'label' => _("From"), 'type' => IMP_SEARCH_HEADER ), 'to' => array( 'label' => _("To"), 'type' => IMP_SEARCH_HEADER ), 'cc' => array( 'label' => _("Cc"), 'type' => IMP_SEARCH_HEADER ), 'bcc' => array( 'label' => _("Bcc"), 'type' => IMP_SEARCH_HEADER ), 'subject' => array( 'label' => _("Subject"), 'type' => IMP_SEARCH_HEADER ), 'body' => array( 'label' => _("Body"), 'type' => IMP_SEARCH_BODY ), 'received_on' => array( 'label' => _("Received On"), 'type' => IMP_SEARCH_DATE ), 'received_until' => array( 'label' => _("Received Until"), 'type' => IMP_SEARCH_DATE ), 'received_since' => array( 'label' => _("Received Since"), 'type' => IMP_SEARCH_DATE ) ); define('IMP_BASE', dirname(__FILE__)); $authentication = OP_HALFOPEN; require_once IMP_BASE . '/lib/base.php'; require_once IMP_BASE . '/lib/Folder.php'; /* Get URL parameter data. */ $search = array(); if (Util::getFormData('no_match')) { require_once IMP_BASE . '/lib/Search.php'; $search = IMP_Search::retrieveUIQuery(); } else { $search['field'] = Util::getFormData('field', array()); if (!empty($search['field']) && !end($search['field'])) { array_pop($search['field']); } $search['field_end'] = count($search['field']); $search['mbox'] = Util::getFormData('mailbox'); $search['match'] = Util::getFormData('search_match'); $search['text'] = Util::getFormData('search_text'); $search['text_not'] = Util::getFormData('search_text_not'); $search['date'] = Util::getFormData('search_date'); $search['flag'] = Util::getFormData('search_flag'); $search['folders'] = Util::getFormData('search_folders', array()); } $curr_date = getdate(); /* Run through the action handlers. */ $actionID = Util::getFormData('actionID'); switch ($actionID) { case 'do_search': /* Create the search query. */ require_once HORDE_LIBS . 'Horde/IMAP/Search.php'; $query = &new IMAP_Search_Query(); /* Flag searches. */ $flag_names = array( IMP_SEARCH_FLAG_SEEN => 'seen', IMP_SEARCH_FLAG_ANSWERED => 'answered', IMP_SEARCH_FLAG_FLAGGED => 'flagged', IMP_SEARCH_FLAG_DELETED => 'deleted' ); foreach ($search['flag'] as $key => $val) { $flag = $flag_names[$key]; switch ($val) { case 0: $query->$flag(true); break; case 1: $query->$flag(false); break; } } /* Field searches. */ $search_array = array(); foreach ($search['field'] as $key => $val) { $ob = &new IMAP_Search_Query(); switch ($fields[$val]['type']) { case IMP_SEARCH_HEADER: if (!empty($search['text'][$key])) { $ob->header($val, $search['text'][$key], $search['text_not'][$key]); $search_array[] = &$ob; } break; case IMP_SEARCH_BODY: if (!empty($search['text'][$key])) { $ob->body($search['text'][$key], $search['text_not'][$key]); $search_array[] = &$ob; } break; case IMP_SEARCH_DATE: if (!empty($search['date'][$key]['day']) && !empty($search['date'][$key]['month']) && !empty($search['date'][$key]['year'])) { if ($val == 'received_on') { $ob->on($search['date'][$key]['day'], $search['date'][$key]['month'], $search['date'][$key]['year']); } elseif ($val == 'received_until') { $ob->before($search['date'][$key]['day'], $search['date'][$key]['month'], $search['date'][$key]['year']); } elseif ($val == 'received_since') { $ob->since($search['date'][$key]['day'], $search['date'][$key]['month'], $search['date'][$key]['year']); } $search_array[] = &$ob; } break; } } /* Search match. */ if ($search['match'] == 'and') { $query->imapAnd($search_array); } elseif ($search['match'] == 'or') { $query->imapOr($search_array); } /* Set the search query in the imp session. */ require_once IMP_BASE . '/lib/Search.php'; IMP_Search::createSearchQuery($query, $search['folders'], $search); /* Redirect to the Mailbox Screen. */ $url = Horde::applicationUrl('mailbox.php'); $url = Util::addParameter($url, 'mailbox', IMP_SEARCH_MBOX); header('Location: ' . $url); exit; break; case 'reset_search': $search['field'] = array(); $search['field_end'] = 0; $search['match'] = null; $search['date'] = $search['text'] = $search['text_not'] = $search['flag'] = array(); $search['folders'] = array(); break; case 'delete_field': $key = Util::getFormData('delete_field_id'); /* Unset all entries in array input and readjust ids. */ $vars = array('field', 'text', 'text_not', 'date'); foreach ($vars as $val) { unset($search[$val][$key]); if (!empty($search[$val])) { $search[$val] = array_values($search[$val]); } } $search['field_end'] = count($search['field']); break; } $title = _("Message Search"); require IMP_TEMPLATES . '/common-header.inc'; IMP::menu(); IMP::status(); require_once IMP_TEMPLATES . '/search/javascript.inc'; require IMP_TEMPLATES . '/search/header.inc'; /* Process the list of fields. */ for ($i = 0; $i <= $search['field_end']; $i++) { $last_field = ($i == $search['field_end']); $curr_field = (isset($search['field'][$i])) ? $search['field'][$i] : null; require IMP_TEMPLATES . '/search/fields.inc'; } $newcol = 1; $numcolumns = 1; $folderlist = ''; $imp_folder = &IMP_Folder::singleton(); if (!$search['mbox']) { $mailboxes = $imp_folder->flist_IMP(); $total = ceil(count($mailboxes) / 3); if (empty($search['folders'])) { /* Try to guess what folder the user wants to search */ if (!empty($imp['mailbox']) && $imp['mailbox'] != IMP_SEARCH_MBOX) { $search['folders'][] = $imp['mailbox']; } elseif (!empty($imp['thismailbox']) && $imp['mailbox'] != IMP_SEARCH_MBOX) { $search['folders'][] = $imp['thismailbox']; } elseif ($prefs->getValue('initial_page') && $prefs->getValue('initial_page') != 'folders.php') { $search['folders'][] = IMP::addPreambleString($prefs->getValue('initial_page')); } else { $search['folders'][] = 'INBOX'; } } foreach ($mailboxes as $mbox) { if (!empty($mbox['val'])) { $newcol++; $label = htmlspecialchars($mbox['val']); $folderlist .= '\n"; if (($newcol > $total) && ($numcolumns != 3)) { $newcol = 1; $numcolumns++; $folderlist .= "\n" . ''; } } } } require IMP_TEMPLATES . '/search/main.inc'; require $registry->getParam('templates', 'horde') . '/common-footer.inc';