add cor to significant contributors
[squirrelmail.git] / src / search.php
1 <?php
2
3 /**
4 * search.php
5 *
6 * IMAP search page
7 *
8 * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas!
9 *
10 * @author Alex Lemaresquier - Brainstorm <alex at brainstorm.fr>
11 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * @version $Id$
14 * @package squirrelmail
15 * @subpackage search
16 * @link http://www.ietf.org/rfc/rfc3501.txt
17 * @todo explain why references are used in function calls
18 */
19
20 /**
21 * Include the SquirrelMail initialization file.
22 */
23 require('../include/init.php');
24
25 /** SquirrelMail required files.
26 */
27 require_once(SM_PATH . 'functions/imap_asearch.php');
28 require_once(SM_PATH . 'functions/imap_messages.php');
29 require_once(SM_PATH . 'functions/imap_general.php');
30 require_once(SM_PATH . 'functions/mime.php');
31 require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()
32 require_once(SM_PATH . 'functions/forms.php');
33 require_once(SM_PATH . 'functions/date.php');
34
35 /** Prefs array ordinals. Must match $recent_prefkeys and $saved_prefkeys
36 */
37 define('ASEARCH_WHERE', 0);
38 define('ASEARCH_MAILBOX', 1);
39 define('ASEARCH_WHAT', 2);
40 define('ASEARCH_UNOP', 3);
41 define('ASEARCH_BIOP', 4);
42 define('ASEARCH_EXCLUDE', 5);
43 define('ASEARCH_SUB', 6);
44 define('ASEARCH_MAX', 7);
45
46 /** Name of session var
47 */
48 define('ASEARCH_CRITERIA', 'criteria');
49
50 /** Builds a href with params
51 * @param string $params optional parameters to GET
52 * @since 1.5.1
53 * @private
54 */
55 function asearch_get_href($params = '')
56 {
57 $href = 'search.php';
58 if ($params != '')
59 $href .= '?' . $params;
60 return $href;
61 }
62
63 /** Builds a [link]
64 * @param string $href (reference) URL
65 * @param string $text link name
66 * @param string $title link title attribute value
67 * @since 1.5.1
68 * @private
69 */
70 function asearch_get_link(&$href, $text, $title = '')
71 {
72 if ($title != '')
73 $title = ' title="' . $title . '"';
74 return '<a href="' . $href . '"' . $title . '>' . $text . '</a>';
75 }
76
77 /** Builds a toggle [link]
78 * @param integer $value
79 * @param string $action
80 * @param array $text_array
81 * @param array $title_array
82 * @since 1.5.1
83 * @private
84 */
85 function asearch_get_toggle_link($value, $action, $text_array, $title_array = array())
86 {
87 $asearch_nz=asearch_nz($title_array[$value]);
88 $asearch_get_href=asearch_get_href($action . '=' . (int)$value);
89 return asearch_get_link($asearch_get_href, $text_array[$value], $asearch_nz);
90 }
91
92 /**
93 * Array sort callback used to sort $imap_asearch_options
94 * @param string $a
95 * @param string $b
96 * @return bool strcoll()-like result
97 * @since 1.5.0
98 * @private
99 */
100 function asearch_unhtml_strcoll($a, $b)
101 {
102 // FIXME: Translation policy says "no html entities in translations"
103 return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b));
104 }
105
106
107 /**
108 * @param string $mailbox mailbox name utf7 encoded inc. special case INBOX
109 * @return string mailbox name ready to display (utf7 decoded or localized INBOX)
110 * @since 1.5.0
111 * @private
112 */
113 function imap_get_mailbox_display($mailbox)
114 {
115 if (strtoupper($mailbox) == 'INBOX')
116 return _("INBOX");
117 return imap_utf7_decode_local($mailbox);
118 }
119
120 /**
121 * @param string $mailbox mailbox name or special case 'All Folders'
122 * @return string mailbox name ready to display (utf7 decoded or localized 'All Folders')
123 * @since 1.5.0
124 * @private
125 */
126 function asearch_get_mailbox_display($mailbox)
127 {
128 if ($mailbox == 'All Folders')
129 return _("All Folders");
130 return imap_get_mailbox_display($mailbox);
131 }
132
133 /**
134 * @param array $color color array (unused)
135 * @param string $txt text to display
136 * @return string title ready to display
137 * @since 1.5.0
138 * @private
139 */
140 function asearch_get_title_display($color, $txt)
141 {
142 return '<b><big>' . $txt . '</big></b>';
143 }
144 /**
145 * @param array $color color array
146 * @param string $txt text to display
147 * @return string error text ready to display
148 * @since 1.5.0
149 * @private
150 */
151 function asearch_get_error_display($color, $txt)
152 {
153 return '<font color="' . $color[2] . '">' . '<b><big>' . $txt . '</big></b></font>';
154 }
155
156 /**
157 * @param array $input_array array to serialize
158 * @return string a string containing a byte-stream representation of value that can be stored anywhere
159 * @since 1.5.0
160 * @private
161 */
162 function asearch_serialize(&$input_array)
163 {
164 global $search_advanced;
165 if ($search_advanced)
166 return serialize($input_array);
167 return $input_array[0];
168 }
169
170 /**
171 * @param string $input_string string to unserialize
172 * @return array
173 * @since 1.5.0
174 * @private
175 */
176 function asearch_unserialize($input_string)
177 {
178 global $search_advanced;
179 if ($search_advanced)
180 return unserialize($input_string);
181 return array($input_string);
182 }
183
184 /**
185 * Gets user's advanced search preferences
186 *
187 * Arguments are different in 1.5.0.
188 * @param string $key the pref key
189 * @param integer $index the pref key index
190 * @param string $default default value
191 * @return string pref value
192 * @since 1.5.0
193 * @private
194 */
195 function asearch_getPref(&$key, $index, $default = '')
196 {
197 global $data_dir, $username, $search_advanced;
198 return getPref($data_dir, $username, $key . ($index + !$search_advanced), $default);
199 }
200
201 /**
202 * Sets user's advanced search preferences
203 *
204 * Arguments are different in 1.5.0.
205 * @param string $key the pref key
206 * @param integer $index the pref key index
207 * @param string $value pref value to set
208 * @return bool status
209 * @since 1.5.0
210 * @private
211 */
212 function asearch_setPref(&$key, $index, $value)
213 {
214 global $data_dir, $username, $search_advanced;
215 return setPref($data_dir, $username, $key . ($index + !$search_advanced), $value);
216 }
217
218 /**
219 * Deletes user's advanced search preferences
220 *
221 * Arguments are different in 1.5.0.
222 * @param string $key the pref key
223 * @param integer $index the pref key index
224 * @return bool status
225 * @since 1.5.0
226 * @private
227 */
228 function asearch_removePref(&$key, $index)
229 {
230 global $data_dir, $username, $search_advanced;
231 return removePref($data_dir, $username, $key . ($index + !$search_advanced));
232 }
233
234 /**
235 * Sanity checks, done before running the imap command and before calling push_recent
236 * @param array $where_array search location data
237 * @param array $what_array search criteria data
238 * @param array $exclude_array excluded criteria data
239 * @return string error message or empty string
240 * @since 1.5.0
241 * @private
242 */
243 function asearch_check_query(&$where_array, &$what_array, &$exclude_array)
244 {
245 global $imap_asearch_opcodes;
246
247 if (empty($where_array))
248 return _("Please enter something to search for");
249 if (count($exclude_array) == count($where_array))
250 return _("There must be at least one criteria to search for");
251 for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) {
252 $where = $where_array[$crit_num];
253 $what = $what_array[$crit_num];
254 if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != '')))
255 return _("Error in criteria argument");
256 }
257 return '';
258 }
259
260 /**
261 * Read the recent searches from the prefs
262 *
263 * Function arguments are different in 1.5.0
264 * @return array recent searches
265 * @since 1.5.0
266 * @private
267 */
268 function asearch_read_recent()
269 {
270 global $recent_prefkeys, $search_memory;
271
272 $recent_array = array();
273 $recent_num = 0;
274 for ($pref_num = 0; $pref_num < $search_memory; $pref_num++) {
275 foreach ($recent_prefkeys as $prefkey) {
276 $pref = asearch_getPref($prefkey, $pref_num);
277 /* if (!empty($pref))*/
278 $recent_array[$prefkey][$recent_num] = $pref;
279 }
280 if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) {
281 foreach ($recent_prefkeys as $key) {
282 array_pop($recent_array[$key]);
283 }
284 // break; //Disabled to support old search code broken prefs
285 }
286 else
287 $recent_num++;
288 }
289 return $recent_array;
290 }
291
292 /**
293 * Read the saved searches from the prefs
294 *
295 * Function arguments are different in 1.5.0
296 * @return array saved searches
297 * @since 1.5.0
298 * @private
299 */
300 function asearch_read_saved()
301 {
302 global $saved_prefkeys;
303
304 $saved_array = array();
305 $saved_key = $saved_prefkeys[0];
306 for ($saved_count = 0; ; $saved_count++) {
307 $pref = asearch_getPref($saved_key, $saved_count);
308 if (empty($pref))
309 break;
310 }
311 for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) {
312 foreach ($saved_prefkeys as $key) {
313 $saved_array[$key][$saved_num] = asearch_getPref($key, $saved_num);
314 }
315 }
316 return $saved_array;
317 }
318
319 /**
320 * Save a recent search to the prefs
321 *
322 * Function arguments are different in 1.5.0
323 * @param integer $recent_index
324 * @since 1.5.0
325 * @private
326 */
327 function asearch_save_recent($recent_index)
328 {
329 global $recent_prefkeys, $saved_prefkeys;
330
331 $saved_array = asearch_read_saved();
332 if (isset($saved_array[$saved_prefkeys[0]])) {
333 $saved_index = count($saved_array[$saved_prefkeys[0]]);
334 } else {
335 $saved_index = 0;
336 }
337 $recent_array = asearch_read_recent();
338 $n = 0;
339 foreach ($recent_prefkeys as $key) {
340 $recent_slice = array_slice($recent_array[$key], $recent_index, 1);
341 if (!empty($recent_slice[0]))
342 asearch_setPref($saved_prefkeys[$n], $saved_index, $recent_slice[0]);
343 else
344 asearch_removePref($saved_prefkeys[$n], $saved_index);
345 $n++;
346 }
347 }
348
349 /**
350 * Write a recent search to prefs
351 *
352 * Function arguments are different in 1.5.0
353 * @param array $recent_array
354 * @since 1.5.0
355 * @private
356 */
357 function asearch_write_recent(&$recent_array)
358 {
359 global $recent_prefkeys, $search_memory;
360
361 $recent_count = min($search_memory, count($recent_array[$recent_prefkeys[0]]));
362 for ($recent_num = 0; $recent_num < $recent_count; $recent_num++) {
363 foreach ($recent_prefkeys as $key) {
364 asearch_setPref($key, $recent_num, $recent_array[$key][$recent_num]);
365 }
366 }
367 for (; $recent_num < $search_memory; $recent_num++) {
368 foreach ($recent_prefkeys as $key) {
369 asearch_removePref($key, $recent_num);
370 }
371 }
372 }
373
374 /**
375 * Remove a recent search from prefs
376 *
377 * Function arguments are different in 1.5.0
378 * @param integer $forget_index removed search number
379 * @since 1.5.0
380 * @private
381 */
382 function asearch_forget_recent($forget_index)
383 {
384 global $recent_prefkeys;
385
386 $recent_array = asearch_read_recent();
387 foreach ($recent_prefkeys as $key) {
388 array_splice($recent_array[$key], $forget_index, 1);
389 }
390 asearch_write_recent($recent_array);
391 }
392
393 /**
394 * Find a recent search in the prefs (used to avoid saving duplicates)
395 * @param array $recent_array
396 * @param array $mailbox_array
397 * @param array $biop_array
398 * @param array $unop_array
399 * @param array $where_array
400 * @param array $what_array
401 * @param array $exclude_array
402 * @param array $sub_array
403 * @return integer
404 * @since 1.5.0
405 * @private
406 */
407 function asearch_find_recent(&$recent_array, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
408 {
409 global $recent_prefkeys, $search_advanced;
410
411 $where_string = asearch_serialize($where_array);
412 $mailbox_string = asearch_serialize($mailbox_array);
413 $what_string = asearch_serialize($what_array);
414 $unop_string = asearch_serialize($unop_array);
415 if ($search_advanced) {
416 $biop_string = asearch_serialize($biop_array);
417 $exclude_string = asearch_serialize($exclude_array);
418 $sub_string = asearch_serialize($sub_array);
419 }
420 $recent_count = count($recent_array[$recent_prefkeys[ASEARCH_WHERE]]);
421 for ($recent_num = 0; $recent_num < $recent_count; $recent_num++) {
422 if (isset($recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num])) {
423 if (
424 $where_string == $recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num] &&
425 $mailbox_string == $recent_array[$recent_prefkeys[ASEARCH_MAILBOX]][$recent_num] &&
426 $what_string == $recent_array[$recent_prefkeys[ASEARCH_WHAT]][$recent_num] &&
427 $unop_string == $recent_array[$recent_prefkeys[ASEARCH_UNOP]][$recent_num] &&
428 ((!$search_advanced) ||
429 ($biop_string == $recent_array[$recent_prefkeys[ASEARCH_BIOP]][$recent_num] &&
430 $exclude_string == $recent_array[$recent_prefkeys[ASEARCH_EXCLUDE]][$recent_num] &&
431 $sub_string == $recent_array[$recent_prefkeys[ASEARCH_SUB]][$recent_num]))
432 )
433 return $recent_num;
434 }
435 }
436 return -1;
437 }
438
439 /**
440 * Push a recent search into the prefs
441 * @param array $recent_array
442 * @param array $mailbox_array
443 * @param array $biop_array
444 * @param array $unop_array
445 * @param array $where_array
446 * @param array $what_array
447 * @param array $exclude_array
448 * @param array $sub_array
449 * @since 1.5.0
450 * @private
451 */
452 function asearch_push_recent(&$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
453 {
454 global $recent_prefkeys, $search_memory;
455 //global $what; // Hack to access issued search from read_body.php
456 $what = 1;
457 /**
458 * Update search history and store it in the session so we can retrieve the
459 * issued search when returning from an external page like read_body.php
460 */
461 $criteria[$what] = array($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
462 sqsession_register($criteria, ASEARCH_CRITERIA);
463 if ($search_memory > 0) {
464 $recent_array = asearch_read_recent();
465 $recent_found = asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
466 if ($recent_found >= 0) { // Remove identical recent
467 foreach ($recent_prefkeys as $key) {
468 array_splice($recent_array[$key], $recent_found, 1);
469 }
470 }
471 $input = array($where_array, $mailbox_array, $what_array, $unop_array, $biop_array, $exclude_array, $sub_array);
472 $i = 0;
473 foreach ($recent_prefkeys as $key) {
474 array_unshift($recent_array[$key], asearch_serialize($input[$i]));
475 $i++;
476 }
477 asearch_write_recent($recent_array);
478 }
479 }
480
481 /**
482 * Edit a recent search
483 *
484 * Function arguments are different in 1.5.0
485 * @global array mailbox_array searched mailboxes
486 * @param mixed $index
487 * @since 1.5.0
488 * @private
489 */
490 function asearch_edit_recent($index)
491 {
492 global $recent_prefkeys, $search_advanced;
493 global $where_array, $mailbox_array, $what_array, $unop_array;
494 global $biop_array, $exclude_array, $sub_array;
495
496 $where_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_WHERE], $index));
497 $mailbox_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_MAILBOX], $index));
498 $what_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_WHAT], $index));
499 $unop_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_UNOP], $index));
500 if ($search_advanced) {
501 $biop_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_BIOP], $index));
502 $exclude_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_EXCLUDE], $index));
503 $sub_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_SUB], $index));
504 }
505 }
506
507 /**
508 * Get last search criteria from session or prefs
509 *
510 * Function arguments are different in 1.5.0
511 * FIXME, try to avoid globals
512 * @param mixed $index
513 * @since 1.5.0
514 * @private
515 */
516 function asearch_edit_last($index) {
517 if (sqGetGlobalVar(ASEARCH_CRITERIA, $criteria, SQ_SESSION)) {
518 global $where_array, $mailbox_array, $what_array, $unop_array;
519 global $biop_array, $exclude_array, $sub_array;
520 $mailbox_array = $criteria[$index][0];
521 $biop_array = $criteria[$index][1];
522 $unop_array = $criteria[$index][2];
523 $where_array = $criteria[$index][3];
524 $what_array = $criteria[$index][4];
525 $exclude_array = $criteria[$index][5];
526 $sub_array = $criteria[$index][6];
527 unset($criteria[$index]);
528 //sqsession_unregister(ASEARCH_CRITERIA);
529 } else {
530 global $search_memory;
531 if ($search_memory > 0) {
532 asearch_edit_recent(0);
533 }
534 }
535 }
536
537 /**
538 * Edit a saved search
539 *
540 * Function arguments are different in 1.5.0
541 * @param mixed $index
542 * @since 1.5.0
543 * @private
544 */
545 function asearch_edit_saved($index)
546 {
547 global $saved_prefkeys, $search_advanced;
548 global $where_array, $mailbox_array, $what_array, $unop_array;
549 global $biop_array, $exclude_array, $sub_array;
550
551 $where_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_WHERE], $index));
552 $mailbox_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_MAILBOX], $index));
553 $what_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_WHAT], $index));
554 $unop_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_UNOP], $index));
555 if ($search_advanced) {
556 $biop_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_BIOP], $index));
557 $exclude_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_EXCLUDE], $index));
558 $sub_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_SUB], $index));
559 }
560 }
561
562 /**
563 * Write a saved search to the prefs
564 *
565 * Function arguments are different in 1.5.0
566 * @param array $saved_array
567 * @since 1.5.0
568 * @private
569 */
570 function asearch_write_saved(&$saved_array)
571 {
572 global $saved_prefkeys;
573
574 $saved_count = count($saved_array[$saved_prefkeys[0]]);
575 for ($saved_num=0; $saved_num < $saved_count; $saved_num++) {
576 foreach ($saved_prefkeys as $key) {
577 asearch_setPref($key, $saved_num, $saved_array[$key][$saved_num]);
578 }
579 }
580 foreach ($saved_prefkeys as $key) {
581 asearch_removePref($key, $saved_count);
582 }
583 }
584
585 /**
586 * Delete a saved search from the prefs
587 *
588 * Function arguments are different in 1.5.0
589 * @param integer $saved_index
590 * @since 1.5.0
591 * @private
592 */
593 function asearch_delete_saved($saved_index)
594 {
595 global $saved_prefkeys;
596
597 $saved_array = asearch_read_saved();
598 $asearch_keys = $saved_prefkeys;
599 foreach ($asearch_keys as $key) {
600 array_splice($saved_array[$key], $saved_index, 1);
601 }
602 asearch_write_saved($saved_array);
603 }
604
605 /** Translate the input date to imap date to local date display,
606 * so the user can know if the date is wrong or illegal
607 * @param string $what date string
608 * @return string locally formatted date or error text
609 * @since 1.5.0
610 * @private
611 */
612 function asearch_get_date_display(&$what)
613 {
614 $what_parts = sqimap_asearch_parse_date($what);
615 if (count($what_parts) == 4) {
616 if (checkdate($what_parts[2], $what_parts[1], $what_parts[3]))
617 return date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3]));
618 //return $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3];
619 return _("(Illegal date)");
620 }
621 return _("(Wrong date)");
622 }
623
624 /**
625 * Translate the query to rough natural display
626 * @param array $color
627 * @param array $mailbox_array
628 * @param array $biop_array
629 * @param array $unop_array
630 * @param array $where_array
631 * @param array $what_array
632 * @param array $exclude_array
633 * @param array $sub_array
634 * @return string rough natural query ready to display
635 * @since 1.5.0
636 * @private
637 */
638 function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
639 {
640 global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options;
641 global $imap_asearch_opcodes;
642
643 $last_mailbox = $mailbox_array[0];
644 if (empty($last_mailbox))
645 $last_mailbox = 'INBOX';
646 $query_display = '';
647 for ($crit_num=0; $crit_num < count($where_array); $crit_num++) {
648 if ((!isset($exclude_array[$crit_num])) || (!$exclude_array[$crit_num])) {
649 $cur_mailbox = $mailbox_array[$crit_num];
650 if (empty($cur_mailbox))
651 $cur_mailbox = 'INBOX';
652 $biop = asearch_nz($biop_array[$crit_num]);
653 if (($query_display == '') || ($cur_mailbox != $last_mailbox)) {
654 $mailbox_display = ' <b>' . htmlspecialchars(asearch_get_mailbox_display($cur_mailbox)) . '</b>';
655 if ($query_display == '')
656 $biop_display = _("In");
657 else
658 $biop_display = $imap_asearch_biops_in[$biop];
659 $last_mailbox = $cur_mailbox;
660 }
661 else {
662 $mailbox_display = '';
663 $biop_display = $imap_asearch_biops[$biop];
664 }
665 $unop = $unop_array[$crit_num];
666 $unop_display = $imap_asearch_unops[$unop];
667 if ($unop_display != '')
668 $unop_display .= ' ';
669 $where = $where_array[$crit_num];
670 $where_display = $unop_display . asearch_nz($imap_asearch_options[$where], $where);
671 $what_type = $imap_asearch_opcodes[$where];
672 $what = $what_array[$crit_num];
673 if ($what_type) { /* Check opcode parameter */
674 if ($what == '')
675 $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)"));
676 else {
677 if ($what_type == 'adate')
678 $what_display = asearch_get_date_display($what);
679 else
680 $what_display = htmlspecialchars($what);
681 $what_display = ' <b>' . $what_display . '</b>';
682 }
683 }
684 else {
685 if ($what)
686 $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)"));
687 else
688 $what_display = '';
689 }
690 if ($mailbox_display != '')
691 $query_display .= ' <u><i>' . $biop_display . '</i></u>' . $mailbox_display . ' <u><i>' . $where_display . '</i></u>' . $what_display;
692 else
693 $query_display .= ' <u><i>' . $biop_display . ' ' . $where_display . '</i></u>' . $what_display;
694 }
695 }
696 return $query_display;
697 }
698
699 /**
700 * Creates button
701 *
702 * @deprecated see form functions available in 1.5.1 and 1.4.3.
703 * @param string $type
704 * @param string $name
705 * @param string $value
706 * @param string $js
707 * @param bool $enabled
708 */
709 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
710 $disabled = ( $enabled ? '' : 'disabled ' );
711 $js = ( $js ? $js.' ' : '' );
712 return '<input '.$disabled.$js.
713 'type="'.$type.
714 '" name="'.$name.
715 '" value="'.$value .
716 '" style="padding: 0px; margin: 0px" />';
717 }
718
719
720 /** Handle the alternate row colors
721 * @param array $color color theme array
722 * @param integer $row_num
723 * @return string color value
724 * @since 1.5.0
725 * @private
726 */
727 function asearch_get_row_color(&$color, $row_num)
728 {
729 /*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/
730 $color_string = $color[4];
731 if ($GLOBALS['alt_index_colors']) {
732 if (($row_num % 2) == 0) {
733 if (!isset($color[12]))
734 $color[12] = '#EAEAEA';
735 $color_string = $color[12];
736 }
737 }
738 return $color_string;
739 }
740
741 /**
742 * Print a whole query array, recent or saved
743 *
744 * Function arguments are different in 1.5.0
745 * @param array $boxes (unused)
746 * @param array $query_array
747 * @param mixed $query_keys
748 * @param array $action_array
749 * @param mixed $title
750 * @param string $show_pref
751 * @since 1.5.0
752 * @private
753 */
754 function asearch_print_query_array(&$boxes, &$query_array, &$query_keys, &$action_array, $title, $show_pref)
755 {
756 global $color;
757 global $data_dir, $username;
758 global $use_icons, $icon_theme;
759
760 $show_flag = getPref($data_dir, $username, $show_pref, 0) & 1;
761 $use_icons_flag = ($use_icons) && ($icon_theme != 'none');
762 if ($use_icons_flag)
763 $text_array = array('<img src="' . SM_PATH . 'images/minus.png" border="0" height="7" width="7" />',
764 '<img src="' . SM_PATH . 'images/plus.png" border="0" height="7" width="7" />');
765 else
766 $text_array = array('-', '+');
767 $toggle_link = asearch_get_toggle_link(!$show_flag, $show_pref, $text_array, array(_("Fold"), _("Unfold")));
768 if (!$use_icons_flag)
769 $toggle_link = '<small>[' . $toggle_link . ']</small>';
770
771 echo "<br />\n";
772 echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"');
773 echo html_tag('tr',
774 html_tag('td', $toggle_link, 'center', $color[5], 'width="5%"')
775 . html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=4'));
776 if ($show_flag) {
777 $main_key = $query_keys[ASEARCH_WHERE];
778 $query_count = count($query_array[$main_key]);
779 for ($query_num = 0, $row_num = 0; $query_num < $query_count; $query_num++) {
780 if (!empty($query_array[$main_key][$query_num])) {
781 echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num));
782
783 unset($search_array);
784 foreach ($query_keys as $query_key) {
785 $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]);
786 }
787 $where_array = $search_array[ASEARCH_WHERE];
788 $mailbox_array = $search_array[ASEARCH_MAILBOX];
789 $what_array = $search_array[ASEARCH_WHAT];
790 $unop_array = $search_array[ASEARCH_UNOP];
791 $biop_array = asearch_nz($search_array[ASEARCH_BIOP], array());
792 $exclude_array = asearch_nz($search_array[ASEARCH_EXCLUDE], array());
793 $sub_array = asearch_nz($search_array[ASEARCH_SUB], array());
794 $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
795
796 echo html_tag('td', $query_num + 1, 'right');
797 echo html_tag('td', $query_display, 'center', '', 'width="80%"');
798 foreach ($action_array as $action => $action_display) {
799 echo html_tag('td', '<a href="' . asearch_get_href('submit=' . $action . '&amp;rownum=' . $query_num) . '">' . $action_display . '</a>', 'center');
800 }
801
802 echo '</tr>' . "\n";
803 $row_num++;
804 }
805 }
806 }
807 echo '</table>' . "\n";
808 }
809
810 /** Print the saved array
811 *
812 * Function arguments are different in 1.5.0
813 * @param array $boxes (unused, see asearch_print_query_array())
814 * @since 1.5.0
815 * @private
816 */
817 function asearch_print_saved(&$boxes)
818 {
819 global $saved_prefkeys;
820
821 $saved_array = asearch_read_saved();
822 if (isset($saved_array[$saved_prefkeys[0]])) {
823 $saved_count = count($saved_array[$saved_prefkeys[0]]);
824 if ($saved_count > 0) {
825 $saved_actions = array('edit_saved' => _("Edit"), 'search_saved' => _("Search"), 'delete_saved' => _("Delete"));
826 asearch_print_query_array($boxes, $saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches"), 'search_show_saved');
827 }
828 }
829 }
830
831 /**
832 * Print the recent array
833 *
834 * Function arguments are different in 1.5.0
835 * @param array $boxes (unused, see asearch_print_query_array())
836 * @since 1.5.0
837 * @private
838 */
839 function asearch_print_recent(&$boxes)
840 {
841 global $recent_prefkeys, $search_memory;
842
843 $recent_array = asearch_read_recent();
844 if (isset($recent_array[$recent_prefkeys[0]])) {
845 $recent_count = count($recent_array[$recent_prefkeys[0]]);
846 if (min($recent_count, $search_memory) > 0) {
847 $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget"));
848 asearch_print_query_array($boxes, $recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches"), 'search_show_recent');
849 }
850 }
851 }
852
853 /**
854 * Build an <option> statement
855 * @param string $var option value
856 * @param string $set default option value
857 * @param string $tit displayed option name
858 * @return string formated html option tag
859 * @since 1.5.0
860 * @private
861 */
862 function asearch_opt($val, $sel, $tit)
863 {
864 return '<option value="' . $val . '"' . ($sel == $val ? ' selected="selected"' : '') . '>' . $tit . '</option>' . "\n";
865 }
866
867 /** Build a <select> statement from an array
868 * @param string $var_name select option name
869 * @param array $opt_array select option values
870 * @param string $cur_val default value
871 * @return string html formated select tag
872 * @deprecated FIXME use standard form functions or
873 * explain why they are not used.
874 * @since 1.5.0
875 * @private
876 */
877 function asearch_opt_array($var_name, $opt_array, $cur_val)
878 {
879 $output = '<select name="' . $var_name . '">' . "\n";
880 foreach($opt_array as $val => $display)
881 $output .= asearch_opt($val, $cur_val, asearch_nz($display, $val));
882 $output .= '</select>' . "\n";
883 return $output;
884 }
885
886 /** Verify that a mailbox exists
887 * @param string $mailbox
888 * @param array $boxes
889 * @return bool mailbox exists
890 * @deprecated FIXME use standard functions
891 * @since 1.5.0
892 * @private
893 */
894 function asearch_mailbox_exists($mailbox, &$boxes)
895 {
896 foreach ($boxes as $box) {
897 if ($box['unformatted'] == $mailbox)
898 return TRUE;
899 }
900 return FALSE;
901 }
902
903 /**
904 * Build the mailbox select
905 * @param stream $imapConnection
906 * @param array $boxes
907 * @param string $mailbox
908 * @param integer $row_num
909 * @since 1.5.1
910 * @private
911 */
912 function asearch_get_form_mailbox($imapConnection, &$boxes, $mailbox, $row_num = 0)
913 {
914 if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) {
915 $missing = asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . htmlspecialchars(asearch_get_mailbox_display($mailbox)));
916 } else {
917 $missing = '';
918 }
919 return '<select name="mailbox[' . $row_num . ']">'
920 . $missing
921 . asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']')
922 . sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL)
923 . '</select>';
924 }
925
926 /**
927 * Build the Include subfolders checkbox
928 * @param string $sub
929 * @param integer $row_num
930 * @return string
931 * @since 1.5.1
932 * @private
933 */
934 function asearch_get_form_sub($sub, $row_num = 0)
935 {
936 return addCheckBox('sub[' . $row_num .']', $sub);
937 }
938
939 /** Build the 2 unop and where selects
940 * @param string $unop default value
941 * @param string $where default value
942 * @param integer $row_num
943 * @return string
944 * @since 1.5.1
945 * @private
946 */
947 function asearch_get_form_location($unop, $where, $row_num = 0)
948 {
949 global $imap_asearch_unops, $imap_asearch_options;
950
951 return asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop)
952 . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where);
953 }
954
955 /** Build the what text input
956 * @param string $what
957 * @param integer $row_num
958 * @return string
959 * @since 1.5.1
960 * @private
961 */
962 function asearch_get_form_what($what, $row_num = 0)
963 {
964 return addInput('what[' . $row_num . ']', $what, '35');
965 }
966
967 /** Build the Exclude criteria checkbox
968 * @param boolean $exclude
969 * @param integer $row_num
970 * @return string
971 * @since 1.5.1
972 * @private
973 */
974 function asearch_get_form_exclude($exclude, $row_num = 0)
975 {
976 return addCheckBox('exclude['.$row_num.']', $exclude);
977 }
978
979 /** Print one advanced form row
980 * @param stream $imapConnection
981 * @param array $boxes
982 * @param string $mailbox
983 * @param mixed $biop
984 * @param string $unop
985 * @param string $where
986 * @param string $what
987 * @param boolean $exclude
988 * @param mixed $sub
989 * @param integer $row_num
990 * @since 1.5.0
991 * @private
992 */
993 function asearch_print_form_row($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num)
994 {
995 global $imap_asearch_biops_in;
996 global $color;
997
998 echo html_tag('tr', '', '', $color[4]);
999
1000 //Binary operator
1001 echo html_tag('td', $row_num ?
1002 asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop)
1003 : '<b>' . _("In") . '</b>', 'center') . "\n";
1004
1005 //Mailbox list and Include Subfolders
1006 echo html_tag('td',
1007 asearch_get_form_mailbox($imapConnection, $boxes, $mailbox, $row_num)
1008 . _("and&nbsp;subfolders:") . asearch_get_form_sub($sub, $row_num), 'center') . "\n";
1009
1010 //Unary operator and Search location
1011 echo html_tag('td', asearch_get_form_location($unop, $where, $row_num), 'center') . "\n";
1012
1013 //Text input
1014 echo html_tag('td', asearch_get_form_what($what, $row_num), 'center') . "\n";
1015
1016 //Exclude criteria
1017 echo html_tag('td', _("Exclude Criteria:") . asearch_get_form_exclude($exclude, $row_num), 'center') . "\n";
1018
1019 echo "</tr>\n";
1020 }
1021
1022 /** Print the advanced search form
1023 * @param stream $imapConnection
1024 * @param array $boxes
1025 * @param array $mailbox_array
1026 * @param array $biop_array
1027 * @param array $unop_array
1028 * @param array $where_array
1029 * @param array $what_array
1030 * @param array $exclude_array
1031 * @param array $sub_array
1032 * @since 1.5.0
1033 * @private
1034 */
1035 function asearch_print_form($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
1036 {
1037 global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html;
1038 global $color;
1039
1040 //Search Form
1041 echo "<br />\n";
1042 echo '<form action="' . asearch_get_href() . '" name="form_asearch">' . "\n";
1043
1044 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"');
1045 echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5'));
1046 $row_count = count($where_array);
1047 for ($row_num = 0; $row_num < $row_count; $row_num++) {
1048 $mailbox = asearch_nz($mailbox_array[$row_num]);
1049 $biop = strip_tags(asearch_nz($biop_array[$row_num]));
1050 $unop = strip_tags(asearch_nz($unop_array[$row_num]));
1051 $where = strip_tags(asearch_nz($where_array[$row_num]));
1052 $what = asearch_nz($what_array[$row_num]);
1053 $exclude = strip_tags(asearch_nz($exclude_array[$row_num]));
1054 $sub = strip_tags(asearch_nz($sub_array[$row_num]));
1055 asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num);
1056 }
1057 echo '</table>' . "\n";
1058
1059 //Submit buttons
1060 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
1061 echo html_tag('tr',
1062 html_tag('td', getButton('submit', 'submit', $search_button_html), 'center') . "\n"
1063 . html_tag('td', getButton('submit', 'submit', $add_criteria_button_html), 'center') . "\n"
1064 . html_tag('td', getButton('submit', 'submit', $del_all_button_html), 'center') . "\n"
1065 . html_tag('td', getButton('submit', 'submit', $del_excluded_button_html), 'center') . "\n"
1066 );
1067 echo '</table>' . "\n";
1068 echo '</form>' . "\n";
1069 }
1070
1071 /** Print one basic form row
1072 * @param stream $imapConnection
1073 * @param array $boxes
1074 * @param string $mailbox
1075 * @param mixed $biop
1076 * @param mixed $unop
1077 * @param string $where
1078 * @param string $what
1079 * @param boolean $exclude
1080 * @param mixed $sub
1081 * @param integer $row_num
1082 * @since 1.5.1
1083 * @private
1084 */
1085 function asearch_print_form_row_basic($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num)
1086 {
1087 global $search_button_html;
1088 global $color;
1089
1090 echo html_tag('tr', '', '', $color[4]);
1091
1092 //Mailbox list
1093 echo html_tag('td', '<b>' . _("In") . '</b> ' . asearch_get_form_mailbox($imapConnection, $boxes, $mailbox), 'center') . "\n";
1094
1095 //Unary operator and Search location
1096 echo html_tag('td', asearch_get_form_location($unop, $where), 'center') . "\n";
1097
1098 //Text input
1099 echo html_tag('td', asearch_get_form_what($what), 'center') . "\n";
1100
1101 //Submit button
1102 echo html_tag('td', getButton('submit', 'submit', $search_button_html), 'center') . "\n";
1103
1104 echo "</tr>\n";
1105 }
1106
1107 /** Print the basic search form
1108 * @param stream $imapConnection
1109 * @param array $boxes
1110 * @param array $mailbox_array
1111 * @param array $biop_array
1112 * @param array $unop_array
1113 * @param array $where_array
1114 * @param array $what_array
1115 * @param array $exclude_array
1116 * @param array $sub_array
1117 * @since 1.5.1
1118 * @private
1119 */
1120 function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
1121 {
1122 global $color;
1123
1124 //Search Form
1125 echo "<br />\n";
1126 echo '<form action="' . asearch_get_href() . '" name="form_asearch">' . "\n";
1127
1128 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"');
1129 //echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=4'));
1130 $row_count = count($where_array);
1131 for ($row_num = 0; $row_num < $row_count; $row_num++) {
1132 $mailbox = asearch_nz($mailbox_array[$row_num]);
1133 $biop = strip_tags(asearch_nz($biop_array[$row_num]));
1134 $unop = strip_tags(asearch_nz($unop_array[$row_num]));
1135 $where = strip_tags(asearch_nz($where_array[$row_num]));
1136 $what = asearch_nz($what_array[$row_num]);
1137 $exclude = strip_tags(asearch_nz($exclude_array[$row_num]));
1138 $sub = strip_tags(asearch_nz($sub_array[$row_num]));
1139 asearch_print_form_row_basic($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num);
1140 }
1141 echo '</table>' . "\n";
1142 echo '</form>' . "\n";
1143 }
1144
1145
1146 /**
1147 * @param array $boxes mailboxes array (reference)
1148 * @return array selectable unformatted mailboxes names
1149 * @since 1.5.0
1150 * @private
1151 */
1152 function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes)
1153 {
1154 $mboxes_array = array();
1155 $boxcount = count($boxes);
1156 for ($boxnum = 0; $boxnum < $boxcount; $boxnum++) {
1157 if (!in_array('noselect', $boxes[$boxnum]['flags']))
1158 $mboxes_array[] = $boxes[$boxnum]['unformatted'];
1159 }
1160 return $mboxes_array;
1161 }
1162
1163 /* ------------------------ main ------------------------ */
1164 /* get globals we will need */
1165 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
1166
1167 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
1168 $checkall = (int) $temp;
1169 }
1170
1171 /**
1172 * Retrieve the mailbox cache from the session.
1173 */
1174 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
1175
1176
1177 $search_button_html = _("Search");
1178 $search_button_text = asearch_unhtmlentities($search_button_html);
1179 $add_criteria_button_html = _("Add New Criteria");
1180 $add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html);
1181 $del_excluded_button_html = _("Remove Excluded Criteria");
1182 $del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html);
1183 $del_all_button_html = _("Remove All Criteria");
1184 $del_all_button_text = asearch_unhtmlentities($del_all_button_html);
1185
1186 /** Maximum number of recent searches to handle
1187 * Default 0
1188 * @global integer $search_memory
1189 */
1190 $search_memory = getPref($data_dir, $username, 'search_memory', 0);
1191
1192 /** Advanced search control
1193 * - 0 => allow basic interface only
1194 * - 1 => allow advanced interface only
1195 * - 2 => allow both
1196 * Default 2
1197 */
1198 $allow_advanced_search = asearch_nz($allow_advanced_search, 2);
1199
1200 /**
1201 * Toggle advanced/basic search
1202 */
1203 if (sqgetGlobalVar('advanced', $search_advanced, SQ_GET)) {
1204 setPref($data_dir, $username, 'search_advanced', $search_advanced & 1);
1205 }
1206 /** If 1, show advanced search interface
1207 * Default from allow_advanced_search pref
1208 * @global integer $search_advanced
1209 */
1210 if ($allow_advanced_search > 1) {
1211 $search_advanced = getPref($data_dir, $username, 'search_advanced', 0);
1212 } else {
1213 $search_advanced = $allow_advanced_search;
1214 }
1215 if ($search_advanced) {
1216 /** Set recent prefkeys according to $search_advanced
1217 * @global array $recent_prefkeys
1218 */
1219 $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_unop', 'asearch_recent_biop', 'asearch_recent_exclude', 'asearch_recent_sub');
1220
1221 /** Set saved prefkeys according to $search_advanced
1222 * @global array $saved_prefkeys
1223 */
1224 $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_unop', 'asearch_saved_biop', 'asearch_saved_exclude', 'asearch_saved_sub');
1225
1226 /*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/
1227 } else {
1228 $recent_prefkeys = array('search_where', 'search_folder', 'search_what', 'search_unop');
1229 $saved_prefkeys = array('saved_where', 'saved_folder', 'saved_what', 'saved_unop');
1230 }
1231
1232 /** How we did enter the form
1233 * - unset : Enter key, or called from outside (eg read_body)
1234 * - $search_button_text : Search button
1235 * - 'Search_no_update' : Search but don't update recent
1236 * - 'Search_last' : Same as no_update but reload and search last
1237 * - 'Search_silent' : Same as no_update but only display results
1238 * - $add_criteria_button_text : Add New Criteria button
1239 * - $del_excluded_button_text : Remove Excluded Criteria button
1240 * - $del_all_button_text : Remove All Criteria button
1241 * - 'save_recent'
1242 * - 'search_recent'
1243 * - 'forget_recent'
1244 * - 'edit_saved'
1245 * - 'search_saved'
1246 * - 'delete_saved'
1247 * @global string $submit
1248 */
1249 $searchpressed = false;
1250 if (isset($_GET['submit'])) {
1251 $submit = strip_tags($_GET['submit']);
1252 }
1253
1254 /** Searched mailboxes
1255 * @global array $mailbox_array
1256 */
1257 if (isset($_GET['mailbox'])) {
1258 $mailbox_array = $_GET['mailbox'];
1259 $targetmailbox = $_GET['mailbox'];
1260 if (!is_array($mailbox_array)) {
1261 $mailbox_array = array($mailbox_array);
1262 }
1263 } else {
1264 $mailbox_array = array();
1265 $targetmailbox = array();
1266 }
1267 $aMailboxGlobalPref = array(
1268 MBX_PREF_SORT => 0,
1269 MBX_PREF_LIMIT => (int) $show_num,
1270 MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge,
1271 MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')
1272 // MBX_PREF_FUTURE => (var) $future
1273 );
1274
1275 /**
1276 * system wide admin settings and incoming vars.
1277 */
1278 $aConfig = array(
1279 // 'allow_thread_sort' => $allow_thread_sort,
1280 // 'allow_server_sort' => $allow_server_sort,
1281 'user' => $username,
1282 'setindex' => 1
1283 );
1284
1285 /** Binary operators
1286 * @global array $biop_array
1287 */
1288 if (isset($_GET['biop'])) {
1289 $biop_array = $_GET['biop'];
1290 if (!is_array($biop_array))
1291 $biop_array = array($biop_array);
1292 } else {
1293 $biop_array = array();
1294 }
1295 /** Unary operators
1296 * @global array $unop_array
1297 */
1298 if (isset($_GET['unop'])) {
1299 $unop_array = $_GET['unop'];
1300 if (!is_array($unop_array))
1301 $unop_array = array($unop_array);
1302 } else {
1303 $unop_array = array();
1304 }
1305 /** Where to search
1306 * @global array $where_array
1307 */
1308 if (isset($_GET['where'])) {
1309 $where_array = $_GET['where'];
1310 if (!is_array($where_array)) {
1311 $where_array = array($where_array);
1312 }
1313 } else {
1314 $where_array = array();
1315 }
1316 /** What to search
1317 * @global array $what_array
1318 */
1319 if (isset($_GET['what'])) {
1320 $what_array = $_GET['what'];
1321 if (!is_array($what_array)) {
1322 $what_array = array($what_array);
1323 }
1324 } else {
1325 $what_array = array();
1326 }
1327 /** Whether to exclude this criteria from search
1328 * @global array $exclude_array
1329 */
1330 if (isset($_GET['exclude'])) {
1331 $exclude_array = $_GET['exclude'];
1332 } else {
1333 $exclude_array = array();
1334 }
1335 /** Search within subfolders
1336 * @global array $sub_array
1337 */
1338 if (isset($_GET['sub'])) {
1339 $sub_array = $_GET['sub'];
1340 } else {
1341 $sub_array = array();
1342 }
1343 /** Row number used by recent and saved stuff
1344 */
1345 if (isset($_GET['rownum'])) {
1346 $submit_rownum = strip_tags($_GET['rownum']);
1347 }
1348 /** Change global sort
1349 */
1350 if (sqgetGlobalVar('srt', $temp, SQ_GET)) {
1351 $srt = (int) $temp;
1352 asearch_edit_last(1);
1353 // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1354 }
1355 if (sqgetGlobalVar('startMessage', $temp, SQ_GET)) {
1356 $startMessage = (int) $temp;
1357 asearch_edit_last(1);
1358 // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1359 }
1360
1361 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
1362 $showall = (int) $temp;
1363 asearch_edit_last(1);
1364 // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1365 }
1366
1367 if ( sqgetGlobalVar('account', $temp, SQ_GET) ) {
1368 $iAccount = (int) $temp;
1369 } else {
1370 $iAccount = 0;
1371 }
1372
1373 /**
1374 * Which templatedir are we using. TODO, add make a config var of this and make it possible to switch templates
1375 */
1376 $sTplDir = SM_PATH . 'templates/default/';
1377
1378
1379 /**
1380 * Incoming submit buttons from the message list with search results
1381 */
1382 if (sqgetGlobalVar('moveButton', $moveButton, SQ_POST) ||
1383 sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST) ||
1384 sqgetGlobalVar('delete', $markDelete, SQ_POST) ||
1385 sqgetGlobalVar('undeleteButton', $undeleteButton, SQ_POST) ||
1386 sqgetGlobalVar('markRead', $markRead, SQ_POST) ||
1387 sqgetGlobalVar('markUnread', $markUnread, SQ_POST) ||
1388 sqgetGlobalVar('markFlagged', $markFlagged, SQ_POST) ||
1389 sqgetGlobalVar('markUnflagged', $markUnflagged, SQ_POST) ||
1390 sqgetGlobalVar('attache', $attache, SQ_POST)) {
1391 asearch_edit_last(1);
1392 $submit = '';
1393 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1394 }
1395
1396
1397
1398 /** Toggle show/hide saved searches
1399 */
1400 if (sqgetGlobalVar('search_show_saved', $search_show_saved, SQ_GET)) {
1401 setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1);
1402 }
1403 /** Toggle show/hide recent searches
1404 */
1405 if (sqgetGlobalVar('search_show_recent', $search_show_recent, SQ_GET)) {
1406 setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1);
1407 }
1408 // end of get globals
1409
1410 /** If TRUE, do not show search interface
1411 * Default FALSE
1412 * @global bool $search_silent
1413 */
1414 $search_silent = FALSE;
1415
1416 /* See how the page was called and fire off correct function */
1417 if ((empty($submit)) && (!empty($where_array))) {
1418 /* This happens when the Enter key is used or called from outside */
1419 $submit = $search_button_text;
1420 /* Hack needed to handle coming back from read_body et als */
1421 if (count($where_array) != count($unop_array)) {
1422 /**
1423 * Hack to use already existen where and what vars.
1424 * where now contains the initiator page of the messagelist
1425 * and in this case 'search'. what contains an index to access
1426 * the search history
1427 */
1428
1429 sqgetGlobalVar('what',$what,SQ_GET);
1430 asearch_edit_last($what);
1431 }
1432 }
1433
1434 if (!isset($submit)) {
1435 $submit = '';
1436 } else {
1437 switch ($submit) {
1438 case $search_button_text:
1439 if (asearch_check_query($where_array, $what_array, $exclude_array) == '') {
1440 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1441 }
1442 break;
1443 case 'Search_silent':
1444 $search_silent = TRUE;
1445 /*nobreak;*/
1446 case 'Search_no_update':
1447 $submit = $search_button_text;
1448 break;
1449 case $del_excluded_button_text:
1450 $delarray = array_keys($exclude_array);
1451 while (!empty($delarray)) {
1452 $delrow = array_pop($delarray);
1453 array_splice($mailbox_array, $delrow, 1);
1454 array_splice($biop_array, $delrow, 1);
1455 array_splice($unop_array, $delrow, 1);
1456 array_splice($where_array, $delrow, 1);
1457 array_splice($what_array, $delrow, 1);
1458 /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */
1459 array_splice($sub_array, $delrow, 1);
1460 }
1461 $exclude_array = array();
1462 break;
1463 case $del_all_button_text:
1464 $mailbox_array = array();
1465 $biop_array = array();
1466 $unop_array = array();
1467 $where_array = array();
1468 $what_array = array();
1469 $exclude_array = array();
1470 $sub_array = array();
1471 break;
1472 case 'save_recent':
1473 asearch_save_recent($submit_rownum);
1474 break;
1475 case 'search_recent':
1476 $submit = $search_button_text;
1477 asearch_edit_recent($submit_rownum);
1478 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1479 break;
1480 case 'edit_recent': /* no link to do this, yet */
1481 asearch_edit_recent($submit_rownum);
1482 break;
1483 case 'forget_recent':
1484 asearch_forget_recent($submit_rownum);
1485 break;
1486 case 'search_saved':
1487 $submit = $search_button_text;
1488 asearch_edit_saved($submit_rownum);
1489 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1490 break;
1491 case 'edit_saved':
1492 asearch_edit_saved($submit_rownum);
1493 break;
1494 case 'delete_saved':
1495 asearch_delete_saved($submit_rownum);
1496 break;
1497 }
1498 }
1499
1500 //Texts in both basic and advanced form
1501 $imap_asearch_unops = array(
1502 '' => '',
1503 'NOT' => _("Not")
1504 );
1505
1506 if ($search_advanced) {
1507 //Texts in advanced form only
1508 $imap_asearch_options = array(
1509 //<message set>,
1510 //'ALL' is binary operator
1511 'ANSWERED' => _("Answered"),
1512 'BCC' => _("Bcc"),
1513 'BEFORE' => _("Before"),
1514 'BODY' => _("Message Body"),
1515 'CC' => _("Cc"),
1516 'DELETED' => _("Deleted"),
1517 'DRAFT' => _("Draft"),
1518 'FLAGGED' => _("Flagged"),
1519 'FROM' => _("Sent By"),
1520 'HEADER' => _("Header Field"),
1521 'KEYWORD' => _("Keyword"),
1522 'LARGER' => _("Larger Than"),
1523 'NEW' => _("New"),
1524 //'NOT' is unary operator
1525 'OLD' => _("Old"),
1526 'ON' => _("On"),
1527 //'OR' is binary operator
1528 'RECENT' => _("Recent"),
1529 'SEEN' => _("Seen"),
1530 'SENTBEFORE' => _("Sent Before"),
1531 'SENTON' => _("Sent On"),
1532 'SENTSINCE' => _("Sent Since"),
1533 'SINCE' => _("Since"),
1534 'SMALLER' => _("Smaller Than"),
1535 'SUBJECT' => _("Subject Contains"),
1536 'TEXT' => _("Header and Body"),
1537 'TO' => _("Sent To"),
1538 //'UID' => 'anum',
1539 /* 'UNANSWERED' => '',
1540 'UNDELETED' => '',
1541 'UNDRAFT' => '',
1542 'UNFLAGGED' => '',
1543 'UNKEYWORD' => _("Unkeyword"),
1544 'UNSEEN' => _("Unseen"),*/
1545 );
1546
1547 $imap_asearch_biops_in = array(
1548 'ALL' => _("And In"),
1549 'OR' => _("Or In")
1550 );
1551
1552 $imap_asearch_biops = array(
1553 'ALL' => _("And"),
1554 'OR' => _("Or")
1555 );
1556 } else {
1557 //Texts in basic form only
1558 $imap_asearch_options = array(
1559 'BCC' => _("Bcc"),
1560 'BODY' => _("Body"),
1561 'CC' => _("Cc"),
1562 'FROM' => _("From"),
1563 'SUBJECT' => _("Subject"),
1564 'TEXT' => _("Everywhere"),
1565 'TO' => _("To"),
1566 );
1567 }
1568
1569 uasort($imap_asearch_options, 'asearch_unhtml_strcoll');
1570
1571 /* open IMAP connection */
1572 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
1573
1574
1575 /* get mailboxes once here */
1576 $boxes = sqimap_mailbox_list($imapConnection);
1577 /* ensure we have a valid default mailbox name */
1578 $mailbox = asearch_nz($mailbox_array[0]);
1579 if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?)
1580 $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;)
1581
1582
1583 /**
1584 * Handle form actions like flag / unflag, seen / unseen, delete
1585 */
1586 if (sqgetGlobalVar('mailbox',$postMailbox,SQ_POST)) {
1587 if ($postMailbox) {
1588 /**
1589 * system wide admin settings and incoming vars.
1590 */
1591 $aConfig = array(
1592 'user' => $username,
1593 );
1594 $aConfig['setindex'] = 1; // $what $where = 'search'
1595 /**
1596 * Set the max cache size to the number of mailboxes to avoid cache cleanups
1597 * when searching all mailboxes
1598 */
1599 $aConfig['max_cache_size'] = count($boxes) +1;
1600
1601 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $postMailbox,$aConfig,array());
1602 $sError = handleMessageListForm($imapConnection,$aMailbox);
1603 /* add the mailbox to the cache */
1604 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1605
1606 if ($sError) {
1607 $note = $sError;
1608 }
1609 }
1610 }
1611
1612 if (isset($aMailbox['FORWARD_SESSION'])) {
1613 /* add the mailbox to the cache */
1614 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1615 sqsession_register($mailbox_cache,'mailbox_cache');
1616
1617 if ($compose_new_win) {
1618 // write the session in order to make sure that the compose window has
1619 // access to the composemessages array which is stored in the session
1620 session_write_close();
1621 // restart the session. Do not use sqsession_is_active because the session_id
1622 // isn't empty after a session_write_close
1623 sqsession_start();
1624
1625 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
1626 $compose_width = '640';
1627 }
1628 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
1629 $compose_height = '550';
1630 }
1631 // do not use &amp;, it will break the query string and $session will not be detected!!!
1632 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
1633 '&session='.$aMailbox['FORWARD_SESSION'];
1634 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", false);
1635 } else {
1636 // save mailboxstate
1637 sqsession_register($aMailbox,'aLastSelectedMailbox');
1638 session_write_close();
1639 // we have to redirect to the compose page
1640 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
1641 '&amp;session='.$aMailbox['FORWARD_SESSION'];
1642 header("Location: $location");
1643 exit;
1644 }
1645 } else {
1646 displayPageHeader($color, $mailbox);
1647 // $compose_uri = $base_uri.'src/compose.php?newmessage=1';
1648 }
1649
1650 if (isset($note)) {
1651 echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n";
1652 }
1653
1654
1655 do_hook('search_before_form');
1656
1657 if (!$search_silent) {
1658 //Add a link to the other search mode if allowed
1659 if ($allow_advanced_search > 1)
1660 $toggle_link = ' - <small>['
1661 . asearch_get_toggle_link(!$search_advanced, 'advanced', array(_("Standard search"), _("Advanced search")))
1662 . ']</small>';
1663 else
1664 $toggle_link = '';
1665
1666 echo html_tag('table',
1667 html_tag('tr', "\n"
1668 . html_tag('td', asearch_get_title_display($color, _("Search")) . $toggle_link, 'center', $color[0])
1669 ) ,
1670 '', '', 'width="100%"') . "\n";
1671 asearch_print_saved($boxes);
1672 asearch_print_recent($boxes);
1673 if (empty($where_array)) {
1674 global $sent_folder;
1675
1676 $mailbox_array[0] = $mailbox;
1677 $biop_array[0] = '';
1678 $unop_array[0] = '';
1679 if ($mailbox == $sent_folder) {
1680 $where_array[0] = 'TO';
1681 } else {
1682 $where_array[0] = 'FROM';
1683 }
1684 $what_array[0] = '';
1685 $exclude_array[0] = '';
1686 $sub_array[0] = '';
1687 }
1688 //Display advanced or basic form
1689 if ($search_advanced) {
1690 if ($submit == $add_criteria_button_text) {
1691 $last_index = max(count($where_array) - 1, 0);
1692 $mailbox_array[] = asearch_nz($mailbox_array[$last_index]);
1693 $biop_array[] = asearch_nz($biop_array[$last_index]);
1694 $unop_array[] = asearch_nz($unop_array[$last_index]);
1695 $where_array[] = asearch_nz($where_array[$last_index]);
1696 $what_array[] = asearch_nz($what_array[$last_index]);
1697 $exclude_array[] = asearch_nz($exclude_array[$last_index]);
1698 $sub_array[] = asearch_nz($sub_array[$last_index]);
1699 }
1700 asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1701 } else {
1702 asearch_print_form_basic($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1703 }
1704 }
1705
1706 do_hook('search_after_form');
1707
1708 if ($submit == $search_button_text) {
1709 $msgsfound = false;
1710 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
1711 echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5]));
1712 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]));
1713 echo '</table>' . "\n";
1714
1715 flush();
1716 $iMsgCnt = 0;
1717 $query_error = asearch_check_query($where_array, $what_array, $exclude_array);
1718 if ($query_error != '') {
1719 echo '<br />' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n";
1720 } else {
1721 $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
1722 /**
1723 * Retrieve the search queries
1724 */
1725 $mboxes_mailbox = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
1726 foreach($mboxes_mailbox as $mbx => $search) {
1727
1728 /**
1729 * until there is no per mailbox option screen to set prefs we override
1730 * the mailboxprefs by the default ones
1731 */
1732
1733 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$iAccount.'_'.$mbx);
1734 if ($aMailboxPrefSer) {
1735 $aMailboxPref = unserialize($aMailboxPrefSer);
1736 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
1737 } else {
1738 setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($default_mailbox_pref));
1739 $aMailboxPref = $default_mailbox_pref;
1740 }
1741 if (isset($srt) && $targetmailbox == $mbx) {
1742 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
1743 }
1744
1745 $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
1746 $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
1747 $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
1748
1749
1750 /**
1751 * until there is no per mailbox option screen to set prefs we override
1752 * the mailboxprefs by the default ones
1753 */
1754 $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
1755 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
1756 $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
1757 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
1758
1759 /**
1760 * Replace From => To in case it concerns a draft or sent folder
1761 */
1762 if (($mbx == $sent_folder || $mbx == $draft_folder) &&
1763 !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
1764 $aNewOrder = array(); // nice var name ;)
1765 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
1766 if ($iCol == SQM_COL_FROM) {
1767 $iCol = SQM_COL_TO;
1768 }
1769 $aNewOrder[] = $iCol;
1770 }
1771 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
1772 setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($aMailboxPref));
1773 }
1774
1775 $aConfig['search'] = $search['search'];
1776 $aConfig['charset'] = $search['charset'];
1777
1778 /**
1779 * Set the max cache size to the number of mailboxes to avoid cache cleanups
1780 * when searching all mailboxes
1781 */
1782 $aConfig['max_cache_size'] = count($mboxes_mailbox) +1;
1783 if (isset($startMessage) && $targetmailbox == $mbx) {
1784 $aConfig['offset'] = $startMessage;
1785 } else {
1786 $aConfig['offset'] = 0;
1787 }
1788 if (isset($showall) && $targetmailbox == $mbx) {
1789 $aConfig['showall'] = $showall;
1790 } else {
1791 if (isset($aConfig['showall'])) {
1792 unset($aConfig['showall']);
1793 }
1794 $showall = false;
1795 }
1796
1797 /**
1798 * Set the config options for the messages list
1799 */
1800 $aColumns = array();
1801 foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
1802 $aColumns[$iCol] = array();
1803 switch ($iCol) {
1804 case SQM_COL_SUBJ:
1805 if ($truncate_subject) {
1806 $aColumns[$iCol]['truncate'] = $truncate_subject;
1807 }
1808 break;
1809 case SQM_COL_FROM:
1810 case SQM_COL_TO:
1811 case SQM_COL_CC:
1812 case SQM_COL_BCC:
1813 if ($truncate_sender) {
1814 $aColumns[$iCol]['truncate'] = $truncate_sender;
1815 }
1816 break;
1817 }
1818 }
1819
1820
1821 $aProps = array(
1822 'columns' => $aColumns,
1823 'config' => array('alt_index_colors' => $alt_index_colors,
1824 'highlight_list' => $message_highlight_list,
1825 'fancy_index_highlite' => $fancy_index_highlite,
1826 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
1827 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '',
1828 'trash_folder' => $trash_folder,
1829 'sent_folder' => $sent_folder,
1830 'draft_folder' => $draft_folder,
1831 'enablesort' => true,
1832 'color' => $color
1833 ),
1834 'mailbox' => $mbx,
1835 'account' => (isset($iAccount)) ? $iAccount : 0,
1836 'module' => 'read_body',
1837 'email' => false);
1838
1839
1840 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mbx,$aConfig,$aMailboxPref);
1841
1842 $iError = 0;
1843 $aTemplate = showMessagesForMailbox($imapConnection, $aMailbox,$aProps, $iError);
1844
1845 // in th future we can make use of multiple message sets, now set it to 1 for search.
1846 $iSetIndex = 1;
1847 if (isset($aMailbox['UIDSET'][$iSetIndex])) {
1848 $iMsgCnt += count($aMailbox['UIDSET'][$iSetIndex]);
1849 }
1850 if ($iError) {
1851 // error handling
1852 } else {
1853 /**
1854 * In the future, move this the the initialisation area
1855 */
1856 sqgetGlobalVar('align',$align,SQ_SESSION);
1857
1858 $oTemplate = new Template($sTplDir);
1859
1860 if ($aMailbox['EXISTS'] > 0) {
1861 if ($iError) {
1862 // TODO
1863 echo "ERROR occured, errorhandler will be implemented very soon";
1864 } else {
1865 foreach ($aTemplate as $k => $v) {
1866 $oTemplate->assign($k, $v);
1867 }
1868
1869 $oTemplate->assign('page_selector', $page_selector);
1870 $oTemplate->assign('page_selector_max', $page_selector_max);
1871 $oTemplate->assign('compact_paginator', $compact_paginator);
1872 $oTemplate->assign('javascript_on', $javascript_on);
1873 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
1874 $oTemplate->assign('icon_theme_path', $icon_theme_path);
1875 $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
1876 $oTemplate->assign('aOrder', array_keys($aColumns));
1877 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
1878 $oTemplate->assign('color', $color);
1879 $oTemplate->assign('align', $align);
1880
1881 $mailbox_display = asearch_get_mailbox_display($aMailbox['NAME']);
1882 if (strtoupper($mbx) == 'INBOX') {
1883 $mailbox_display = _("INBOX");
1884 } else {
1885 $mailbox_display = imap_utf7_decode_local($mbx);
1886 }
1887
1888 echo '<br /><b><big>' . _("Folder:") . ' '. htmlspecialchars($mailbox_display) . '&nbsp;</big></b>';
1889
1890 $oTemplate->display('message_list.tpl');
1891 }
1892 }
1893 }
1894
1895 /* add the mailbox to the cache */
1896 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1897
1898 }
1899 }
1900 if(!$iMsgCnt) {
1901 echo '<br />' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n";
1902 }
1903 }
1904
1905 do_hook('search_bottom');
1906 sqimap_logout($imapConnection);
1907 $oTemplate->display('footer.tpl');
1908 sqsession_register($mailbox_cache,'mailbox_cache');
1909
1910 ?>