086fa085621b9e5069a98a665590d1de344ab3c4
2 /******************************************************************
4 *****************************************************************/
6 include("../functions/imap.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");
16 $imap_search_php = true;
18 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) {
19 global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
20 $urlMailbox = urlencode($mailbox);
22 # Construct the Search QuERY
24 if ($languages[$squirrelmail_language]["CHARSET"]) {
25 $ss = "a001 SEARCH CHARSET ".$languages[$squirrelmail_language]["CHARSET"]." ALL $search_where \"$search_what\"\r\n";
27 $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
29 fputs($imapConnection,$ss);
31 # Read Data Back From IMAP
32 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
33 unset($messagelist); $msgs=""; $c = 0;
35 #Keep going till we find the SEARCH responce
36 while ($c < count($readin)) {
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));
42 $errors = $errors.$readin[$c];
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>";
51 echo "<!-- ".$errors." -->";
54 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
55 # exsitising code with a search true/false varible.
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);
63 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
65 $from[$q] = $hdr->from
;
66 $date[$q] = $hdr->date
;
67 $subject[$q] = $hdr->subject
;
69 $priority[$q] = $hdr->priority
;
71 $id[$q] = $messagelist[$q];
73 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
77 while ($j < count($messagelist)) {
78 $date[$j] = ereg_replace(" ", " ", $date[$j]);
79 $tmpdate = explode(" ", trim($date[$j]));
81 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
82 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
83 $messages[$j]["ID"] = $id[$j];
84 $messages[$j]["FROM"] = decodeHeader($from[$j]);
85 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
86 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
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];
93 while ($num < count($flags[$j])) {
94 if ($flags[$j][$num] == "Deleted") {
95 $messages[$j]["FLAG_DELETED"] = true;
97 else if ($flags[$j][$num] == "Answered") {
98 $messages[$j]["FLAG_ANSWERED"] = true;
100 else if ($flags[$j][$num] == "Seen") {
101 $messages[$j]["FLAG_SEEN"] = true;
103 else if ($flags[$j][$num] == "Flagged") {
104 $messages[$j]["FLAG_FLAGGED"] = true;
111 /** Find and remove the ones that are deleted */
114 while ($j < count($messagelist)) {
115 if ($messages[$j]["FLAG_DELETED"] == true) {
119 $msgs[$i] = $messages[$j];
126 // There's gotta be messages in the array for it to sort them.
128 if (count($messagelist) > 0) {
130 echo "<center><b>" . _("Found") . " " . count($messagelist) . " " . _("messages") . "</b></center>\n";
132 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
133 echo "<TR><TD BGCOLOR=\"$color[0]\">";
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 width=\"100%\">\n";
138 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
139 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
140 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
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";
150 echo " </SELECT></SMALL></TT>";
151 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
154 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
155 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
159 do_hook("mailbox_form_before");
161 echo "<TR><TD BGCOLOR=\"$color[0]\">";
162 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
163 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
165 for ($i=1; $i <= count($index_order); $i++
) {
166 switch ($index_order[$i]) {
168 echo " <TD WIDTH=1%><B> </B></TD>";
171 if ($mailbox == $sent_folder)
172 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
174 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
177 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
179 echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
181 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
184 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
186 echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
188 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
190 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
193 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
195 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
197 echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
199 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
202 echo " <TD WIDTH=1%> </TD>\n";
205 echo " <TD WIDTH=1%><b>" . _("Size")."</b></TD>\n";
211 while ($j < count($msgs)) {
212 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
216 echo "</tr></td></table>";