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);
19 # Construct the Search QuERY
20 $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
21 fputs($imapConnection,$ss);
23 #Read Data Back From IMAP
24 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
25 unset($messagelist); $msgs=""; $c = 0;
26 #Keep going till we find the SEARCH responce
27 while ($c < count($readin)) {
28 #Check to see if a SEARCH Responce was recived
29 if (substr($readin[$c],0,9) == "* SEARCH ")
30 $messagelist = explode(" ",substr($readin[$c],9));
32 $errors = $errors.$readin[$c];
35 #If nothing is found * SEARCH should be the first error else echo errors
36 if (strstr($errors,"* SEARCH")) {
37 echo "<br><CENTER>No Messages Found</CENTER>";
40 echo "<!-- ".$errors." -->";
43 #HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify exsitising code with a search true/false varible.
47 for ($q = 0; $q < count($messagelist); $q++
) {
48 $messagelist[$q] = trim($messagelist[$q]);
49 if ($mailbox == $sent_folder)
50 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
52 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
53 $from[$q] = $hdr->from
;
54 $date[$q] = $hdr->date
;
55 $subject[$q] = $hdr->subject
;
56 $id[$q] = $messagelist[$q];
58 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
62 while ($j < count($messagelist)) {
63 $date[$j] = ereg_replace(" ", " ", $date[$j]);
64 $tmpdate = explode(" ", trim($date[$j]));
66 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
67 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
68 $messages[$j]["ID"] = $id[$j];
69 $messages[$j]["FROM"] = decodeHeader($from[$j]);
70 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
73 while ($num < count($flags[$j])) {
74 if ($flags[$j][$num] == "Deleted") {
75 $messages[$j]["FLAG_DELETED"] = true;
77 else if ($flags[$j][$num] == "Answered") {
78 $messages[$j]["FLAG_ANSWERED"] = true;
80 else if ($flags[$j][$num] == "Seen") {
81 $messages[$j]["FLAG_SEEN"] = true;
83 else if ($flags[$j][$num] == "Flagged") {
84 $messages[$j]["FLAG_FLAGGED"] = true;
91 /** Find and remove the ones that are deleted */
94 while ($j < count($messagelist)) {
95 if ($messages[$j]["FLAG_DELETED"] == true) {
99 $msgs[$i] = $messages[$j];
106 // There's gotta be messages in the array for it to sort them.
108 # Carn't Use the Display messages function it assumes messages are in order.
109 # Again More code Hacked from else where
111 # AT THE MOMENT YOU CARN'T SORT SEARCH RESULTS
113 # ACTULLY THE CODE IS PROLLY BROKEN ANY HOW!
115 if (count($messagelist) > 0) {
117 echo "<CENTER>"._("Found")." ".count($messagelist)." "._("Messages")."</CENTER>\n";
119 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
120 echo "<TR><TD BGCOLOR=\"$color[0]\">";
122 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=0\">";
123 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0>\n";
125 echo " <TD WIDTH=60% ALIGN=LEFT>\n";
126 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
127 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
129 $boxes = sqimap_mailbox_list($imapConnection);
130 for ($i = 0; $i < count($boxes); $i++
) {
131 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
132 $box = $boxes[$i]["unformatted"];
133 $box2 = replace_spaces($boxes[$i]["formatted"]);
134 echo " <OPTION VALUE=\"$box\">$box2\n";
137 echo " </SELECT></SMALL></TT>";
138 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
141 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
142 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
146 echo "</TABLE>\n\n\n";
148 echo "<TR><TD BGCOLOR=\"$color[0]\">";
149 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[4]\">";
150 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
151 echo " <TD WIDTH=1%><B> </B></TD>";
153 if ($mailbox == $sent_folder)
154 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
156 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
158 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
159 echo " <TD WIDTH=1%> </TD>\n";
160 /** SUBJECT HEADER **/
161 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
164 while ($j < count($msgs)) {
165 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0);
166 //echo $msgs[$j]["SUBJECT"]."<br>";