deleted html output
[squirrelmail.git] / functions / imap_search.php
1 <?php
2
3 /**
4 * imap_search.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * IMAP search routines
10 *
11 * $Id$
12 */
13
14 require_once('../functions/imap.php');
15 require_once('../functions/date.php');
16 require_once('../functions/array.php');
17 require_once('../functions/mailbox_display.php');
18 require_once('../functions/mime.php');
19
20 function sqimap_search($imapConnection, $search_where, $search_what, $mailbox,
21 $color, $search_position = '', $search_all, $count_all) {
22
23 global $message_highlight_list, $squirrelmail_language, $languages,
24 $index_order, $pos, $allow_charset_search, $uid_support;
25
26 $pos = $search_position;
27
28 $urlMailbox = urlencode($mailbox);
29
30 /* construct the search query, taking multiple search terms into account */
31 $multi_search = array();
32 $search_what = trim($search_what);
33 $search_what = ereg_replace('[ ]{2,}', ' ', $search_what);
34 $multi_search = explode(' ', $search_what);
35 $search_string = '';
36 foreach ($multi_search as $multi_search_part) {
37 $search_string .= $search_where . ' {' . strlen($multi_search_part)
38 . "}\r\n" . $multi_search_part . ' ';
39 }
40
41 $search_string = trim($search_string);
42
43 /* now use $search_string in the imap search */
44 if ($allow_charset_search && isset($languages[$squirrelmail_language]['CHARSET']) &&
45 $languages[$squirrelmail_language]['CHARSET']) {
46 $ss = "SEARCH CHARSET "
47 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
48 . " ALL $search_string";
49 } else {
50 $ss = "SEARCH ALL $search_string";
51 }
52
53 /* read data back from IMAP */
54 $readin = sqimap_run_command($imapConnection, $ss, false, $result, $message, $uid_support);
55
56 /* try US-ASCII charset if search fails */
57 if (isset($languages[$squirrelmail_language]['CHARSET'])
58 && strtolower($result) == 'no') {
59 $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_string";
60 $readin = sqimap_run_command ($imapConnection, $ss, true,
61 $result, $message);
62 }
63
64 unset($messagelist);
65
66 /* Keep going till we find the SEARCH response */
67 foreach ($readin as $readin_part) {
68 /* Check to see if a SEARCH response was received */
69 if (substr($readin_part, 0, 9) == '* SEARCH ') {
70 $messagelist = preg_split("/ /", substr($readin_part, 9));
71 } else if (isset($errors)) {
72 $errors = $errors.$readin_part;
73 } else {
74 $errors = $readin_part;
75 }
76 }
77
78 /* If nothing is found * SEARCH should be the first error else echo errors */
79 if (isset($errors)) {
80 if (strstr($errors,'* SEARCH')) {
81 return array();
82 }
83 echo "<!-- $errors -->";
84 }
85
86
87 global $sent_folder;
88
89 $cnt = count($messagelist);
90 for ($q = 0; $q < $cnt; $q++) {
91 $id[$q] = trim($messagelist[$q]);
92 }
93 $issent = ($mailbox == $sent_folder);
94
95 $msgs = fillMessageArray($imapConnection,$id,$issent,$cnt);
96
97 return $msgs;
98 }
99
100
101
102 ?>