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