c61bb006 |
1 | <?php |
245a6892 |
2 | |
35586184 |
3 | /** |
a5ee5ac2 |
4 | * search.php |
35586184 |
5 | * |
82d304a0 |
6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
40fbe929 |
9 | * IMAP 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$ |
8f6f9ba5 |
14 | * @package squirrelmail |
313fd1f4 |
15 | * @link http://www.ietf.org/rfc/rfc3501.txt |
40fbe929 |
16 | * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr |
35586184 |
17 | */ |
2d367c68 |
18 | |
30967a1e |
19 | /** |
20 | * Path for SquirrelMail required files. |
21 | * @ignore |
22 | */ |
86725763 |
23 | define('SM_PATH','../'); |
24 | |
7d60bda5 |
25 | /** SquirrelMail required files. |
26 | */ |
08185f2a |
27 | require_once(SM_PATH . 'include/validate.php'); |
b2e7eb53 |
28 | require_once(SM_PATH . 'functions/strings.php'); |
6b37252b |
29 | require_once(SM_PATH . 'functions/imap_asearch.php'); |
86725763 |
30 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
b65c5db0 |
31 | require_once(SM_PATH . 'functions/imap_messages.php'); |
0ca9a6ec |
32 | require_once(SM_PATH . 'functions/mime.php'); |
b2e7eb53 |
33 | require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()... |
c61bb006 |
34 | |
7d60bda5 |
35 | /** Prefs array ordinals. Must match $recent_prefkeys and $saved_prefkeys |
36 | */ |
37 | define('ASEARCH_WHERE', 0); |
38 | define('ASEARCH_MAILBOX', 1); |
39 | define('ASEARCH_WHAT', 2); |
40 | define('ASEARCH_UNOP', 3); |
41 | define('ASEARCH_BIOP', 4); |
42 | define('ASEARCH_EXCLUDE', 5); |
43 | define('ASEARCH_SUB', 6); |
5b6abe97 |
44 | define('ASEARCH_MAX', 7); |
45 | |
46 | /** Name of session var |
47 | */ |
48 | define('ASEARCH_CRITERIA', 'criteria'); |
7d60bda5 |
49 | |
50 | /** Builds a href with params |
5b6abe97 |
51 | * @param string $params optional parameters to GET |
7d60bda5 |
52 | */ |
53 | function asearch_get_href($params = '') |
54 | { |
55 | $href = 'search.php'; |
56 | if ($params != '') |
57 | $href .= '?' . $params; |
58 | return $href; |
59 | } |
60 | |
61 | /** Builds a [link] |
5b6abe97 |
62 | * @param string $href (reference) |
63 | * @param string $text |
64 | * @param string $title |
7d60bda5 |
65 | */ |
94375458 |
66 | function asearch_get_link(&$href, $text, $title = '') |
7d60bda5 |
67 | { |
94375458 |
68 | if ($title != '') |
69 | $title = ' title="' . $title . '"'; |
5b6abe97 |
70 | return '<a href="' . $href . '"' . $title . '>' . $text . '</a>'; |
7d60bda5 |
71 | } |
72 | |
73 | /** Builds a toggle [link] |
5b6abe97 |
74 | * @param integer $value |
75 | * @param string $action |
76 | * @param array $text_array |
77 | * @param array $title_array |
7d60bda5 |
78 | */ |
94375458 |
79 | function asearch_get_toggle_link($value, $action, $text_array, $title_array = array()) |
7d60bda5 |
80 | { |
94375458 |
81 | return asearch_get_link(asearch_get_href($action . '=' . (int)$value), $text_array[$value], asearch_nz($title_array[$value])); |
7d60bda5 |
82 | } |
83 | |
40fbe929 |
84 | /** |
85 | * @param string $a |
86 | * @param string $b |
87 | * @return bool strcoll()-like result |
88 | */ |
6b37252b |
89 | function asearch_unhtml_strcoll($a, $b) |
90 | { |
91 | return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b)); |
92 | } |
40fbe929 |
93 | |
94 | /** |
7d60bda5 |
95 | * @param string $mailbox mailbox name utf7 encoded inc. special case INBOX |
96 | * @return string mailbox name ready to display (utf7 decoded or localized INBOX) |
40fbe929 |
97 | */ |
6b37252b |
98 | function imap_get_mailbox_display($mailbox) |
99 | { |
3dffe83f |
100 | if (strtoupper($mailbox) == 'INBOX') |
6b37252b |
101 | return _("INBOX"); |
102 | return imap_utf7_decode_local($mailbox); |
103 | } |
56e0b3b7 |
104 | |
40fbe929 |
105 | /** |
7d60bda5 |
106 | * @param string $mailbox mailbox name or special case 'All Folders' |
107 | * @return string mailbox name ready to display (utf7 decoded or localized 'All Folders') |
40fbe929 |
108 | */ |
6b37252b |
109 | function asearch_get_mailbox_display($mailbox) |
110 | { |
111 | if ($mailbox == 'All Folders') |
112 | return _("All Folders"); |
113 | return imap_get_mailbox_display($mailbox); |
114 | } |
0b97a708 |
115 | |
40fbe929 |
116 | /** |
117 | * @param array $color color array |
118 | * @param string $txt text to display |
119 | * @return string title ready to display |
120 | */ |
7d60bda5 |
121 | function asearch_get_title_display(&$color, $txt) |
6b37252b |
122 | { |
123 | return '<b><big>' . $txt . '</big></b>'; |
124 | } |
0b97a708 |
125 | |
40fbe929 |
126 | /** |
127 | * @param array $color color array |
128 | * @param string $txt text to display |
129 | * @return string error text ready to display |
130 | */ |
7d60bda5 |
131 | function asearch_get_error_display(&$color, $txt) |
6b37252b |
132 | { |
05f5b952 |
133 | return '<font color="' . $color[2] . '">' . '<b><big>' . $txt . '</big></b></font>'; |
0b97a708 |
134 | } |
6b37252b |
135 | |
40fbe929 |
136 | /** |
137 | * @param array $input_array array to serialize |
138 | * @return string a string containing a byte-stream representation of value that can be stored anywhere |
139 | */ |
7d60bda5 |
140 | function asearch_serialize(&$input_array) |
6b37252b |
141 | { |
7d60bda5 |
142 | global $search_advanced; |
143 | if ($search_advanced) |
144 | return serialize($input_array); |
145 | return $input_array[0]; |
0b97a708 |
146 | } |
6b37252b |
147 | |
40fbe929 |
148 | /** |
149 | * @param string $input_string string to unserialize |
150 | * @return array |
151 | */ |
6b37252b |
152 | function asearch_unserialize($input_string) |
153 | { |
7d60bda5 |
154 | global $search_advanced; |
155 | if ($search_advanced) |
156 | return unserialize($input_string); |
157 | return array($input_string); |
0b97a708 |
158 | } |
6b37252b |
159 | |
40fbe929 |
160 | /** |
40fbe929 |
161 | * @param string $key the pref key |
162 | * @param integer $index the pref key index |
163 | * @param string $default default value |
164 | * @return string pref value |
165 | */ |
7d60bda5 |
166 | function asearch_getPref(&$key, $index, $default = '') |
6b37252b |
167 | { |
7d60bda5 |
168 | global $data_dir, $username, $search_advanced; |
169 | return getPref($data_dir, $username, $key . ($index + !$search_advanced), $default); |
0b97a708 |
170 | } |
6b37252b |
171 | |
40fbe929 |
172 | /** |
40fbe929 |
173 | * @param string $key the pref key |
174 | * @param integer $index the pref key index |
175 | * @param string $value pref value to set |
176 | * @return bool status |
177 | */ |
7d60bda5 |
178 | function asearch_setPref(&$key, $index, $value) |
6b37252b |
179 | { |
7d60bda5 |
180 | global $data_dir, $username, $search_advanced; |
181 | return setPref($data_dir, $username, $key . ($index + !$search_advanced), $value); |
0b97a708 |
182 | } |
6b37252b |
183 | |
40fbe929 |
184 | /** |
40fbe929 |
185 | * @param string $key the pref key |
186 | * @param integer $index the pref key index |
187 | * @return bool status |
188 | */ |
7d60bda5 |
189 | function asearch_removePref(&$key, $index) |
6b37252b |
190 | { |
7d60bda5 |
191 | global $data_dir, $username, $search_advanced; |
192 | return removePref($data_dir, $username, $key . ($index + !$search_advanced)); |
0b97a708 |
193 | } |
0b97a708 |
194 | |
7d60bda5 |
195 | /** Sanity checks, done before running the imap command and before calling push_recent |
196 | */ |
197 | function asearch_check_query(&$where_array, &$what_array, &$exclude_array) |
6b37252b |
198 | { |
05f5b952 |
199 | global $imap_asearch_opcodes; |
200 | |
6b37252b |
201 | if (empty($where_array)) |
202 | return _("Please enter something to search for"); |
203 | if (count($exclude_array) == count($where_array)) |
204 | return _("There must be at least one criteria to search for"); |
05f5b952 |
205 | for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) { |
206 | $where = $where_array[$crit_num]; |
207 | $what = $what_array[$crit_num]; |
208 | if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != ''))) |
209 | return _("Error in criteria argument"); |
210 | } |
6b37252b |
211 | return ''; |
56e0b3b7 |
212 | } |
213 | |
7d60bda5 |
214 | /** Read the recent searches from the prefs |
215 | */ |
216 | function asearch_read_recent() |
6b37252b |
217 | { |
7d60bda5 |
218 | global $recent_prefkeys, $search_memory; |
6b37252b |
219 | |
220 | $recent_array = array(); |
7d60bda5 |
221 | $recent_num = 0; |
222 | for ($pref_num = 0; $pref_num < $search_memory; $pref_num++) { |
6b37252b |
223 | foreach ($recent_prefkeys as $prefkey) { |
7d60bda5 |
224 | $pref = asearch_getPref($prefkey, $pref_num); |
6b37252b |
225 | /* if (!empty($pref))*/ |
226 | $recent_array[$prefkey][$recent_num] = $pref; |
227 | } |
228 | if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) { |
229 | foreach ($recent_prefkeys as $key) { |
230 | array_pop($recent_array[$key]); |
231 | } |
7d60bda5 |
232 | // break; //Disabled to support old search code broken prefs |
6b37252b |
233 | } |
7d60bda5 |
234 | else |
235 | $recent_num++; |
6b37252b |
236 | } |
237 | return $recent_array; |
56e0b3b7 |
238 | } |
23a9084b |
239 | |
7d60bda5 |
240 | /** Read the saved searches from the prefs |
241 | */ |
242 | function asearch_read_saved() |
6b37252b |
243 | { |
244 | global $saved_prefkeys; |
245 | |
246 | $saved_array = array(); |
247 | $saved_key = $saved_prefkeys[0]; |
248 | for ($saved_count = 0; ; $saved_count++) { |
7d60bda5 |
249 | $pref = asearch_getPref($saved_key, $saved_count); |
6b37252b |
250 | if (empty($pref)) |
251 | break; |
252 | } |
253 | for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) { |
254 | foreach ($saved_prefkeys as $key) { |
7d60bda5 |
255 | $saved_array[$key][$saved_num] = asearch_getPref($key, $saved_num); |
6b37252b |
256 | } |
257 | } |
258 | return $saved_array; |
259 | } |
260 | |
7d60bda5 |
261 | /** Save a recent search to the prefs |
262 | */ |
263 | function asearch_save_recent($recent_index) |
6b37252b |
264 | { |
265 | global $recent_prefkeys, $saved_prefkeys; |
266 | |
7d60bda5 |
267 | $saved_array = asearch_read_saved(); |
6b37252b |
268 | $saved_index = count($saved_array[$saved_prefkeys[0]]); |
7d60bda5 |
269 | $recent_array = asearch_read_recent(); |
6b37252b |
270 | $n = 0; |
271 | foreach ($recent_prefkeys as $key) { |
272 | $recent_slice = array_slice($recent_array[$key], $recent_index, 1); |
273 | if (!empty($recent_slice[0])) |
7d60bda5 |
274 | asearch_setPref($saved_prefkeys[$n], $saved_index, $recent_slice[0]); |
6b37252b |
275 | else |
7d60bda5 |
276 | asearch_removePref($saved_prefkeys[$n], $saved_index); |
6b37252b |
277 | $n++; |
278 | } |
279 | } |
280 | |
7d60bda5 |
281 | /** Write a recent search to prefs |
282 | */ |
283 | function asearch_write_recent(&$recent_array) |
6b37252b |
284 | { |
7d60bda5 |
285 | global $recent_prefkeys, $search_memory; |
6b37252b |
286 | |
7d60bda5 |
287 | $recent_count = min($search_memory, count($recent_array[$recent_prefkeys[0]])); |
288 | for ($recent_num = 0; $recent_num < $recent_count; $recent_num++) { |
6b37252b |
289 | foreach ($recent_prefkeys as $key) { |
7d60bda5 |
290 | asearch_setPref($key, $recent_num, $recent_array[$key][$recent_num]); |
6b37252b |
291 | } |
292 | } |
7d60bda5 |
293 | for (; $recent_num < $search_memory; $recent_num++) { |
6b37252b |
294 | foreach ($recent_prefkeys as $key) { |
7d60bda5 |
295 | asearch_removePref($key, $recent_num); |
6b37252b |
296 | } |
297 | } |
298 | } |
299 | |
7d60bda5 |
300 | /** Remove a recent search from prefs |
301 | */ |
302 | function asearch_forget_recent($forget_index) |
6b37252b |
303 | { |
304 | global $recent_prefkeys; |
305 | |
7d60bda5 |
306 | $recent_array = asearch_read_recent(); |
6b37252b |
307 | foreach ($recent_prefkeys as $key) { |
308 | array_splice($recent_array[$key], $forget_index, 1); |
309 | } |
7d60bda5 |
310 | asearch_write_recent($recent_array); |
6b37252b |
311 | } |
312 | |
7d60bda5 |
313 | /** Find a recent search in the prefs (used to avoid saving duplicates) |
314 | */ |
315 | function asearch_find_recent(&$recent_array, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array) |
6b37252b |
316 | { |
7d60bda5 |
317 | global $recent_prefkeys, $search_advanced; |
6b37252b |
318 | |
6b37252b |
319 | $where_string = asearch_serialize($where_array); |
7d60bda5 |
320 | $mailbox_string = asearch_serialize($mailbox_array); |
6b37252b |
321 | $what_string = asearch_serialize($what_array); |
7d60bda5 |
322 | $unop_string = asearch_serialize($unop_array); |
323 | if ($search_advanced) { |
324 | $biop_string = asearch_serialize($biop_array); |
325 | $exclude_string = asearch_serialize($exclude_array); |
326 | $sub_string = asearch_serialize($sub_array); |
327 | } |
328 | $recent_count = count($recent_array[$recent_prefkeys[ASEARCH_WHERE]]); |
329 | for ($recent_num = 0; $recent_num < $recent_count; $recent_num++) { |
330 | if (isset($recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num])) { |
6b37252b |
331 | if ( |
7d60bda5 |
332 | $where_string == $recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num] && |
333 | $mailbox_string == $recent_array[$recent_prefkeys[ASEARCH_MAILBOX]][$recent_num] && |
334 | $what_string == $recent_array[$recent_prefkeys[ASEARCH_WHAT]][$recent_num] && |
335 | $unop_string == $recent_array[$recent_prefkeys[ASEARCH_UNOP]][$recent_num] && |
336 | ((!$search_advanced) || |
337 | ($biop_string == $recent_array[$recent_prefkeys[ASEARCH_BIOP]][$recent_num] && |
338 | $exclude_string == $recent_array[$recent_prefkeys[ASEARCH_EXCLUDE]][$recent_num] && |
339 | $sub_string == $recent_array[$recent_prefkeys[ASEARCH_SUB]][$recent_num])) |
6b37252b |
340 | ) |
c2d47d51 |
341 | return $recent_num; |
6b37252b |
342 | } |
343 | } |
c2d47d51 |
344 | return -1; |
6b37252b |
345 | } |
346 | |
7d60bda5 |
347 | /** Push a recent search into the prefs |
348 | */ |
349 | function asearch_push_recent(&$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array) |
6b37252b |
350 | { |
7d60bda5 |
351 | global $recent_prefkeys, $search_memory; |
6b37252b |
352 | |
5b6abe97 |
353 | $criteria = array($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
354 | sqsession_register($criteria, ASEARCH_CRITERIA); |
7d60bda5 |
355 | if ($search_memory > 0) { |
356 | $recent_array = asearch_read_recent(); |
40fbe929 |
357 | $recent_found = asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
358 | if ($recent_found >= 0) { // Remove identical recent |
6b37252b |
359 | foreach ($recent_prefkeys as $key) { |
c2d47d51 |
360 | array_splice($recent_array[$key], $recent_found, 1); |
6b37252b |
361 | } |
c2d47d51 |
362 | } |
7d60bda5 |
363 | $input = array($where_array, $mailbox_array, $what_array, $unop_array, $biop_array, $exclude_array, $sub_array); |
c2d47d51 |
364 | $i = 0; |
365 | foreach ($recent_prefkeys as $key) { |
366 | array_unshift($recent_array[$key], asearch_serialize($input[$i])); |
367 | $i++; |
368 | } |
7d60bda5 |
369 | asearch_write_recent($recent_array); |
6b37252b |
370 | } |
371 | } |
372 | |
7d60bda5 |
373 | /** Edit a recent search |
2d2f8bb8 |
374 | * @global array mailbox_array searched mailboxes |
40fbe929 |
375 | */ |
7d60bda5 |
376 | function asearch_edit_recent($index) |
6b37252b |
377 | { |
7d60bda5 |
378 | global $recent_prefkeys, $search_advanced; |
379 | global $where_array, $mailbox_array, $what_array, $unop_array; |
380 | global $biop_array, $exclude_array, $sub_array; |
381 | |
382 | $where_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_WHERE], $index)); |
383 | $mailbox_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_MAILBOX], $index)); |
384 | $what_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_WHAT], $index)); |
385 | $unop_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_UNOP], $index)); |
386 | if ($search_advanced) { |
387 | $biop_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_BIOP], $index)); |
388 | $exclude_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_EXCLUDE], $index)); |
389 | $sub_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_SUB], $index)); |
390 | } |
6b37252b |
391 | } |
392 | |
958becc9 |
393 | /** Get last search criteria from session or prefs |
7d60bda5 |
394 | */ |
395 | function asearch_edit_last() |
6b37252b |
396 | { |
5b6abe97 |
397 | if (sqGetGlobalVar(ASEARCH_CRITERIA, $criteria, SQ_SESSION)) { |
398 | global $where_array, $mailbox_array, $what_array, $unop_array; |
399 | global $biop_array, $exclude_array, $sub_array; |
400 | $mailbox_array = $criteria[0]; |
401 | $biop_array = $criteria[1]; |
402 | $unop_array = $criteria[2]; |
403 | $where_array = $criteria[3]; |
404 | $what_array = $criteria[4]; |
405 | $exclude_array = $criteria[5]; |
406 | $sub_array = $criteria[6]; |
407 | sqsession_unregister(ASEARCH_CRITERIA); |
408 | } |
409 | else { |
958becc9 |
410 | global $search_memory; |
5b6abe97 |
411 | if ($search_memory > 0) |
958becc9 |
412 | asearch_edit_recent(0); |
5b6abe97 |
413 | } |
6b37252b |
414 | } |
415 | |
7d60bda5 |
416 | /** Edit a saved search |
417 | */ |
418 | function asearch_edit_saved($index) |
6b37252b |
419 | { |
7d60bda5 |
420 | global $saved_prefkeys, $search_advanced; |
421 | global $where_array, $mailbox_array, $what_array, $unop_array; |
422 | global $biop_array, $exclude_array, $sub_array; |
423 | |
424 | $where_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_WHERE], $index)); |
425 | $mailbox_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_MAILBOX], $index)); |
426 | $what_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_WHAT], $index)); |
427 | $unop_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_UNOP], $index)); |
428 | if ($search_advanced) { |
429 | $biop_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_BIOP], $index)); |
430 | $exclude_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_EXCLUDE], $index)); |
431 | $sub_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_SUB], $index)); |
432 | } |
6b37252b |
433 | } |
434 | |
7d60bda5 |
435 | /** Write a saved search to the prefs |
436 | */ |
437 | function asearch_write_saved(&$saved_array) |
6b37252b |
438 | { |
439 | global $saved_prefkeys; |
440 | |
441 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
442 | for ($saved_num=0; $saved_num < $saved_count; $saved_num++) { |
443 | foreach ($saved_prefkeys as $key) { |
7d60bda5 |
444 | asearch_setPref($key, $saved_num, $saved_array[$key][$saved_num]); |
6b37252b |
445 | } |
446 | } |
447 | foreach ($saved_prefkeys as $key) { |
7d60bda5 |
448 | asearch_removePref($key, $saved_count); |
6b37252b |
449 | } |
450 | } |
451 | |
7d60bda5 |
452 | /** Delete a saved search from the prefs |
453 | */ |
454 | function asearch_delete_saved($saved_index) |
6b37252b |
455 | { |
456 | global $saved_prefkeys; |
457 | |
7d60bda5 |
458 | $saved_array = asearch_read_saved(); |
6b37252b |
459 | $asearch_keys = $saved_prefkeys; |
460 | foreach ($asearch_keys as $key) { |
461 | array_splice($saved_array[$key], $saved_index, 1); |
462 | } |
7d60bda5 |
463 | asearch_write_saved($saved_array); |
6b37252b |
464 | } |
465 | |
7d60bda5 |
466 | /** Translate the input date to imap date to local date display, |
467 | * so the user can know if the date is wrong or illegal |
468 | * @return string locally formatted date or error text |
469 | */ |
470 | function asearch_get_date_display(&$what) |
6b37252b |
471 | { |
472 | $what_parts = sqimap_asearch_parse_date($what); |
473 | if (count($what_parts) == 4) { |
7d60bda5 |
474 | if (checkdate($what_parts[2], $what_parts[1], $what_parts[3])) |
475 | return date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3])); |
476 | //return $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3]; |
477 | return _("(Illegal date)"); |
6b37252b |
478 | } |
7d60bda5 |
479 | return _("(Wrong date)"); |
6b37252b |
480 | } |
481 | |
7d60bda5 |
482 | /** Translate the query to rough natural display |
483 | * @return string rough natural query ready to display |
484 | */ |
485 | function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array) |
6b37252b |
486 | { |
487 | global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options; |
488 | global $imap_asearch_opcodes; |
489 | |
490 | $last_mailbox = $mailbox_array[0]; |
491 | if (empty($last_mailbox)) |
492 | $last_mailbox = 'INBOX'; |
05f5b952 |
493 | $query_display = ''; |
494 | for ($crit_num=0; $crit_num < count($where_array); $crit_num++) { |
495 | if ((!isset($exclude_array[$crit_num])) || (!$exclude_array[$crit_num])) { |
496 | $cur_mailbox = $mailbox_array[$crit_num]; |
6b37252b |
497 | if (empty($cur_mailbox)) |
498 | $cur_mailbox = 'INBOX'; |
05f5b952 |
499 | $biop = asearch_nz($biop_array[$crit_num]); |
500 | if (($query_display == '') || ($cur_mailbox != $last_mailbox)) { |
958becc9 |
501 | $mailbox_display = ' <b>' . asearch_get_mailbox_display($cur_mailbox) . '</b>'; |
05f5b952 |
502 | if ($query_display == '') |
6b37252b |
503 | $biop_display = _("In"); |
504 | else |
505 | $biop_display = $imap_asearch_biops_in[$biop]; |
506 | $last_mailbox = $cur_mailbox; |
507 | } |
508 | else { |
509 | $mailbox_display = ''; |
510 | $biop_display = $imap_asearch_biops[$biop]; |
511 | } |
05f5b952 |
512 | $unop = $unop_array[$crit_num]; |
6b37252b |
513 | $unop_display = $imap_asearch_unops[$unop]; |
6b37252b |
514 | if ($unop_display != '') |
5b6abe97 |
515 | $unop_display .= ' '; |
516 | $where = $where_array[$crit_num]; |
517 | $where_display = $unop_display . asearch_nz($imap_asearch_options[$where], $where); |
6b37252b |
518 | $what_type = $imap_asearch_opcodes[$where]; |
05f5b952 |
519 | $what = $what_array[$crit_num]; |
520 | if ($what_type) { /* Check opcode parameter */ |
521 | if ($what == '') |
522 | $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)")); |
6b37252b |
523 | else { |
05f5b952 |
524 | if ($what_type == 'adate') |
525 | $what_display = asearch_get_date_display($what); |
6b37252b |
526 | else |
a722a461 |
527 | $what_display = htmlspecialchars($what); |
958becc9 |
528 | $what_display = ' <b>' . $what_display . '</b>'; |
6b37252b |
529 | } |
6b37252b |
530 | } |
05f5b952 |
531 | else { |
532 | if ($what) |
533 | $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)")); |
534 | else |
535 | $what_display = ''; |
536 | } |
5b6abe97 |
537 | if ($mailbox_display != '') |
958becc9 |
538 | $query_display .= ' <u><i>' . $biop_display . '</i></u>' . $mailbox_display . ' <u><i>' . $where_display . '</i></u>' . $what_display; |
5b6abe97 |
539 | else |
958becc9 |
540 | $query_display .= ' <u><i>' . $biop_display . ' ' . $where_display . '</i></u>' . $what_display; |
6b37252b |
541 | } |
542 | } |
05f5b952 |
543 | return $query_display; |
6b37252b |
544 | } |
545 | |
7d60bda5 |
546 | /** Handle the alternate row colors |
547 | * @return string color value |
548 | */ |
549 | function asearch_get_row_color(&$color, $row_num) |
6b37252b |
550 | { |
551 | /*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/ |
552 | $color_string = $color[4]; |
553 | if ($GLOBALS['alt_index_colors']) { |
554 | if (($row_num % 2) == 0) { |
555 | if (!isset($color[12])) |
556 | $color[12] = '#EAEAEA'; |
557 | $color_string = $color[12]; |
558 | } |
559 | } |
560 | return $color_string; |
561 | } |
562 | |
7d60bda5 |
563 | /** Print a whole query array, recent or saved |
564 | */ |
565 | function asearch_print_query_array(&$boxes, &$query_array, &$query_keys, &$action_array, $title, $show_pref) |
6b37252b |
566 | { |
567 | global $color; |
7d60bda5 |
568 | global $data_dir, $username; |
5b6abe97 |
569 | global $use_icons, $icon_theme; |
7d60bda5 |
570 | |
571 | $show_flag = getPref($data_dir, $username, $show_pref, 0) & 1; |
5b6abe97 |
572 | $use_icons_flag = ($use_icons) && ($icon_theme != 'none'); |
573 | if ($use_icons_flag) |
958becc9 |
574 | $text_array = array('<img src="' . SM_PATH . 'images/minus.png" border="0" height="7" width="7" />', |
575 | '<img src="' . SM_PATH . 'images/plus.png" border="0" height="7" width="7" />'); |
5b6abe97 |
576 | else |
4b155bc2 |
577 | $text_array = array('-', '+'); |
5b6abe97 |
578 | $toggle_link = asearch_get_toggle_link(!$show_flag, $show_pref, $text_array, array(_("Fold"), _("Unfold"))); |
579 | if (!$use_icons_flag) |
580 | $toggle_link = '<small>[' . $toggle_link . ']</small>'; |
6b37252b |
581 | |
958becc9 |
582 | echo "<br />\n"; |
920ec5ec |
583 | echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"'); |
94375458 |
584 | echo html_tag('tr', |
585 | html_tag('td', $toggle_link, 'center', $color[5], 'width="5%"') |
586 | . html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=4')); |
7d60bda5 |
587 | if ($show_flag) { |
588 | $main_key = $query_keys[ASEARCH_WHERE]; |
589 | $query_count = count($query_array[$main_key]); |
590 | for ($query_num = 0, $row_num = 0; $query_num < $query_count; $query_num++) { |
591 | if (!empty($query_array[$main_key][$query_num])) { |
592 | echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num)); |
593 | |
594 | unset($search_array); |
595 | foreach ($query_keys as $query_key) { |
596 | $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]); |
597 | } |
598 | $where_array = $search_array[ASEARCH_WHERE]; |
599 | $mailbox_array = $search_array[ASEARCH_MAILBOX]; |
600 | $what_array = $search_array[ASEARCH_WHAT]; |
601 | $unop_array = $search_array[ASEARCH_UNOP]; |
602 | $biop_array = asearch_nz($search_array[ASEARCH_BIOP], array()); |
603 | $exclude_array = asearch_nz($search_array[ASEARCH_EXCLUDE], array()); |
604 | $sub_array = asearch_nz($search_array[ASEARCH_SUB], array()); |
605 | $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
606 | |
607 | echo html_tag('td', $query_num + 1, 'right'); |
608 | echo html_tag('td', $query_display, 'center', '', 'width="80%"'); |
609 | foreach ($action_array as $action => $action_display) { |
610 | echo html_tag('td', '<a href="' . asearch_get_href('submit=' . $action . '&rownum=' . $query_num) . '">' . $action_display . '</a>', 'center'); |
611 | } |
6b37252b |
612 | |
7d60bda5 |
613 | echo '</tr>' . "\n"; |
614 | $row_num++; |
615 | } |
6b37252b |
616 | } |
617 | } |
618 | echo '</table>' . "\n"; |
619 | } |
620 | |
7d60bda5 |
621 | /** Print the saved array |
622 | */ |
623 | function asearch_print_saved(&$boxes) |
6b37252b |
624 | { |
625 | global $saved_prefkeys; |
626 | |
7d60bda5 |
627 | $saved_array = asearch_read_saved(); |
05f5b952 |
628 | if (isset($saved_array[$saved_prefkeys[0]])) { |
629 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
630 | if ($saved_count > 0) { |
631 | $saved_actions = array('edit_saved' => _("edit"), 'search_saved' => _("search"), 'delete_saved' => _("delete")); |
7d60bda5 |
632 | asearch_print_query_array($boxes, $saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches"), 'search_show_saved'); |
05f5b952 |
633 | } |
6b37252b |
634 | } |
70c4fd84 |
635 | } |
6c8388a9 |
636 | |
7d60bda5 |
637 | /** |
638 | * Print the recent array |
639 | */ |
640 | function asearch_print_recent(&$boxes) |
6b37252b |
641 | { |
7d60bda5 |
642 | global $recent_prefkeys, $search_memory; |
6b37252b |
643 | |
7d60bda5 |
644 | $recent_array = asearch_read_recent(); |
05f5b952 |
645 | if (isset($recent_array[$recent_prefkeys[0]])) { |
646 | $recent_count = count($recent_array[$recent_prefkeys[0]]); |
7d60bda5 |
647 | if (min($recent_count, $search_memory) > 0) { |
05f5b952 |
648 | $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget")); |
7d60bda5 |
649 | asearch_print_query_array($boxes, $recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches"), 'search_show_recent'); |
05f5b952 |
650 | } |
6b37252b |
651 | } |
56e0b3b7 |
652 | } |
653 | |
7d60bda5 |
654 | /** Build an <option> statement |
655 | */ |
920ec5ec |
656 | function asearch_opt($val, $sel, $tit) |
6b37252b |
657 | { |
f8984459 |
658 | return '<option value="' . $val . '"' . ($sel == $val ? ' selected' : '') . '>' . $tit . '</option>' . "\n"; |
6b37252b |
659 | } |
660 | |
7d60bda5 |
661 | /** Build a <select> statement from an array |
662 | */ |
6b37252b |
663 | function asearch_opt_array($var_name, $opt_array, $cur_val) |
664 | { |
665 | $output = '<select name="' . $var_name . '">' . "\n"; |
666 | foreach($opt_array as $val => $display) |
7d60bda5 |
667 | $output .= asearch_opt($val, $cur_val, asearch_nz($display, $val)); |
6b37252b |
668 | $output .= '</select>' . "\n"; |
669 | return $output; |
670 | } |
671 | |
7d60bda5 |
672 | /** Verify that a mailbox exists |
673 | * @return bool mailbox exists |
674 | */ |
675 | function asearch_mailbox_exists($mailbox, &$boxes) |
920ec5ec |
676 | { |
677 | foreach ($boxes as $box) { |
678 | if ($box['unformatted'] == $mailbox) |
679 | return TRUE; |
680 | } |
681 | return FALSE; |
682 | } |
683 | |
5b6abe97 |
684 | /** Build the mailbox select |
685 | */ |
7d60bda5 |
686 | function asearch_get_form_mailbox($imapConnection, &$boxes, $mailbox, $row_num = 0) |
6b37252b |
687 | { |
7d60bda5 |
688 | if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) |
689 | $missing = asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . asearch_get_mailbox_display($mailbox)); |
690 | else |
691 | $missing = ''; |
692 | return '<select name="mailbox[' . $row_num . ']">' |
693 | . $missing |
694 | . asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']') |
695 | . sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL) |
696 | . '</select>'; |
697 | } |
698 | |
5b6abe97 |
699 | /** Build the Include subfolders checkbox |
700 | */ |
7d60bda5 |
701 | function asearch_get_form_sub($sub, $row_num = 0) |
702 | { |
703 | return function_exists('addCheckBox') ? addCheckBox('sub[' . $row_num .']', $sub) |
958becc9 |
704 | : '<input type="checkbox" name="sub[' . $row_num .']"' . ($sub ? ' checked="checked"' : '') . ' />'; |
7d60bda5 |
705 | } |
706 | |
5b6abe97 |
707 | /** Build the 2 unop and where selects |
708 | */ |
7d60bda5 |
709 | function asearch_get_form_location($unop, $where, $row_num = 0) |
710 | { |
711 | global $imap_asearch_unops, $imap_asearch_options; |
712 | |
713 | return asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop) |
714 | . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where); |
715 | } |
716 | |
5b6abe97 |
717 | /** Build the what text input |
718 | */ |
7d60bda5 |
719 | function asearch_get_form_what($what, $row_num = 0) |
720 | { |
721 | return function_exists('addInput') ? addInput('what[' . $row_num . ']', $what, '35') |
958becc9 |
722 | : '<input type="text" size="35" name="what[' . $row_num . ']" value="' . htmlspecialchars($what) . '" />'; |
7d60bda5 |
723 | } |
724 | |
5b6abe97 |
725 | /** Build the Exclude criteria checkbox |
726 | */ |
7d60bda5 |
727 | function asearch_get_form_exclude($exclude, $row_num = 0) |
728 | { |
729 | return function_exists('addCheckBox') ? addCheckBox('exclude['.$row_num.']', $exclude) |
958becc9 |
730 | : '<input type="checkbox" name="exclude[' . $row_num .']"' . ($exclude ? ' checked="checked"' : '') . ' />'; |
7d60bda5 |
731 | } |
732 | |
733 | /** Print one advanced form row |
734 | */ |
735 | function asearch_print_form_row($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num) |
736 | { |
737 | global $imap_asearch_biops_in; |
6b37252b |
738 | global $color; |
739 | |
920ec5ec |
740 | echo html_tag('tr', '', '', $color[4]); |
6b37252b |
741 | |
7d60bda5 |
742 | //Binary operator |
743 | echo html_tag('td', $row_num ? |
744 | asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop) |
745 | : '<b>' . _("In") . '</b>', 'center') . "\n"; |
746 | |
747 | //Mailbox list and Include Subfolders |
920ec5ec |
748 | echo html_tag('td', |
7d60bda5 |
749 | asearch_get_form_mailbox($imapConnection, $boxes, $mailbox, $row_num) |
750 | . _("and subfolders:") . asearch_get_form_sub($sub, $row_num), 'center') . "\n"; |
6b37252b |
751 | |
7d60bda5 |
752 | //Unary operator and Search location |
753 | echo html_tag('td', asearch_get_form_location($unop, $where, $row_num), 'center') . "\n"; |
6b37252b |
754 | |
7d60bda5 |
755 | //Text input |
756 | echo html_tag('td', asearch_get_form_what($what, $row_num), 'center') . "\n"; |
757 | |
758 | //Exclude criteria |
759 | echo html_tag('td', _("Exclude Criteria:") . asearch_get_form_exclude($exclude, $row_num), 'center') . "\n"; |
6b37252b |
760 | |
761 | echo "</tr>\n"; |
762 | } |
763 | |
7d60bda5 |
764 | /** Print the advanced search form |
765 | */ |
766 | function asearch_print_form($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
6b37252b |
767 | { |
768 | global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html; |
769 | global $color; |
770 | |
7d60bda5 |
771 | //Search Form |
958becc9 |
772 | echo "<br />\n"; |
7d60bda5 |
773 | echo '<form action="' . asearch_get_href() . '" name="form_asearch">' . "\n"; |
6b37252b |
774 | |
920ec5ec |
775 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"'); |
776 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5')); |
edda50ae |
777 | $row_count = count($where_array); |
6b37252b |
778 | for ($row_num = 0; $row_num < $row_count; $row_num++) { |
edda50ae |
779 | $mailbox = asearch_nz($mailbox_array[$row_num]); |
6b37252b |
780 | $biop = strip_tags(asearch_nz($biop_array[$row_num])); |
781 | $unop = strip_tags(asearch_nz($unop_array[$row_num])); |
edda50ae |
782 | $where = strip_tags(asearch_nz($where_array[$row_num])); |
6b37252b |
783 | $what = asearch_nz($what_array[$row_num]); |
784 | $exclude = strip_tags(asearch_nz($exclude_array[$row_num])); |
40fbe929 |
785 | $sub = strip_tags(asearch_nz($sub_array[$row_num])); |
786 | asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num); |
6b37252b |
787 | } |
788 | echo '</table>' . "\n"; |
789 | |
7d60bda5 |
790 | //Submit buttons |
920ec5ec |
791 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
6b37252b |
792 | echo html_tag('tr', |
793 | html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n" |
794 | . html_tag('td', getButton('SUBMIT', 'submit', $add_criteria_button_html), 'center') . "\n" |
795 | . html_tag('td', getButton('SUBMIT', 'submit', $del_all_button_html), 'center') . "\n" |
796 | . html_tag('td', getButton('SUBMIT', 'submit', $del_excluded_button_html), 'center') . "\n" |
797 | ); |
798 | echo '</table>' . "\n"; |
799 | echo '</form>' . "\n"; |
800 | } |
801 | |
7d60bda5 |
802 | /** Print one basic form row |
803 | */ |
804 | function asearch_print_form_row_basic($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num) |
805 | { |
806 | global $search_button_html; |
807 | global $color; |
808 | |
809 | echo html_tag('tr', '', '', $color[4]); |
810 | |
811 | //Mailbox list |
812 | echo html_tag('td', '<b>' . _("In") . '</b> ' . asearch_get_form_mailbox($imapConnection, $boxes, $mailbox), 'center') . "\n"; |
813 | |
814 | //Unary operator and Search location |
815 | echo html_tag('td', asearch_get_form_location($unop, $where), 'center') . "\n"; |
816 | |
817 | //Text input |
818 | echo html_tag('td', asearch_get_form_what($what), 'center') . "\n"; |
819 | |
820 | //Submit button |
821 | echo html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n"; |
822 | |
823 | echo "</tr>\n"; |
824 | } |
825 | |
826 | /** Print the basic search form |
827 | */ |
828 | function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
829 | { |
830 | global $color; |
831 | |
832 | //Search Form |
958becc9 |
833 | echo "<br />\n"; |
7d60bda5 |
834 | echo '<form action="' . asearch_get_href() . '" name="form_asearch">' . "\n"; |
835 | |
836 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"'); |
837 | //echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=4')); |
838 | $row_count = count($where_array); |
839 | for ($row_num = 0; $row_num < $row_count; $row_num++) { |
840 | $mailbox = asearch_nz($mailbox_array[$row_num]); |
841 | $biop = strip_tags(asearch_nz($biop_array[$row_num])); |
842 | $unop = strip_tags(asearch_nz($unop_array[$row_num])); |
843 | $where = strip_tags(asearch_nz($where_array[$row_num])); |
844 | $what = asearch_nz($what_array[$row_num]); |
845 | $exclude = strip_tags(asearch_nz($exclude_array[$row_num])); |
846 | $sub = strip_tags(asearch_nz($sub_array[$row_num])); |
847 | asearch_print_form_row_basic($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num); |
848 | } |
849 | echo '</table>' . "\n"; |
850 | echo '</form>' . "\n"; |
851 | } |
852 | |
853 | /** Print the $msgs messages from $mailbox mailbox |
854 | */ |
139b3991 |
855 | function asearch_print_mailbox_msgs($imapConnection, $mbxresponse, $mailbox, $id, $cnt, $sort, $color, $where, $what) |
6b37252b |
856 | { |
cf6cb8b1 |
857 | if ($cnt > 0) { |
c2d47d51 |
858 | global $allow_server_sort, $allow_thread_sort, $thread_sort_messages; |
139b3991 |
859 | $msgs = sqimap_get_small_header_list ($imapConnection, $id, count($id)); |
c2d47d51 |
860 | $thread_sort_messages = 0; |
861 | if ($allow_thread_sort) { |
862 | global $data_dir, $username; |
863 | $thread_sort_messages = getPref($data_dir, $username, 'thread_' . $mailbox); |
139b3991 |
864 | //$msort = $msgs; |
865 | //$real_sort = 6; |
c2d47d51 |
866 | } |
867 | elseif ($allow_server_sort) { |
139b3991 |
868 | //$msort = $msgs; |
869 | //$real_sort = 6; |
c2d47d51 |
870 | } |
871 | else { |
139b3991 |
872 | //$msort = calc_msort($msgs, $sort); |
873 | //$real_sort = $sort; |
c2d47d51 |
874 | } |
70f1b6b5 |
875 | |
7d60bda5 |
876 | $mailbox_display = asearch_get_mailbox_display($mailbox); |
877 | $mailbox_title = '<b><big>' . _("Folder:") . ' '. $mailbox_display . ' </big></b>'; |
878 | $devel = check_sm_version(1, 5, 0); |
879 | if (!$devel) { |
880 | echo html_tag('div', $mailbox_title, 'center') . "\n"; |
881 | $mailbox_title = get_selectall_link(1, $real_sort); |
882 | } |
6b37252b |
883 | $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt); |
70f1b6b5 |
884 | |
7d60bda5 |
885 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
0fd2f513 |
886 | |
6b37252b |
887 | echo '<tr><td>'; |
7d60bda5 |
888 | if ($devel) |
139b3991 |
889 | mail_message_listing_beginning($imapConnection, $mbxresponse, $mailbox, $sort, $msg_cnt_str, $mailbox_title, 1, 1); |
7d60bda5 |
890 | else |
139b3991 |
891 | mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $mailbox_title, 1, 1); |
6b37252b |
892 | echo '</td></tr>'; |
70f1b6b5 |
893 | |
139b3991 |
894 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
70f1b6b5 |
895 | |
6b37252b |
896 | echo '<tr><td>'; |
897 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
898 | echo ' <tr><td>'; |
70f1b6b5 |
899 | |
6b37252b |
900 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
901 | echo ' <tr><td>'; |
c2d47d51 |
902 | printHeader($mailbox, $sort, $color, !$thread_sort_messages); |
139b3991 |
903 | displayMessageArray($imapConnection, $cnt, 1, $id, $msgs, $mailbox, $sort, $cnt, $where, $what); |
6b37252b |
904 | echo ' </td></tr>'; |
905 | echo ' </table>'; |
906 | echo ' </td></tr>'; |
907 | echo ' </table>'; |
139b3991 |
908 | mail_message_listing_end($cnt, '', $msg_cnt_str, $color); |
6b37252b |
909 | echo '</td></tr>'; |
70f1b6b5 |
910 | |
6b37252b |
911 | echo '</table>'; |
912 | } |
139b3991 |
913 | } |
59a623e6 |
914 | |
40fbe929 |
915 | /** |
916 | * @param array $boxes mailboxes array (reference) |
917 | * @return array selectable unformatted mailboxes names |
918 | */ |
919 | function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes) |
920 | { |
921 | $mboxes_array = array(); |
922 | $boxcount = count($boxes); |
7d60bda5 |
923 | for ($boxnum = 0; $boxnum < $boxcount; $boxnum++) { |
40fbe929 |
924 | if (!in_array('noselect', $boxes[$boxnum]['flags'])) |
925 | $mboxes_array[] = $boxes[$boxnum]['unformatted']; |
926 | } |
927 | return $mboxes_array; |
928 | } |
929 | |
0d672ac0 |
930 | /* ------------------------ main ------------------------ */ |
7d60bda5 |
931 | /* get globals we will need */ |
6b37252b |
932 | sqgetGlobalVar('username', $username, SQ_SESSION); |
933 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
7d60bda5 |
934 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
935 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
6b37252b |
936 | |
ad2212db |
937 | if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) { |
139b3991 |
938 | $checkall = (int) $temp; |
ad2212db |
939 | } |
940 | |
139b3991 |
941 | |
6b37252b |
942 | $search_button_html = _("Search"); |
943 | $search_button_text = asearch_unhtmlentities($search_button_html); |
944 | $add_criteria_button_html = _("Add New Criteria"); |
945 | $add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html); |
34a85c56 |
946 | $del_excluded_button_html = _("Remove Excluded Criteria"); |
6b37252b |
947 | $del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html); |
34a85c56 |
948 | $del_all_button_html = _("Remove All Criteria"); |
6b37252b |
949 | $del_all_button_text = asearch_unhtmlentities($del_all_button_html); |
950 | |
7d60bda5 |
951 | /** Maximum number of recent searches to handle |
952 | * Default 0 |
953 | * @global integer $search_memory |
954 | */ |
955 | $search_memory = getPref($data_dir, $username, 'search_memory', 0); |
956 | |
957 | /** Advanced search control |
958 | * - 0 => allow basic interface only |
959 | * - 1 => allow advanced interface only |
960 | * - 2 => allow both |
961 | * Default 2 |
962 | * @global integer $allow_advanced_search |
963 | */ |
5b6abe97 |
964 | $allow_advanced_search = asearch_nz($allow_advanced_search, 2); |
6b37252b |
965 | |
7d60bda5 |
966 | /** |
967 | * Toggle advanced/basic search |
968 | */ |
969 | if (sqgetGlobalVar('advanced', $search_advanced, SQ_GET)) |
970 | setPref($data_dir, $username, 'search_advanced', $search_advanced & 1); |
6b37252b |
971 | |
7d60bda5 |
972 | /** If 1, show advanced search interface |
973 | * Default from allow_advanced_search pref |
974 | * @global integer $search_advanced |
975 | */ |
976 | if ($allow_advanced_search > 1) |
977 | $search_advanced = getPref($data_dir, $username, 'search_advanced', 0); |
978 | else |
979 | $search_advanced = $allow_advanced_search; |
6b37252b |
980 | |
7d60bda5 |
981 | if ($search_advanced) { |
982 | /** Set recent prefkeys according to $search_advanced |
983 | * @global array $recent_prefkeys |
984 | */ |
985 | $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_unop', 'asearch_recent_biop', 'asearch_recent_exclude', 'asearch_recent_sub'); |
986 | |
987 | /** Set saved prefkeys according to $search_advanced |
988 | * @global array $saved_prefkeys |
989 | */ |
990 | $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_unop', 'asearch_saved_biop', 'asearch_saved_exclude', 'asearch_saved_sub'); |
991 | |
992 | /*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/ |
993 | } |
994 | else { |
995 | $recent_prefkeys = array('search_where', 'search_folder', 'search_what', 'search_unop'); |
996 | $saved_prefkeys = array('saved_where', 'saved_folder', 'saved_what', 'saved_unop'); |
997 | } |
6b37252b |
998 | |
2d2f8bb8 |
999 | /** How we did enter the form |
1000 | * - unset : Enter key, or called from outside (eg read_body) |
1001 | * - $search_button_text : Search button |
1002 | * - 'Search_no_update' : Search but don't update recent |
1003 | * - 'Search_last' : Same as no_update but reload and search last |
1004 | * - 'Search_silent' : Same as no_update but only display results |
1005 | * - $add_criteria_button_text : Add New Criteria button |
1006 | * - $del_excluded_button_text : Remove Excluded Criteria button |
1007 | * - $del_all_button_text : Remove All Criteria button |
1008 | * - 'save_recent' |
1009 | * - 'search_recent' |
1010 | * - 'forget_recent' |
1011 | * - 'edit_saved' |
1012 | * - 'search_saved' |
1013 | * - 'delete_saved' |
1014 | * @global string $submit |
1015 | */ |
6b37252b |
1016 | if (isset($_GET['submit'])) |
1017 | $submit = strip_tags($_GET['submit']); |
1018 | |
2d2f8bb8 |
1019 | /** Searched mailboxes |
1020 | * @global array $mailbox_array |
1021 | */ |
6b37252b |
1022 | if (isset($_GET['mailbox'])) { |
1023 | $mailbox_array = $_GET['mailbox']; |
1024 | if (!is_array($mailbox_array)) |
1025 | $mailbox_array = array($mailbox_array); |
56e0b3b7 |
1026 | } |
6b37252b |
1027 | else |
1028 | $mailbox_array = array(); |
1029 | |
2d2f8bb8 |
1030 | /** Binary operators |
1031 | * @global array $biop_array |
1032 | */ |
6b37252b |
1033 | if (isset($_GET['biop'])) { |
1034 | $biop_array = $_GET['biop']; |
1035 | if (!is_array($biop_array)) |
1036 | $biop_array = array($biop_array); |
c1cb7ba4 |
1037 | } |
6b37252b |
1038 | else |
1039 | $biop_array = array(); |
c1cb7ba4 |
1040 | |
2d2f8bb8 |
1041 | /** Unary operators |
1042 | * @global array $unop_array |
1043 | */ |
6b37252b |
1044 | if (isset($_GET['unop'])) { |
1045 | $unop_array = $_GET['unop']; |
1046 | if (!is_array($unop_array)) |
1047 | $unop_array = array($unop_array); |
548a552a |
1048 | } |
6b37252b |
1049 | else |
1050 | $unop_array = array(); |
1051 | |
2d2f8bb8 |
1052 | /** Where to search |
1053 | * @global array $where_array |
1054 | */ |
6b37252b |
1055 | if (isset($_GET['where'])) { |
1056 | $where_array = $_GET['where']; |
1057 | if (!is_array($where_array)) |
1058 | $where_array = array($where_array); |
1059 | } |
1060 | else |
1061 | $where_array = array(); |
1062 | |
2d2f8bb8 |
1063 | /** What to search |
1064 | * @global array $what_array |
1065 | */ |
6b37252b |
1066 | if (isset($_GET['what'])) { |
1067 | $what_array = $_GET['what']; |
1068 | if (!is_array($what_array)) |
1069 | $what_array = array($what_array); |
1070 | } |
1071 | else |
1072 | $what_array = array(); |
1073 | |
2d2f8bb8 |
1074 | /** Whether to exclude this criteria from search |
1075 | * @global array $exclude_array |
1076 | */ |
6b37252b |
1077 | if (isset($_GET['exclude'])) |
1078 | $exclude_array = $_GET['exclude']; |
1079 | else |
1080 | $exclude_array = array(); |
1081 | |
2d2f8bb8 |
1082 | /** Search within subfolders |
1083 | * @global array $sub_array |
1084 | */ |
40fbe929 |
1085 | if (isset($_GET['sub'])) |
1086 | $sub_array = $_GET['sub']; |
1087 | else |
1088 | $sub_array = array(); |
1089 | |
2d2f8bb8 |
1090 | /** Row number used by recent and saved stuff |
1091 | */ |
c2d47d51 |
1092 | if (isset($_GET['rownum'])) |
6b37252b |
1093 | $submit_rownum = strip_tags($_GET['rownum']); |
c2d47d51 |
1094 | |
2d2f8bb8 |
1095 | /** Change global sort |
1096 | */ |
c2d47d51 |
1097 | if (sqgetGlobalVar('newsort', $newsort, SQ_GET)) { |
1098 | setPref($data_dir, $username, 'sort', $newsort); |
1099 | $sort = $newsort; |
1100 | sqsession_register($sort, 'sort'); |
7d60bda5 |
1101 | asearch_edit_last(); |
c2d47d51 |
1102 | } |
1103 | |
7d60bda5 |
1104 | /** Toggle mailbox threading |
2d2f8bb8 |
1105 | */ |
c2d47d51 |
1106 | if (sqgetGlobalVar('set_thread', $set_thread, SQ_GET)) { |
7d60bda5 |
1107 | setPref($data_dir, $username, 'thread_' . $mailbox_array[0], $set_thread & 1); |
1108 | asearch_edit_last(); |
56e0b3b7 |
1109 | } |
6b37252b |
1110 | |
7d60bda5 |
1111 | /** Toggle show/hide saved searches |
1112 | */ |
1113 | if (sqgetGlobalVar('search_show_saved', $search_show_saved, SQ_GET)) |
1114 | setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1); |
1115 | |
1116 | /** Toggle show/hide recent searches |
1117 | */ |
1118 | if (sqgetGlobalVar('search_show_recent', $search_show_recent, SQ_GET)) |
1119 | setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1); |
1120 | |
1121 | // end of get globals |
6b37252b |
1122 | |
40fbe929 |
1123 | /** If TRUE, do not show search interface |
7d60bda5 |
1124 | * Default FALSE |
40fbe929 |
1125 | * @global bool $search_silent |
1126 | */ |
7d60bda5 |
1127 | $search_silent = FALSE; |
6b37252b |
1128 | |
1129 | /* See how the page was called and fire off correct function */ |
7d60bda5 |
1130 | if ((empty($submit)) && (!empty($where_array))) { |
6b37252b |
1131 | /* This happens when the Enter key is used or called from outside */ |
1132 | $submit = $search_button_text; |
1133 | if (count($where_array) != count($unop_array)) /* Hack needed to handle coming back from read_body et als */ |
7d60bda5 |
1134 | asearch_edit_last(); |
56e0b3b7 |
1135 | } |
6b37252b |
1136 | |
1137 | if (!isset($submit)) { |
1138 | $submit = ''; |
56e0b3b7 |
1139 | } |
6b37252b |
1140 | else { |
1141 | switch ($submit) { |
1142 | case $search_button_text: |
05f5b952 |
1143 | if (asearch_check_query($where_array, $what_array, $exclude_array) == '') |
7d60bda5 |
1144 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
6b37252b |
1145 | break; |
1146 | case 'Search_silent': |
1147 | $search_silent = TRUE; |
1148 | /*nobreak;*/ |
1149 | case 'Search_no_update': |
1150 | $submit = $search_button_text; |
1151 | break; |
1152 | case $del_excluded_button_text: |
1153 | $delarray = array_keys($exclude_array); |
1154 | while (!empty($delarray)) { |
1155 | $delrow = array_pop($delarray); |
1156 | array_splice($mailbox_array, $delrow, 1); |
1157 | array_splice($biop_array, $delrow, 1); |
1158 | array_splice($unop_array, $delrow, 1); |
1159 | array_splice($where_array, $delrow, 1); |
1160 | array_splice($what_array, $delrow, 1); |
1161 | /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */ |
40fbe929 |
1162 | array_splice($sub_array, $delrow, 1); |
6b37252b |
1163 | } |
1164 | $exclude_array = array(); |
1165 | break; |
1166 | case $del_all_button_text: |
1167 | $mailbox_array = array(); |
1168 | $biop_array = array(); |
1169 | $unop_array = array(); |
1170 | $where_array = array(); |
1171 | $what_array = array(); |
1172 | $exclude_array = array(); |
40fbe929 |
1173 | $sub_array = array(); |
6b37252b |
1174 | break; |
1175 | case 'save_recent': |
7d60bda5 |
1176 | asearch_save_recent($submit_rownum); |
6b37252b |
1177 | break; |
1178 | case 'search_recent': |
1179 | $submit = $search_button_text; |
7d60bda5 |
1180 | asearch_edit_recent($submit_rownum); |
1181 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
1182 | break; |
6b37252b |
1183 | case 'edit_recent': /* no link to do this, yet */ |
7d60bda5 |
1184 | asearch_edit_recent($submit_rownum); |
6b37252b |
1185 | break; |
1186 | case 'forget_recent': |
7d60bda5 |
1187 | asearch_forget_recent($submit_rownum); |
6b37252b |
1188 | break; |
1189 | case 'search_saved': |
1190 | $submit = $search_button_text; |
7d60bda5 |
1191 | asearch_edit_saved($submit_rownum); |
1192 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
1193 | break; |
6b37252b |
1194 | case 'edit_saved': |
7d60bda5 |
1195 | asearch_edit_saved($submit_rownum); |
6b37252b |
1196 | break; |
1197 | case 'delete_saved': |
7d60bda5 |
1198 | asearch_delete_saved($submit_rownum); |
6b37252b |
1199 | break; |
1200 | } |
56e0b3b7 |
1201 | } |
23a9084b |
1202 | |
7d60bda5 |
1203 | //Texts in both basic and advanced form |
1204 | $imap_asearch_unops = array( |
1205 | '' => '', |
1206 | 'NOT' => _("Not") |
1207 | ); |
1208 | |
1209 | if ($search_advanced) { |
1210 | //Texts in advanced form only |
1211 | $imap_asearch_options = array( |
1212 | //<message set>, |
1213 | //'ALL' is binary operator |
1214 | 'ANSWERED' => _("Answered"), |
1215 | 'BCC' => _("Bcc"), |
1216 | 'BEFORE' => _("Before"), |
1217 | 'BODY' => _("Message Body"), |
1218 | 'CC' => _("CC"), |
1219 | 'DELETED' => _("Deleted"), |
1220 | 'DRAFT' => _("Draft"), |
1221 | 'FLAGGED' => _("Flagged"), |
1222 | 'FROM' => _("Sent By"), |
1223 | 'HEADER' => _("Header Field"), |
1224 | 'KEYWORD' => _("Keyword"), |
1225 | 'LARGER' => _("Larger Than"), |
1226 | 'NEW' => _("New"), |
1227 | //'NOT' is unary operator |
1228 | 'OLD' => _("Old"), |
1229 | 'ON' => _("On"), |
1230 | //'OR' is binary operator |
1231 | 'RECENT' => _("Recent"), |
1232 | 'SEEN' => _("Seen"), |
1233 | 'SENTBEFORE' => _("Sent Before"), |
1234 | 'SENTON' => _("Sent On"), |
1235 | 'SENTSINCE' => _("Sent Since"), |
1236 | 'SINCE' => _("Since"), |
1237 | 'SMALLER' => _("Smaller Than"), |
1238 | 'SUBJECT' => _("Subject Contains"), |
1239 | 'TEXT' => _("Header and Body"), |
1240 | 'TO' => _("Sent To"), |
1241 | //'UID' => 'anum', |
1242 | /* 'UNANSWERED' => '', |
1243 | 'UNDELETED' => '', |
1244 | 'UNDRAFT' => '', |
1245 | 'UNFLAGGED' => '', |
1246 | 'UNKEYWORD' => _("Unkeyword"), |
1247 | 'UNSEEN' => _("Unseen"),*/ |
1248 | ); |
1249 | |
1250 | $imap_asearch_biops_in = array( |
1251 | 'ALL' => _("And In"), |
1252 | 'OR' => _("Or In") |
1253 | ); |
1254 | |
1255 | $imap_asearch_biops = array( |
1256 | 'ALL' => _("And"), |
1257 | 'OR' => _("Or") |
1258 | ); |
1259 | } |
1260 | else { |
1261 | //Texts in basic form only |
1262 | $imap_asearch_options = array( |
1263 | 'BCC' => _("Bcc"), |
1264 | 'BODY' => _("Body"), |
1265 | 'CC' => _("Cc"), |
1266 | 'FROM' => _("From"), |
1267 | 'SUBJECT' => _("Subject"), |
1268 | 'TEXT' => _("Everywhere"), |
1269 | 'TO' => _("To"), |
1270 | ); |
1271 | } |
1272 | |
1273 | uasort($imap_asearch_options, 'asearch_unhtml_strcoll'); |
1274 | |
6b37252b |
1275 | /* open IMAP connection */ |
1276 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
5b6abe97 |
1277 | /* get mailboxes once here */ |
6b37252b |
1278 | $boxes = sqimap_mailbox_list($imapConnection); |
99f3175e |
1279 | /* ensure we have a valid default mailbox name */ |
edda50ae |
1280 | $mailbox = asearch_nz($mailbox_array[0]); |
1281 | if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?) |
1282 | $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;) |
99f3175e |
1283 | |
6b37252b |
1284 | if (isset($composenew) && $composenew) { |
7d60bda5 |
1285 | $comp_uri = "../src/compose.php?mailbox=" . urlencode($mailbox) |
1286 | . "&session=$composesession&attachedmessages=true&"; |
6b37252b |
1287 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
56e0b3b7 |
1288 | } |
6b37252b |
1289 | else |
1290 | displayPageHeader($color, $mailbox); |
184ef883 |
1291 | |
6b37252b |
1292 | do_hook('search_before_form'); |
d81e351b |
1293 | |
6b37252b |
1294 | if (!$search_silent) { |
7d60bda5 |
1295 | //Add a link to the other search mode if allowed |
1296 | if ($allow_advanced_search > 1) |
5b6abe97 |
1297 | $toggle_link = ' - <small>[' |
1298 | . asearch_get_toggle_link(!$search_advanced, 'advanced', array(_("Standard search"), _("Advanced search"))) |
1299 | . ']</small>'; |
7d60bda5 |
1300 | else |
1301 | $toggle_link = ''; |
1302 | |
920ec5ec |
1303 | echo html_tag('table', |
7d60bda5 |
1304 | html_tag('tr', "\n" |
1305 | . html_tag('td', asearch_get_title_display($color, _("Search")) . $toggle_link, 'center', $color[0]) |
6b37252b |
1306 | ) , |
1307 | '', '', 'width="100%"') . "\n"; |
7d60bda5 |
1308 | asearch_print_saved($boxes); |
1309 | asearch_print_recent($boxes); |
edda50ae |
1310 | if (empty($where_array)) { |
40fbe929 |
1311 | global $sent_folder; |
1312 | |
edda50ae |
1313 | $mailbox_array[0] = $mailbox; |
1314 | $biop_array[0] = ''; |
1315 | $unop_array[0] = ''; |
40fbe929 |
1316 | if ($mailbox == $sent_folder) |
1317 | $where_array[0] = 'TO'; |
1318 | else |
1319 | $where_array[0] = 'FROM'; |
edda50ae |
1320 | $what_array[0] = ''; |
1321 | $exclude_array[0] = ''; |
40fbe929 |
1322 | $sub_array[0] = ''; |
edda50ae |
1323 | } |
7d60bda5 |
1324 | //Display advanced or basic form |
1325 | if ($search_advanced) { |
1326 | if ($submit == $add_criteria_button_text) { |
1327 | $last_index = max(count($where_array) - 1, 0); |
1328 | $mailbox_array[] = asearch_nz($mailbox_array[$last_index]); |
1329 | $biop_array[] = asearch_nz($biop_array[$last_index]); |
1330 | $unop_array[] = asearch_nz($unop_array[$last_index]); |
1331 | $where_array[] = asearch_nz($where_array[$last_index]); |
1332 | $what_array[] = asearch_nz($what_array[$last_index]); |
1333 | $exclude_array[] = asearch_nz($exclude_array[$last_index]); |
1334 | $sub_array[] = asearch_nz($sub_array[$last_index]); |
1335 | } |
1336 | asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
edda50ae |
1337 | } |
7d60bda5 |
1338 | else |
1339 | asearch_print_form_basic($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
6b37252b |
1340 | } |
1341 | |
d81e351b |
1342 | /********************************************************************* |
1343 | * Check to see if we can use cache or not. Currently the only time * |
1344 | * when you will not use it is when a link on the left hand frame is * |
1345 | * used. Also check to make sure we actually have the array in the * |
1346 | * registered session data. :) * |
1347 | *********************************************************************/ |
edda50ae |
1348 | if (!isset($use_mailbox_cache)) |
d81e351b |
1349 | $use_mailbox_cache = 0; |
d81e351b |
1350 | |
88cb1b4d |
1351 | do_hook('search_after_form'); |
56e0b3b7 |
1352 | |
6b37252b |
1353 | if ($submit == $search_button_text) { |
920ec5ec |
1354 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
1355 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5])); |
40fbe929 |
1356 | 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])); |
313fd1f4 |
1357 | echo '</table>' . "\n"; |
05f5b952 |
1358 | |
2303858b |
1359 | flush(); |
1360 | |
05f5b952 |
1361 | $query_error = asearch_check_query($where_array, $what_array, $exclude_array); |
6b37252b |
1362 | if ($query_error != '') |
958becc9 |
1363 | echo '<br />' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n"; |
6b37252b |
1364 | else { |
40fbe929 |
1365 | // Disable thread sort for now if there is more than one mailbox or at least one 'All Folders' |
c2d47d51 |
1366 | global $allow_thread_sort; |
1367 | $old_allow_thread_sort = $allow_thread_sort; |
40fbe929 |
1368 | $allow_thread_sort = ((count(array_unique($mailbox_array)) <= 1) && (!in_array('All Folders', $mailbox_array))); |
6b37252b |
1369 | |
40fbe929 |
1370 | $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes); |
1371 | $mboxes_msgs = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array); |
6b37252b |
1372 | if (empty($mboxes_msgs)) |
958becc9 |
1373 | echo '<br />' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n"; |
6b37252b |
1374 | else { |
1375 | foreach($mboxes_msgs as $mailbox => $msgs) { |
958becc9 |
1376 | echo '<br />'; |
9db01361 |
1377 | $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox); |
139b3991 |
1378 | //$msgs = sqimap_get_small_header_list ($imapConnection, $msgs, count($msgs)); |
6b37252b |
1379 | /* For now just keep the first criteria to make the regular search happy if the user tries to come back to search */ |
7d60bda5 |
1380 | /* $where = asearch_serialize($where_array); |
1381 | $what = asearch_serialize($what_array);*/ |
1382 | $where = $where_array[0]; |
1383 | $what = $what_array[0]; |
9db01361 |
1384 | asearch_print_mailbox_msgs($imapConnection, $mbxresponse, $mailbox, $msgs, count($msgs), $sort, $color, urlencode($where), urlencode($what)); |
6b37252b |
1385 | } |
1386 | } |
1387 | |
c2d47d51 |
1388 | $allow_thread_sort = $old_allow_thread_sort; // Restore thread sort |
59a623e6 |
1389 | } |
56e0b3b7 |
1390 | } |
1391 | |
70c4fd84 |
1392 | do_hook('search_bottom'); |
6b37252b |
1393 | sqimap_logout($imapConnection); |
dcc1cc82 |
1394 | echo '</body></html>'; |
99d2a184 |
1395 | |
139b3991 |
1396 | ?> |