bb73170f |
1 | <?php |
2 | |
3 | /** |
4 | * search_advanced.php |
5 | * |
6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * IMAP Advanced search page |
10 | * |
30967a1e |
11 | * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas! |
12 | * |
13 | * @version $Id$ |
bb73170f |
14 | * @package squirrelmail |
15 | * @link http://www.ietf.org/rfc/rfc3501.txt |
16 | * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr |
bb73170f |
17 | */ |
18 | |
30967a1e |
19 | /** |
20 | * Path for SquirrelMail required files. |
21 | * @ignore |
22 | */ |
bb73170f |
23 | define('SM_PATH','../'); |
24 | |
25 | /** SquirrelMail required files. */ |
26 | require_once(SM_PATH . 'include/validate.php'); |
27 | require_once(SM_PATH . 'functions/strings.php'); |
28 | require_once(SM_PATH . 'functions/imap_asearch.php'); |
29 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
30 | require_once(SM_PATH . 'functions/imap_messages.php'); |
31 | require_once(SM_PATH . 'functions/mime.php'); |
32 | require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()... |
33 | |
34 | /** |
35 | * @param string $a |
36 | * @param string $b |
37 | * @return bool strcoll()-like result |
38 | */ |
39 | function asearch_unhtml_strcoll($a, $b) |
40 | { |
41 | return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b)); |
42 | } |
43 | |
44 | /** |
45 | * @param string $mailbox mailbox name |
46 | * @return string mailbox name ready to display |
47 | */ |
48 | function imap_get_mailbox_display($mailbox) |
49 | { |
50 | if (strtoupper($mailbox) == 'INBOX') |
51 | return _("INBOX"); |
52 | return imap_utf7_decode_local($mailbox); |
53 | } |
54 | |
55 | /** |
56 | * @param string $mailbox mailbox name |
57 | * @return string mailbox name ready to display |
58 | */ |
59 | function asearch_get_mailbox_display($mailbox) |
60 | { |
61 | if ($mailbox == 'All Folders') |
62 | return _("All Folders"); |
63 | return imap_get_mailbox_display($mailbox); |
64 | } |
65 | |
66 | /** |
67 | * @param array $color color array |
68 | * @param string $txt text to display |
69 | * @return string title ready to display |
70 | */ |
71 | function asearch_get_title_display($color, $txt) |
72 | { |
73 | return '<b><big>' . $txt . '</big></b>'; |
74 | } |
75 | |
76 | /** |
77 | * @param array $color color array |
78 | * @param string $txt text to display |
79 | * @return string error text ready to display |
80 | */ |
81 | function asearch_get_error_display($color, $txt) |
82 | { |
83 | return '<font color="' . $color[2] . '">' . '<b><big>' . $txt . '</big></b></font>'; |
84 | } |
85 | |
86 | /** |
87 | * @param array $input_array array to serialize |
88 | * @return string a string containing a byte-stream representation of value that can be stored anywhere |
89 | */ |
90 | function asearch_serialize($input_array) |
91 | { |
92 | return serialize($input_array); |
93 | } |
94 | |
95 | /** |
96 | * @param string $input_string string to unserialize |
97 | * @return array |
98 | */ |
99 | function asearch_unserialize($input_string) |
100 | { |
101 | return unserialize($input_string); |
102 | } |
103 | |
104 | /** |
105 | * @param string $data_dir prefs data dir or dsn |
106 | * @param string $username the username |
107 | * @param string $key the pref key |
108 | * @param integer $index the pref key index |
109 | * @param string $default default value |
110 | * @return string pref value |
111 | */ |
112 | function asearch_getPref($data_dir, $username, $key, $index, $default = '') |
113 | { |
114 | return getPref($data_dir, $username, $key . $index, $default); |
115 | } |
116 | |
117 | /** |
118 | * @param string $data_dir prefs data dir or dsn |
119 | * @param string $username the username |
120 | * @param string $key the pref key |
121 | * @param integer $index the pref key index |
122 | * @param string $value pref value to set |
123 | * @return bool status |
124 | */ |
125 | function asearch_setPref($data_dir, $username, $key, $index, $value) |
126 | { |
127 | return setPref($data_dir, $username, $key . $index, $value); |
128 | } |
129 | |
130 | /** |
131 | * @param string $data_dir prefs data dir or dsn |
132 | * @param string $username the username |
133 | * @param string $key the pref key |
134 | * @param integer $index the pref key index |
135 | * @return bool status |
136 | */ |
137 | function asearch_removePref($data_dir, $username, $key, $index) |
138 | { |
139 | return removePref($data_dir, $username, $key . $index); |
140 | } |
141 | |
142 | /** Sanity checks, done before running the imap command and before push_recent */ |
143 | function asearch_check_query($where_array, $what_array, $exclude_array) |
144 | { |
145 | global $imap_asearch_opcodes; |
146 | |
147 | if (empty($where_array)) |
148 | return _("Please enter something to search for"); |
149 | if (count($exclude_array) == count($where_array)) |
150 | return _("There must be at least one criteria to search for"); |
151 | for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) { |
152 | $where = $where_array[$crit_num]; |
153 | $what = $what_array[$crit_num]; |
154 | if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != ''))) |
155 | return _("Error in criteria argument"); |
156 | } |
157 | return ''; |
158 | } |
159 | |
160 | /** Read the recent searches */ |
161 | function asearch_read_recent($data_dir, $username) |
162 | { |
163 | global $recent_prefkeys; |
164 | |
165 | $recent_array = array(); |
166 | $recent_max = getPref($data_dir, $username, 'search_memory', 0); |
167 | for ($recent_num = 0; $recent_num < $recent_max; $recent_num++) { |
168 | foreach ($recent_prefkeys as $prefkey) { |
169 | $pref = asearch_getPref($data_dir, $username, $prefkey, $recent_num); |
170 | /* if (!empty($pref))*/ |
171 | $recent_array[$prefkey][$recent_num] = $pref; |
172 | } |
173 | if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) { |
174 | foreach ($recent_prefkeys as $key) { |
175 | array_pop($recent_array[$key]); |
176 | } |
177 | break; |
178 | } |
179 | } |
180 | return $recent_array; |
181 | } |
182 | |
183 | /** Get the saved searches */ |
184 | function asearch_read_saved($data_dir, $username) |
185 | { |
186 | global $saved_prefkeys; |
187 | |
188 | $saved_array = array(); |
189 | $saved_key = $saved_prefkeys[0]; |
190 | for ($saved_count = 0; ; $saved_count++) { |
191 | $pref = asearch_getPref($data_dir, $username, $saved_key, $saved_count); |
192 | if (empty($pref)) |
193 | break; |
194 | } |
195 | for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) { |
196 | foreach ($saved_prefkeys as $key) { |
197 | $saved_array[$key][$saved_num] = asearch_getPref($data_dir, $username, $key, $saved_num); |
198 | } |
199 | } |
200 | return $saved_array; |
201 | } |
202 | |
203 | /** Save a recent search */ |
204 | function asearch_save_recent($data_dir, $username, $recent_index) |
205 | { |
206 | global $recent_prefkeys, $saved_prefkeys; |
207 | |
208 | $saved_array = asearch_read_saved($data_dir, $username); |
209 | $saved_index = count($saved_array[$saved_prefkeys[0]]); |
210 | $recent_array = asearch_read_recent($data_dir, $username); |
211 | $n = 0; |
212 | foreach ($recent_prefkeys as $key) { |
213 | $recent_slice = array_slice($recent_array[$key], $recent_index, 1); |
214 | if (!empty($recent_slice[0])) |
215 | asearch_setPref($data_dir, $username, $saved_prefkeys[$n], $saved_index, $recent_slice[0]); |
216 | else |
217 | asearch_removePref($data_dir, $username, $saved_prefkeys[$n], $saved_index); |
218 | $n++; |
219 | } |
220 | } |
221 | |
222 | /** Write a recent search */ |
223 | function asearch_write_recent($data_dir, $username, $recent_array) |
224 | { |
225 | global $recent_prefkeys; |
226 | |
227 | $recent_max = getPref($data_dir, $username, 'search_memory', 0); |
228 | $recent_count = min($recent_max, count($recent_array[$recent_prefkeys[0]])); |
229 | for ($recent_num=0; $recent_num < $recent_count; $recent_num++) { |
230 | foreach ($recent_prefkeys as $key) { |
231 | asearch_setPref($data_dir, $username, $key, $recent_num, $recent_array[$key][$recent_num]); |
232 | } |
233 | } |
234 | for (; $recent_num < $recent_max; $recent_num++) { |
235 | foreach ($recent_prefkeys as $key) { |
236 | asearch_removePref($data_dir, $username, $key, $recent_num); |
237 | } |
238 | } |
239 | } |
240 | |
241 | /** Forget a recent search */ |
242 | function asearch_forget_recent($data_dir, $username, $forget_index) |
243 | { |
244 | global $recent_prefkeys; |
245 | |
246 | $recent_array = asearch_read_recent($data_dir, $username); |
247 | foreach ($recent_prefkeys as $key) { |
248 | array_splice($recent_array[$key], $forget_index, 1); |
249 | } |
250 | asearch_write_recent($data_dir, $username, $recent_array); |
251 | } |
252 | |
253 | /** Find a recent search */ |
254 | function asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
255 | { |
256 | global $recent_prefkeys; |
257 | |
258 | $mailbox_string = asearch_serialize($mailbox_array); |
259 | $biop_string = asearch_serialize($biop_array); |
260 | $unop_string = asearch_serialize($unop_array); |
261 | $where_string = asearch_serialize($where_array); |
262 | $what_string = asearch_serialize($what_array); |
263 | $exclude_string = asearch_serialize($exclude_array); |
264 | $sub_string = asearch_serialize($sub_array); |
265 | $recent_count = count($recent_array[$recent_prefkeys[0]]); |
266 | for ($recent_num=0; $recent_num<$recent_count; $recent_num++) { |
267 | if (isset($recent_array[$recent_prefkeys[0]][$recent_num])) { |
268 | if ( |
269 | $mailbox_string == $recent_array['asearch_recent_mailbox'][$recent_num] && |
270 | $biop_string == $recent_array['asearch_recent_biop'][$recent_num] && |
271 | $unop_string == $recent_array['asearch_recent_unop'][$recent_num] && |
272 | $where_string == $recent_array['asearch_recent_where'][$recent_num] && |
273 | $what_string == $recent_array['asearch_recent_what'][$recent_num] && |
274 | $exclude_string == $recent_array['asearch_recent_exclude'][$recent_num] && |
275 | $sub_string == $recent_array['asearch_recent_sub'][$recent_num] |
276 | ) |
277 | return $recent_num; |
278 | } |
279 | } |
280 | return -1; |
281 | } |
282 | |
283 | /** Push a recent search */ |
284 | function asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
285 | { |
286 | global $recent_prefkeys; |
287 | |
288 | $recent_max = getPref($data_dir, $username, 'search_memory', 0); |
289 | if ($recent_max > 0) { |
290 | $recent_array = asearch_read_recent($data_dir, $username); |
291 | $recent_found = asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
292 | if ($recent_found >= 0) { // Remove identical recent |
293 | foreach ($recent_prefkeys as $key) { |
294 | array_splice($recent_array[$key], $recent_found, 1); |
295 | } |
296 | } |
297 | $input = array($where_array, $mailbox_array, $what_array, $biop_array, $unop_array, $exclude_array, $sub_array); |
298 | $i = 0; |
299 | foreach ($recent_prefkeys as $key) { |
300 | array_unshift($recent_array[$key], asearch_serialize($input[$i])); |
301 | $i++; |
302 | } |
303 | asearch_write_recent($data_dir, $username, $recent_array); |
304 | } |
305 | } |
306 | |
307 | /** |
308 | * Edit a recent search |
309 | * @global array mailbox_array searched mailboxes |
310 | */ |
311 | function asearch_edit_recent($data_dir, $username, $index) |
312 | { |
313 | global $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array; |
314 | |
315 | $mailbox_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_mailbox', $index)); |
316 | $biop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_biop', $index)); |
317 | $unop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_unop', $index)); |
318 | $where_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_where', $index)); |
319 | $what_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_what', $index)); |
320 | $exclude_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_exclude', $index)); |
321 | $sub_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_sub', $index)); |
322 | } |
323 | |
324 | /** Edit the last recent search if the prefs permit it */ |
325 | function asearch_edit_last($data_dir, $username) |
326 | { |
327 | if (getPref($data_dir, $username, 'search_memory', 0) > 0) |
328 | asearch_edit_recent($data_dir, $username, 0); |
329 | } |
330 | |
331 | /** Edit a saved search */ |
332 | function asearch_edit_saved($data_dir, $username, $index) |
333 | { |
334 | global $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array; |
335 | |
336 | $mailbox_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_mailbox', $index)); |
337 | $biop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_biop', $index)); |
338 | $unop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_unop', $index)); |
339 | $where_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_where', $index)); |
340 | $what_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_what', $index)); |
341 | $exclude_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_exclude', $index)); |
342 | $sub_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_sub', $index)); |
343 | } |
344 | |
345 | /** Write a saved searches */ |
346 | function asearch_write_saved($data_dir, $username, $saved_array) |
347 | { |
348 | global $saved_prefkeys; |
349 | |
350 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
351 | for ($saved_num=0; $saved_num < $saved_count; $saved_num++) { |
352 | foreach ($saved_prefkeys as $key) { |
353 | asearch_setPref($data_dir, $username, $key, $saved_num, $saved_array[$key][$saved_num]); |
354 | } |
355 | } |
356 | foreach ($saved_prefkeys as $key) { |
357 | asearch_removePref($data_dir, $username, $key, $saved_count); |
358 | } |
359 | } |
360 | |
361 | /** Delete a saved search */ |
362 | function asearch_delete_saved($data_dir, $username, $saved_index) |
363 | { |
364 | global $saved_prefkeys; |
365 | |
366 | $saved_array = asearch_read_saved($data_dir, $username); |
367 | $asearch_keys = $saved_prefkeys; |
368 | foreach ($asearch_keys as $key) { |
369 | array_splice($saved_array[$key], $saved_index, 1); |
370 | } |
371 | asearch_write_saved($data_dir, $username, $saved_array); |
372 | } |
373 | |
374 | /** Translate the input date to imap date to local date display, so the user can know if the date is wrong or illegal */ |
375 | function asearch_get_date_display($what) |
376 | { |
377 | $what_parts = sqimap_asearch_parse_date($what); |
378 | if (count($what_parts) == 4) { |
379 | if (checkdate($what_parts[2], $what_parts[1], $what_parts[3])) { |
380 | $what_display = date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3])); |
381 | /*$what_display = $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3];*/ |
382 | } |
383 | else |
384 | $what_display = _("(Illegal date)"); |
385 | } |
386 | else |
387 | $what_display = _("(Wrong date)"); |
388 | return $what_display; |
389 | } |
390 | |
391 | /** Translate the query to rough natural display */ |
392 | function asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
393 | { |
394 | global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options; |
395 | global $imap_asearch_opcodes; |
396 | |
397 | $last_mailbox = $mailbox_array[0]; |
398 | if (empty($last_mailbox)) |
399 | $last_mailbox = 'INBOX'; |
400 | $query_display = ''; |
401 | for ($crit_num=0; $crit_num < count($where_array); $crit_num++) { |
402 | if ((!isset($exclude_array[$crit_num])) || (!$exclude_array[$crit_num])) { |
403 | $cur_mailbox = $mailbox_array[$crit_num]; |
404 | if (empty($cur_mailbox)) |
405 | $cur_mailbox = 'INBOX'; |
406 | $biop = asearch_nz($biop_array[$crit_num]); |
407 | if (($query_display == '') || ($cur_mailbox != $last_mailbox)) { |
408 | $mailbox_display = ' <B>' . asearch_get_mailbox_display($cur_mailbox) . '</B>'; |
409 | if ($query_display == '') |
410 | $biop_display = _("In"); |
411 | else |
412 | $biop_display = $imap_asearch_biops_in[$biop]; |
413 | $last_mailbox = $cur_mailbox; |
414 | } |
415 | else { |
416 | $mailbox_display = ''; |
417 | $biop_display = $imap_asearch_biops[$biop]; |
418 | } |
419 | $biop_display = ' <U><I>' . $biop_display . '</I></U>'; |
420 | $unop = $unop_array[$crit_num]; |
421 | $unop_display = $imap_asearch_unops[$unop]; |
422 | $where = $where_array[$crit_num]; |
423 | $where_display = $imap_asearch_options[$where]; |
424 | if ($unop_display != '') |
425 | $where_display = ' <U><I>' . $unop_display . ' ' . $where_display . '</I></U>'; |
426 | else |
427 | $where_display = ' <U><I>' . $where_display . '</I></U>'; |
428 | $what_type = $imap_asearch_opcodes[$where]; |
429 | $what = $what_array[$crit_num]; |
430 | if ($what_type) { /* Check opcode parameter */ |
431 | if ($what == '') |
432 | $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)")); |
433 | else { |
434 | if ($what_type == 'adate') |
435 | $what_display = asearch_get_date_display($what); |
436 | else |
437 | $what_display = htmlspecialchars($what); |
438 | $what_display = ' <B>' . $what_display . '</B>'; |
439 | } |
440 | } |
441 | else { |
442 | if ($what) |
443 | $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)")); |
444 | else |
445 | $what_display = ''; |
446 | } |
447 | $query_display .= ' ' . $biop_display . $mailbox_display . $where_display . $what_display; |
448 | } |
449 | } |
450 | return $query_display; |
451 | } |
452 | |
453 | /** Handle the alternate row colors */ |
454 | function asearch_get_row_color($color, $row_num) |
455 | { |
456 | /*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/ |
457 | $color_string = $color[4]; |
458 | if ($GLOBALS['alt_index_colors']) { |
459 | if (($row_num % 2) == 0) { |
460 | if (!isset($color[12])) |
461 | $color[12] = '#EAEAEA'; |
462 | $color_string = $color[12]; |
463 | } |
464 | } |
465 | return $color_string; |
466 | } |
467 | |
468 | /** Print a whole query array, recent or saved */ |
469 | function asearch_print_query_array($query_array, $query_keys, $action_array, $title) |
470 | { |
471 | global $color; |
472 | |
473 | echo "<br>\n"; |
474 | echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"'); |
475 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=5')); |
476 | $main_key = $query_keys[0]; |
477 | $query_count = count($query_array[$main_key]); |
478 | for ($query_num=0, $row_num=0; $query_num<$query_count; $query_num++) { |
479 | if (!empty($query_array[$main_key][$query_num])) { |
480 | echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num)); |
481 | |
482 | unset($search_array); |
483 | foreach ($query_keys as $query_key) { |
484 | $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]); |
485 | } |
486 | $mailbox_array = $search_array[1]; |
487 | $biop_array = $search_array[3]; |
488 | $unop_array = $search_array[4]; |
489 | $where_array = $search_array[0]; |
490 | $what_array = $search_array[2]; |
491 | $exclude_array = $search_array[5]; |
492 | $sub_array = $search_array[6]; |
493 | $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
494 | |
495 | echo html_tag('td', $query_num+1, 'right'); |
496 | echo html_tag('td', $query_display, 'center', '', 'width="80%"'); |
497 | foreach ($action_array as $action => $action_display) { |
498 | echo html_tag('td', '<a href=search_advanced.php?submit=' . $action . '&rownum=' . $query_num . '>' . $action_display . '</a>', 'center'); |
499 | } |
500 | |
501 | echo '</tr>' . "\n"; |
502 | $row_num++; |
503 | } |
504 | } |
505 | echo '</table>' . "\n"; |
506 | } |
507 | |
508 | /** Print the saved array */ |
509 | function asearch_print_saved($data_dir, $username) |
510 | { |
511 | global $saved_prefkeys; |
512 | |
513 | $saved_array = asearch_read_saved($data_dir, $username); |
514 | if (isset($saved_array[$saved_prefkeys[0]])) { |
515 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
516 | if ($saved_count > 0) { |
517 | $saved_actions = array('edit_saved' => _("edit"), 'search_saved' => _("search"), 'delete_saved' => _("delete")); |
518 | asearch_print_query_array($saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches")); |
519 | } |
520 | } |
521 | } |
522 | |
523 | /** Print the recent array */ |
524 | function asearch_print_recent($data_dir, $username) |
525 | { |
526 | global $recent_prefkeys; |
527 | |
528 | $recent_array = asearch_read_recent($data_dir, $username); |
529 | if (isset($recent_array[$recent_prefkeys[0]])) { |
530 | $recent_count = count($recent_array[$recent_prefkeys[0]]); |
531 | $recent_max = min($recent_count, getPref($data_dir, $username, 'search_memory', 0)); |
532 | if ($recent_max > 0) { |
533 | $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget")); |
534 | asearch_print_query_array($recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches")); |
535 | } |
536 | } |
537 | } |
538 | |
539 | /** Build an <option> statement */ |
540 | function asearch_opt($val, $sel, $tit) |
541 | { |
542 | return '<option value="' . $val . '"' . ($sel == $val ? ' selected' : '') . '>' . $tit . '</option>' . "\n"; |
543 | } |
544 | |
545 | /** Build a <select> statement from an array */ |
546 | function asearch_opt_array($var_name, $opt_array, $cur_val) |
547 | { |
548 | $output = '<select name="' . $var_name . '">' . "\n"; |
549 | foreach($opt_array as $val => $display) |
550 | $output .= asearch_opt($val, $cur_val, $display); |
551 | $output .= '</select>' . "\n"; |
552 | return $output; |
553 | } |
554 | |
555 | /** Verify that a mailbox exists */ |
556 | function asearch_mailbox_exists($mailbox, $boxes) |
557 | { |
558 | foreach ($boxes as $box) { |
559 | if ($box['unformatted'] == $mailbox) |
560 | return TRUE; |
561 | } |
562 | return FALSE; |
563 | } |
564 | |
565 | /** Print one form row */ |
566 | function asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num) |
567 | { |
568 | global $imap_asearch_biops_in, $imap_asearch_unops, $imap_asearch_options; |
569 | global $color; |
570 | |
571 | echo html_tag('tr', '', '', $color[4]); |
572 | |
573 | echo html_tag('td', '', 'center'); |
574 | /* Binary operator */ |
575 | if ($row_num) |
576 | echo asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop); |
577 | else |
578 | echo /*'<input type="hidden" name="biop[0]" value="">' .*/ '<b>' . _("In") . '</b>'; |
579 | echo "</td>\n"; |
580 | |
581 | echo html_tag('td', '', 'center'); |
582 | /* Mailbox list */ |
583 | echo '<select name="mailbox[' . $row_num . ']">'; |
584 | if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) |
585 | echo asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . asearch_get_mailbox_display($mailbox)); |
586 | echo asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']'); |
587 | echo sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL); |
588 | echo '</select>' . "\n"; |
589 | |
590 | /* Include Subfolders */ |
591 | echo _("and subfolders:") . '<input type=checkbox name="sub[' . $row_num .']"' . ($sub ? ' CHECKED' : '') . '></td>' . "\n"; |
592 | |
593 | /* Unary operator and Search location */ |
594 | echo html_tag('td', |
595 | asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop) |
596 | . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where), |
597 | 'center'); |
598 | |
599 | /* Text input */ |
600 | $what_disp = htmlspecialchars($what); |
601 | echo html_tag('td', '<input type="text" size="35" name="what[' . $row_num . ']" value="' . $what_disp . '">', 'center') . "\n"; |
602 | |
603 | /* Exclude criteria */ |
604 | echo html_tag('td', |
605 | _("Exclude Criteria:") . '<input type=checkbox name="exclude[' . $row_num .']"' . ($exclude ? ' CHECKED' : '') . '>', 'center', '') . "\n"; |
606 | |
607 | echo "</tr>\n"; |
608 | } |
609 | |
610 | /** Print the search form */ |
611 | function asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
612 | { |
613 | global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html; |
614 | global $color; |
615 | |
616 | /* Search Form */ |
617 | echo "<br>\n"; |
618 | echo '<form action="search_advanced.php" name="form_asearch">' . "\n"; |
619 | |
620 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"'); |
621 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5')); |
622 | $row_count = count($where_array); |
623 | for ($row_num = 0; $row_num < $row_count; $row_num++) { |
624 | $mailbox = asearch_nz($mailbox_array[$row_num]); |
625 | $biop = strip_tags(asearch_nz($biop_array[$row_num])); |
626 | $unop = strip_tags(asearch_nz($unop_array[$row_num])); |
627 | $where = strip_tags(asearch_nz($where_array[$row_num])); |
628 | $what = asearch_nz($what_array[$row_num]); |
629 | $exclude = strip_tags(asearch_nz($exclude_array[$row_num])); |
630 | $sub = strip_tags(asearch_nz($sub_array[$row_num])); |
631 | asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num); |
632 | } |
633 | echo '</table>' . "\n"; |
634 | |
635 | /* Submit buttons */ |
636 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
637 | echo html_tag('tr', |
638 | html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n" |
639 | . html_tag('td', getButton('SUBMIT', 'submit', $add_criteria_button_html), 'center') . "\n" |
640 | . html_tag('td', getButton('SUBMIT', 'submit', $del_all_button_html), 'center') . "\n" |
641 | . html_tag('td', getButton('SUBMIT', 'submit', $del_excluded_button_html), 'center') . "\n" |
642 | ); |
643 | echo '</table>' . "\n"; |
644 | echo '</form>' . "\n"; |
645 | } |
646 | |
647 | /** Print the $msgs messages from $mailbox mailbox */ |
648 | function asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, $cnt, $sort, $color, $where, $what) |
649 | { |
650 | if ($cnt > 0) { |
651 | global $allow_server_sort, $allow_thread_sort, $thread_sort_messages; |
652 | |
653 | $thread_sort_messages = 0; |
654 | if ($allow_thread_sort) { |
655 | global $data_dir, $username; |
656 | $thread_sort_messages = getPref($data_dir, $username, 'thread_' . $mailbox); |
657 | $msort = $msgs; |
658 | $real_sort = 6; |
659 | } |
660 | elseif ($allow_server_sort) { |
661 | $msort = $msgs; |
662 | $real_sort = 6; |
663 | } |
664 | else { |
665 | $msort = calc_msort($msgs, $sort); |
666 | $real_sort = $sort; |
667 | } |
668 | $mailbox_display = asearch_get_mailbox_display($mailbox); |
669 | |
670 | $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt); |
671 | $paginator_str = '<b><big>' . _("Folder:") . ' '. $mailbox_display . '</big></b>'; |
672 | |
673 | echo '<br><table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
674 | |
675 | echo '<tr><td>'; |
676 | mail_message_listing_beginning($imapConnection, NULL, $mailbox, $real_sort, $msg_cnt_str, $paginator_str, 1, 1); |
677 | echo '</td></tr>'; |
678 | |
679 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
680 | |
681 | echo '<tr><td>'; |
682 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
683 | echo ' <tr><td>'; |
684 | |
685 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
686 | echo ' <tr><td>'; |
687 | printHeader($mailbox, $sort, $color, !$thread_sort_messages); |
688 | displayMessageArray($imapConnection, $cnt, 1, $msort, $mailbox, $real_sort, $color, $cnt, $where, $what); |
689 | echo ' </td></tr>'; |
690 | echo ' </table>'; |
691 | echo ' </td></tr>'; |
692 | echo ' </table>'; |
693 | mail_message_listing_end($cnt, '', $msg_cnt_str, $color); |
694 | echo '</td></tr>'; |
695 | |
696 | echo '</table>'; |
697 | } |
698 | } |
699 | |
700 | /** |
701 | * @param array $boxes mailboxes array (reference) |
702 | * @return array selectable unformatted mailboxes names |
703 | */ |
704 | function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes) |
705 | { |
706 | $mboxes_array = array(); |
707 | $boxcount = count($boxes); |
708 | for ($boxnum=0; $boxnum<$boxcount; $boxnum++) { |
709 | if (!in_array('noselect', $boxes[$boxnum]['flags'])) |
710 | $mboxes_array[] = $boxes[$boxnum]['unformatted']; |
711 | } |
712 | return $mboxes_array; |
713 | } |
714 | |
715 | /* ------------------------ main ------------------------ */ |
716 | /* get globals we may need */ |
717 | sqgetGlobalVar('username', $username, SQ_SESSION); |
718 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
719 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); /* we really need this? */ |
720 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); /* do we really need this? */ |
721 | |
722 | $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_biop', 'asearch_recent_unop', 'asearch_recent_exclude', 'asearch_recent_sub'); |
723 | $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_biop', 'asearch_saved_unop', 'asearch_saved_exclude', 'asearch_saved_sub'); |
724 | /*$asearch_keys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/ |
725 | |
726 | $search_button_html = _("Search"); |
727 | $search_button_text = asearch_unhtmlentities($search_button_html); |
728 | $add_criteria_button_html = _("Add New Criteria"); |
729 | $add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html); |
730 | $del_excluded_button_html = _("Remove Excluded Criteria"); |
731 | $del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html); |
732 | $del_all_button_html = _("Remove All Criteria"); |
733 | $del_all_button_text = asearch_unhtmlentities($del_all_button_html); |
734 | |
735 | $imap_asearch_options = array( |
736 | /* <message set>, */ |
737 | /*'ALL' is binary operator */ |
738 | 'ANSWERED' => _("Answered"), |
739 | 'BCC' => _("Bcc"), |
740 | 'BEFORE' => _("Before"), |
741 | 'BODY' => _("Message Body"), |
742 | 'CC' => _("CC"), |
743 | 'DELETED' => _("Deleted"), |
744 | 'DRAFT' => _("Draft"), |
745 | 'FLAGGED' => _("Flagged"), |
746 | 'FROM' => _("Sent By"), |
747 | 'HEADER' => _("Header Field"), |
748 | 'KEYWORD' => _("Keyword"), |
749 | 'LARGER' => _("Larger Than"), |
750 | 'NEW' => _("New"), |
751 | /*'NOT' is unary operator */ |
752 | 'OLD' => _("Old"), |
753 | 'ON' => _("On"), |
754 | /*'OR' is binary operator */ |
755 | 'RECENT' => _("Recent"), |
756 | 'SEEN' => _("Seen"), |
757 | 'SENTBEFORE' => _("Sent Before"), |
758 | 'SENTON' => _("Sent On"), |
759 | 'SENTSINCE' => _("Sent Since"), |
760 | 'SINCE' => _("Since"), |
761 | 'SMALLER' => _("Smaller Than"), |
762 | 'SUBJECT' => _("Subject Contains"), |
763 | 'TEXT' => _("Header and Body"), |
764 | 'TO' => _("Sent To"), |
765 | /*'UID' => 'anum',*/ |
766 | /*'UNANSWERED' => '', |
767 | 'UNDELETED' => '', |
768 | 'UNDRAFT' => '', |
769 | 'UNFLAGGED' => '', |
770 | 'UNKEYWORD' => _("Unkeyword"), |
771 | 'UNSEEN' => _("Unseen"),*/ |
772 | ); |
773 | uasort($imap_asearch_options, 'asearch_unhtml_strcoll'); |
774 | |
775 | $imap_asearch_unops = array( |
776 | '' => '', |
777 | 'NOT' => _("Not") |
778 | ); |
779 | |
780 | $imap_asearch_biops_in = array( |
781 | 'ALL' => _("And In"), |
782 | 'OR' => _("Or In") |
783 | ); |
784 | |
785 | $imap_asearch_biops = array( |
786 | 'ALL' => _("And"), |
787 | 'OR' => _("Or") |
788 | ); |
789 | |
790 | /** How we did enter the form |
791 | * - unset : Enter key, or called from outside (eg read_body) |
792 | * - $search_button_text : Search button |
793 | * - 'Search_no_update' : Search but don't update recent |
794 | * - 'Search_last' : Same as no_update but reload and search last |
795 | * - 'Search_silent' : Same as no_update but only display results |
796 | * - $add_criteria_button_text : Add New Criteria button |
797 | * - $del_excluded_button_text : Remove Excluded Criteria button |
798 | * - $del_all_button_text : Remove All Criteria button |
799 | * - 'save_recent' |
800 | * - 'search_recent' |
801 | * - 'forget_recent' |
802 | * - 'edit_saved' |
803 | * - 'search_saved' |
804 | * - 'delete_saved' |
805 | * @global string $submit |
806 | */ |
807 | if (isset($_GET['submit'])) |
808 | $submit = strip_tags($_GET['submit']); |
809 | |
810 | /** Searched mailboxes |
811 | * @global array $mailbox_array |
812 | */ |
813 | if (isset($_GET['mailbox'])) { |
814 | $mailbox_array = $_GET['mailbox']; |
815 | if (!is_array($mailbox_array)) |
816 | $mailbox_array = array($mailbox_array); |
817 | } |
818 | else |
819 | $mailbox_array = array(); |
820 | |
821 | /** Binary operators |
822 | * @global array $biop_array |
823 | */ |
824 | if (isset($_GET['biop'])) { |
825 | $biop_array = $_GET['biop']; |
826 | if (!is_array($biop_array)) |
827 | $biop_array = array($biop_array); |
828 | } |
829 | else |
830 | $biop_array = array(); |
831 | |
832 | /** Unary operators |
833 | * @global array $unop_array |
834 | */ |
835 | if (isset($_GET['unop'])) { |
836 | $unop_array = $_GET['unop']; |
837 | if (!is_array($unop_array)) |
838 | $unop_array = array($unop_array); |
839 | } |
840 | else |
841 | $unop_array = array(); |
842 | |
843 | /** Where to search |
844 | * @global array $where_array |
845 | */ |
846 | if (isset($_GET['where'])) { |
847 | $where_array = $_GET['where']; |
848 | if (!is_array($where_array)) |
849 | $where_array = array($where_array); |
850 | } |
851 | else |
852 | $where_array = array(); |
853 | |
854 | /** What to search |
855 | * @global array $what_array |
856 | */ |
857 | if (isset($_GET['what'])) { |
858 | $what_array = $_GET['what']; |
859 | if (!is_array($what_array)) |
860 | $what_array = array($what_array); |
861 | } |
862 | else |
863 | $what_array = array(); |
864 | |
865 | /** Whether to exclude this criteria from search |
866 | * @global array $exclude_array |
867 | */ |
868 | if (isset($_GET['exclude'])) |
869 | $exclude_array = $_GET['exclude']; |
870 | else |
871 | $exclude_array = array(); |
872 | |
873 | /** Search within subfolders |
874 | * @global array $sub_array |
875 | */ |
876 | if (isset($_GET['sub'])) |
877 | $sub_array = $_GET['sub']; |
878 | else |
879 | $sub_array = array(); |
880 | |
881 | /** Row number used by recent and saved stuff |
882 | */ |
883 | if (isset($_GET['rownum'])) |
884 | $submit_rownum = strip_tags($_GET['rownum']); |
885 | |
886 | /** Change global sort |
887 | */ |
888 | if (sqgetGlobalVar('newsort', $newsort, SQ_GET)) { |
889 | setPref($data_dir, $username, 'sort', $newsort); |
890 | $sort = $newsort; |
891 | sqsession_register($sort, 'sort'); |
892 | asearch_edit_last($data_dir, $username); |
893 | } |
894 | |
895 | /** Change mailbox threading |
896 | */ |
897 | if (sqgetGlobalVar('set_thread', $set_thread, SQ_GET)) { |
898 | setPref($data_dir, $username, 'thread_' . $mailbox_array[0], ($set_thread == 1) ? 1 : 0 ); |
899 | asearch_edit_last($data_dir, $username); |
900 | } |
901 | |
902 | /* end of get globals */ |
903 | |
904 | /** If TRUE, do not show search interface |
905 | * @global bool $search_silent |
906 | */ |
907 | $search_silent = FALSE; /* Default is normal behaviour */ |
908 | |
909 | /* See how the page was called and fire off correct function */ |
910 | if ((!isset($submit) || empty($submit)) && !empty($where_array)) { |
911 | /* This happens when the Enter key is used or called from outside */ |
912 | $submit = $search_button_text; |
913 | if (count($where_array) != count($unop_array)) /* Hack needed to handle coming back from read_body et als */ |
914 | asearch_edit_last($data_dir, $username); |
915 | } |
916 | |
917 | if (!isset($submit)) { |
918 | $submit = ''; |
919 | } |
920 | else { |
921 | switch ($submit) { |
922 | case $search_button_text: |
923 | if (asearch_check_query($where_array, $what_array, $exclude_array) == '') |
924 | asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
925 | break; |
926 | case 'Search_silent': |
927 | $search_silent = TRUE; |
928 | /*nobreak;*/ |
929 | case 'Search_no_update': |
930 | $submit = $search_button_text; |
931 | break; |
932 | case $del_excluded_button_text: |
933 | $delarray = array_keys($exclude_array); |
934 | while (!empty($delarray)) { |
935 | $delrow = array_pop($delarray); |
936 | array_splice($mailbox_array, $delrow, 1); |
937 | array_splice($biop_array, $delrow, 1); |
938 | array_splice($unop_array, $delrow, 1); |
939 | array_splice($where_array, $delrow, 1); |
940 | array_splice($what_array, $delrow, 1); |
941 | /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */ |
942 | array_splice($sub_array, $delrow, 1); |
943 | } |
944 | $exclude_array = array(); |
945 | break; |
946 | case $del_all_button_text: |
947 | $mailbox_array = array(); |
948 | $biop_array = array(); |
949 | $unop_array = array(); |
950 | $where_array = array(); |
951 | $what_array = array(); |
952 | $exclude_array = array(); |
953 | $sub_array = array(); |
954 | break; |
955 | case 'save_recent': |
956 | asearch_save_recent($data_dir, $username, $submit_rownum); |
957 | break; |
958 | case 'search_recent': |
959 | $submit = $search_button_text; |
960 | asearch_edit_recent($data_dir, $username, $submit_rownum); |
961 | asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
962 | break; |
963 | case 'edit_recent': /* no link to do this, yet */ |
964 | asearch_edit_recent($data_dir, $username, $submit_rownum); |
965 | break; |
966 | case 'forget_recent': |
967 | asearch_forget_recent($data_dir, $username, $submit_rownum); |
968 | break; |
969 | case 'search_saved': |
970 | $submit = $search_button_text; |
971 | asearch_edit_saved($data_dir, $username, $submit_rownum); |
972 | asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
973 | break; |
974 | case 'edit_saved': |
975 | asearch_edit_saved($data_dir, $username, $submit_rownum); |
976 | break; |
977 | case 'delete_saved': |
978 | asearch_delete_saved($data_dir, $username, $submit_rownum); |
979 | break; |
980 | } |
981 | } |
982 | |
983 | /* open IMAP connection */ |
984 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
985 | /* get mailbox names once here */ |
986 | $boxes = sqimap_mailbox_list($imapConnection); |
987 | /* ensure we have a valid default mailbox name */ |
988 | $mailbox = asearch_nz($mailbox_array[0]); |
989 | if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?) |
990 | $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;) |
991 | |
992 | if (isset($composenew) && $composenew) { |
993 | $comp_uri = "../src/compose.php?mailbox=" . urlencode($mailbox) . |
994 | "&session=$composesession&attachedmessages=true&"; |
995 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
996 | } |
997 | else |
998 | displayPageHeader($color, $mailbox); |
999 | |
1000 | do_hook('search_before_form'); |
1001 | |
1002 | if (!$search_silent) { |
1003 | echo html_tag('table', |
1004 | html_tag('tr', "\n" . |
1005 | html_tag('td', asearch_get_title_display($color, _("Search")), 'center', $color[0]) |
1006 | ) , |
1007 | '', '', 'width="100%"') . "\n"; |
1008 | asearch_print_saved($data_dir, $username); |
1009 | asearch_print_recent($data_dir, $username); |
1010 | if (empty($where_array)) { |
1011 | global $sent_folder; |
1012 | |
1013 | $mailbox_array[0] = $mailbox; |
1014 | $biop_array[0] = ''; |
1015 | $unop_array[0] = ''; |
1016 | if ($mailbox == $sent_folder) |
1017 | $where_array[0] = 'TO'; |
1018 | else |
1019 | $where_array[0] = 'FROM'; |
1020 | $what_array[0] = ''; |
1021 | $exclude_array[0] = ''; |
1022 | $sub_array[0] = ''; |
1023 | } |
1024 | if ($submit == $add_criteria_button_text) { |
1025 | $last_index = max(count($where_array) - 1, 0); |
1026 | $mailbox_array[] = asearch_nz($mailbox_array[$last_index]); |
1027 | $biop_array[] = asearch_nz($biop_array[$last_index]); |
1028 | $unop_array[] = asearch_nz($unop_array[$last_index]); |
1029 | $where_array[] = asearch_nz($where_array[$last_index]); |
1030 | $what_array[] = asearch_nz($what_array[$last_index]); |
1031 | $exclude_array[] = asearch_nz($exclude_array[$last_index]); |
1032 | $sub_array[] = asearch_nz($sub_array[$last_index]); |
1033 | } |
1034 | asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
1035 | } |
1036 | |
1037 | /********************************************************************* |
1038 | * Check to see if we can use cache or not. Currently the only time * |
1039 | * when you will not use it is when a link on the left hand frame is * |
1040 | * used. Also check to make sure we actually have the array in the * |
1041 | * registered session data. :) * |
1042 | *********************************************************************/ |
1043 | if (!isset($use_mailbox_cache)) |
1044 | $use_mailbox_cache = 0; |
1045 | |
1046 | do_hook('search_after_form'); |
1047 | |
1048 | if ($submit == $search_button_text) { |
1049 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
1050 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5])); |
1051 | echo html_tag('tr', html_tag('td', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array), 'center', $color[4])); |
1052 | echo '</table>' . "\n"; |
1053 | |
1054 | flush(); |
1055 | |
1056 | $query_error = asearch_check_query($where_array, $what_array, $exclude_array); |
1057 | if ($query_error != '') |
1058 | echo '<br>' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n"; |
1059 | else { |
1060 | |
1061 | // Disable thread sort for now if there is more than one mailbox or at least one 'All Folders' |
1062 | global $allow_thread_sort; |
1063 | $old_allow_thread_sort = $allow_thread_sort; |
1064 | $allow_thread_sort = ((count(array_unique($mailbox_array)) <= 1) && (!in_array('All Folders', $mailbox_array))); |
1065 | |
1066 | $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes); |
1067 | $mboxes_msgs = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array); |
1068 | if (empty($mboxes_msgs)) |
1069 | echo '<br>' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n"; |
1070 | else { |
1071 | foreach($mboxes_msgs as $mailbox => $msgs) { |
1072 | sqimap_mailbox_select($imapConnection, $mailbox); |
1073 | $msgs = fillMessageArray($imapConnection, $msgs, count($msgs)); |
1074 | /* For now just keep the first criteria to make the regular search happy if the user tries to come back to search */ |
1075 | /* $where = asearch_serialize($where_array); |
1076 | $what = asearch_serialize($what_array);*/ |
1077 | $where = $where_array[0]; |
1078 | $what = $what_array[0]; |
1079 | asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, count($msgs), $sort, $color, urlencode($where), urlencode($what)); |
1080 | } |
1081 | } |
1082 | |
1083 | $allow_thread_sort = $old_allow_thread_sort; // Restore thread sort |
1084 | } |
1085 | } |
1086 | |
1087 | do_hook('search_bottom'); |
1088 | sqimap_logout($imapConnection); |
1089 | echo '</body></html>'; |
1090 | |
1091 | ?> |