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