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