c61bb006 |
1 | <?php |
245a6892 |
2 | |
35586184 |
3 | /** |
a5ee5ac2 |
4 | * search.php |
35586184 |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * $Id$ |
10 | */ |
2d367c68 |
11 | |
86725763 |
12 | /* Path for SquirrelMail required files. */ |
13 | define('SM_PATH','../'); |
14 | |
15 | /* SquirrelMail required files. */ |
08185f2a |
16 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
17 | require_once(SM_PATH . 'functions/imap.php'); |
18 | require_once(SM_PATH . 'functions/imap_search.php'); |
19 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/strings.php'); |
c61bb006 |
21 | |
e92eab8b |
22 | global $allow_thread_sort; |
56e0b3b7 |
23 | |
0b97a708 |
24 | /* get globals we may need */ |
25 | |
f38b7cf0 |
26 | sqgetGlobalVar('username', $username, SQ_SESSION); |
27 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
28 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
29 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
0b97a708 |
30 | |
31 | if (isset($_GET['mailbox'])) { |
32 | $mailbox = strip_tags($_GET['mailbox']); |
33 | } |
34 | if (isset($_GET['submit'])) { |
35 | $submit = strip_tags($_GET['submit']); |
36 | } |
37 | if (isset($_GET['what'])) { |
38 | $what = $_GET['what']; |
39 | } |
40 | if (isset($_GET['where'])) { |
41 | $where = strip_tags($_GET['where']); |
42 | } |
43 | if (isset($_GET['checkall'])) { |
44 | $checkall = strip_tags($_GET['checkall']); |
45 | } |
46 | if (isset($_GET['count'])) { |
47 | $count = strip_tags($_GET['count']); |
48 | } |
49 | /* end of get globals */ |
50 | |
23a9084b |
51 | /* here are some functions, could go in imap_search.php |
23a9084b |
52 | this was here, pretty handy */ |
29eb5486 |
53 | function s_opt( $val, $sel, $tit ) { |
54 | echo " <option value=\"$val\""; |
0d672ac0 |
55 | if ( $sel == $val ) { |
bd9bbfef |
56 | echo ' selected'; |
99d2a184 |
57 | } |
29eb5486 |
58 | echo ">$tit</option>\n"; |
59 | } |
99d2a184 |
60 | |
bebf762c |
61 | /* function to get the recent searches and put them in the attributes array */ |
62 | function get_recent($username, $data_dir) { |
63 | $attributes = array(); |
64 | $types = array('search_what', 'search_where', 'search_folder'); |
56e0b3b7 |
65 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
56e0b3b7 |
66 | for ($x=1;$x<=$recent_count;$x++) { |
bebf762c |
67 | reset($types); |
68 | foreach ($types as $key) { |
69 | $attributes[$key][$x] = getPref($data_dir, $username, $key.$x, ""); |
70 | } |
56e0b3b7 |
71 | } |
bebf762c |
72 | return $attributes; |
56e0b3b7 |
73 | } |
74 | |
bebf762c |
75 | /* function to get the saved searches and put them in the saved_attributes array */ |
76 | function get_saved($username, $data_dir) { |
77 | $saved_attributes = array(); |
78 | $types = array('saved_what', 'saved_where', 'saved_folder'); |
79 | foreach ($types as $key) { |
80 | for ($x=1;;$x++) { |
81 | $saved_attributes[$key][$x] = getPref($data_dir, $username, $key."$x", ""); |
82 | if ($saved_attributes[$key][$x] == "") { |
83 | array_pop($saved_attributes[$key]); |
84 | break; |
85 | } |
86 | } |
56e0b3b7 |
87 | } |
bebf762c |
88 | return $saved_attributes; |
56e0b3b7 |
89 | } |
90 | |
23a9084b |
91 | /* function to update recent pref arrays */ |
92 | function update_recent($what, $where, $mailbox, $username, $data_dir) { |
bebf762c |
93 | $attributes = array(); |
94 | $types = array('search_what', 'search_where', 'search_folder'); |
95 | $input = array($what, $where, $mailbox); |
96 | $attributes = get_recent( $username, $data_dir); |
97 | reset($types); |
70c4fd84 |
98 | $dupe = 'no'; |
bebf762c |
99 | for ($i=1;$i<=count($attributes['search_what']);$i++) { |
100 | if (isset($attributes['search_what'][$i])) { |
101 | if ($what == $attributes['search_what'][$i] && |
102 | $where == $attributes['search_where'][$i] && |
103 | $mailbox == $attributes['search_folder'][$i]) { |
104 | $dupe = 'yes'; |
105 | } |
23a9084b |
106 | } |
107 | } |
70c4fd84 |
108 | if ($dupe == 'no') { |
bebf762c |
109 | $i = 0; |
110 | foreach ($types as $key) { |
111 | array_push ($attributes[$key], $input[$i]); |
112 | array_shift ($attributes[$key]); |
113 | $i++; |
114 | } |
115 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
116 | $n=0; |
117 | for ($i=1;$i<=$recent_count;$i++) { |
118 | reset($types); |
119 | foreach ($types as $key) { |
120 | setPref($data_dir, $username, $key.$i, $attributes[$key][$n]); |
121 | } |
122 | $n++; |
123 | } |
56e0b3b7 |
124 | } |
125 | } |
126 | |
23a9084b |
127 | /* function to forget a recent search */ |
56e0b3b7 |
128 | function forget_recent($forget_index, $username, $data_dir) { |
bebf762c |
129 | $attributes = array(); |
130 | $types = array('search_what', 'search_where', 'search_folder'); |
131 | $attributes = get_recent( $username, $data_dir); |
132 | reset($types); |
133 | foreach ($types as $key) { |
7dba227d |
134 | array_splice($attributes[$key], $forget_index - 1, 1); |
bebf762c |
135 | array_unshift($attributes[$key], ''); |
136 | } |
137 | reset($types); |
56e0b3b7 |
138 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
139 | $n=0; |
140 | for ($i=1;$i<=$recent_count;$i++) { |
bebf762c |
141 | reset($types); |
142 | foreach ($types as $key) { |
143 | setPref($data_dir, $username, $key.$i, $attributes[$key][$n]); |
144 | } |
23a9084b |
145 | $n++; |
56e0b3b7 |
146 | } |
147 | } |
23a9084b |
148 | |
149 | /* function to delete a saved search */ |
56e0b3b7 |
150 | function delete_saved($delete_index, $username, $data_dir) { |
bebf762c |
151 | $types = array('saved_what', 'saved_where', 'saved_folder'); |
152 | $attributes = get_saved($username, $data_dir); |
153 | foreach ($types as $key) { |
154 | array_splice($attributes[$key], $delete_index, 1); |
155 | } |
156 | reset($types); |
56e0b3b7 |
157 | $n=0; |
bebf762c |
158 | $saved_count = count($attributes['saved_what']); |
56e0b3b7 |
159 | $last_element = $saved_count + 1; |
56e0b3b7 |
160 | for ($i=1;$i<=$saved_count;$i++) { |
bebf762c |
161 | reset($types); |
162 | foreach ($types as $key) { |
163 | setPref($data_dir, $username, $key.$i, $attributes[$key][$n]); |
164 | } |
23a9084b |
165 | $n++; |
56e0b3b7 |
166 | } |
bebf762c |
167 | reset($types); |
168 | foreach($types as $key) { |
169 | removePref($data_dir, $username, $key.$last_element); |
56e0b3b7 |
170 | } |
70c4fd84 |
171 | } |
6c8388a9 |
172 | |
23a9084b |
173 | /* function to save a search from recent to saved */ |
56e0b3b7 |
174 | function save_recent($save_index, $username, $data_dir) { |
bebf762c |
175 | $attributes = array(); |
176 | $types = array('search_what', 'search_where', 'search_folder'); |
177 | $saved_types = array(0 => 'saved_what', 1 => 'saved_where', 2 => 'saved_folder'); |
178 | $saved_array = get_saved($username, $data_dir); |
179 | $save_index = $save_index -1; |
180 | $saved_count = (count($saved_array['saved_what']) + 1); |
181 | $attributes = get_recent ($username, $data_dir); |
182 | $n = 0; |
183 | foreach ($types as $key) { |
184 | $slice = array_slice($attributes[$key], $save_index, 1); |
185 | $name = $saved_types[$n]; |
186 | setPref($data_dir, $username, $name.$saved_count, $slice[0]); |
187 | $n++; |
188 | } |
56e0b3b7 |
189 | } |
190 | |
d215ca7d |
191 | function printSearchMessages($msgs,$mailbox, $cnt, $imapConnection, $where, $what, $usecache = false, $newsort = false) { |
59a623e6 |
192 | global $sort, $color; |
193 | |
cf6cb8b1 |
194 | if ($cnt > 0) { |
195 | $msort = calc_msort($msgs, $sort); |
59a623e6 |
196 | if ( $mailbox == 'INBOX' ) { |
197 | $showbox = _("INBOX"); |
198 | } else { |
199 | $showbox = imap_utf7_decode_local($mailbox); |
200 | } |
201 | echo html_tag( 'div', '<b><big>' . _("Folder:") . ' '. $showbox.'</big></b>','center') . "\n"; |
202 | |
70f1b6b5 |
203 | |
204 | $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt); |
4a6762c5 |
205 | $toggle_all = get_selectall_link(1, $sort); |
70f1b6b5 |
206 | |
0fd2f513 |
207 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
208 | echo '<tr><td>'; |
209 | |
70f1b6b5 |
210 | mail_message_listing_beginning($imapConnection, $mailbox, $sort, |
4a6762c5 |
211 | $msg_cnt_str, $toggle_all, 1); |
70f1b6b5 |
212 | |
0fd2f513 |
213 | echo '</td></tr>'; |
214 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
215 | echo '<tr><td>'; |
216 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
217 | echo ' <tr><td>'; |
218 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
219 | echo '<tr><td>'; |
70f1b6b5 |
220 | |
221 | printHeader($mailbox, 6, $color, false); |
222 | |
59a623e6 |
223 | displayMessageArray($imapConnection, $cnt, 1, |
d215ca7d |
224 | $msort, $mailbox, $sort, $color, $cnt, $where, $what); |
70f1b6b5 |
225 | |
0fd2f513 |
226 | echo '</td></tr></table></td></tr></table>'; |
70f1b6b5 |
227 | mail_message_listing_end($cnt, '', $msg_cnt_str, $color); |
4a6762c5 |
228 | echo '</td></tr></table>'; |
59a623e6 |
229 | } |
230 | } |
231 | |
0d672ac0 |
232 | /* ------------------------ main ------------------------ */ |
233 | |
23a9084b |
234 | /* reset these arrays on each page load just in case */ |
bebf762c |
235 | $attributes = array (); |
236 | $saved_attributes = array (); |
70c4fd84 |
237 | $search_all = 'none'; |
23a9084b |
238 | $perbox_count = array (); |
aa45f943 |
239 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
56e0b3b7 |
240 | |
23a9084b |
241 | /* get mailbox names */ |
29eb5486 |
242 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
c1cb7ba4 |
243 | $boxes = sqimap_mailbox_list($imapConnection); |
244 | |
23a9084b |
245 | /* set current mailbox to INBOX if none was selected or if page |
246 | was called to search all folders. */ |
14c62c12 |
247 | if ( !isset($mailbox) || $mailbox == 'None' || $mailbox == '' ) { |
56e0b3b7 |
248 | $mailbox = $boxes[0]['unformatted']; |
249 | } |
3b7d68e6 |
250 | if ($mailbox == 'All Folders') { |
70c4fd84 |
251 | $search_all = 'all'; |
c1cb7ba4 |
252 | } |
253 | |
548a552a |
254 | if (isset($composenew) && $composenew) { |
d7f8e6e6 |
255 | $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox). |
256 | "&session=$composesession&attachedmessages=true&"; |
b899bb85 |
257 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
548a552a |
258 | } else { |
259 | displayPageHeader($color, $mailbox); |
260 | } |
23a9084b |
261 | /* See how the page was called and fire off correct function */ |
d4144adf |
262 | if ((!isset($submit) || empty($submit)) && !empty($what)) { |
70c4fd84 |
263 | $submit = _("Search"); |
d4144adf |
264 | } |
70c4fd84 |
265 | if ( !isset( $submit ) ) { |
70c4fd84 |
266 | $submit = ''; |
267 | } else if ($submit == _("Search") && !empty($what)) { |
aa45f943 |
268 | if ($recent_count > 0) { |
269 | update_recent($what, $where, $mailbox, $username, $data_dir); |
270 | } |
56e0b3b7 |
271 | } |
88cb1b4d |
272 | elseif ($submit == 'forget') { |
56e0b3b7 |
273 | forget_recent($count, $username, $data_dir); |
274 | } |
88cb1b4d |
275 | elseif ($submit == 'save') { |
56e0b3b7 |
276 | save_recent($count, $username, $data_dir); |
277 | } |
88cb1b4d |
278 | elseif ($submit == 'delete') { |
56e0b3b7 |
279 | delete_saved($count, $username, $data_dir); |
280 | } |
23a9084b |
281 | |
29eb5486 |
282 | do_hook('search_before_form'); |
56e0b3b7 |
283 | |
6206f6c4 |
284 | echo html_tag( 'table', |
dcbe1ecc |
285 | html_tag( 'tr', "\n" . |
286 | html_tag( 'td', '<b>' . _("Search") . '</b>', 'center', $color[0] ) |
287 | ) , |
288 | '', '', 'width="100%"') . "\n"; |
c61bb006 |
289 | |
23a9084b |
290 | /* update the recent and saved searches from the pref files */ |
bebf762c |
291 | $attributes = get_recent($username, $data_dir); |
bebf762c |
292 | $saved_attributes = get_saved($username, $data_dir); |
293 | $saved_count = count($saved_attributes['saved_what']); |
91954f9e |
294 | $count_all = 0; |
a7d0eaf6 |
295 | |
184ef883 |
296 | /* Saved Search Table */ |
56e0b3b7 |
297 | if ($saved_count > 0) { |
dcbe1ecc |
298 | echo "<br>\n" |
299 | . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' ) |
300 | . html_tag( 'tr', |
301 | html_tag( 'td', '<b>Saved Searches</b>', 'center' ) |
302 | ) |
303 | . html_tag( 'tr' ) |
304 | . html_tag( 'td' ) |
305 | . html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="2" cellspacing="2" border="0"' ); |
184ef883 |
306 | for ($i=0; $i < $saved_count; ++$i) { |
88cb1b4d |
307 | if ($i % 2) { |
dcbe1ecc |
308 | echo html_tag( 'tr', '', '', $color[0] ); |
88cb1b4d |
309 | } else { |
dcbe1ecc |
310 | echo html_tag( 'tr', '', '', $color[4] ); |
184ef883 |
311 | } |
e842b215 |
312 | echo html_tag( 'td', imap_utf7_decode_local($saved_attributes['saved_folder'][$i]), 'left', '', 'width="35%"' ) |
dcbe1ecc |
313 | . html_tag( 'td', $saved_attributes['saved_what'][$i], 'left' ) |
314 | . html_tag( 'td', $saved_attributes['saved_where'][$i], 'center' ) |
315 | . html_tag( 'td', '', 'right' ) |
316 | . '<a href=search.php' |
e842b215 |
317 | . '?mailbox=' . htmlspecialchars($saved_attributes['saved_folder'][$i]) |
318 | . '&what=' . htmlspecialchars($saved_attributes['saved_what'][$i]) |
319 | . '&where=' . htmlspecialchars($saved_attributes['saved_where'][$i]) |
dcbe1ecc |
320 | . '>' . _("edit") . '</a>' |
88cb1b4d |
321 | . ' | ' |
dcbe1ecc |
322 | . '<a href=search.php' |
bebf762c |
323 | . '?mailbox=' . urlencode($saved_attributes['saved_folder'][$i]) |
324 | . '&what=' . urlencode($saved_attributes['saved_what'][$i]) |
325 | . '&where=' . urlencode($saved_attributes['saved_where'][$i]) |
5e9e90fd |
326 | . '&submit=Search_no_update' |
dcbe1ecc |
327 | . '>' . _("search") . '</a>' |
88cb1b4d |
328 | . ' | ' |
dcbe1ecc |
329 | . "<a href=search.php?count=$i&submit=delete>" |
88cb1b4d |
330 | . _("delete") |
dcbe1ecc |
331 | . '</a>' |
332 | . '</td></tr>'; |
56e0b3b7 |
333 | } |
dcbe1ecc |
334 | echo "</table></td></tr></table>\n"; |
a7d0eaf6 |
335 | } |
336 | |
56e0b3b7 |
337 | if ($recent_count > 0) { |
fab3baa6 |
338 | echo "<br>\n" |
339 | . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' ) |
340 | . html_tag( 'tr', |
341 | html_tag( 'td', '<b>' . _("Recent Searches") . '</b>', 'center' ) |
342 | ) |
343 | . html_tag( 'tr' ) |
344 | . html_tag( 'td' ) |
345 | . html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="0" cellspacing="0" border="0"' ); |
bebf762c |
346 | for ($i=1; $i <= $recent_count; ++$i) { |
347 | if (isset($attributes['search_folder'][$i])) { |
348 | if ($attributes['search_folder'][$i] == "") { |
349 | $attributes['search_folder'][$i] = "INBOX"; |
350 | } |
184ef883 |
351 | } |
352 | if ($i % 2) { |
fab3baa6 |
353 | echo html_tag( 'tr', '', '', $color[0] ); |
184ef883 |
354 | } else { |
fab3baa6 |
355 | echo html_tag( 'tr', '', '', $color[0] ); |
184ef883 |
356 | } |
bebf762c |
357 | if (isset($attributes['search_what'][$i]) && |
358 | !empty($attributes['search_what'][$i])) { |
e842b215 |
359 | echo html_tag( 'td', imap_utf7_decode_local($attributes['search_folder'][$i]), 'left', '', 'width="35%"' ) |
360 | . html_tag( 'td', htmlspecialchars($attributes['search_what'][$i]), 'left' ) |
fab3baa6 |
361 | . html_tag( 'td', $attributes['search_where'][$i], 'center' ) |
362 | . html_tag( 'td', '', 'right' ) |
363 | . "<a href=search.php?count=$i&submit=save>" |
184ef883 |
364 | . _("save") |
fab3baa6 |
365 | . '</a>' |
184ef883 |
366 | . ' | ' |
fab3baa6 |
367 | . '<a href=search.php' |
bebf762c |
368 | . '?mailbox=' . urlencode($attributes['search_folder'][$i]) |
369 | . '&what=' . urlencode($attributes['search_what'][$i]) |
370 | . '&where=' . urlencode($attributes['search_where'][$i]) |
5e9e90fd |
371 | . '&submit=Search_no_update' |
fab3baa6 |
372 | . '>' . _("search") . '</a>' |
184ef883 |
373 | . ' | ' |
fab3baa6 |
374 | . "<a href=search.php?count=$i&submit=forget>" |
184ef883 |
375 | . _("forget") |
fab3baa6 |
376 | . '</a>' |
377 | . '</td></tr>'; |
0d672ac0 |
378 | } |
bebf762c |
379 | } |
fab3baa6 |
380 | echo '</table></td></tr></table><br>'; |
56e0b3b7 |
381 | } |
184ef883 |
382 | |
d81e351b |
383 | |
384 | if (isset($newsort)) { |
385 | $sort = $newsort; |
9837b0a5 |
386 | sqsession_register($sort, 'sort'); |
d81e351b |
387 | } |
388 | |
389 | /********************************************************************* |
390 | * Check to see if we can use cache or not. Currently the only time * |
391 | * when you will not use it is when a link on the left hand frame is * |
392 | * used. Also check to make sure we actually have the array in the * |
393 | * registered session data. :) * |
394 | *********************************************************************/ |
395 | if (! isset($use_mailbox_cache)) { |
396 | $use_mailbox_cache = 0; |
397 | } |
398 | |
399 | /* There is a problem with registered vars in 4.1 */ |
400 | /* |
401 | if( substr( phpversion(), 0, 3 ) == '4.1' ) { |
402 | $use_mailbox_cache = FALSE; |
403 | } |
404 | */ |
405 | |
184ef883 |
406 | /* Search Form */ |
fab3baa6 |
407 | echo html_tag( 'div', '<b>' . _("Current Search") . '</b>', 'left' ) . "\n" |
408 | . '<form action="search.php" name="s">' |
409 | . html_tag( 'table', '', '', '', 'width="95%" cellpadding="0" cellspacing="0" border="0"' ) |
410 | . html_tag( 'tr' ) |
411 | . html_tag( 'td', '', 'left' ) |
be2d5495 |
412 | . '<select name="mailbox">' |
413 | . '<option value="All Folders"'; |
414 | if ($mailbox == 'All Folders') { |
415 | echo ' selected'; |
416 | } |
c0c1781d |
417 | echo '>[ ' . _("All Folders") . " ]</option>\n"; |
be2d5495 |
418 | |
419 | $show_selected = array(strtolower($mailbox)); |
420 | echo sqimap_mailbox_option_list($imapConnection, $show_selected, 0, $boxes); |
421 | |
422 | echo ' </select>'. |
423 | " </td>\n"; |
88cb1b4d |
424 | if ( !isset( $what ) ) { |
425 | $what = ''; |
426 | } |
e970aa41 |
427 | if ( !isset( $where ) ) { |
0fd2f513 |
428 | $where = 'FROM'; |
e970aa41 |
429 | } |
430 | |
431 | |
56e0b3b7 |
432 | $what_disp = str_replace(',', ' ', $what); |
433 | $what_disp = str_replace('\\\\', '\\', $what_disp); |
434 | $what_disp = str_replace('\\"', '"', $what_disp); |
435 | $what_disp = str_replace('"', '"', $what_disp); |
fab3baa6 |
436 | echo html_tag( 'td', '<input type="text" size="35" name="what" value="' . $what_disp . '">' . "\n", 'center' ) |
437 | . html_tag( 'td', '', 'right' ) |
438 | . "<select name=\"where\">"; |
56e0b3b7 |
439 | s_opt( 'BODY', $where, _("Body") ); |
440 | s_opt( 'TEXT', $where, _("Everywhere") ); |
441 | s_opt( 'SUBJECT', $where, _("Subject") ); |
442 | s_opt( 'FROM', $where, _("From") ); |
443 | s_opt( 'CC', $where, _("Cc") ); |
444 | s_opt( 'TO', $where, _("To") ); |
fab3baa6 |
445 | echo " </select>\n" . |
446 | " </td>\n". |
447 | html_tag( 'td', '<input type="submit" name="submit" value="' . _("Search") . '">' . "\n", 'center', '', 'colspan="3"' ) . |
448 | " </tr>\n". |
449 | "</form>\n". |
450 | " </table>\n". |
451 | "</td></tr></table>\n"; |
56e0b3b7 |
452 | |
453 | |
88cb1b4d |
454 | do_hook('search_after_form'); |
56e0b3b7 |
455 | |
88cb1b4d |
456 | /* |
457 | search all folders option still in the works. returns a table for each |
70c4fd84 |
458 | folder it finds a match in. |
88cb1b4d |
459 | */ |
56e0b3b7 |
460 | |
e92eab8b |
461 | $old_value = 0; |
794d59c0 |
462 | if ($allow_thread_sort == TRUE) { |
e92eab8b |
463 | $old_value = $allow_thread_sort; |
794d59c0 |
464 | $allow_thread_sort = FALSE; |
e92eab8b |
465 | } |
466 | |
88cb1b4d |
467 | if ($search_all == 'all') { |
468 | $mailbox == ''; |
56e0b3b7 |
469 | $boxcount = count($boxes); |
d81e351b |
470 | echo '<BR><CENTER><B>' . |
88cb1b4d |
471 | _("Search Results") . |
1ba8cd6b |
472 | "</B></CENTER><BR>\n"; |
56e0b3b7 |
473 | for ($x=0;$x<$boxcount;$x++) { |
474 | if (!in_array('noselect', $boxes[$x]['flags'])) { |
88cb1b4d |
475 | $mailbox = $boxes[$x]['unformatted']; |
476 | } |
70c4fd84 |
477 | if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) { |
56e0b3b7 |
478 | sqimap_mailbox_select($imapConnection, $mailbox); |
d81e351b |
479 | $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all); |
480 | $count_all = count($msgs); |
70f1b6b5 |
481 | printSearchMessages($msgs, $mailbox, $count_all, $imapConnection, |
d215ca7d |
482 | $where, $what, false, false); |
d81e351b |
483 | array_push($perbox_count, $count_all); |
23a9084b |
484 | } |
485 | } |
486 | for ($i=0;$i<count($perbox_count);$i++) { |
59a623e6 |
487 | if ($perbox_count[$i]) { |
488 | $count_all = true; |
e13e66be |
489 | break; |
88cb1b4d |
490 | } |
491 | } |
59a623e6 |
492 | if (!$count_all) { |
493 | echo '<br><center>' . _("No Messages Found") . '</center>'; |
56e0b3b7 |
494 | } |
0d672ac0 |
495 | } |
0d672ac0 |
496 | |
23a9084b |
497 | /* search one folder option */ |
56e0b3b7 |
498 | else { |
70c4fd84 |
499 | if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) { |
dcbe1ecc |
500 | echo '<br>' |
501 | . html_tag( 'div', '<b>' . _("Search Results") . '</b>', 'center' ) . "\n"; |
56e0b3b7 |
502 | sqimap_mailbox_select($imapConnection, $mailbox); |
d81e351b |
503 | $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all); |
59a623e6 |
504 | if (count($msgs)) { |
70f1b6b5 |
505 | printSearchMessages($msgs, $mailbox, count($msgs), $imapConnection, |
d215ca7d |
506 | $where, $what, false, false); |
59a623e6 |
507 | } else { |
508 | echo '<br><center>' . _("No Messages Found") . '</center>'; |
509 | } |
56e0b3b7 |
510 | } |
29eb5486 |
511 | } |
56e0b3b7 |
512 | |
23a9084b |
513 | /* must have search terms to search */ |
70c4fd84 |
514 | if ($submit == _("Search") && empty($what)) { |
dcbe1ecc |
515 | echo '<br>' |
516 | . html_tag( 'div', '<b>Please enter something to search for</b>', 'center' ) . "\n"; |
56e0b3b7 |
517 | } |
518 | |
e92eab8b |
519 | $allow_thread_sort = $old_value; |
520 | |
d81e351b |
521 | |
70c4fd84 |
522 | do_hook('search_bottom'); |
56e0b3b7 |
523 | sqimap_logout ($imapConnection); |
29eb5486 |
524 | echo '</body></html>'; |
99d2a184 |
525 | |
91954f9e |
526 | ?> |