- echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
- echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5]));
- echo html_tag('tr', html_tag('td', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array), 'center', $color[4]));
- echo '</table>' . "\n";
-
- flush();
-
- $query_error = asearch_check_query($where_array, $what_array, $exclude_array);
- if ($query_error != '')
- echo '<br>' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n";
- else {
- // Disable thread sort for now if there is more than one mailbox or at least one 'All Folders'
- global $allow_thread_sort;
- $old_allow_thread_sort = $allow_thread_sort;
- $allow_thread_sort = ((count(array_unique($mailbox_array)) <= 1) && (!in_array('All Folders', $mailbox_array)));
-
- $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
- $mboxes_msgs = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
- if (empty($mboxes_msgs))
- echo '<br>' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n";
- else {
- foreach($mboxes_msgs as $mailbox => $msgs) {
- echo '<br>';
- sqimap_mailbox_select($imapConnection, $mailbox);
- $msgs = fillMessageArray($imapConnection, $msgs, count($msgs));
-/* For now just keep the first criteria to make the regular search happy if the user tries to come back to search */
-/* $where = asearch_serialize($where_array);
- $what = asearch_serialize($what_array);*/
- $where = $where_array[0];
- $what = $what_array[0];
- asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, count($msgs), $sort, $color, urlencode($where), urlencode($what));
- }
- }
-
- $allow_thread_sort = $old_allow_thread_sort; // Restore thread sort
- }
+ $msgsfound = false;
+ echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
+ echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5]));
+ echo html_tag('tr', html_tag('td', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array), 'center', $color[4]));
+ echo '</table>' . "\n";
+
+ flush();
+
+ $query_error = asearch_check_query($where_array, $what_array, $exclude_array);
+ if ($query_error != '') {
+ echo '<br />' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n";
+ } else {
+ $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
+ /**
+ * Retrieve the search queries
+ */
+ $mboxes_mailbox = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
+ foreach($mboxes_mailbox as $mbx => $search) {
+ $aMailboxPrefSer=getPref($data_dir, $username, "pref_$mbx");
+
+ if ($aMailboxPrefSer) {
+ $aMailboxPref = unserialize($aMailboxPrefSer);
+ } else {
+ setUserPref($username,"pref_$mbx",serialize($aMailboxGlobalPref));
+ $aMailboxPref = $aMailboxGlobalPref;
+ }
+ if (isset($srt) && $targetmailbox == $mbx) {
+ $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
+ }
+ if (isset($startMessage) && $targetmailbox == $mbx) {
+ $aConfig['offset'] = $startMessage;
+ } else if (isset($aConfig['offset'])) {
+ unset($aConfig['offset']);
+ }
+ if (isset($showall) && $targetmailbox == $mbx) {
+ $aConfig['showall'] = $showall;
+ } else if (isset($aConfig['showall'])) {
+ unset($aConfig['showall']);
+ }
+ /**
+ * Set the max cache size to the number of mailboxes to avoid cache cleanups
+ * when searching all mailboxes
+ */
+ $aConfig['max_cache_size'] = count($mboxes_mailbox) +1;
+
+ /**
+ * until there is no per mailbox option screen to set prefs we override
+ * the mailboxprefs by the default ones
+ */
+ $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
+ $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
+ $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
+
+ $aConfig['search'] = $search['search'];
+ $aConfig['charset'] = $search['charset'];
+ $aConfig['setindex'] = 1; // $what $where = 'search'
+
+ $aMailbox = sqm_api_mailbox_select($imapConnection,$mbx,$aConfig,$aMailboxPref);
+ /**
+ * Handle form actions like flag / unflag, seen / unseen, delete
+ */
+ if (sqgetGlobalVar('mailbox',$postMailbox,SQ_POST)) {
+ if ($postMailbox === $mbx) {
+ handleMessageListForm($imapConnection,$aMailbox);
+ }
+ }
+ if (fetchMessageHeaders($imapConnection, $aMailbox)) {
+ $msgsfound = true;
+ echo '<br />';
+ asearch_print_mailbox_msgs($imapConnection, $aMailbox, $color);
+ flush();
+ }
+ /* add the mailbox to the cache */
+ $mailbox_cache[$aMailbox['NAME']] = $aMailbox;
+
+ }
+ }
+ if(!$msgsfound) {
+ echo '<br />' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n";
+ }