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.
59 for ($q = 0; $q < count($messagelist); $q++
) {
60 $messagelist[$q] = trim($messagelist[$q]);
61 if ($mailbox == $sent_folder)
62 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
64 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
66 $from[$q] = $hdr->from
;
67 $date[$q] = $hdr->date
;
68 $subject[$q] = $hdr->subject
;
70 $priority[$q] = $hdr->priority
;
72 $size[$q] = $hdr->size
;
73 $type[$q] = $hdr->type0
;
74 $id[$q] = $messagelist[$q];
75 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
79 while ($j < count($messagelist)) {
80 $date[$j] = ereg_replace(" ", " ", $date[$j]);
81 $tmpdate = explode(" ", trim($date[$j]));
83 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
84 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
85 $messages[$j]["ID"] = $id[$j];
86 $messages[$j]["FROM"] = decodeHeader($from[$j]);
87 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
88 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
89 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
90 $messages[$j]["TO"] = decodeHeader($to[$j]);
91 $messages[$j]["PRIORITY"] = $priority[$j];
92 $messages[$j]["CC"] = $cc[$j];
93 $messages[$j]["SIZE"] = $size[$j];
94 $messages[$j]["TYPE0"] = $type[$j];
97 while ($num < count($flags[$j])) {
98 if ($flags[$j][$num] == "Deleted") {
99 $messages[$j]["FLAG_DELETED"] = true;
101 else if ($flags[$j][$num] == "Answered") {
102 $messages[$j]["FLAG_ANSWERED"] = true;
104 else if ($flags[$j][$num] == "Seen") {
105 $messages[$j]["FLAG_SEEN"] = true;
107 else if ($flags[$j][$num] == "Flagged") {
108 $messages[$j]["FLAG_FLAGGED"] = true;
115 /** Find and remove the ones that are deleted */
118 while ($j < count($messagelist)) {
119 if ($messages[$j]["FLAG_DELETED"] == true) {
123 $msgs[$i] = $messages[$j];
130 // There's gotta be messages in the array for it to sort them.
132 if (count($messagelist) > 0) {
134 mail_message_listing_beginning($imapConnection,
135 "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=".urlencode($search_where)."&what=".urlencode($search_what),
136 '', -1, '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
140 while ($j < count($msgs)) {
141 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
145 echo "</tr></td></table>";