fixed undefined notice
[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('username', $username, SQ_SESSION);
1166 sqgetGlobalVar('key', $key, SQ_COOKIE);
1167 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
1168 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
1169
1170 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
1171 $checkall = (int) $temp;
1172 }
1173
1174 /**
1175 * Retrieve the mailbox cache from the session.
1176 */
1177 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
1178
1179
1180 $search_button_html = _("Search");
1181 $search_button_text = asearch_unhtmlentities($search_button_html);
1182 $add_criteria_button_html = _("Add New Criteria");
1183 $add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html);
1184 $del_excluded_button_html = _("Remove Excluded Criteria");
1185 $del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html);
1186 $del_all_button_html = _("Remove All Criteria");
1187 $del_all_button_text = asearch_unhtmlentities($del_all_button_html);
1188
1189 /** Maximum number of recent searches to handle
1190 * Default 0
1191 * @global integer $search_memory
1192 */
1193 $search_memory = getPref($data_dir, $username, 'search_memory', 0);
1194
1195 /** Advanced search control
1196 * - 0 => allow basic interface only
1197 * - 1 => allow advanced interface only
1198 * - 2 => allow both
1199 * Default 2
1200 */
1201 $allow_advanced_search = asearch_nz($allow_advanced_search, 2);
1202
1203 /**
1204 * Toggle advanced/basic search
1205 */
1206 if (sqgetGlobalVar('advanced', $search_advanced, SQ_GET)) {
1207 setPref($data_dir, $username, 'search_advanced', $search_advanced & 1);
1208 }
1209 /** If 1, show advanced search interface
1210 * Default from allow_advanced_search pref
1211 * @global integer $search_advanced
1212 */
1213 if ($allow_advanced_search > 1) {
1214 $search_advanced = getPref($data_dir, $username, 'search_advanced', 0);
1215 } else {
1216 $search_advanced = $allow_advanced_search;
1217 }
1218 if ($search_advanced) {
1219 /** Set recent prefkeys according to $search_advanced
1220 * @global array $recent_prefkeys
1221 */
1222 $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_unop', 'asearch_recent_biop', 'asearch_recent_exclude', 'asearch_recent_sub');
1223
1224 /** Set saved prefkeys according to $search_advanced
1225 * @global array $saved_prefkeys
1226 */
1227 $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_unop', 'asearch_saved_biop', 'asearch_saved_exclude', 'asearch_saved_sub');
1228
1229 /*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/
1230 } else {
1231 $recent_prefkeys = array('search_where', 'search_folder', 'search_what', 'search_unop');
1232 $saved_prefkeys = array('saved_where', 'saved_folder', 'saved_what', 'saved_unop');
1233 }
1234
1235 /** How we did enter the form
1236 * - unset : Enter key, or called from outside (eg read_body)
1237 * - $search_button_text : Search button
1238 * - 'Search_no_update' : Search but don't update recent
1239 * - 'Search_last' : Same as no_update but reload and search last
1240 * - 'Search_silent' : Same as no_update but only display results
1241 * - $add_criteria_button_text : Add New Criteria button
1242 * - $del_excluded_button_text : Remove Excluded Criteria button
1243 * - $del_all_button_text : Remove All Criteria button
1244 * - 'save_recent'
1245 * - 'search_recent'
1246 * - 'forget_recent'
1247 * - 'edit_saved'
1248 * - 'search_saved'
1249 * - 'delete_saved'
1250 * @global string $submit
1251 */
1252 $searchpressed = false;
1253 if (isset($_GET['submit'])) {
1254 $submit = strip_tags($_GET['submit']);
1255 }
1256
1257 /** Searched mailboxes
1258 * @global array $mailbox_array
1259 */
1260 if (isset($_GET['mailbox'])) {
1261 $mailbox_array = $_GET['mailbox'];
1262 $targetmailbox = $_GET['mailbox'];
1263 if (!is_array($mailbox_array)) {
1264 $mailbox_array = array($mailbox_array);
1265 }
1266 } else {
1267 $mailbox_array = array();
1268 $targetmailbox = array();
1269 }
1270 $aMailboxGlobalPref = array(
1271 MBX_PREF_SORT => 0,
1272 MBX_PREF_LIMIT => (int) $show_num,
1273 MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge,
1274 MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')
1275 // MBX_PREF_FUTURE => (var) $future
1276 );
1277
1278 /**
1279 * system wide admin settings and incoming vars.
1280 */
1281 $aConfig = array(
1282 // 'allow_thread_sort' => $allow_thread_sort,
1283 // 'allow_server_sort' => $allow_server_sort,
1284 'user' => $username,
1285 'setindex' => 1
1286 );
1287
1288 /** Binary operators
1289 * @global array $biop_array
1290 */
1291 if (isset($_GET['biop'])) {
1292 $biop_array = $_GET['biop'];
1293 if (!is_array($biop_array))
1294 $biop_array = array($biop_array);
1295 } else {
1296 $biop_array = array();
1297 }
1298 /** Unary operators
1299 * @global array $unop_array
1300 */
1301 if (isset($_GET['unop'])) {
1302 $unop_array = $_GET['unop'];
1303 if (!is_array($unop_array))
1304 $unop_array = array($unop_array);
1305 } else {
1306 $unop_array = array();
1307 }
1308 /** Where to search
1309 * @global array $where_array
1310 */
1311 if (isset($_GET['where'])) {
1312 $where_array = $_GET['where'];
1313 if (!is_array($where_array)) {
1314 $where_array = array($where_array);
1315 }
1316 } else {
1317 $where_array = array();
1318 }
1319 /** What to search
1320 * @global array $what_array
1321 */
1322 if (isset($_GET['what'])) {
1323 $what_array = $_GET['what'];
1324 if (!is_array($what_array)) {
1325 $what_array = array($what_array);
1326 }
1327 } else {
1328 $what_array = array();
1329 }
1330 /** Whether to exclude this criteria from search
1331 * @global array $exclude_array
1332 */
1333 if (isset($_GET['exclude'])) {
1334 $exclude_array = $_GET['exclude'];
1335 } else {
1336 $exclude_array = array();
1337 }
1338 /** Search within subfolders
1339 * @global array $sub_array
1340 */
1341 if (isset($_GET['sub'])) {
1342 $sub_array = $_GET['sub'];
1343 } else {
1344 $sub_array = array();
1345 }
1346 /** Row number used by recent and saved stuff
1347 */
1348 if (isset($_GET['rownum'])) {
1349 $submit_rownum = strip_tags($_GET['rownum']);
1350 }
1351 /** Change global sort
1352 */
1353 if (sqgetGlobalVar('srt', $temp, SQ_GET)) {
1354 $srt = (int) $temp;
1355 asearch_edit_last(1);
1356 // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1357 }
1358 if (sqgetGlobalVar('startMessage', $temp, SQ_GET)) {
1359 $startMessage = (int) $temp;
1360 asearch_edit_last(1);
1361 // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1362 }
1363
1364 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
1365 $showall = (int) $temp;
1366 asearch_edit_last(1);
1367 // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1368 }
1369
1370 if ( sqgetGlobalVar('account', $temp, SQ_GET) ) {
1371 $iAccount = (int) $temp;
1372 } else {
1373 $iAccount = 0;
1374 }
1375
1376 /**
1377 * Which templatedir are we using. TODO, add make a config var of this and make it possible to switch templates
1378 */
1379 $sTplDir = SM_PATH . 'templates/default/';
1380
1381
1382 /**
1383 * Incoming submit buttons from the message list with search results
1384 */
1385 if (sqgetGlobalVar('moveButton', $moveButton, SQ_POST) ||
1386 sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST) ||
1387 sqgetGlobalVar('delete', $markDelete, SQ_POST) ||
1388 sqgetGlobalVar('undeleteButton', $undeleteButton, SQ_POST) ||
1389 sqgetGlobalVar('markRead', $markRead, SQ_POST) ||
1390 sqgetGlobalVar('markUnread', $markUnread, SQ_POST) ||
1391 sqgetGlobalVar('markFlagged', $markFlagged, SQ_POST) ||
1392 sqgetGlobalVar('markUnflagged', $markUnflagged, SQ_POST) ||
1393 sqgetGlobalVar('attache', $attache, SQ_POST)) {
1394 asearch_edit_last(1);
1395 $submit = '';
1396 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1397 }
1398
1399
1400
1401 /** Toggle show/hide saved searches
1402 */
1403 if (sqgetGlobalVar('search_show_saved', $search_show_saved, SQ_GET)) {
1404 setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1);
1405 }
1406 /** Toggle show/hide recent searches
1407 */
1408 if (sqgetGlobalVar('search_show_recent', $search_show_recent, SQ_GET)) {
1409 setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1);
1410 }
1411 // end of get globals
1412
1413 /** If TRUE, do not show search interface
1414 * Default FALSE
1415 * @global bool $search_silent
1416 */
1417 $search_silent = FALSE;
1418
1419 /* See how the page was called and fire off correct function */
1420 if ((empty($submit)) && (!empty($where_array))) {
1421 /* This happens when the Enter key is used or called from outside */
1422 $submit = $search_button_text;
1423 /* Hack needed to handle coming back from read_body et als */
1424 if (count($where_array) != count($unop_array)) {
1425 /**
1426 * Hack to use already existen where and what vars.
1427 * where now contains the initiator page of the messagelist
1428 * and in this case 'search'. what contains an index to access
1429 * the search history
1430 */
1431
1432 sqgetGlobalVar('what',$what,SQ_GET);
1433 asearch_edit_last($what);
1434 }
1435 }
1436
1437 if (!isset($submit)) {
1438 $submit = '';
1439 } else {
1440 switch ($submit) {
1441 case $search_button_text:
1442 if (asearch_check_query($where_array, $what_array, $exclude_array) == '') {
1443 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1444 }
1445 break;
1446 case 'Search_silent':
1447 $search_silent = TRUE;
1448 /*nobreak;*/
1449 case 'Search_no_update':
1450 $submit = $search_button_text;
1451 break;
1452 case $del_excluded_button_text:
1453 $delarray = array_keys($exclude_array);
1454 while (!empty($delarray)) {
1455 $delrow = array_pop($delarray);
1456 array_splice($mailbox_array, $delrow, 1);
1457 array_splice($biop_array, $delrow, 1);
1458 array_splice($unop_array, $delrow, 1);
1459 array_splice($where_array, $delrow, 1);
1460 array_splice($what_array, $delrow, 1);
1461 /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */
1462 array_splice($sub_array, $delrow, 1);
1463 }
1464 $exclude_array = array();
1465 break;
1466 case $del_all_button_text:
1467 $mailbox_array = array();
1468 $biop_array = array();
1469 $unop_array = array();
1470 $where_array = array();
1471 $what_array = array();
1472 $exclude_array = array();
1473 $sub_array = array();
1474 break;
1475 case 'save_recent':
1476 asearch_save_recent($submit_rownum);
1477 break;
1478 case 'search_recent':
1479 $submit = $search_button_text;
1480 asearch_edit_recent($submit_rownum);
1481 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1482 break;
1483 case 'edit_recent': /* no link to do this, yet */
1484 asearch_edit_recent($submit_rownum);
1485 break;
1486 case 'forget_recent':
1487 asearch_forget_recent($submit_rownum);
1488 break;
1489 case 'search_saved':
1490 $submit = $search_button_text;
1491 asearch_edit_saved($submit_rownum);
1492 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1493 break;
1494 case 'edit_saved':
1495 asearch_edit_saved($submit_rownum);
1496 break;
1497 case 'delete_saved':
1498 asearch_delete_saved($submit_rownum);
1499 break;
1500 }
1501 }
1502
1503 //Texts in both basic and advanced form
1504 $imap_asearch_unops = array(
1505 '' => '',
1506 'NOT' => _("Not")
1507 );
1508
1509 if ($search_advanced) {
1510 //Texts in advanced form only
1511 $imap_asearch_options = array(
1512 //<message set>,
1513 //'ALL' is binary operator
1514 'ANSWERED' => _("Answered"),
1515 'BCC' => _("Bcc"),
1516 'BEFORE' => _("Before"),
1517 'BODY' => _("Message Body"),
1518 'CC' => _("Cc"),
1519 'DELETED' => _("Deleted"),
1520 'DRAFT' => _("Draft"),
1521 'FLAGGED' => _("Flagged"),
1522 'FROM' => _("Sent By"),
1523 'HEADER' => _("Header Field"),
1524 'KEYWORD' => _("Keyword"),
1525 'LARGER' => _("Larger Than"),
1526 'NEW' => _("New"),
1527 //'NOT' is unary operator
1528 'OLD' => _("Old"),
1529 'ON' => _("On"),
1530 //'OR' is binary operator
1531 'RECENT' => _("Recent"),
1532 'SEEN' => _("Seen"),
1533 'SENTBEFORE' => _("Sent Before"),
1534 'SENTON' => _("Sent On"),
1535 'SENTSINCE' => _("Sent Since"),
1536 'SINCE' => _("Since"),
1537 'SMALLER' => _("Smaller Than"),
1538 'SUBJECT' => _("Subject Contains"),
1539 'TEXT' => _("Header and Body"),
1540 'TO' => _("Sent To"),
1541 //'UID' => 'anum',
1542 /* 'UNANSWERED' => '',
1543 'UNDELETED' => '',
1544 'UNDRAFT' => '',
1545 'UNFLAGGED' => '',
1546 'UNKEYWORD' => _("Unkeyword"),
1547 'UNSEEN' => _("Unseen"),*/
1548 );
1549
1550 $imap_asearch_biops_in = array(
1551 'ALL' => _("And In"),
1552 'OR' => _("Or In")
1553 );
1554
1555 $imap_asearch_biops = array(
1556 'ALL' => _("And"),
1557 'OR' => _("Or")
1558 );
1559 } else {
1560 //Texts in basic form only
1561 $imap_asearch_options = array(
1562 'BCC' => _("Bcc"),
1563 'BODY' => _("Body"),
1564 'CC' => _("Cc"),
1565 'FROM' => _("From"),
1566 'SUBJECT' => _("Subject"),
1567 'TEXT' => _("Everywhere"),
1568 'TO' => _("To"),
1569 );
1570 }
1571
1572 uasort($imap_asearch_options, 'asearch_unhtml_strcoll');
1573
1574 /* open IMAP connection */
1575 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1576
1577
1578 /* get mailboxes once here */
1579 $boxes = sqimap_mailbox_list($imapConnection);
1580 /* ensure we have a valid default mailbox name */
1581 $mailbox = asearch_nz($mailbox_array[0]);
1582 if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?)
1583 $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;)
1584
1585
1586 /**
1587 * Handle form actions like flag / unflag, seen / unseen, delete
1588 */
1589 if (sqgetGlobalVar('mailbox',$postMailbox,SQ_POST)) {
1590 if ($postMailbox) {
1591 /**
1592 * system wide admin settings and incoming vars.
1593 */
1594 $aConfig = array(
1595 'user' => $username,
1596 );
1597 $aConfig['setindex'] = 1; // $what $where = 'search'
1598 /**
1599 * Set the max cache size to the number of mailboxes to avoid cache cleanups
1600 * when searching all mailboxes
1601 */
1602 $aConfig['max_cache_size'] = count($boxes) +1;
1603
1604 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $postMailbox,$aConfig,array());
1605 $sError = handleMessageListForm($imapConnection,$aMailbox);
1606 /* add the mailbox to the cache */
1607 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1608
1609 if ($sError) {
1610 $note = $sError;
1611 }
1612 }
1613 }
1614
1615 if (isset($aMailbox['FORWARD_SESSION'])) {
1616 /* add the mailbox to the cache */
1617 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1618 sqsession_register($mailbox_cache,'mailbox_cache');
1619
1620 if ($compose_new_win) {
1621 // write the session in order to make sure that the compose window has
1622 // access to the composemessages array which is stored in the session
1623 session_write_close();
1624 // restart the session. Do not use sqsession_is_active because the session_id
1625 // isn't empty after a session_write_close
1626 sqsession_start();
1627
1628 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
1629 $compose_width = '640';
1630 }
1631 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
1632 $compose_height = '550';
1633 }
1634 // do not use &amp;, it will break the query string and $session will not be detected!!!
1635 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
1636 '&session='.$aMailbox['FORWARD_SESSION'];
1637 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", false);
1638 } else {
1639 // save mailboxstate
1640 sqsession_register($aMailbox,'aLastSelectedMailbox');
1641 session_write_close();
1642 // we have to redirect to the compose page
1643 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
1644 '&amp;session='.$aMailbox['FORWARD_SESSION'];
1645 header("Location: $location");
1646 exit;
1647 }
1648 } else {
1649 displayPageHeader($color, $mailbox);
1650 // $compose_uri = $base_uri.'src/compose.php?newmessage=1';
1651 }
1652
1653 if (isset($note)) {
1654 echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n";
1655 }
1656
1657
1658 do_hook('search_before_form');
1659
1660 if (!$search_silent) {
1661 //Add a link to the other search mode if allowed
1662 if ($allow_advanced_search > 1)
1663 $toggle_link = ' - <small>['
1664 . asearch_get_toggle_link(!$search_advanced, 'advanced', array(_("Standard search"), _("Advanced search")))
1665 . ']</small>';
1666 else
1667 $toggle_link = '';
1668
1669 echo html_tag('table',
1670 html_tag('tr', "\n"
1671 . html_tag('td', asearch_get_title_display($color, _("Search")) . $toggle_link, 'center', $color[0])
1672 ) ,
1673 '', '', 'width="100%"') . "\n";
1674 asearch_print_saved($boxes);
1675 asearch_print_recent($boxes);
1676 if (empty($where_array)) {
1677 global $sent_folder;
1678
1679 $mailbox_array[0] = $mailbox;
1680 $biop_array[0] = '';
1681 $unop_array[0] = '';
1682 if ($mailbox == $sent_folder) {
1683 $where_array[0] = 'TO';
1684 } else {
1685 $where_array[0] = 'FROM';
1686 }
1687 $what_array[0] = '';
1688 $exclude_array[0] = '';
1689 $sub_array[0] = '';
1690 }
1691 //Display advanced or basic form
1692 if ($search_advanced) {
1693 if ($submit == $add_criteria_button_text) {
1694 $last_index = max(count($where_array) - 1, 0);
1695 $mailbox_array[] = asearch_nz($mailbox_array[$last_index]);
1696 $biop_array[] = asearch_nz($biop_array[$last_index]);
1697 $unop_array[] = asearch_nz($unop_array[$last_index]);
1698 $where_array[] = asearch_nz($where_array[$last_index]);
1699 $what_array[] = asearch_nz($what_array[$last_index]);
1700 $exclude_array[] = asearch_nz($exclude_array[$last_index]);
1701 $sub_array[] = asearch_nz($sub_array[$last_index]);
1702 }
1703 asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1704 } else {
1705 asearch_print_form_basic($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1706 }
1707 }
1708
1709 do_hook('search_after_form');
1710
1711 if ($submit == $search_button_text) {
1712 $msgsfound = false;
1713 echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"');
1714 echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5]));
1715 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]));
1716 echo '</table>' . "\n";
1717
1718 flush();
1719 $iMsgCnt = 0;
1720 $query_error = asearch_check_query($where_array, $what_array, $exclude_array);
1721 if ($query_error != '') {
1722 echo '<br />' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n";
1723 } else {
1724 $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
1725 /**
1726 * Retrieve the search queries
1727 */
1728 $mboxes_mailbox = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
1729 foreach($mboxes_mailbox as $mbx => $search) {
1730
1731 /**
1732 * until there is no per mailbox option screen to set prefs we override
1733 * the mailboxprefs by the default ones
1734 */
1735
1736 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$iAccount.'_'.$mbx);
1737 if ($aMailboxPrefSer) {
1738 $aMailboxPref = unserialize($aMailboxPrefSer);
1739 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
1740 } else {
1741 setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($default_mailbox_pref));
1742 $aMailboxPref = $default_mailbox_pref;
1743 }
1744 if (isset($srt) && $targetmailbox == $mbx) {
1745 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
1746 }
1747
1748 $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
1749 $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
1750 $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
1751
1752
1753 /**
1754 * until there is no per mailbox option screen to set prefs we override
1755 * the mailboxprefs by the default ones
1756 */
1757 $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
1758 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
1759 $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
1760 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
1761
1762 /**
1763 * Replace From => To in case it concerns a draft or sent folder
1764 */
1765 if (($mbx == $sent_folder || $mbx == $draft_folder) &&
1766 !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
1767 $aNewOrder = array(); // nice var name ;)
1768 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
1769 if ($iCol == SQM_COL_FROM) {
1770 $iCol = SQM_COL_TO;
1771 }
1772 $aNewOrder[] = $iCol;
1773 }
1774 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
1775 setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($aMailboxPref));
1776 }
1777
1778 $aConfig['search'] = $search['search'];
1779 $aConfig['charset'] = $search['charset'];
1780
1781 /**
1782 * Set the max cache size to the number of mailboxes to avoid cache cleanups
1783 * when searching all mailboxes
1784 */
1785 $aConfig['max_cache_size'] = count($mboxes_mailbox) +1;
1786 if (isset($startMessage) && $targetmailbox == $mbx) {
1787 $aConfig['offset'] = $startMessage;
1788 } else {
1789 $aConfig['offset'] = 0;
1790 }
1791 if (isset($showall) && $targetmailbox == $mbx) {
1792 $aConfig['showall'] = $showall;
1793 } else {
1794 if (isset($aConfig['showall'])) {
1795 unset($aConfig['showall']);
1796 }
1797 $showall = false;
1798 }
1799
1800 /**
1801 * Set the config options for the messages list
1802 */
1803 $aColumns = array();
1804 foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
1805 $aColumns[$iCol] = array();
1806 switch ($iCol) {
1807 case SQM_COL_SUBJ:
1808 if ($truncate_subject) {
1809 $aColumns[$iCol]['truncate'] = $truncate_subject;
1810 }
1811 break;
1812 case SQM_COL_FROM:
1813 case SQM_COL_TO:
1814 case SQM_COL_CC:
1815 case SQM_COL_BCC:
1816 if ($truncate_sender) {
1817 $aColumns[$iCol]['truncate'] = $truncate_sender;
1818 }
1819 break;
1820 }
1821 }
1822
1823
1824 $aProps = array(
1825 'columns' => $aColumns,
1826 'config' => array('alt_index_colors' => $alt_index_colors,
1827 'highlight_list' => $message_highlight_list,
1828 'fancy_index_highlite' => $fancy_index_highlite,
1829 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
1830 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '',
1831 'trash_folder' => $trash_folder,
1832 'sent_folder' => $sent_folder,
1833 'draft_folder' => $draft_folder,
1834 'enablesort' => true,
1835 'color' => $color
1836 ),
1837 'mailbox' => $mbx,
1838 'account' => (isset($iAccount)) ? $iAccount : 0,
1839 'module' => 'read_body',
1840 'email' => false);
1841
1842
1843 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mbx,$aConfig,$aMailboxPref);
1844
1845 $iError = 0;
1846 $aTemplate = showMessagesForMailbox($imapConnection, $aMailbox,$aProps, $iError);
1847
1848 // in th future we can make use of multiple message sets, now set it to 1 for search.
1849 $iSetIndex = 1;
1850 if (isset($aMailbox['UIDSET'][$iSetIndex])) {
1851 $iMsgCnt += count($aMailbox['UIDSET'][$iSetIndex]);
1852 }
1853 if ($iError) {
1854 // error handling
1855 } else {
1856 /**
1857 * In the future, move this the the initialisation area
1858 */
1859 sqgetGlobalVar('align',$align,SQ_SESSION);
1860
1861 $oTemplate = new Template($sTplDir);
1862
1863 if ($aMailbox['EXISTS'] > 0) {
1864 if ($iError) {
1865 // TODO
1866 echo "ERROR occured, errorhandler will be implemented very soon";
1867 } else {
1868 foreach ($aTemplate as $k => $v) {
1869 $oTemplate->assign($k, $v);
1870 }
1871
1872 $oTemplate->assign('page_selector', $page_selector);
1873 $oTemplate->assign('page_selector_max', $page_selector_max);
1874 $oTemplate->assign('compact_paginator', $compact_paginator);
1875 $oTemplate->assign('javascript_on', $javascript_on);
1876 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
1877 $oTemplate->assign('icon_theme_path', $icon_theme_path);
1878 $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
1879 $oTemplate->assign('aOrder', array_keys($aColumns));
1880 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
1881 $oTemplate->assign('color', $color);
1882 $oTemplate->assign('align', $align);
1883
1884 $mailbox_display = asearch_get_mailbox_display($aMailbox['NAME']);
1885 if (strtoupper($mbx) == 'INBOX') {
1886 $mailbox_display = _("INBOX");
1887 } else {
1888 $mailbox_display = imap_utf7_decode_local($mbx);
1889 }
1890
1891 echo '<br /><b><big>' . _("Folder:") . ' '. htmlspecialchars($mailbox_display) . '&nbsp;</big></b>';
1892
1893 $oTemplate->display('message_list.tpl');
1894 }
1895 }
1896 }
1897
1898 /* add the mailbox to the cache */
1899 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1900
1901 }
1902 }
1903 if(!$iMsgCnt) {
1904 echo '<br />' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n";
1905 }
1906 }
1907
1908 do_hook('search_bottom');
1909 sqimap_logout($imapConnection);
1910 $oTemplate->display('footer.tpl');
1911 sqsession_register($mailbox_cache,'mailbox_cache');
1912
1913 ?>