b40cb4f7d3bc92e67ef73d6665a5d117c3ae8467
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 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) {
18 $urlMailbox = urlencode($mailbox);
20 # Construct the Search QuERY
22 $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
23 fputs($imapConnection,$ss);
25 # Read Data Back From IMAP
26 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
27 unset($messagelist); $msgs=""; $c = 0;
29 #Keep going till we find the SEARCH responce
30 while ($c < count($readin)) {
32 #Check to see if a SEARCH Responce was recived
33 if (substr($readin[$c],0,9) == "* SEARCH ")
34 $messagelist = explode(" ",substr($readin[$c],9));
36 $errors = $errors.$readin[$c];
40 #If nothing is found * SEARCH should be the first error else echo errors
41 if (strstr($errors,"* SEARCH")) {
42 echo "<br><CENTER>No Messages Found</CENTER>";
45 echo "<!-- ".$errors." -->";
48 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
49 # exsitising code with a search true/false varible.
52 for ($q = 0; $q < count($messagelist); $q++
) {
53 $messagelist[$q] = trim($messagelist[$q]);
54 if ($mailbox == $sent_folder)
55 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
57 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
58 $from[$q] = $hdr->from
;
59 $date[$q] = $hdr->date
;
60 $subject[$q] = $hdr->subject
;
61 $id[$q] = $messagelist[$q];
63 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
67 while ($j < count($messagelist)) {
68 $date[$j] = ereg_replace(" ", " ", $date[$j]);
69 $tmpdate = explode(" ", trim($date[$j]));
71 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
72 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
73 $messages[$j]["ID"] = $id[$j];
74 $messages[$j]["FROM"] = decodeHeader($from[$j]);
75 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
78 while ($num < count($flags[$j])) {
79 if ($flags[$j][$num] == "Deleted") {
80 $messages[$j]["FLAG_DELETED"] = true;
82 else if ($flags[$j][$num] == "Answered") {
83 $messages[$j]["FLAG_ANSWERED"] = true;
85 else if ($flags[$j][$num] == "Seen") {
86 $messages[$j]["FLAG_SEEN"] = true;
88 else if ($flags[$j][$num] == "Flagged") {
89 $messages[$j]["FLAG_FLAGGED"] = true;
96 /** Find and remove the ones that are deleted */
99 while ($j < count($messagelist)) {
100 if ($messages[$j]["FLAG_DELETED"] == true) {
104 $msgs[$i] = $messages[$j];
111 // There's gotta be messages in the array for it to sort them.
113 # Carn't Use the Display messages function it assumes messages are in order.
114 # Again More code Hacked from else where
115 # AT THE MOMENT YOU CARN'T SORT SEARCH RESULTS
116 # ACTULLY THE CODE IS PROLLY BROKEN ANY HOW!
118 if (count($messagelist) > 0) {
120 echo "<center><b>" . _("Found") . " " . count($messagelist) . " " . _("messages") . "</b></center>\n";
122 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
123 echo "<TR><TD BGCOLOR=\"$color[0]\">";
125 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)."\">";
126 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0>\n";
128 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
129 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
130 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
132 $boxes = sqimap_mailbox_list($imapConnection);
133 for ($i = 0; $i < count($boxes); $i++
) {
134 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
135 $box = $boxes[$i]["unformatted"];
136 $box2 = replace_spaces($boxes[$i]["formatted"]);
137 echo " <OPTION VALUE=\"$box\">$box2\n";
140 echo " </SELECT></SMALL></TT>";
141 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
144 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
145 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
149 echo "</TABLE>\n\n\n";
151 echo "<TR><TD BGCOLOR=\"$color[0]\">";
152 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
153 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
154 echo " <TD WIDTH=1%><B> </B></TD>";
156 if ($mailbox == $sent_folder)
157 echo " <TD WIDTH=30%><B>". _("To") ."</B></td>";
159 echo " <TD WIDTH=30%><B>". _("From") ."</B></td>";
161 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B></td>";
162 echo " <TD WIDTH=1%> </TD>\n";
163 /** SUBJECT HEADER **/
164 echo " <TD WIDTH=%><B>". _("Subject") ."</B></td>\n";
167 while ($j < count($msgs)) {
168 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
169 //echo $msgs[$j]["SUBJECT"]."<br>";
173 echo "</tr></td></table>";