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