6e189ce2 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
15e6162e |
4 | * imap_search.php |
35586184 |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
35586184 |
8 | * |
15e6162e |
9 | * IMAP search routines |
35586184 |
10 | * |
15e6162e |
11 | * $Id$ |
35586184 |
12 | */ |
13 | |
35586184 |
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'); |
2ba13803 |
19 | |
53828ec5 |
20 | function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color, $search_position = '') { |
2ba13803 |
21 | |
29eb5486 |
22 | global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order; |
53828ec5 |
23 | global $pos; |
24 | |
25 | $pos = $search_position; |
2ba13803 |
26 | |
29eb5486 |
27 | $urlMailbox = urlencode($mailbox); |
2ba13803 |
28 | |
29eb5486 |
29 | /* Construct the Search QuERY */ |
29eb5486 |
30 | if (isset($languages[$squirrelmail_language]['CHARSET']) && |
31 | $languages[$squirrelmail_language]['CHARSET']) { |
1c72b151 |
32 | $ss = "SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\""; |
29eb5486 |
33 | } else { |
1c72b151 |
34 | $ss .= "SEARCH ALL $search_where \"$search_what\""; |
29eb5486 |
35 | } |
29eb5486 |
36 | |
37 | /* Read Data Back From IMAP */ |
1c72b151 |
38 | $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message); |
29eb5486 |
39 | if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') { |
1c72b151 |
40 | $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\""; |
41 | $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message); |
29eb5486 |
42 | } |
2ba13803 |
43 | |
29eb5486 |
44 | unset($messagelist); $msgs=""; $c = 0; |
2ba13803 |
45 | |
29eb5486 |
46 | /* Keep going till we find the SEARCH responce */ |
47 | while ($c < count( $readin )) { |
2ba13803 |
48 | |
29eb5486 |
49 | /* Check to see if a SEARCH Responce was recived */ |
50 | if (substr($readin[$c],0,9) == "* SEARCH ") |
51 | $messagelist = explode(" ",substr($readin[$c],9)); |
52 | else if (isset($errors)) |
53 | $errors = $errors.$readin[$c]; |
54 | else |
55 | $errors = $readin[$c]; |
56 | $c++; |
57 | } |
2ba13803 |
58 | |
29eb5486 |
59 | /* If nothing is found * SEARCH should be the first error else echo errors */ |
60 | if (isset($errors) && strstr($errors,"* SEARCH")) { |
61 | echo '<br><CENTER>' . _("No Messages Found") . '</CENTER>'; |
62 | return; |
63 | } else if (isset($errors)) { |
64 | echo "<!-- ".$errors." -->"; |
65 | } |
2ba13803 |
66 | |
29eb5486 |
67 | /* |
68 | HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify |
69 | exsitising code with a search true/false varible. |
70 | */ |
2ba13803 |
71 | |
29eb5486 |
72 | global $sent_folder; |
73 | for ($q = 0; $q < count($messagelist); $q++) { |
74 | $id[$q] = trim($messagelist[$q]); |
75 | } |
76 | $issent = ($mailbox == $sent_folder); |
77 | $hdr_list = sqimap_get_small_header_list($imapConnection, $id, $issent); |
78 | $flags = sqimap_get_flags_list($imapConnection, $id, $issent); |
79 | foreach ($hdr_list as $hdr) { |
80 | $from[] = $hdr->from; |
81 | $date[] = $hdr->date; |
82 | $subject[] = $hdr->subject; |
83 | $to[] = $hdr->to; |
84 | $priority[] = $hdr->priority; |
85 | $cc[] = $hdr->cc; |
86 | $size[] = $hdr->size; |
87 | $type[] = $hdr->type0; |
88 | } |
2ba13803 |
89 | |
29eb5486 |
90 | $j = 0; |
91 | while ($j < count($messagelist)) { |
92 | $date[$j] = ereg_replace(' ', ' ', $date[$j]); |
93 | $tmpdate = explode(" ", trim($date[$j])); |
94 | |
95 | $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); |
96 | $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); |
97 | $messages[$j]["ID"] = $id[$j]; |
98 | $messages[$j]["FROM"] = decodeHeader($from[$j]); |
99 | $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j]))); |
100 | $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); |
101 | $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j])); |
102 | $messages[$j]["TO"] = decodeHeader($to[$j]); |
103 | $messages[$j]["PRIORITY"] = $priority[$j]; |
104 | $messages[$j]["CC"] = $cc[$j]; |
105 | $messages[$j]["SIZE"] = $size[$j]; |
106 | $messages[$j]["TYPE0"] = $type[$j]; |
107 | |
108 | $num = 0; |
109 | while ($num < count($flags[$j])) { |
110 | if ($flags[$j][$num] == 'Deleted') { |
111 | $messages[$j]['FLAG_DELETED'] = true; |
112 | } else if ($flags[$j][$num] == 'Answered') { |
113 | $messages[$j]['FLAG_ANSWERED'] = true; |
114 | } else if ($flags[$j][$num] == 'Seen') { |
115 | $messages[$j]['FLAG_SEEN'] = true; |
116 | } else if ($flags[$j][$num] == 'Flagged') { |
117 | $messages[$j]['FLAG_FLAGGED'] = true; |
2ba13803 |
118 | } |
29eb5486 |
119 | $num++; |
fc05541b |
120 | } |
29eb5486 |
121 | $j++; |
122 | } |
2ba13803 |
123 | |
29eb5486 |
124 | /* Find and remove the ones that are deleted */ |
125 | $i = 0; |
126 | $j = 0; |
127 | while ($j < count($messagelist)) { |
128 | if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) { |
1809bad8 |
129 | $j++; |
29eb5486 |
130 | continue; |
2ba13803 |
131 | } |
29eb5486 |
132 | $msgs[$i] = $messages[$j]; |
2ba13803 |
133 | |
29eb5486 |
134 | $i++; |
135 | $j++; |
136 | } |
137 | $numMessages = $i; |
2ba13803 |
138 | |
29eb5486 |
139 | /* There's gotta be messages in the array for it to sort them. */ |
2ba13803 |
140 | |
29eb5486 |
141 | if (count($messagelist) > 0) { |
142 | $j=0; |
53828ec5 |
143 | if (!isset ($msg)) { |
144 | $msg = ''; |
145 | } |
7c0060c9 |
146 | |
29eb5486 |
147 | mail_message_listing_beginning( $imapConnection, |
53828ec5 |
148 | "move_messages.php?msg=$msg&mailbox=$urlMailbox&pos=$pos&where=" . urlencode($search_where) . "&what=".urlencode($search_what), |
7c0060c9 |
149 | $mailbox, |
150 | -1, |
29eb5486 |
151 | '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>', |
152 | get_selectall_link($start_msg, $sort) ); |
2ba13803 |
153 | |
29eb5486 |
154 | |
155 | while ($j < count($msgs)) { |
156 | printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what); |
157 | $j++; |
2ba13803 |
158 | } |
7c0060c9 |
159 | echo '</table></td></tr></table></form>'; |
160 | |
2ba13803 |
161 | } |
29eb5486 |
162 | } |
fc05541b |
163 | |
1c72b151 |
164 | ?> |