+ echo '</table>' . "\n";
+
+/* Submit buttons */
+ echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"' );
+ echo html_tag('tr',
+ html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n"
+ . html_tag('td', getButton('SUBMIT', 'submit', $add_criteria_button_html), 'center') . "\n"
+ . html_tag('td', getButton('SUBMIT', 'submit', $del_all_button_html), 'center') . "\n"
+ . html_tag('td', getButton('SUBMIT', 'submit', $del_excluded_button_html), 'center') . "\n"
+ );
+ echo '</table>' . "\n";
+ echo '</form>' . "\n";
+}
+
+/* print the $msgs messages from $mailbox mailbox */
+/* this is almost the original code */
+function asearch_print_mailbox_msgs($msgs, $mailbox, $cnt, $imapConnection, $where, $what, $usecache = false, $newsort = false)
+{
+ global $sort, $color;
+
+ if ($cnt > 0) {
+ $msort = calc_msort($msgs, $sort);
+ $showbox = asearch_get_mailbox_display($mailbox);
+ echo html_tag( 'div', '<b><big>' . _("Folder:") . ' '. $showbox.'</big></b>','center') . "\n";
+
+ $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt);
+ $toggle_all = get_selectall_link(1, $sort);
+
+ echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
+
+ echo '<tr><td>';
+ mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $toggle_all, 1);
+ echo '</td></tr>';
+
+ echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
+
+ echo '<tr><td>';
+ echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
+ echo ' <tr><td>';
+
+ echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
+ echo ' <tr><td>';
+ printHeader($mailbox, 6, $color, false);
+ displayMessageArray($imapConnection, $cnt, 1, $msort, $mailbox, $sort, $color, $cnt, $where, $what);
+ echo ' </td></tr>';
+ echo ' </table>';
+ echo ' </td></tr>';
+ echo ' </table>';
+ mail_message_listing_end($cnt, '', $msg_cnt_str, $color);
+ echo '</td></tr>';
+
+ echo '</table>';
+ }
+}
+
+/* ------------------------ main ------------------------ */
+global $allow_thread_sort;
+
+/* get globals we may need */
+
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
+sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+
+$recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_biop', 'asearch_recent_unop', 'asearch_recent_exclude');
+$saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_biop', 'asearch_saved_unop', 'asearch_saved_exclude');
+/*$asearch_keys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude');*/
+
+$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(s)");
+$del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html);
+$del_all_button_html = _("Remove All Criteria(s)");
+$del_all_button_text = asearch_unhtmlentities($del_all_button_html);
+
+$imap_asearch_options = array(
+/* <message set>, */
+/*'ALL' is binary operator */
+ 'ANSWERED' => _("Answered"),
+ 'BCC' => _("Bcc"),
+ 'BEFORE' => _("Before"),
+ 'BODY' => _("Message Body"),
+ 'CC' => _("CC"),
+ 'DELETED' => _("Deleted"),
+ 'DRAFT' => _("Draft"),
+ 'FLAGGED' => _("Flagged"),
+ 'FROM' => _("Sent By"),
+ 'HEADER' => _("Header Field"),
+ 'KEYWORD' => _("Keyword"),
+ 'LARGER' => _("Larger Than"),
+ 'NEW' => _("New"),
+/*'NOT' is unary operator */
+ 'OLD' => _("Old"),
+ 'ON' => _("On"),
+/*'OR' is binary operator */
+ 'RECENT' => _("Recent"),
+ 'SEEN' => _("Seen"),
+ 'SENTBEFORE' => _("Sent Before"),
+ 'SENTON' => _("Sent On"),
+ 'SENTSINCE' => _("Sent Since"),
+ 'SINCE' => _("Since"),
+ 'SMALLER' => _("Smaller Than"),
+ 'SUBJECT' => _("Subject Contains"),
+ 'TEXT' => _("Header and Body"),
+ 'TO' => _("Sent To"),
+/*'UID' => 'anum',*/
+/*'UNANSWERED' => '',
+ 'UNDELETED' => '',
+ 'UNDRAFT' => '',
+ 'UNFLAGGED' => '',
+ 'UNKEYWORD' => _("Unkeyword"),
+ 'UNSEEN' => _("Unseen"),*/
+);
+uasort($imap_asearch_options, 'asearch_unhtml_strcoll');
+
+$imap_asearch_unops = array(
+ '' => '',
+ 'NOT' => _("Not")
+);
+
+$imap_asearch_biops_in = array(
+ 'ALL' => _("And In"),
+ 'OR' => _("Or In")
+);
+
+$imap_asearch_biops = array(
+ 'ALL' => _("And"),
+ 'OR' => _("Or")
+);
+
+/*
+ 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(s) button
+ $del_all_button_text : Remove All Criteria(s) button
+ 'save_recent'
+ 'search_recent'
+ 'forget_recent'
+ 'edit_saved'
+ 'search_saved'
+ 'delete_saved'
+*/
+if (isset($_GET['submit']))
+ $submit = strip_tags($_GET['submit']);
+
+/* Used by search */
+if (isset($_GET['mailbox'])) {
+ $mailbox_array = $_GET['mailbox'];
+ if (!is_array($mailbox_array))
+ $mailbox_array = array($mailbox_array);
+}
+else
+ $mailbox_array = array();
+
+if (isset($_GET['biop'])) {
+ $biop_array = $_GET['biop'];
+ if (!is_array($biop_array))
+ $biop_array = array($biop_array);
+}
+else
+ $biop_array = array();
+
+if (isset($_GET['unop'])) {
+ $unop_array = $_GET['unop'];
+ if (!is_array($unop_array))
+ $unop_array = array($unop_array);
+}
+else
+ $unop_array = array();
+
+if (isset($_GET['where'])) {
+ $where_array = $_GET['where'];
+ if (!is_array($where_array))
+ $where_array = array($where_array);
+}
+else
+ $where_array = array();
+
+if (isset($_GET['what'])) {
+ $what_array = $_GET['what'];
+ if (!is_array($what_array))
+ $what_array = array($what_array);