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) { |
a3432f47 |
19 | global $msgs, $message_highlight_list, $squirrelmail_language, $languages; |
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; |
130 | echo "<center><b>" . _("Found") . " " . count($messagelist) . " " . _("messages") . "</b></center>\n"; |
131 | echo "<br>\n"; |
132 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>"; |
133 | echo "<TR><TD BGCOLOR=\"$color[0]\">"; |
134 | |
135 | echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&where=".urlencode($search_where)."&what=".urlencode($search_what)."\">"; |
136 | echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0>\n"; |
137 | echo " <TR>\n"; |
98fe1e9f |
138 | echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n"; |
1809bad8 |
139 | echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>"; |
140 | echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">"; |
141 | |
142 | $boxes = sqimap_mailbox_list($imapConnection); |
143 | for ($i = 0; $i < count($boxes); $i++) { |
144 | if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") { |
145 | $box = $boxes[$i]["unformatted"]; |
146 | $box2 = replace_spaces($boxes[$i]["formatted"]); |
147 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
148 | } |
149 | } |
150 | echo " </SELECT></SMALL></TT>"; |
151 | echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n"; |
152 | |
153 | echo " </TD>\n"; |
154 | echo " <TD WIDTH=40% ALIGN=RIGHT>\n"; |
155 | echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n"; |
156 | echo " </TD>"; |
157 | echo " </TR>\n"; |
158 | |
159 | echo "</TABLE>\n\n\n"; |
160 | echo "</TD></TR>"; |
161 | echo "<TR><TD BGCOLOR=\"$color[0]\">"; |
98fe1e9f |
162 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">"; |
1809bad8 |
163 | echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">"; |
164 | echo " <TD WIDTH=1%><B> </B></TD>"; |
165 | /** FROM HEADER **/ |
166 | if ($mailbox == $sent_folder) |
167 | echo " <TD WIDTH=30%><B>". _("To") ."</B></td>"; |
168 | else |
169 | echo " <TD WIDTH=30%><B>". _("From") ."</B></td>"; |
170 | /** DATE HEADER **/ |
171 | echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B></td>"; |
172 | echo " <TD WIDTH=1%> </TD>\n"; |
173 | /** SUBJECT HEADER **/ |
174 | echo " <TD WIDTH=%><B>". _("Subject") ."</B></td>\n"; |
175 | echo "</TR>"; |
176 | |
177 | while ($j < count($msgs)) { |
178 | printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what); |
1809bad8 |
179 | $j++; |
fc05541b |
180 | } |
1809bad8 |
181 | echo "</table>"; |
182 | echo "</tr></td></table>"; |
fc05541b |
183 | } |
1809bad8 |
184 | } |
fc05541b |
185 | |
186 | ?> |