Back out support for using SM without Frames
[squirrelmail.git] / src / search.php
CommitLineData
c61bb006 1<?php
245a6892 2
35586184 3/**
a5ee5ac2 4 * search.php
35586184 5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
40fbe929 9 * IMAP search page
10 *
11 * $Id$
8f6f9ba5 12 * @package squirrelmail
40fbe929 13 * @link ftp://ftp.rfc-editor.org/in-notes/rfc3501.txt
14 * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr
15 *
16 * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas!
35586184 17 */
2d367c68 18
8f6f9ba5 19/** Path for SquirrelMail required files. */
86725763 20define('SM_PATH','../');
21
40fbe929 22/** SquirrelMail required files. */
08185f2a 23require_once(SM_PATH . 'include/validate.php');
b2e7eb53 24require_once(SM_PATH . 'functions/strings.php');
6b37252b 25require_once(SM_PATH . 'functions/imap_asearch.php');
86725763 26require_once(SM_PATH . 'functions/imap_mailbox.php');
b65c5db0 27require_once(SM_PATH . 'functions/imap_messages.php');
0ca9a6ec 28require_once(SM_PATH . 'functions/mime.php');
b2e7eb53 29require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()...
c61bb006 30
40fbe929 31/**
32 * @param string $a
33 * @param string $b
34 * @return bool strcoll()-like result
35 */
6b37252b 36function asearch_unhtml_strcoll($a, $b)
37{
38 return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b));
39}
40fbe929 40
41/**
42 * @param string $mailbox mailbox name
43 * @return string mailbox name ready to display
44 */
6b37252b 45function imap_get_mailbox_display($mailbox)
46{
3dffe83f 47 if (strtoupper($mailbox) == 'INBOX')
6b37252b 48 return _("INBOX");
49 return imap_utf7_decode_local($mailbox);
50}
56e0b3b7 51
40fbe929 52/**
53 * @param string $mailbox mailbox name
54 * @return string mailbox name ready to display
55 */
6b37252b 56function asearch_get_mailbox_display($mailbox)
57{
58 if ($mailbox == 'All Folders')
59 return _("All Folders");
60 return imap_get_mailbox_display($mailbox);
61}
0b97a708 62
40fbe929 63/**
64 * @param array $color color array
65 * @param string $txt text to display
66 * @return string title ready to display
67 */
05f5b952 68function asearch_get_title_display($color, $txt)
6b37252b 69{
70 return '<b><big>' . $txt . '</big></b>';
71}
0b97a708 72
40fbe929 73/**
74 * @param array $color color array
75 * @param string $txt text to display
76 * @return string error text ready to display
77 */
05f5b952 78function asearch_get_error_display($color, $txt)
6b37252b 79{
05f5b952 80 return '<font color="' . $color[2] . '">' . '<b><big>' . $txt . '</big></b></font>';
0b97a708 81}
6b37252b 82
40fbe929 83/**
84 * @param array $input_array array to serialize
85 * @return string a string containing a byte-stream representation of value that can be stored anywhere
86 */
6b37252b 87function asearch_serialize($input_array)
88{
6b37252b 89 return serialize($input_array);
0b97a708 90}
6b37252b 91
40fbe929 92/**
93 * @param string $input_string string to unserialize
94 * @return array
95 */
6b37252b 96function asearch_unserialize($input_string)
97{
6b37252b 98 return unserialize($input_string);
0b97a708 99}
6b37252b 100
40fbe929 101/**
102 * @param string $data_dir prefs data dir or dsn
103 * @param string $username the username
104 * @param string $key the pref key
105 * @param integer $index the pref key index
106 * @param string $default default value
107 * @return string pref value
108 */
6b37252b 109function asearch_getPref($data_dir, $username, $key, $index, $default = '')
110{
111 return getPref($data_dir, $username, $key . $index, $default);
0b97a708 112}
6b37252b 113
40fbe929 114/**
115 * @param string $data_dir prefs data dir or dsn
116 * @param string $username the username
117 * @param string $key the pref key
118 * @param integer $index the pref key index
119 * @param string $value pref value to set
120 * @return bool status
121 */
6b37252b 122function asearch_setPref($data_dir, $username, $key, $index, $value)
123{
124 return setPref($data_dir, $username, $key . $index, $value);
0b97a708 125}
6b37252b 126
40fbe929 127/**
128 * @param string $data_dir prefs data dir or dsn
129 * @param string $username the username
130 * @param string $key the pref key
131 * @param integer $index the pref key index
132 * @return bool status
133 */
6b37252b 134function asearch_removePref($data_dir, $username, $key, $index)
135{
136 return removePref($data_dir, $username, $key . $index);
0b97a708 137}
0b97a708 138
40fbe929 139/** Sanity checks, done before running the imap command and before push_recent */
05f5b952 140function asearch_check_query($where_array, $what_array, $exclude_array)
6b37252b 141{
05f5b952 142 global $imap_asearch_opcodes;
143
6b37252b 144 if (empty($where_array))
145 return _("Please enter something to search for");
146 if (count($exclude_array) == count($where_array))
147 return _("There must be at least one criteria to search for");
05f5b952 148 for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) {
149 $where = $where_array[$crit_num];
150 $what = $what_array[$crit_num];
151 if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != '')))
152 return _("Error in criteria argument");
153 }
6b37252b 154 return '';
56e0b3b7 155}
156
40fbe929 157/** Read the recent searches */
6b37252b 158function asearch_read_recent($data_dir, $username)
159{
160 global $recent_prefkeys;
161
162 $recent_array = array();
163 $recent_max = getPref($data_dir, $username, 'search_memory', 0);
164 for ($recent_num = 0; $recent_num < $recent_max; $recent_num++) {
165 foreach ($recent_prefkeys as $prefkey) {
166 $pref = asearch_getPref($data_dir, $username, $prefkey, $recent_num);
167/* if (!empty($pref))*/
168 $recent_array[$prefkey][$recent_num] = $pref;
169 }
170 if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) {
171 foreach ($recent_prefkeys as $key) {
172 array_pop($recent_array[$key]);
173 }
174 break;
175 }
176 }
177 return $recent_array;
56e0b3b7 178}
23a9084b 179
40fbe929 180/** Get the saved searches */
6b37252b 181function asearch_read_saved($data_dir, $username)
182{
183 global $saved_prefkeys;
184
185 $saved_array = array();
186 $saved_key = $saved_prefkeys[0];
187 for ($saved_count = 0; ; $saved_count++) {
188 $pref = asearch_getPref($data_dir, $username, $saved_key, $saved_count);
189 if (empty($pref))
190 break;
191 }
192 for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) {
193 foreach ($saved_prefkeys as $key) {
194 $saved_array[$key][$saved_num] = asearch_getPref($data_dir, $username, $key, $saved_num);
195 }
196 }
197 return $saved_array;
198}
199
40fbe929 200/** Save a recent search */
6b37252b 201function asearch_save_recent($data_dir, $username, $recent_index)
202{
203 global $recent_prefkeys, $saved_prefkeys;
204
205 $saved_array = asearch_read_saved($data_dir, $username);
206 $saved_index = count($saved_array[$saved_prefkeys[0]]);
207 $recent_array = asearch_read_recent($data_dir, $username);
208 $n = 0;
209 foreach ($recent_prefkeys as $key) {
210 $recent_slice = array_slice($recent_array[$key], $recent_index, 1);
211 if (!empty($recent_slice[0]))
212 asearch_setPref($data_dir, $username, $saved_prefkeys[$n], $saved_index, $recent_slice[0]);
213 else
214 asearch_removePref($data_dir, $username, $saved_prefkeys[$n], $saved_index);
215 $n++;
216 }
217}
218
40fbe929 219/** Write a recent search */
6b37252b 220function asearch_write_recent($data_dir, $username, $recent_array)
221{
222 global $recent_prefkeys;
223
224 $recent_max = getPref($data_dir, $username, 'search_memory', 0);
225 $recent_count = min($recent_max, count($recent_array[$recent_prefkeys[0]]));
226 for ($recent_num=0; $recent_num < $recent_count; $recent_num++) {
227 foreach ($recent_prefkeys as $key) {
228 asearch_setPref($data_dir, $username, $key, $recent_num, $recent_array[$key][$recent_num]);
229 }
230 }
231 for (; $recent_num < $recent_max; $recent_num++) {
232 foreach ($recent_prefkeys as $key) {
233 asearch_removePref($data_dir, $username, $key, $recent_num);
234 }
235 }
236}
237
40fbe929 238/** Forget a recent search */
6b37252b 239function asearch_forget_recent($data_dir, $username, $forget_index)
240{
241 global $recent_prefkeys;
242
243 $recent_array = asearch_read_recent($data_dir, $username);
244 foreach ($recent_prefkeys as $key) {
245 array_splice($recent_array[$key], $forget_index, 1);
246 }
247 asearch_write_recent($data_dir, $username, $recent_array);
248}
249
40fbe929 250/** Find a recent search */
251function asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
6b37252b 252{
253 global $recent_prefkeys;
254
255 $mailbox_string = asearch_serialize($mailbox_array);
256 $biop_string = asearch_serialize($biop_array);
257 $unop_string = asearch_serialize($unop_array);
258 $where_string = asearch_serialize($where_array);
259 $what_string = asearch_serialize($what_array);
260 $exclude_string = asearch_serialize($exclude_array);
40fbe929 261 $sub_string = asearch_serialize($sub_array);
6b37252b 262 $recent_count = count($recent_array[$recent_prefkeys[0]]);
263 for ($recent_num=0; $recent_num<$recent_count; $recent_num++) {
264 if (isset($recent_array[$recent_prefkeys[0]][$recent_num])) {
265 if (
266 $mailbox_string == $recent_array['asearch_recent_mailbox'][$recent_num] &&
267 $biop_string == $recent_array['asearch_recent_biop'][$recent_num] &&
268 $unop_string == $recent_array['asearch_recent_unop'][$recent_num] &&
269 $where_string == $recent_array['asearch_recent_where'][$recent_num] &&
270 $what_string == $recent_array['asearch_recent_what'][$recent_num] &&
40fbe929 271 $exclude_string == $recent_array['asearch_recent_exclude'][$recent_num] &&
272 $sub_string == $recent_array['asearch_recent_sub'][$recent_num]
6b37252b 273 )
c2d47d51 274 return $recent_num;
6b37252b 275 }
276 }
c2d47d51 277 return -1;
6b37252b 278}
279
40fbe929 280/** Push a recent search */
281function asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
6b37252b 282{
283 global $recent_prefkeys;
284
285 $recent_max = getPref($data_dir, $username, 'search_memory', 0);
286 if ($recent_max > 0) {
287 $recent_array = asearch_read_recent($data_dir, $username);
40fbe929 288 $recent_found = asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
c2d47d51 289 if ($recent_found >= 0) { // Remove identical recent
6b37252b 290 foreach ($recent_prefkeys as $key) {
c2d47d51 291 array_splice($recent_array[$key], $recent_found, 1);
6b37252b 292 }
c2d47d51 293 }
40fbe929 294 $input = array($where_array, $mailbox_array, $what_array, $biop_array, $unop_array, $exclude_array, $sub_array);
c2d47d51 295 $i = 0;
296 foreach ($recent_prefkeys as $key) {
297 array_unshift($recent_array[$key], asearch_serialize($input[$i]));
298 $i++;
299 }
300 asearch_write_recent($data_dir, $username, $recent_array);
6b37252b 301 }
302}
303
40fbe929 304/**
305 * Edit a recent search
2d2f8bb8 306 * @global array mailbox_array searched mailboxes
40fbe929 307 */
6b37252b 308function asearch_edit_recent($data_dir, $username, $index)
309{
40fbe929 310 global $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array;
6b37252b 311
312 $mailbox_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_mailbox', $index));
313 $biop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_biop', $index));
314 $unop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_unop', $index));
315 $where_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_where', $index));
316 $what_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_what', $index));
317 $exclude_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_exclude', $index));
40fbe929 318 $sub_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_sub', $index));
6b37252b 319}
320
40fbe929 321/** Edit the last recent search if the prefs permit it */
6b37252b 322function asearch_edit_last($data_dir, $username)
323{
324 if (getPref($data_dir, $username, 'search_memory', 0) > 0)
325 asearch_edit_recent($data_dir, $username, 0);
326}
327
40fbe929 328/** Edit a saved search */
6b37252b 329function asearch_edit_saved($data_dir, $username, $index)
330{
40fbe929 331 global $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array;
6b37252b 332
333 $mailbox_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_mailbox', $index));
334 $biop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_biop', $index));
335 $unop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_unop', $index));
336 $where_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_where', $index));
337 $what_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_what', $index));
338 $exclude_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_exclude', $index));
40fbe929 339 $sub_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_sub', $index));
6b37252b 340}
341
40fbe929 342/** Write a saved searches */
6b37252b 343function asearch_write_saved($data_dir, $username, $saved_array)
344{
345 global $saved_prefkeys;
346
347 $saved_count = count($saved_array[$saved_prefkeys[0]]);
348 for ($saved_num=0; $saved_num < $saved_count; $saved_num++) {
349 foreach ($saved_prefkeys as $key) {
350 asearch_setPref($data_dir, $username, $key, $saved_num, $saved_array[$key][$saved_num]);
351 }
352 }
353 foreach ($saved_prefkeys as $key) {
354 asearch_removePref($data_dir, $username, $key, $saved_count);
355 }
356}
357
40fbe929 358/** Delete a saved search */
6b37252b 359function asearch_delete_saved($data_dir, $username, $saved_index)
360{
361 global $saved_prefkeys;
362
363 $saved_array = asearch_read_saved($data_dir, $username);
364 $asearch_keys = $saved_prefkeys;
365 foreach ($asearch_keys as $key) {
366 array_splice($saved_array[$key], $saved_index, 1);
367 }
368 asearch_write_saved($data_dir, $username, $saved_array);
369}
370
40fbe929 371/** Translate the input date to imap date to local date display, so the user can know if the date is wrong or illegal */
6b37252b 372function asearch_get_date_display($what)
373{
374 $what_parts = sqimap_asearch_parse_date($what);
375 if (count($what_parts) == 4) {
376 if (checkdate($what_parts[2], $what_parts[1], $what_parts[3])) {
edda50ae 377 $what_display = date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3]));
6b37252b 378 /*$what_display = $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3];*/
379 }
380 else
381 $what_display = _("(Illegal date)");
382 }
383 else
384 $what_display = _("(Wrong date)");
385 return $what_display;
386}
387
40fbe929 388/** Translate the query to rough natural display */
389function asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
6b37252b 390{
391 global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options;
392 global $imap_asearch_opcodes;
393
394 $last_mailbox = $mailbox_array[0];
395 if (empty($last_mailbox))
396 $last_mailbox = 'INBOX';
05f5b952 397 $query_display = '';
398 for ($crit_num=0; $crit_num < count($where_array); $crit_num++) {
399 if ((!isset($exclude_array[$crit_num])) || (!$exclude_array[$crit_num])) {
400 $cur_mailbox = $mailbox_array[$crit_num];
6b37252b 401 if (empty($cur_mailbox))
402 $cur_mailbox = 'INBOX';
05f5b952 403 $biop = asearch_nz($biop_array[$crit_num]);
404 if (($query_display == '') || ($cur_mailbox != $last_mailbox)) {
6b37252b 405 $mailbox_display = ' <B>' . asearch_get_mailbox_display($cur_mailbox) . '</B>';
05f5b952 406 if ($query_display == '')
6b37252b 407 $biop_display = _("In");
408 else
409 $biop_display = $imap_asearch_biops_in[$biop];
410 $last_mailbox = $cur_mailbox;
411 }
412 else {
413 $mailbox_display = '';
414 $biop_display = $imap_asearch_biops[$biop];
415 }
416 $biop_display = ' <U><I>' . $biop_display . '</I></U>';
05f5b952 417 $unop = $unop_array[$crit_num];
6b37252b 418 $unop_display = $imap_asearch_unops[$unop];
05f5b952 419 $where = $where_array[$crit_num];
6b37252b 420 $where_display = $imap_asearch_options[$where];
421 if ($unop_display != '')
422 $where_display = ' <U><I>' . $unop_display . ' ' . $where_display . '</I></U>';
423 else
424 $where_display = ' <U><I>' . $where_display . '</I></U>';
425 $what_type = $imap_asearch_opcodes[$where];
05f5b952 426 $what = $what_array[$crit_num];
427 if ($what_type) { /* Check opcode parameter */
428 if ($what == '')
429 $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)"));
6b37252b 430 else {
05f5b952 431 if ($what_type == 'adate')
432 $what_display = asearch_get_date_display($what);
6b37252b 433 else
a722a461 434 $what_display = htmlspecialchars($what);
05f5b952 435 $what_display = ' <B>' . $what_display . '</B>';
6b37252b 436 }
6b37252b 437 }
05f5b952 438 else {
439 if ($what)
440 $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)"));
441 else
442 $what_display = '';
443 }
444 $query_display .= ' ' . $biop_display . $mailbox_display . $where_display . $what_display;
6b37252b 445 }
446 }
05f5b952 447 return $query_display;
6b37252b 448}
449
40fbe929 450/** Handle the alternate row colors */
6b37252b 451function asearch_get_row_color($color, $row_num)
452{
453/*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/
454 $color_string = $color[4];
455 if ($GLOBALS['alt_index_colors']) {
456 if (($row_num % 2) == 0) {
457 if (!isset($color[12]))
458 $color[12] = '#EAEAEA';
459 $color_string = $color[12];
460 }
461 }
462 return $color_string;
463}
464
40fbe929 465/** Print a whole query array, recent or saved */
6b37252b 466function asearch_print_query_array($query_array, $query_keys, $action_array, $title)
467{
468 global $color;
469
470 echo "<br>\n";
920ec5ec 471 echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"');
472 echo html_tag('tr', html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=5'));
6b37252b 473 $main_key = $query_keys[0];
474 $query_count = count($query_array[$main_key]);
475 for ($query_num=0, $row_num=0; $query_num<$query_count; $query_num++) {
476 if (!empty($query_array[$main_key][$query_num])) {
477 echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num));
478
479 unset($search_array);
480 foreach ($query_keys as $query_key) {
481 $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]);
482 }
483 $mailbox_array = $search_array[1];
484 $biop_array = $search_array[3];
485 $unop_array = $search_array[4];
486 $where_array = $search_array[0];
487 $what_array = $search_array[2];
488 $exclude_array = $search_array[5];
40fbe929 489 $sub_array = $search_array[6];
490 $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
6b37252b 491
920ec5ec 492 echo html_tag('td', $query_num+1, 'right');
493 echo html_tag('td', $query_display, 'center', '', 'width="80%"');
6b37252b 494 foreach ($action_array as $action => $action_display) {
495 echo html_tag('td', '<a href=search.php?submit=' . $action . '&amp;rownum=' . $query_num . '>' . $action_display . '</a>', 'center');
496 }
497
498 echo '</tr>' . "\n";
499 $row_num++;
500 }
501 }
502 echo '</table>' . "\n";
503}
504
40fbe929 505/** Print the saved array */
6b37252b 506function asearch_print_saved($data_dir, $username)
507{
508 global $saved_prefkeys;
509
510 $saved_array = asearch_read_saved($data_dir, $username);
05f5b952 511 if (isset($saved_array[$saved_prefkeys[0]])) {
512 $saved_count = count($saved_array[$saved_prefkeys[0]]);
513 if ($saved_count > 0) {
514 $saved_actions = array('edit_saved' => _("edit"), 'search_saved' => _("search"), 'delete_saved' => _("delete"));
515 asearch_print_query_array($saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches"));
516 }
6b37252b 517 }
70c4fd84 518}
6c8388a9 519
40fbe929 520/** Print the recent array */
6b37252b 521function asearch_print_recent($data_dir, $username)
522{
523 global $recent_prefkeys;
524
525 $recent_array = asearch_read_recent($data_dir, $username);
05f5b952 526 if (isset($recent_array[$recent_prefkeys[0]])) {
527 $recent_count = count($recent_array[$recent_prefkeys[0]]);
528 $recent_max = min($recent_count, getPref($data_dir, $username, 'search_memory', 0));
529 if ($recent_max > 0) {
530 $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget"));
531 asearch_print_query_array($recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches"));
532 }
6b37252b 533 }
56e0b3b7 534}
535
40fbe929 536/** Build an <option> statement */
920ec5ec 537function asearch_opt($val, $sel, $tit)
6b37252b 538{
920ec5ec 539 return '<option value="' . $val . '"' . ($sel == $val ? ' selected' : '') . '>' . $tit . '</option>' . "\n";
6b37252b 540}
541
40fbe929 542/** Build a <select> statement from an array */
6b37252b 543function asearch_opt_array($var_name, $opt_array, $cur_val)
544{
545 $output = '<select name="' . $var_name . '">' . "\n";
546 foreach($opt_array as $val => $display)
547 $output .= asearch_opt($val, $cur_val, $display);
548 $output .= '</select>' . "\n";
549 return $output;
550}
551
40fbe929 552/** Verify that a mailbox exists */
920ec5ec 553function asearch_mailbox_exists($mailbox, $boxes)
554{
555 foreach ($boxes as $box) {
556 if ($box['unformatted'] == $mailbox)
557 return TRUE;
558 }
559 return FALSE;
560}
561
40fbe929 562/** Print one form row */
563function asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num)
6b37252b 564{
565 global $imap_asearch_biops_in, $imap_asearch_unops, $imap_asearch_options;
566 global $color;
567
920ec5ec 568 echo html_tag('tr', '', '', $color[4]);
6b37252b 569
920ec5ec 570 echo html_tag('td', '', 'center');
6b37252b 571/* Binary operator */
05f5b952 572 if ($row_num)
573 echo asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop);
6b37252b 574 else
575 echo /*'<input type="hidden" name="biop[0]" value="">' .*/ '<b>' . _("In") . '</b>';
576 echo "</td>\n";
577
920ec5ec 578 echo html_tag('td', '', 'center');
6b37252b 579/* Mailbox list */
920ec5ec 580 echo '<select name="mailbox[' . $row_num . ']">';
581 if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes)))
582 echo asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . asearch_get_mailbox_display($mailbox));
583 echo asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']');
40fbe929 584 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL);
585 echo '</select>' . "\n";
586
587/* Include Subfolders */
588 echo _("and&nbsp;subfolders:") . '<input type=checkbox name="sub[' . $row_num .']"' . ($sub ? ' CHECKED' : '') . '></td>' . "\n";
6b37252b 589
590/* Unary operator and Search location */
920ec5ec 591 echo html_tag('td',
05f5b952 592 asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop)
593 . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where),
6b37252b 594 'center');
595
596/* Text input */
b2e7eb53 597 $what_disp = htmlspecialchars($what);
920ec5ec 598 echo html_tag('td', '<input type="text" size="35" name="what[' . $row_num . ']" value="' . $what_disp . '">', 'center') . "\n";
6b37252b 599
600/* Exclude criteria */
920ec5ec 601 echo html_tag('td',
05f5b952 602 _("Exclude Criteria:") . '<input type=checkbox name="exclude[' . $row_num .']"' . ($exclude ? ' CHECKED' : '') . '>', 'center', '') . "\n";
6b37252b 603
604 echo "</tr>\n";
605}
606
40fbe929 607/** Print the search form */
608function asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
6b37252b 609{
610 global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html;
611 global $color;
612
613 /* Search Form */
5a383256 614 echo "<br>\n";
6b37252b 615 echo '<form action="search.php" name="form_asearch">' . "\n";
616
920ec5ec 617 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"');
618 echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5'));
edda50ae 619 $row_count = count($where_array);
6b37252b 620 for ($row_num = 0; $row_num < $row_count; $row_num++) {
edda50ae 621 $mailbox = asearch_nz($mailbox_array[$row_num]);
6b37252b 622 $biop = strip_tags(asearch_nz($biop_array[$row_num]));
623 $unop = strip_tags(asearch_nz($unop_array[$row_num]));
edda50ae 624 $where = strip_tags(asearch_nz($where_array[$row_num]));
6b37252b 625 $what = asearch_nz($what_array[$row_num]);
626 $exclude = strip_tags(asearch_nz($exclude_array[$row_num]));
40fbe929 627 $sub = strip_tags(asearch_nz($sub_array[$row_num]));
628 asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num);
6b37252b 629 }
630 echo '</table>' . "\n";
631
632/* Submit buttons */
920ec5ec 633 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
6b37252b 634 echo html_tag('tr',
635 html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n"
636 . html_tag('td', getButton('SUBMIT', 'submit', $add_criteria_button_html), 'center') . "\n"
637 . html_tag('td', getButton('SUBMIT', 'submit', $del_all_button_html), 'center') . "\n"
638 . html_tag('td', getButton('SUBMIT', 'submit', $del_excluded_button_html), 'center') . "\n"
639 );
640 echo '</table>' . "\n";
641 echo '</form>' . "\n";
642}
643
40fbe929 644/** Print the $msgs messages from $mailbox mailbox */
c2d47d51 645function asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, $cnt, $sort, $color, $where, $what)
6b37252b 646{
cf6cb8b1 647 if ($cnt > 0) {
c2d47d51 648 global $allow_server_sort, $allow_thread_sort, $thread_sort_messages;
649
650 $thread_sort_messages = 0;
651 if ($allow_thread_sort) {
652 global $data_dir, $username;
653 $thread_sort_messages = getPref($data_dir, $username, 'thread_' . $mailbox);
654 $msort = $msgs;
655 $real_sort = 6;
656 }
657 elseif ($allow_server_sort) {
658 $msort = $msgs;
659 $real_sort = 6;
660 }
661 else {
662 $msort = calc_msort($msgs, $sort);
663 $real_sort = $sort;
664 }
665 $mailbox_display = asearch_get_mailbox_display($mailbox);
666 echo html_tag('div', '<b><big>' . _("Folder:") . ' '. $mailbox_display . '</big></b>','center') . "\n";
70f1b6b5 667
6b37252b 668 $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt);
c2d47d51 669 $toggle_all = get_selectall_link(1, $real_sort);
70f1b6b5 670
6b37252b 671 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
0fd2f513 672
6b37252b 673 echo '<tr><td>';
c2d47d51 674 mail_message_listing_beginning($imapConnection, $mailbox, $real_sort, $msg_cnt_str, $toggle_all, 1);
6b37252b 675 echo '</td></tr>';
70f1b6b5 676
6b37252b 677 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
70f1b6b5 678
6b37252b 679 echo '<tr><td>';
680 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
681 echo ' <tr><td>';
70f1b6b5 682
6b37252b 683 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
684 echo ' <tr><td>';
c2d47d51 685 printHeader($mailbox, $sort, $color, !$thread_sort_messages);
686 displayMessageArray($imapConnection, $cnt, 1, $msort, $mailbox, $real_sort, $color, $cnt, $where, $what);
6b37252b 687 echo ' </td></tr>';
688 echo ' </table>';
689 echo ' </td></tr>';
690 echo ' </table>';
691 mail_message_listing_end($cnt, '', $msg_cnt_str, $color);
692 echo '</td></tr>';
70f1b6b5 693
6b37252b 694 echo '</table>';
695 }
59a623e6 696}
697
40fbe929 698/**
699 * @param array $boxes mailboxes array (reference)
700 * @return array selectable unformatted mailboxes names
701 */
702function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes)
703{
704 $mboxes_array = array();
705 $boxcount = count($boxes);
706 for ($boxnum=0; $boxnum<$boxcount; $boxnum++) {
707 if (!in_array('noselect', $boxes[$boxnum]['flags']))
708 $mboxes_array[] = $boxes[$boxnum]['unformatted'];
709 }
710 return $mboxes_array;
711}
712
0d672ac0 713/* ------------------------ main ------------------------ */
6b37252b 714/* get globals we may need */
6b37252b 715sqgetGlobalVar('username', $username, SQ_SESSION);
716sqgetGlobalVar('key', $key, SQ_COOKIE);
bfc5b989 717sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); /* we really need this? */
e5cbf2f9 718sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); /* do we really need this? */
c1cb7ba4 719
40fbe929 720$recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_biop', 'asearch_recent_unop', 'asearch_recent_exclude', 'asearch_recent_sub');
721$saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_biop', 'asearch_saved_unop', 'asearch_saved_exclude', 'asearch_saved_sub');
722/*$asearch_keys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/
6b37252b 723
724$search_button_html = _("Search");
725$search_button_text = asearch_unhtmlentities($search_button_html);
726$add_criteria_button_html = _("Add New Criteria");
727$add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html);
34a85c56 728$del_excluded_button_html = _("Remove Excluded Criteria");
6b37252b 729$del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html);
34a85c56 730$del_all_button_html = _("Remove All Criteria");
6b37252b 731$del_all_button_text = asearch_unhtmlentities($del_all_button_html);
732
733$imap_asearch_options = array(
734/* <message set>, */
735/*'ALL' is binary operator */
736 'ANSWERED' => _("Answered"),
737 'BCC' => _("Bcc"),
738 'BEFORE' => _("Before"),
739 'BODY' => _("Message Body"),
740 'CC' => _("CC"),
741 'DELETED' => _("Deleted"),
742 'DRAFT' => _("Draft"),
743 'FLAGGED' => _("Flagged"),
744 'FROM' => _("Sent By"),
745 'HEADER' => _("Header Field"),
746 'KEYWORD' => _("Keyword"),
747 'LARGER' => _("Larger Than"),
748 'NEW' => _("New"),
749/*'NOT' is unary operator */
750 'OLD' => _("Old"),
751 'ON' => _("On"),
752/*'OR' is binary operator */
753 'RECENT' => _("Recent"),
754 'SEEN' => _("Seen"),
755 'SENTBEFORE' => _("Sent Before"),
756 'SENTON' => _("Sent On"),
757 'SENTSINCE' => _("Sent Since"),
758 'SINCE' => _("Since"),
759 'SMALLER' => _("Smaller Than"),
760 'SUBJECT' => _("Subject Contains"),
761 'TEXT' => _("Header and Body"),
762 'TO' => _("Sent To"),
763/*'UID' => 'anum',*/
764/*'UNANSWERED' => '',
765 'UNDELETED' => '',
766 'UNDRAFT' => '',
767 'UNFLAGGED' => '',
768 'UNKEYWORD' => _("Unkeyword"),
769 'UNSEEN' => _("Unseen"),*/
770);
771uasort($imap_asearch_options, 'asearch_unhtml_strcoll');
772
773$imap_asearch_unops = array(
774 '' => '',
775 'NOT' => _("Not")
776);
777
778$imap_asearch_biops_in = array(
779 'ALL' => _("And In"),
780 'OR' => _("Or In")
781);
782
783$imap_asearch_biops = array(
784 'ALL' => _("And"),
785 'OR' => _("Or")
786);
787
2d2f8bb8 788/** How we did enter the form
789 * - unset : Enter key, or called from outside (eg read_body)
790 * - $search_button_text : Search button
791 * - 'Search_no_update' : Search but don't update recent
792 * - 'Search_last' : Same as no_update but reload and search last
793 * - 'Search_silent' : Same as no_update but only display results
794 * - $add_criteria_button_text : Add New Criteria button
795 * - $del_excluded_button_text : Remove Excluded Criteria button
796 * - $del_all_button_text : Remove All Criteria button
797 * - 'save_recent'
798 * - 'search_recent'
799 * - 'forget_recent'
800 * - 'edit_saved'
801 * - 'search_saved'
802 * - 'delete_saved'
803 * @global string $submit
804 */
6b37252b 805if (isset($_GET['submit']))
806 $submit = strip_tags($_GET['submit']);
807
2d2f8bb8 808/** Searched mailboxes
809 * @global array $mailbox_array
810 */
6b37252b 811if (isset($_GET['mailbox'])) {
812 $mailbox_array = $_GET['mailbox'];
813 if (!is_array($mailbox_array))
814 $mailbox_array = array($mailbox_array);
56e0b3b7 815}
6b37252b 816else
817 $mailbox_array = array();
818
2d2f8bb8 819/** Binary operators
820 * @global array $biop_array
821 */
6b37252b 822if (isset($_GET['biop'])) {
823 $biop_array = $_GET['biop'];
824 if (!is_array($biop_array))
825 $biop_array = array($biop_array);
c1cb7ba4 826}
6b37252b 827else
828 $biop_array = array();
c1cb7ba4 829
2d2f8bb8 830/** Unary operators
831 * @global array $unop_array
832 */
6b37252b 833if (isset($_GET['unop'])) {
834 $unop_array = $_GET['unop'];
835 if (!is_array($unop_array))
836 $unop_array = array($unop_array);
548a552a 837}
6b37252b 838else
839 $unop_array = array();
840
2d2f8bb8 841/** Where to search
842 * @global array $where_array
843 */
6b37252b 844if (isset($_GET['where'])) {
845 $where_array = $_GET['where'];
846 if (!is_array($where_array))
847 $where_array = array($where_array);
848}
849else
850 $where_array = array();
851
2d2f8bb8 852/** What to search
853 * @global array $what_array
854 */
6b37252b 855if (isset($_GET['what'])) {
856 $what_array = $_GET['what'];
857 if (!is_array($what_array))
858 $what_array = array($what_array);
859}
860else
861 $what_array = array();
862
2d2f8bb8 863/** Whether to exclude this criteria from search
864 * @global array $exclude_array
865 */
6b37252b 866if (isset($_GET['exclude']))
867 $exclude_array = $_GET['exclude'];
868else
869 $exclude_array = array();
870
2d2f8bb8 871/** Search within subfolders
872 * @global array $sub_array
873 */
40fbe929 874if (isset($_GET['sub']))
875 $sub_array = $_GET['sub'];
876else
877 $sub_array = array();
878
2d2f8bb8 879/** Row number used by recent and saved stuff
880 */
c2d47d51 881if (isset($_GET['rownum']))
6b37252b 882 $submit_rownum = strip_tags($_GET['rownum']);
c2d47d51 883
2d2f8bb8 884/** Change global sort
885 */
c2d47d51 886if (sqgetGlobalVar('newsort', $newsort, SQ_GET)) {
887 setPref($data_dir, $username, 'sort', $newsort);
888 $sort = $newsort;
889 sqsession_register($sort, 'sort');
890 asearch_edit_last($data_dir, $username);
891}
892
2d2f8bb8 893/** Change mailbox threading
894 */
c2d47d51 895if (sqgetGlobalVar('set_thread', $set_thread, SQ_GET)) {
896 setPref($data_dir, $username, 'thread_' . $mailbox_array[0], ($set_thread == 1) ? 1 : 0 );
897 asearch_edit_last($data_dir, $username);
56e0b3b7 898}
6b37252b 899
900/* end of get globals */
901
40fbe929 902/** If TRUE, do not show search interface
903 * @global bool $search_silent
904 */
6b37252b 905$search_silent = FALSE; /* Default is normal behaviour */
906
907/* See how the page was called and fire off correct function */
908if ((!isset($submit) || empty($submit)) && !empty($where_array)) {
909 /* This happens when the Enter key is used or called from outside */
910 $submit = $search_button_text;
911 if (count($where_array) != count($unop_array)) /* Hack needed to handle coming back from read_body et als */
912 asearch_edit_last($data_dir, $username);
56e0b3b7 913}
6b37252b 914
915if (!isset($submit)) {
916 $submit = '';
56e0b3b7 917}
6b37252b 918else {
919 switch ($submit) {
920 case $search_button_text:
05f5b952 921 if (asearch_check_query($where_array, $what_array, $exclude_array) == '')
40fbe929 922 asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
6b37252b 923 break;
924 case 'Search_silent':
925 $search_silent = TRUE;
926 /*nobreak;*/
927 case 'Search_no_update':
928 $submit = $search_button_text;
929 break;
930 case $del_excluded_button_text:
931 $delarray = array_keys($exclude_array);
932 while (!empty($delarray)) {
933 $delrow = array_pop($delarray);
934 array_splice($mailbox_array, $delrow, 1);
935 array_splice($biop_array, $delrow, 1);
936 array_splice($unop_array, $delrow, 1);
937 array_splice($where_array, $delrow, 1);
938 array_splice($what_array, $delrow, 1);
939/* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */
40fbe929 940 array_splice($sub_array, $delrow, 1);
6b37252b 941 }
942 $exclude_array = array();
943 break;
944 case $del_all_button_text:
945 $mailbox_array = array();
946 $biop_array = array();
947 $unop_array = array();
948 $where_array = array();
949 $what_array = array();
950 $exclude_array = array();
40fbe929 951 $sub_array = array();
6b37252b 952 break;
953 case 'save_recent':
954 asearch_save_recent($data_dir, $username, $submit_rownum);
955 break;
956 case 'search_recent':
957 $submit = $search_button_text;
c2d47d51 958 asearch_edit_recent($data_dir, $username, $submit_rownum);
40fbe929 959 asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
c2d47d51 960 break;
6b37252b 961 case 'edit_recent': /* no link to do this, yet */
962 asearch_edit_recent($data_dir, $username, $submit_rownum);
963 break;
964 case 'forget_recent':
965 asearch_forget_recent($data_dir, $username, $submit_rownum);
966 break;
967 case 'search_saved':
968 $submit = $search_button_text;
c2d47d51 969 asearch_edit_saved($data_dir, $username, $submit_rownum);
40fbe929 970 asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
c2d47d51 971 break;
6b37252b 972 case 'edit_saved':
973 asearch_edit_saved($data_dir, $username, $submit_rownum);
974 break;
975 case 'delete_saved':
976 asearch_delete_saved($data_dir, $username, $submit_rownum);
977 break;
978 }
56e0b3b7 979}
23a9084b 980
6b37252b 981/* open IMAP connection */
982$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
983/* get mailbox names once here */
984$boxes = sqimap_mailbox_list($imapConnection);
99f3175e 985/* ensure we have a valid default mailbox name */
edda50ae 986$mailbox = asearch_nz($mailbox_array[0]);
987if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?)
988 $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;)
99f3175e 989
6b37252b 990if (isset($composenew) && $composenew) {
991 $comp_uri = "../src/compose.php?mailbox=" . urlencode($mailbox) .
992 "&amp;session=$composesession&amp;attachedmessages=true&amp";
993 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
56e0b3b7 994}
6b37252b 995else
996 displayPageHeader($color, $mailbox);
184ef883 997
6b37252b 998do_hook('search_before_form');
d81e351b 999
6b37252b 1000if (!$search_silent) {
920ec5ec 1001 echo html_tag('table',
1002 html_tag('tr', "\n" .
1003 html_tag('td', asearch_get_title_display($color, _("Search")), 'center', $color[0])
6b37252b 1004 ) ,
1005 '', '', 'width="100%"') . "\n";
1006 asearch_print_saved($data_dir, $username);
1007 asearch_print_recent($data_dir, $username);
edda50ae 1008 if (empty($where_array)) {
40fbe929 1009 global $sent_folder;
1010
edda50ae 1011 $mailbox_array[0] = $mailbox;
1012 $biop_array[0] = '';
1013 $unop_array[0] = '';
40fbe929 1014 if ($mailbox == $sent_folder)
1015 $where_array[0] = 'TO';
1016 else
1017 $where_array[0] = 'FROM';
edda50ae 1018 $what_array[0] = '';
1019 $exclude_array[0] = '';
40fbe929 1020 $sub_array[0] = '';
edda50ae 1021 }
1022 if ($submit == $add_criteria_button_text) {
1023 $last_index = max(count($where_array) - 1, 0);
1024 $mailbox_array[] = asearch_nz($mailbox_array[$last_index]);
1025 $biop_array[] = asearch_nz($biop_array[$last_index]);
1026 $unop_array[] = asearch_nz($unop_array[$last_index]);
1027 $where_array[] = asearch_nz($where_array[$last_index]);
1028 $what_array[] = asearch_nz($what_array[$last_index]);
1029 $exclude_array[] = asearch_nz($exclude_array[$last_index]);
40fbe929 1030 $sub_array[] = asearch_nz($sub_array[$last_index]);
edda50ae 1031 }
40fbe929 1032 asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
6b37252b 1033}
1034
d81e351b 1035/*********************************************************************
1036 * Check to see if we can use cache or not. Currently the only time *
1037 * when you will not use it is when a link on the left hand frame is *
1038 * used. Also check to make sure we actually have the array in the *
1039 * registered session data. :) *
1040 *********************************************************************/
edda50ae 1041if (!isset($use_mailbox_cache))
d81e351b 1042 $use_mailbox_cache = 0;
d81e351b 1043
88cb1b4d 1044do_hook('search_after_form');
56e0b3b7 1045
6b37252b 1046if ($submit == $search_button_text) {
920ec5ec 1047 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
1048 echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5]));
40fbe929 1049 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]));
05f5b952 1050 echo '</table><br>' . "\n";
1051
1052 $query_error = asearch_check_query($where_array, $what_array, $exclude_array);
6b37252b 1053 if ($query_error != '')
920ec5ec 1054 echo '<br>' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n";
6b37252b 1055 else {
c2d47d51 1056
40fbe929 1057 // Disable thread sort for now if there is more than one mailbox or at least one 'All Folders'
c2d47d51 1058 global $allow_thread_sort;
1059 $old_allow_thread_sort = $allow_thread_sort;
40fbe929 1060 $allow_thread_sort = ((count(array_unique($mailbox_array)) <= 1) && (!in_array('All Folders', $mailbox_array)));
6b37252b 1061
40fbe929 1062 $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
1063 $mboxes_msgs = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
6b37252b 1064 if (empty($mboxes_msgs))
920ec5ec 1065 echo '<br>' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n";
6b37252b 1066 else {
1067 foreach($mboxes_msgs as $mailbox => $msgs) {
1068 sqimap_mailbox_select($imapConnection, $mailbox);
1069 $msgs = fillMessageArray($imapConnection, $msgs, count($msgs));
1070/* For now just keep the first criteria to make the regular search happy if the user tries to come back to search */
1071/* $where = asearch_serialize($where_array);
1072 $what = asearch_serialize($what_array);*/
1073 $where = $where_array[0];
1074 $what = $what_array[0];
c2d47d51 1075 asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, count($msgs), $sort, $color, urlencode($where), urlencode($what));
6b37252b 1076 }
1077 }
1078
c2d47d51 1079 $allow_thread_sort = $old_allow_thread_sort; // Restore thread sort
59a623e6 1080 }
56e0b3b7 1081}
1082
70c4fd84 1083do_hook('search_bottom');
6b37252b 1084sqimap_logout($imapConnection);
dcc1cc82 1085echo '</body></html>';
99d2a184 1086
dcc1cc82 1087?>