2 /******************************************************************
5 *****************************************************************/
7 include("../functions/imap.php");
9 include("../functions/date.php");
10 if (!isset($array_php))
11 include("../functions/array.php");
12 if (!isset($mailbox_display_php))
13 include("../functions/mailbox_display.php");
14 if (!isset($mime_php))
15 include("../functions/mime.php");
17 $imap_search_php = true;
19 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color) {
20 global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
21 $urlMailbox = urlencode($mailbox);
23 # Construct the Search QuERY
25 if (isset($languages[$squirrelmail_language]["CHARSET"]) && $languages[$squirrelmail_language]["CHARSET"]) {
26 $ss = "a001 SEARCH CHARSET ".$languages[$squirrelmail_language]["CHARSET"]." ALL $search_where \"$search_what\"\r\n";
28 $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
30 fputs($imapConnection,$ss);
32 # Read Data Back From IMAP
33 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
34 unset($messagelist); $msgs=""; $c = 0;
36 #Keep going till we find the SEARCH responce
37 while ($c < count($readin)) {
39 #Check to see if a SEARCH Responce was recived
40 if (substr($readin[$c],0,9) == "* SEARCH ")
41 $messagelist = explode(" ",substr($readin[$c],9));
42 else if (isset($errors))
43 $errors = $errors.$readin[$c];
45 $errors = $readin[$c];
49 #If nothing is found * SEARCH should be the first error else echo errors
50 if (isset($errors) && strstr($errors,"* SEARCH")) {
51 echo "<br><CENTER>No Messages Found</CENTER>";
53 } else if (isset($errors)) {
54 echo "<!-- ".$errors." -->";
57 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
58 # exsitising code with a search true/false varible.
62 for ($q = 0; $q < count($messagelist); $q++
) {
63 $messagelist[$q] = trim($messagelist[$q]);
64 if ($mailbox == $sent_folder)
65 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
67 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
69 $from[$q] = $hdr->from
;
70 $date[$q] = $hdr->date
;
71 $subject[$q] = $hdr->subject
;
73 $priority[$q] = $hdr->priority
;
75 $size[$q] = $hdr->size
;
76 $type[$q] = $hdr->type0
;
77 $id[$q] = $messagelist[$q];
78 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
82 while ($j < count($messagelist)) {
83 $date[$j] = ereg_replace(" ", " ", $date[$j]);
84 $tmpdate = explode(" ", trim($date[$j]));
86 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
87 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
88 $messages[$j]["ID"] = $id[$j];
89 $messages[$j]["FROM"] = decodeHeader($from[$j]);
90 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
91 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
92 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
93 $messages[$j]["TO"] = decodeHeader($to[$j]);
94 $messages[$j]["PRIORITY"] = $priority[$j];
95 $messages[$j]["CC"] = $cc[$j];
96 $messages[$j]["SIZE"] = $size[$j];
97 $messages[$j]["TYPE0"] = $type[$j];
100 while ($num < count($flags[$j])) {
101 if ($flags[$j][$num] == "Deleted") {
102 $messages[$j]["FLAG_DELETED"] = true;
104 else if ($flags[$j][$num] == "Answered") {
105 $messages[$j]["FLAG_ANSWERED"] = true;
107 else if ($flags[$j][$num] == "Seen") {
108 $messages[$j]["FLAG_SEEN"] = true;
110 else if ($flags[$j][$num] == "Flagged") {
111 $messages[$j]["FLAG_FLAGGED"] = true;
118 /** Find and remove the ones that are deleted */
121 while ($j < count($messagelist)) {
122 if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) {
126 $msgs[$i] = $messages[$j];
133 // There's gotta be messages in the array for it to sort them.
135 if (count($messagelist) > 0) {
137 if (!isset ($msg)) { $msg = ""; }
138 mail_message_listing_beginning($imapConnection,
139 "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=".urlencode($search_where)."&what=".urlencode($search_what),
140 '', -1, '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
144 while ($j < count($msgs)) {
145 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
149 echo "</tr></td></table>";