fsf changes, meant to be rebased on upstream
[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>
77a1e3d1 11 * @copyright 1999-2022 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)) {
3047e291 583 $mailbox_display = ' <span class="mailbox">' . sm_encode_html_special_chars(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
3047e291 609 $what_display = sm_encode_html_special_chars($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
67fc0e24 677 $oTemplate->assign('save_recent', '../src/search.php?submit=save_recent&smtoken=' . sm_generate_security_token() . '&rownum=');
678 $oTemplate->assign('do_recent', '../src/search.php?submit=search_recent&smtoken=' . sm_generate_security_token() . '&rownum=');
679 $oTemplate->assign('forget_recent', '../src/search.php?submit=forget_recent&smtoken=' . sm_generate_security_token() . '&rownum=');
146acc11 680
67fc0e24 681 $oTemplate->assign('edit_saved', '../src/search.php?submit=edit_saved&smtoken=' . sm_generate_security_token() . '&rownum=');
682 $oTemplate->assign('do_saved', '../src/search.php?submit=search_saved&smtoken=' . sm_generate_security_token() . '&rownum=');
683 $oTemplate->assign('delete_saved', '../src/search.php?submit=delete_saved&smtoken=' . sm_generate_security_token() . '&rownum=');
146acc11 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))) {
3047e291 785 $a[$mailbox] = '[' . _("Missing") . '] ' . sm_encode_html_special_chars(asearch_get_mailbox_display($mailbox));
146acc11 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
199a9ab8 809 echo '<form action="../src/search.php" name="form_asearch">' . "\n"
810 . addHidden('smtoken', sm_generate_security_token()) . "\n";
146acc11 811 $oTemplate->display('search_advanced.tpl');
812 echo "</form>\n";
7d60bda5 813}
814
815/** Print the basic search form
b4425d7c 816 * @param stream $imapConnection
817 * @param array $boxes
818 * @param array $mailbox_array
819 * @param array $biop_array
820 * @param array $unop_array
821 * @param array $where_array
822 * @param array $what_array
823 * @param array $exclude_array
824 * @param array $sub_array
825 * @since 1.5.1
826 * @private
134e4174 827 */
7d60bda5 828function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
829{
146acc11 830 global $allow_advanced_search, $search_advanced, $oTemplate, $imap_asearch_unops, $imap_asearch_options;
831
832 $row_num = 0;
833 $mailbox = asearch_nz($mailbox_array[$row_num]);
834 $biop = strip_tags(asearch_nz($biop_array[$row_num]));
835 $unop = strip_tags(asearch_nz($unop_array[$row_num]));
836 $where = strip_tags(asearch_nz($where_array[$row_num]));
837 $what = asearch_nz($what_array[$row_num]);
838 $exclude = strip_tags(asearch_nz($exclude_array[$row_num]));
839 $sub = strip_tags(asearch_nz($sub_array[$row_num]));
840
841 # Build the mailbox array
842 $a = array();
843 if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) {
3047e291 844 $a[$mailbox] = '[' . _("Missing") . '] ' . sm_encode_html_special_chars(asearch_get_mailbox_display($mailbox));
8cc8ec79 845 }
146acc11 846 $a['All Folders'] = '[' . asearch_get_mailbox_display('All Folders') . ']';
847 $a = array_merge($a, sqimap_mailbox_option_array($imapConnection, 0, $boxes, NULL));
848
849 if ($allow_advanced_search > 1) {
850 $link = '../src/search.php?advanced='.($search_advanced ? 0 : 1);
851 $txt = $search_advanced ? _("Standard Search") : _("Advanced search");
852 } else {
853 $link = NULL;
854 $txt = NULL;
855 }
856
857 $oTemplate->assign('allow_advanced_search', $allow_advanced_search > 1);
858 $oTemplate->assign('adv_toggle_text', $txt);
859 $oTemplate->assign('adv_toggle_link', $link);
860
861 $oTemplate->assign('mailbox_options', $a);
862 $oTemplate->assign('unary_options', $imap_asearch_unops);
863 $oTemplate->assign('where_options', $imap_asearch_options);
864
3047e291 865 $oTemplate->assign('mailbox_sel', strtolower(sm_encode_html_special_chars($mailbox)));
146acc11 866 $oTemplate->assign('unary_sel', $unop);
867 $oTemplate->assign('where_sel', $where);
868 $oTemplate->assign('what_val', $what);
869
199a9ab8 870 echo '<form action="../src/search.php" name="form_asearch">' . "\n"
871 . addHidden('smtoken', sm_generate_security_token()) . "\n";
146acc11 872 $oTemplate->display('search.tpl');
873 echo "</form>\n";
7d60bda5 874}
875
59a623e6 876
40fbe929 877/**
134e4174 878 * @param array $boxes mailboxes array (reference)
879 * @return array selectable unformatted mailboxes names
b4425d7c 880 * @since 1.5.0
881 * @private
134e4174 882 */
40fbe929 883function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes)
884{
8cc8ec79 885 $mboxes_array = array();
886 $boxcount = count($boxes);
887 for ($boxnum = 0; $boxnum < $boxcount; $boxnum++) {
888 if (!in_array('noselect', $boxes[$boxnum]['flags']))
889 $mboxes_array[] = $boxes[$boxnum]['unformatted'];
890 }
891 return $mboxes_array;
40fbe929 892}
893
0d672ac0 894/* ------------------------ main ------------------------ */
7d60bda5 895/* get globals we will need */
2131e73e 896sqgetGlobalVar('smtoken', $submitted_token, SQ_FORM, '');
7d60bda5 897sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
55521a07 898sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
6b37252b 899
e0a6645e 900if (!sqgetGlobalVar('checkall',$checkall,SQ_GET)) {
901 $checkall = false;
ad2212db 902}
903
52bf380f 904if (!sqgetGlobalVar('preselected', $preselected, SQ_GET) || !is_array($preselected)) {
905 $preselected = array();
906} else {
907 $preselected = array_keys($preselected);
908}
909
324ac3c5 910/**
911 * Retrieve the mailbox cache from the session.
912 */
913sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
914
6b37252b 915$search_button_html = _("Search");
916$search_button_text = asearch_unhtmlentities($search_button_html);
917$add_criteria_button_html = _("Add New Criteria");
918$add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html);
34a85c56 919$del_excluded_button_html = _("Remove Excluded Criteria");
6b37252b 920$del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html);
34a85c56 921$del_all_button_html = _("Remove All Criteria");
6b37252b 922$del_all_button_text = asearch_unhtmlentities($del_all_button_html);
923
7d60bda5 924/** Maximum number of recent searches to handle
134e4174 925 * Default 0
926 * @global integer $search_memory
927 */
7d60bda5 928$search_memory = getPref($data_dir, $username, 'search_memory', 0);
929
930/** Advanced search control
134e4174 931 * - 0 => allow basic interface only
932 * - 1 => allow advanced interface only
933 * - 2 => allow both
934 * Default 2
935 */
5b6abe97 936$allow_advanced_search = asearch_nz($allow_advanced_search, 2);
6b37252b 937
7d60bda5 938/**
134e4174 939 * Toggle advanced/basic search
940 */
324ac3c5 941if (sqgetGlobalVar('advanced', $search_advanced, SQ_GET)) {
8cc8ec79 942 setPref($data_dir, $username, 'search_advanced', $search_advanced & 1);
324ac3c5 943}
7d60bda5 944/** If 1, show advanced search interface
134e4174 945 * Default from allow_advanced_search pref
946 * @global integer $search_advanced
947 */
324ac3c5 948if ($allow_advanced_search > 1) {
8cc8ec79 949 $search_advanced = getPref($data_dir, $username, 'search_advanced', 0);
324ac3c5 950} else {
8cc8ec79 951 $search_advanced = $allow_advanced_search;
324ac3c5 952}
7d60bda5 953if ($search_advanced) {
954/** Set recent prefkeys according to $search_advanced
134e4174 955 * @global array $recent_prefkeys
956 */
8cc8ec79 957 $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 958
959/** Set saved prefkeys according to $search_advanced
134e4174 960 * @global array $saved_prefkeys
961 */
8cc8ec79 962 $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 963
964/*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/
324ac3c5 965} else {
8cc8ec79 966 $recent_prefkeys = array('search_where', 'search_folder', 'search_what', 'search_unop');
967 $saved_prefkeys = array('saved_where', 'saved_folder', 'saved_what', 'saved_unop');
7d60bda5 968}
6b37252b 969
2d2f8bb8 970/** How we did enter the form
134e4174 971 * - unset : Enter key, or called from outside (eg read_body)
972 * - $search_button_text : Search button
973 * - 'Search_no_update' : Search but don't update recent
974 * - 'Search_last' : Same as no_update but reload and search last
975 * - 'Search_silent' : Same as no_update but only display results
976 * - $add_criteria_button_text : Add New Criteria button
977 * - $del_excluded_button_text : Remove Excluded Criteria button
978 * - $del_all_button_text : Remove All Criteria button
979 * - 'save_recent'
980 * - 'search_recent'
981 * - 'forget_recent'
982 * - 'edit_saved'
983 * - 'search_saved'
984 * - 'delete_saved'
985 * @global string $submit
986 */
e09e556f 987$searchpressed = false;
7dc61587 988//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
324ac3c5 989if (isset($_GET['submit'])) {
8cc8ec79 990 $submit = strip_tags($_GET['submit']);
324ac3c5 991}
e09e556f 992
2d2f8bb8 993/** Searched mailboxes
134e4174 994 * @global array $mailbox_array
995 */
7dc61587 996/* when using compact paginator, mailbox might be indicated in $startMessage, so look for it now ($startMessage is then processed farther below) */
997$mailbox = '';
998$startMessage = '';
999if (sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit', SQ_FORM)) {
1000 if (strstr($temp, '_')) list($startMessage, $mailbox) = explode('_', $temp);
1001 else $startMessage = $temp;
1002}
1003if (empty($mailbox)) sqGetGlobalVar('mailbox', $mailbox, SQ_GET, '');
1004if (!empty($mailbox)) {
1005 $mailbox_array = $mailbox;
1006 $targetmailbox = $mailbox;
324ac3c5 1007 if (!is_array($mailbox_array)) {
8cc8ec79 1008 $mailbox_array = array($mailbox_array);
324ac3c5 1009 }
1010} else {
8cc8ec79 1011 $mailbox_array = array();
d0dd72b5 1012 $targetmailbox = array();
324ac3c5 1013}
1014$aMailboxGlobalPref = array(
1015 MBX_PREF_SORT => 0,
1016 MBX_PREF_LIMIT => (int) $show_num,
1017 MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge,
1018 MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')
1019 // MBX_PREF_FUTURE => (var) $future
1020 );
1021
1022/**
1023 * system wide admin settings and incoming vars.
1024 */
1025$aConfig = array(
f027a882 1026// 'allow_thread_sort' => $allow_thread_sort,
1027// 'allow_server_sort' => $allow_server_sort,
324ac3c5 1028 'user' => $username,
91c27aee 1029 'setindex' => 1
324ac3c5 1030 );
6b37252b 1031
2d2f8bb8 1032/** Binary operators
134e4174 1033 * @global array $biop_array
1034 */
7dc61587 1035//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
6b37252b 1036if (isset($_GET['biop'])) {
8cc8ec79 1037 $biop_array = $_GET['biop'];
1038 if (!is_array($biop_array))
1039 $biop_array = array($biop_array);
324ac3c5 1040} else {
8cc8ec79 1041 $biop_array = array();
324ac3c5 1042}
2d2f8bb8 1043/** Unary operators
134e4174 1044 * @global array $unop_array
1045 */
7dc61587 1046//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
6b37252b 1047if (isset($_GET['unop'])) {
8cc8ec79 1048 $unop_array = $_GET['unop'];
1049 if (!is_array($unop_array))
1050 $unop_array = array($unop_array);
324ac3c5 1051} else {
8cc8ec79 1052 $unop_array = array();
324ac3c5 1053}
2d2f8bb8 1054/** Where to search
134e4174 1055 * @global array $where_array
1056 */
7dc61587 1057//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
6b37252b 1058if (isset($_GET['where'])) {
8cc8ec79 1059 $where_array = $_GET['where'];
324ac3c5 1060 if (!is_array($where_array)) {
8cc8ec79 1061 $where_array = array($where_array);
324ac3c5 1062 }
1063} else {
8cc8ec79 1064 $where_array = array();
324ac3c5 1065}
2d2f8bb8 1066/** What to search
134e4174 1067 * @global array $what_array
1068 */
7dc61587 1069//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
6b37252b 1070if (isset($_GET['what'])) {
8cc8ec79 1071 $what_array = $_GET['what'];
324ac3c5 1072 if (!is_array($what_array)) {
8cc8ec79 1073 $what_array = array($what_array);
324ac3c5 1074 }
1075} else {
8cc8ec79 1076 $what_array = array();
324ac3c5 1077}
2d2f8bb8 1078/** Whether to exclude this criteria from search
134e4174 1079 * @global array $exclude_array
1080 */
7dc61587 1081//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
324ac3c5 1082if (isset($_GET['exclude'])) {
8cc8ec79 1083 $exclude_array = $_GET['exclude'];
324ac3c5 1084} else {
8cc8ec79 1085 $exclude_array = array();
324ac3c5 1086}
2d2f8bb8 1087/** Search within subfolders
134e4174 1088 * @global array $sub_array
1089 */
7dc61587 1090//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
324ac3c5 1091if (isset($_GET['sub'])) {
8cc8ec79 1092 $sub_array = $_GET['sub'];
324ac3c5 1093} else {
8cc8ec79 1094 $sub_array = array();
324ac3c5 1095}
2d2f8bb8 1096/** Row number used by recent and saved stuff
134e4174 1097 */
7dc61587 1098//FIXME: Why is there so much access to $_GET in this file? What's wrong with sqGetGlobalVar?
324ac3c5 1099if (isset($_GET['rownum'])) {
6b37252b 1100 $submit_rownum = strip_tags($_GET['rownum']);
324ac3c5 1101}
2d2f8bb8 1102/** Change global sort
134e4174 1103 */
324ac3c5 1104if (sqgetGlobalVar('srt', $temp, SQ_GET)) {
1105 $srt = (int) $temp;
1106 asearch_edit_last(1);
91c27aee 1107// asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
324ac3c5 1108}
7dc61587 1109/* already retrieved startMessage above */
1110if (!empty($startMessage)) {
1111 $startMessage = (int) $startMessage;
324ac3c5 1112 asearch_edit_last(1);
91c27aee 1113// asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
c2d47d51 1114}
1115
324ac3c5 1116if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
1117 $showall = (int) $temp;
1118 asearch_edit_last(1);
91c27aee 1119// asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
56e0b3b7 1120}
91c27aee 1121
1122if ( sqgetGlobalVar('account', $temp, SQ_GET) ) {
1123 $iAccount = (int) $temp;
1124} else {
1125 $iAccount = 0;
1126}
1127
1128/**
324ac3c5 1129 * Incoming submit buttons from the message list with search results
1130 */
1131if (sqgetGlobalVar('moveButton', $moveButton, SQ_POST) ||
1132 sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST) ||
1133 sqgetGlobalVar('delete', $markDelete, SQ_POST) ||
1134 sqgetGlobalVar('undeleteButton', $undeleteButton, SQ_POST) ||
1135 sqgetGlobalVar('markRead', $markRead, SQ_POST) ||
1136 sqgetGlobalVar('markUnread', $markUnread, SQ_POST) ||
1137 sqgetGlobalVar('markFlagged', $markFlagged, SQ_POST) ||
1138 sqgetGlobalVar('markUnflagged', $markUnflagged, SQ_POST) ||
1139 sqgetGlobalVar('attache', $attache, SQ_POST)) {
1140 asearch_edit_last(1);
1141 $submit = '';
1142 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1143}
1144
1145
6b37252b 1146
7d60bda5 1147/** Toggle show/hide saved searches
134e4174 1148 */
324ac3c5 1149if (sqgetGlobalVar('search_show_saved', $search_show_saved, SQ_GET)) {
8cc8ec79 1150 setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1);
324ac3c5 1151}
7d60bda5 1152/** Toggle show/hide recent searches
134e4174 1153 */
324ac3c5 1154if (sqgetGlobalVar('search_show_recent', $search_show_recent, SQ_GET)) {
8cc8ec79 1155 setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1);
324ac3c5 1156}
7d60bda5 1157// end of get globals
6b37252b 1158
40fbe929 1159/** If TRUE, do not show search interface
134e4174 1160 * Default FALSE
1161 * @global bool $search_silent
1162 */
7d60bda5 1163$search_silent = FALSE;
6b37252b 1164
1165/* See how the page was called and fire off correct function */
7d60bda5 1166if ((empty($submit)) && (!empty($where_array))) {
8cc8ec79 1167 /* This happens when the Enter key is used or called from outside */
1168 $submit = $search_button_text;
324ac3c5 1169 /* Hack needed to handle coming back from read_body et als */
1170 if (count($where_array) != count($unop_array)) {
1171 /**
1172 * Hack to use already existen where and what vars.
1173 * where now contains the initiator page of the messagelist
1174 * and in this case 'search'. what contains an index to access
1175 * the search history
1176 */
1177
1178 sqgetGlobalVar('what',$what,SQ_GET);
1179 asearch_edit_last($what);
1180 }
56e0b3b7 1181}
6b37252b 1182
1183if (!isset($submit)) {
8cc8ec79 1184 $submit = '';
324ac3c5 1185} else {
199a9ab8 1186
1187 // first validate security token
2cefa62a 1188 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 1189
8cc8ec79 1190 switch ($submit) {
324ac3c5 1191 case $search_button_text:
1192 if (asearch_check_query($where_array, $what_array, $exclude_array) == '') {
1193 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
1194 }
8cc8ec79 1195 break;
324ac3c5 1196 case 'Search_silent':
1197 $search_silent = TRUE;
8cc8ec79 1198 /*nobreak;*/
324ac3c5 1199 case 'Search_no_update':
1200 $submit = $search_button_text;
8cc8ec79 1201 break;
324ac3c5 1202 case $del_excluded_button_text:
1203 $delarray = array_keys($exclude_array);
1204 while (!empty($delarray)) {
1205 $delrow = array_pop($delarray);
1206 array_splice($mailbox_array, $delrow, 1);
1207 array_splice($biop_array, $delrow, 1);
1208 array_splice($unop_array, $delrow, 1);
1209 array_splice($where_array, $delrow, 1);
1210 array_splice($what_array, $delrow, 1);
134e4174 1211 /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */
324ac3c5 1212 array_splice($sub_array, $delrow, 1);
1213 }
1214 $exclude_array = array();
8cc8ec79 1215 break;
324ac3c5 1216 case $del_all_button_text:
1217 $mailbox_array = array();
1218 $biop_array = array();
1219 $unop_array = array();
1220 $where_array = array();
1221 $what_array = array();
1222 $exclude_array = array();
1223 $sub_array = array();
8cc8ec79 1224 break;
324ac3c5 1225 case 'save_recent':
1226 asearch_save_recent($submit_rownum);
8cc8ec79 1227 break;
324ac3c5 1228 case 'search_recent':
1229 $submit = $search_button_text;
1230 asearch_edit_recent($submit_rownum);
1231 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
8cc8ec79 1232 break;
134e4174 1233 case 'edit_recent': /* no link to do this, yet */
324ac3c5 1234 asearch_edit_recent($submit_rownum);
8cc8ec79 1235 break;
324ac3c5 1236 case 'forget_recent':
1237 asearch_forget_recent($submit_rownum);
8cc8ec79 1238 break;
324ac3c5 1239 case 'search_saved':
1240 $submit = $search_button_text;
1241 asearch_edit_saved($submit_rownum);
1242 asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
8cc8ec79 1243 break;
324ac3c5 1244 case 'edit_saved':
1245 asearch_edit_saved($submit_rownum);
8cc8ec79 1246 break;
324ac3c5 1247 case 'delete_saved':
1248 asearch_delete_saved($submit_rownum);
8cc8ec79 1249 break;
1250 }
56e0b3b7 1251}
23a9084b 1252
7d60bda5 1253//Texts in both basic and advanced form
1254$imap_asearch_unops = array(
8cc8ec79 1255 '' => '',
1256 'NOT' => _("Not")
7d60bda5 1257);
1258
1259if ($search_advanced) {
8cc8ec79 1260 //Texts in advanced form only
1261 $imap_asearch_options = array(
1262 //<message set>,
1263 //'ALL' is binary operator
1264 'ANSWERED' => _("Answered"),
1265 'BCC' => _("Bcc"),
1266 'BEFORE' => _("Before"),
1267 'BODY' => _("Message Body"),
48027e89 1268 'CC' => _("Cc"),
8cc8ec79 1269 'DELETED' => _("Deleted"),
1270 'DRAFT' => _("Draft"),
1271 'FLAGGED' => _("Flagged"),
1272 'FROM' => _("Sent By"),
1273 'HEADER' => _("Header Field"),
1274 'KEYWORD' => _("Keyword"),
1275 'LARGER' => _("Larger Than"),
1276 'NEW' => _("New"),
1277 //'NOT' is unary operator
1278 'OLD' => _("Old"),
1279 'ON' => _("On"),
1280 //'OR' is binary operator
1281 'RECENT' => _("Recent"),
1282 'SEEN' => _("Seen"),
1283 'SENTBEFORE' => _("Sent Before"),
1284 'SENTON' => _("Sent On"),
1285 'SENTSINCE' => _("Sent Since"),
1286 'SINCE' => _("Since"),
1287 'SMALLER' => _("Smaller Than"),
1288 'SUBJECT' => _("Subject Contains"),
1289 'TEXT' => _("Header and Body"),
1290 'TO' => _("Sent To"),
1291 //'UID' => 'anum',
134e4174 1292/* 'UNANSWERED' => '',
8cc8ec79 1293 'UNDELETED' => '',
1294 'UNDRAFT' => '',
1295 'UNFLAGGED' => '',
1296 'UNKEYWORD' => _("Unkeyword"),
1297 'UNSEEN' => _("Unseen"),*/
1298 );
1299
1300 $imap_asearch_biops_in = array(
1301 'ALL' => _("And In"),
1302 'OR' => _("Or In")
1303 );
1304
1305 $imap_asearch_biops = array(
1306 'ALL' => _("And"),
1307 'OR' => _("Or")
1308 );
324ac3c5 1309} else {
8cc8ec79 1310 //Texts in basic form only
1311 $imap_asearch_options = array(
1312 'BCC' => _("Bcc"),
1313 'BODY' => _("Body"),
1314 'CC' => _("Cc"),
1315 'FROM' => _("From"),
1316 'SUBJECT' => _("Subject"),
1317 'TEXT' => _("Everywhere"),
1318 'TO' => _("To"),
1319 );
7d60bda5 1320}
1321
1322uasort($imap_asearch_options, 'asearch_unhtml_strcoll');
1323
6b37252b 1324/* open IMAP connection */
a9805897 1325global $imap_stream_options; // in case not defined in config
1326$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
324ac3c5 1327
1328
5b6abe97 1329/* get mailboxes once here */
6b37252b 1330$boxes = sqimap_mailbox_list($imapConnection);
99f3175e 1331/* ensure we have a valid default mailbox name */
edda50ae 1332$mailbox = asearch_nz($mailbox_array[0]);
876fdb60 1333if ($mailbox == '')
134e4174 1334 $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;)
99f3175e 1335
91c27aee 1336
1337/**
1338* Handle form actions like flag / unflag, seen / unseen, delete
1339*/
1340if (sqgetGlobalVar('mailbox',$postMailbox,SQ_POST)) {
1341 if ($postMailbox) {
1342 /**
1343 * system wide admin settings and incoming vars.
1344 */
1345 $aConfig = array(
1346 'user' => $username,
1347 );
1348 $aConfig['setindex'] = 1; // $what $where = 'search'
1349 /**
1350 * Set the max cache size to the number of mailboxes to avoid cache cleanups
1351 * when searching all mailboxes
1352 */
1353 $aConfig['max_cache_size'] = count($boxes) +1;
1354
1355 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $postMailbox,$aConfig,array());
1356 $sError = handleMessageListForm($imapConnection,$aMailbox);
1357 /* add the mailbox to the cache */
1358 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1359
1360 if ($sError) {
1361 $note = $sError;
1362 }
1363 }
1364}
1365
1366if (isset($aMailbox['FORWARD_SESSION'])) {
1367 /* add the mailbox to the cache */
1368 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1369 sqsession_register($mailbox_cache,'mailbox_cache');
1370
1371 if ($compose_new_win) {
1372 // write the session in order to make sure that the compose window has
1373 // access to the composemessages array which is stored in the session
1374 session_write_close();
8517e764 1375 // restart the session. Do not use sqsession_is_active because the session_id
1376 // isn't empty after a session_write_close
3a1de9f1 1377 sqsession_start();
91c27aee 1378
1379 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
1380 $compose_width = '640';
1381 }
1382 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
1383 $compose_height = '550';
1384 }
1385 // do not use &amp;, it will break the query string and $session will not be detected!!!
e506b6e5 1386 $comp_uri = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
1387 . '&session='.$aMailbox['FORWARD_SESSION']['SESSION_NUMBER']
1388 . '&smaction=forward_as_attachment'
1389 . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
91c27aee 1390 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", false);
1391 } else {
1392 // save mailboxstate
1393 sqsession_register($aMailbox,'aLastSelectedMailbox');
1394 session_write_close();
1395 // we have to redirect to the compose page
e506b6e5 1396 $location = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
1397 . '&session='.$aMailbox['FORWARD_SESSION']['SESSION_NUMBER']
1398 . '&smaction=forward_as_attachment'
1399 . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
91c27aee 1400 header("Location: $location");
1401 exit;
1402 }
324ac3c5 1403} else {
8cc8ec79 1404 displayPageHeader($color, $mailbox);
91c27aee 1405// $compose_uri = $base_uri.'src/compose.php?newmessage=1';
1406}
1407
1408if (isset($note)) {
146acc11 1409 $oTemplate->assign('note', $note);
1410 $oTemplate->display('note.tpl');
324ac3c5 1411}
91c27aee 1412
6e515418 1413do_hook('search_before_form', $null);
d81e351b 1414
6b37252b 1415if (!$search_silent) {
8cc8ec79 1416 asearch_print_saved($boxes);
1417 asearch_print_recent($boxes);
1418 if (empty($where_array)) {
1419 global $sent_folder;
1420
1421 $mailbox_array[0] = $mailbox;
1422 $biop_array[0] = '';
1423 $unop_array[0] = '';
324ac3c5 1424 if ($mailbox == $sent_folder) {
8cc8ec79 1425 $where_array[0] = 'TO';
324ac3c5 1426 } else {
8cc8ec79 1427 $where_array[0] = 'FROM';
324ac3c5 1428 }
8cc8ec79 1429 $what_array[0] = '';
1430 $exclude_array[0] = '';
1431 $sub_array[0] = '';
1432 }
1433 //Display advanced or basic form
1434 if ($search_advanced) {
1435 if ($submit == $add_criteria_button_text) {
1436 $last_index = max(count($where_array) - 1, 0);
1437 $mailbox_array[] = asearch_nz($mailbox_array[$last_index]);
1438 $biop_array[] = asearch_nz($biop_array[$last_index]);
1439 $unop_array[] = asearch_nz($unop_array[$last_index]);
1440 $where_array[] = asearch_nz($where_array[$last_index]);
1441 $what_array[] = asearch_nz($what_array[$last_index]);
1442 $exclude_array[] = asearch_nz($exclude_array[$last_index]);
1443 $sub_array[] = asearch_nz($sub_array[$last_index]);
1444 }
1445 asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
324ac3c5 1446 } else {
8cc8ec79 1447 asearch_print_form_basic($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
324ac3c5 1448 }
6b37252b 1449}
1450
6e515418 1451do_hook('search_after_form', $null);
56e0b3b7 1452
6b37252b 1453if ($submit == $search_button_text) {
a73ae1c2 1454 $msgsfound = false;
8cc8ec79 1455
146acc11 1456 $err = asearch_check_query($where_array, $what_array, $exclude_array);
1457
1458 $oTemplate->assign('query_has_error', $err!='');
1459 $oTemplate->assign('query_error', $err=='' ? NULL : $err);
1460 $oTemplate->assign('query', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array));
1461
1462 $oTemplate->display('search_result_top.tpl');
1463
8cc8ec79 1464 flush();
e09e556f 1465 $iMsgCnt = 0;
146acc11 1466 if ($err == '') {
8cc8ec79 1467 $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
324ac3c5 1468 /**
1469 * Retrieve the search queries
1470 */
1471 $mboxes_mailbox = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
1472 foreach($mboxes_mailbox as $mbx => $search) {
324ac3c5 1473
91c27aee 1474 /**
1475 * until there is no per mailbox option screen to set prefs we override
1476 * the mailboxprefs by the default ones
1477 */
1478
1479 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$iAccount.'_'.$mbx);
324ac3c5 1480 if ($aMailboxPrefSer) {
1481 $aMailboxPref = unserialize($aMailboxPrefSer);
91c27aee 1482 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
324ac3c5 1483 } else {
91c27aee 1484 setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($default_mailbox_pref));
1485 $aMailboxPref = $default_mailbox_pref;
8cc8ec79 1486 }
324ac3c5 1487 if (isset($srt) && $targetmailbox == $mbx) {
1488 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
1489 }
91c27aee 1490
1491 $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
1492 $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
1493 $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
1494
324ac3c5 1495
1496 /**
1497 * until there is no per mailbox option screen to set prefs we override
1498 * the mailboxprefs by the default ones
1499 */
1500 $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
1501 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
1502 $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
91c27aee 1503 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
1504
1505 /**
1506 * Replace From => To in case it concerns a draft or sent folder
1507 */
1508 if (($mbx == $sent_folder || $mbx == $draft_folder) &&
1509 !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
1510 $aNewOrder = array(); // nice var name ;)
1511 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
1512 if ($iCol == SQM_COL_FROM) {
1513 $iCol = SQM_COL_TO;
1514 }
1515 $aNewOrder[] = $iCol;
1516 }
1517 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
f16dc830 1518 setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($aMailboxPref));
91c27aee 1519 }
324ac3c5 1520
324ac3c5 1521 $aConfig['search'] = $search['search'];
1522 $aConfig['charset'] = $search['charset'];
324ac3c5 1523
324ac3c5 1524 /**
91c27aee 1525 * Set the max cache size to the number of mailboxes to avoid cache cleanups
1526 * when searching all mailboxes
1527 */
1528 $aConfig['max_cache_size'] = count($mboxes_mailbox) +1;
1529 if (isset($startMessage) && $targetmailbox == $mbx) {
1530 $aConfig['offset'] = $startMessage;
e09e556f 1531 } else {
1532 $aConfig['offset'] = 0;
91c27aee 1533 }
1534 if (isset($showall) && $targetmailbox == $mbx) {
1535 $aConfig['showall'] = $showall;
1536 } else {
1537 if (isset($aConfig['showall'])) {
1538 unset($aConfig['showall']);
1539 }
1540 $showall = false;
1541 }
1542
1543 /**
1544 * Set the config options for the messages list
324ac3c5 1545 */
91c27aee 1546 $aColumns = array();
1547 foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
1548 $aColumns[$iCol] = array();
1549 switch ($iCol) {
1550 case SQM_COL_SUBJ:
1551 if ($truncate_subject) {
1552 $aColumns[$iCol]['truncate'] = $truncate_subject;
1553 }
1554 break;
1555 case SQM_COL_FROM:
1556 case SQM_COL_TO:
1557 case SQM_COL_CC:
1558 case SQM_COL_BCC:
1559 if ($truncate_sender) {
1560 $aColumns[$iCol]['truncate'] = $truncate_sender;
1561 }
1562 break;
324ac3c5 1563 }
1564 }
91c27aee 1565
1566
1567 $aProps = array(
1568 'columns' => $aColumns,
1569 'config' => array('alt_index_colors' => $alt_index_colors,
1570 'highlight_list' => $message_highlight_list,
1571 'fancy_index_highlite' => $fancy_index_highlite,
1572 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
1573 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '',
1574 'trash_folder' => $trash_folder,
1575 'sent_folder' => $sent_folder,
1576 'draft_folder' => $draft_folder,
1577 'enablesort' => true,
1578 'color' => $color
1579 ),
1580 'mailbox' => $mbx,
1581 'account' => (isset($iAccount)) ? $iAccount : 0,
1582 'module' => 'read_body',
1583 'email' => false);
1584
1585
1586 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mbx,$aConfig,$aMailboxPref);
1587
1588 $iError = 0;
1589 $aTemplate = showMessagesForMailbox($imapConnection, $aMailbox,$aProps, $iError);
e09e556f 1590
1591 // in th future we can make use of multiple message sets, now set it to 1 for search.
1592 $iSetIndex = 1;
1593 if (isset($aMailbox['UIDSET'][$iSetIndex])) {
1594 $iMsgCnt += count($aMailbox['UIDSET'][$iSetIndex]);
1595 }
91c27aee 1596 if ($iError) {
1597 // error handling
1598 } else {
1599 /**
1600 * In the future, move this the the initialisation area
1601 */
1602 sqgetGlobalVar('align',$align,SQ_SESSION);
1603
146acc11 1604 /**
1605 * TODO: Clean up handling of message list once the template is cleaned up.
1606 */
91c27aee 1607 if ($aMailbox['EXISTS'] > 0) {
91c27aee 1608 if ($iError) {
1942248e 1609 // TODO: Implement an error handler in the search page.
e09e556f 1610 echo "ERROR occured, errorhandler will be implemented very soon";
91c27aee 1611 } else {
e09e556f 1612 foreach ($aTemplate as $k => $v) {
1613 $oTemplate->assign($k, $v);
1614 }
29997535 1615
146acc11 1616 $mailbox_display = asearch_get_mailbox_display($aMailbox['NAME']);
1617 if (strtoupper($mbx) == 'INBOX') {
1618 $mailbox_display = _("INBOX");
1619 } else {
1620 $mailbox_display = imap_utf7_decode_local($mbx);
1621 }
1622
3047e291 1623 $oTemplate->assign('mailbox_name', sm_encode_html_special_chars($mailbox_display));
146acc11 1624 $oTemplate->display('search_result_mailbox.tpl');
1625
e09e556f 1626 $oTemplate->assign('page_selector', $page_selector);
1627 $oTemplate->assign('page_selector_max', $page_selector_max);
1628 $oTemplate->assign('compact_paginator', $compact_paginator);
457e8593 1629 $oTemplate->assign('javascript_on', checkForJavascript());
fe8103c2 1630 $oTemplate->assign('base_uri', sqm_baseuri());
e09e556f 1631 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
29997535 1632 $oTemplate->assign('icon_theme_path', $icon_theme_path);
e09e556f 1633 $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
1634 $oTemplate->assign('aOrder', array_keys($aColumns));
1635 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
1636 $oTemplate->assign('color', $color);
1637 $oTemplate->assign('align', $align);
e0a6645e 1638 $oTemplate->assign('checkall', $checkall);
52bf380f 1639 $oTemplate->assign('preselected', $preselected);
e09e556f 1640
969c1e9f 1641 global $show_personal_names;
1642 $oTemplate->assign('show_personal_names', $show_personal_names);
1643
47485591 1644 global $accesskey_mailbox_toggle_selected, $accesskey_mailbox_thread;
1645 $oTemplate->assign('accesskey_mailbox_toggle_selected', $accesskey_mailbox_toggle_selected);
1646 $oTemplate->assign('accesskey_mailbox_thread', $accesskey_mailbox_thread);
1647
e09e556f 1648 $oTemplate->display('message_list.tpl');
1649 }
91c27aee 1650 }
a73ae1c2 1651 }
91c27aee 1652
324ac3c5 1653 /* add the mailbox to the cache */
91c27aee 1654 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
8cc8ec79 1655
324ac3c5 1656 }
8cc8ec79 1657 }
e09e556f 1658 if(!$iMsgCnt) {
146acc11 1659 $oTemplate->display('search_result_empty.tpl');
a73ae1c2 1660 }
56e0b3b7 1661}
1662
6e515418 1663do_hook('search_bottom', $null);
6b37252b 1664sqimap_logout($imapConnection);
146acc11 1665
5c4ff7bf 1666$oTemplate->display('footer.tpl');
324ac3c5 1667sqsession_register($mailbox_cache,'mailbox_cache');