+ for ($boxnum = 0; $boxnum < $boxcount; $boxnum++) {
+ if (!in_array('noselect', $boxes[$boxnum]['flags']))
+ $mboxes_array[] = $boxes[$boxnum]['unformatted'];
+ }
+ return $mboxes_array;
+}
+
+/* ------------------------ main ------------------------ */
+/* get globals we will need */
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
+sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+
+if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
+ $checkall = (int) $temp;
+}
+
+/**
+ * Retrieve the mailbox cache from the session.
+ */
+sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
+
+
+$search_button_html = _("Search");
+$search_button_text = asearch_unhtmlentities($search_button_html);
+$add_criteria_button_html = _("Add New Criteria");
+$add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html);
+$del_excluded_button_html = _("Remove Excluded Criteria");
+$del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html);
+$del_all_button_html = _("Remove All Criteria");
+$del_all_button_text = asearch_unhtmlentities($del_all_button_html);
+
+/** Maximum number of recent searches to handle
+ * Default 0
+ * @global integer $search_memory
+ */
+$search_memory = getPref($data_dir, $username, 'search_memory', 0);
+
+/** Advanced search control
+ * - 0 => allow basic interface only
+ * - 1 => allow advanced interface only
+ * - 2 => allow both
+ * Default 2
+ */
+$allow_advanced_search = asearch_nz($allow_advanced_search, 2);
+
+/**
+ * Toggle advanced/basic search
+ */
+if (sqgetGlobalVar('advanced', $search_advanced, SQ_GET)) {
+ setPref($data_dir, $username, 'search_advanced', $search_advanced & 1);
+}
+/** If 1, show advanced search interface
+ * Default from allow_advanced_search pref
+ * @global integer $search_advanced
+ */
+if ($allow_advanced_search > 1) {
+ $search_advanced = getPref($data_dir, $username, 'search_advanced', 0);
+} else {
+ $search_advanced = $allow_advanced_search;
+}
+if ($search_advanced) {
+/** Set recent prefkeys according to $search_advanced
+ * @global array $recent_prefkeys
+ */
+ $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_unop', 'asearch_recent_biop', 'asearch_recent_exclude', 'asearch_recent_sub');
+
+/** Set saved prefkeys according to $search_advanced
+ * @global array $saved_prefkeys
+ */
+ $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_unop', 'asearch_saved_biop', 'asearch_saved_exclude', 'asearch_saved_sub');
+
+/*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/
+} else {
+ $recent_prefkeys = array('search_where', 'search_folder', 'search_what', 'search_unop');
+ $saved_prefkeys = array('saved_where', 'saved_folder', 'saved_what', 'saved_unop');
+}
+
+/** How we did enter the form
+ * - unset : Enter key, or called from outside (eg read_body)
+ * - $search_button_text : Search button
+ * - 'Search_no_update' : Search but don't update recent
+ * - 'Search_last' : Same as no_update but reload and search last
+ * - 'Search_silent' : Same as no_update but only display results
+ * - $add_criteria_button_text : Add New Criteria button
+ * - $del_excluded_button_text : Remove Excluded Criteria button
+ * - $del_all_button_text : Remove All Criteria button
+ * - 'save_recent'
+ * - 'search_recent'
+ * - 'forget_recent'
+ * - 'edit_saved'
+ * - 'search_saved'
+ * - 'delete_saved'
+ * @global string $submit
+ */
+if (isset($_GET['submit'])) {
+ $submit = strip_tags($_GET['submit']);
+}
+/** Searched mailboxes
+ * @global array $mailbox_array
+ */
+if (isset($_GET['mailbox'])) {
+ $mailbox_array = $_GET['mailbox'];
+ $targetmailbox = $_GET['mailbox'];
+ if (!is_array($mailbox_array)) {
+ $mailbox_array = array($mailbox_array);
+ }
+} else {
+ $mailbox_array = array();
+ $targetmailbox = array();
+}
+$aMailboxGlobalPref = array(
+ MBX_PREF_SORT => 0,
+ MBX_PREF_LIMIT => (int) $show_num,
+ MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge,
+ MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')
+ // MBX_PREF_FUTURE => (var) $future
+ );
+
+/**
+ * system wide admin settings and incoming vars.
+ */
+$aConfig = array(
+ 'allow_thread_sort' => $allow_thread_sort,
+ 'allow_server_sort' => $allow_server_sort,
+ 'user' => $username,
+ 'max_cache_size'
+ );
+
+/** Binary operators
+ * @global array $biop_array
+ */
+if (isset($_GET['biop'])) {
+ $biop_array = $_GET['biop'];
+ if (!is_array($biop_array))
+ $biop_array = array($biop_array);
+} else {
+ $biop_array = array();
+}
+/** Unary operators
+ * @global array $unop_array
+ */
+if (isset($_GET['unop'])) {
+ $unop_array = $_GET['unop'];
+ if (!is_array($unop_array))
+ $unop_array = array($unop_array);
+} else {
+ $unop_array = array();
+}
+/** Where to search
+ * @global array $where_array
+ */
+if (isset($_GET['where'])) {
+ $where_array = $_GET['where'];
+ if (!is_array($where_array)) {
+ $where_array = array($where_array);
+ }
+} else {
+ $where_array = array();
+}
+/** What to search
+ * @global array $what_array
+ */
+if (isset($_GET['what'])) {
+ $what_array = $_GET['what'];
+ if (!is_array($what_array)) {
+ $what_array = array($what_array);
+ }
+} else {
+ $what_array = array();
+}
+/** Whether to exclude this criteria from search
+ * @global array $exclude_array
+ */
+if (isset($_GET['exclude'])) {
+ $exclude_array = $_GET['exclude'];
+} else {
+ $exclude_array = array();
+}
+/** Search within subfolders
+ * @global array $sub_array
+ */
+if (isset($_GET['sub'])) {
+ $sub_array = $_GET['sub'];
+} else {
+ $sub_array = array();
+}
+/** Row number used by recent and saved stuff
+ */
+if (isset($_GET['rownum'])) {
+ $submit_rownum = strip_tags($_GET['rownum']);
+}
+/** Change global sort
+ */
+if (sqgetGlobalVar('srt', $temp, SQ_GET)) {
+ $srt = (int) $temp;
+ asearch_edit_last(1);
+ asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
+}
+if (sqgetGlobalVar('startMessage', $temp, SQ_GET)) {
+ $startMessage = (int) $temp;
+ asearch_edit_last(1);
+ asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
+}
+
+if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
+ $showall = (int) $temp;
+ asearch_edit_last(1);
+ asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
+}
+/**
+ * Incoming submit buttons from the message list with search results
+ */
+if (sqgetGlobalVar('moveButton', $moveButton, SQ_POST) ||
+ sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST) ||
+ sqgetGlobalVar('delete', $markDelete, SQ_POST) ||
+ sqgetGlobalVar('undeleteButton', $undeleteButton, SQ_POST) ||
+ sqgetGlobalVar('markRead', $markRead, SQ_POST) ||
+ sqgetGlobalVar('markUnread', $markUnread, SQ_POST) ||
+ sqgetGlobalVar('markFlagged', $markFlagged, SQ_POST) ||
+ sqgetGlobalVar('markUnflagged', $markUnflagged, SQ_POST) ||
+ sqgetGlobalVar('attache', $attache, SQ_POST)) {
+ asearch_edit_last(1);
+ $submit = '';
+ asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
+}
+
+
+
+/** Toggle show/hide saved searches
+ */
+if (sqgetGlobalVar('search_show_saved', $search_show_saved, SQ_GET)) {
+ setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1);
+}
+/** Toggle show/hide recent searches
+ */
+if (sqgetGlobalVar('search_show_recent', $search_show_recent, SQ_GET)) {
+ setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1);
+}
+// end of get globals
+
+/** If TRUE, do not show search interface
+ * Default FALSE
+ * @global bool $search_silent
+ */
+$search_silent = FALSE;
+
+/* See how the page was called and fire off correct function */
+if ((empty($submit)) && (!empty($where_array))) {
+ /* This happens when the Enter key is used or called from outside */
+ $submit = $search_button_text;
+ /* Hack needed to handle coming back from read_body et als */
+ if (count($where_array) != count($unop_array)) {
+ /**
+ * Hack to use already existen where and what vars.
+ * where now contains the initiator page of the messagelist
+ * and in this case 'search'. what contains an index to access
+ * the search history
+ */
+
+ sqgetGlobalVar('what',$what,SQ_GET);
+ asearch_edit_last($what);
+ }
+}
+
+if (!isset($submit)) {
+ $submit = '';
+} else {
+ switch ($submit) {
+ case $search_button_text:
+ if (asearch_check_query($where_array, $what_array, $exclude_array) == '') {
+ asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);