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