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