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