a82242fd207233a9b9406943cdb72984cd330dbb
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;
20 $urlMailbox = urlencode($mailbox);
22 # Construct the Search QuERY
24 $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
25 fputs($imapConnection,$ss);
27 # Read Data Back From IMAP
28 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
29 unset($messagelist); $msgs=""; $c = 0;
31 #Keep going till we find the SEARCH responce
32 while ($c < count($readin)) {
34 #Check to see if a SEARCH Responce was recived
35 if (substr($readin[$c],0,9) == "* SEARCH ")
36 $messagelist = explode(" ",substr($readin[$c],9));
38 $errors = $errors.$readin[$c];
42 #If nothing is found * SEARCH should be the first error else echo errors
43 if (strstr($errors,"* SEARCH")) {
44 echo "<br><CENTER>No Messages Found</CENTER>";
47 echo "<!-- ".$errors." -->";
50 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
51 # exsitising code with a search true/false varible.
54 for ($q = 0; $q < count($messagelist); $q++
) {
55 $messagelist[$q] = trim($messagelist[$q]);
56 if ($mailbox == $sent_folder)
57 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
59 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
61 $from[$q] = $hdr->from
;
62 $date[$q] = $hdr->date
;
63 $subject[$q] = $hdr->subject
;
65 $priority[$q] = $hdr->priority
;
67 $id[$q] = $messagelist[$q];
69 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
73 while ($j < count($messagelist)) {
74 $date[$j] = ereg_replace(" ", " ", $date[$j]);
75 $tmpdate = explode(" ", trim($date[$j]));
77 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
78 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
79 $messages[$j]["ID"] = $id[$j];
80 $messages[$j]["FROM"] = decodeHeader($from[$j]);
81 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
82 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
83 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
84 $messages[$j]["TO"] = decodeHeader($to[$j]);
85 $messages[$j]["PRIORITY"] = $priority[$j];
86 $messages[$j]["CC"] = $cc[$j];
89 while ($num < count($flags[$j])) {
90 if ($flags[$j][$num] == "Deleted") {
91 $messages[$j]["FLAG_DELETED"] = true;
93 else if ($flags[$j][$num] == "Answered") {
94 $messages[$j]["FLAG_ANSWERED"] = true;
96 else if ($flags[$j][$num] == "Seen") {
97 $messages[$j]["FLAG_SEEN"] = true;
99 else if ($flags[$j][$num] == "Flagged") {
100 $messages[$j]["FLAG_FLAGGED"] = true;
107 /** Find and remove the ones that are deleted */
110 while ($j < count($messagelist)) {
111 if ($messages[$j]["FLAG_DELETED"] == true) {
115 $msgs[$i] = $messages[$j];
122 // There's gotta be messages in the array for it to sort them.
124 # Carn't Use the Display messages function it assumes messages are in order.
125 # Again More code Hacked from else where
126 # AT THE MOMENT YOU CARN'T SORT SEARCH RESULTS
127 # ACTULLY THE CODE IS PROLLY BROKEN ANY HOW!
129 if (count($messagelist) > 0) {
131 echo "<center><b>" . _("Found") . " " . count($messagelist) . " " . _("messages") . "</b></center>\n";
133 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
134 echo "<TR><TD BGCOLOR=\"$color[0]\">";
136 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)."\">";
137 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0>\n";
139 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
140 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
141 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
143 $boxes = sqimap_mailbox_list($imapConnection);
144 for ($i = 0; $i < count($boxes); $i++
) {
145 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
146 $box = $boxes[$i]["unformatted"];
147 $box2 = replace_spaces($boxes[$i]["formatted"]);
148 echo " <OPTION VALUE=\"$box\">$box2\n";
151 echo " </SELECT></SMALL></TT>";
152 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
155 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
156 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
160 echo "</TABLE>\n\n\n";
162 echo "<TR><TD BGCOLOR=\"$color[0]\">";
163 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
164 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
165 echo " <TD WIDTH=1%><B> </B></TD>";
167 if ($mailbox == $sent_folder)
168 echo " <TD WIDTH=30%><B>". _("To") ."</B></td>";
170 echo " <TD WIDTH=30%><B>". _("From") ."</B></td>";
172 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B></td>";
173 echo " <TD WIDTH=1%> </TD>\n";
174 /** SUBJECT HEADER **/
175 echo " <TD WIDTH=%><B>". _("Subject") ."</B></td>\n";
178 while ($j < count($msgs)) {
179 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
183 echo "</tr></td></table>";