993a23aa2d420d56b1a1e40569e5455cc29a145e
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", false, $result, $message);
34 if (isset($languages[$squirrelmail_language]["CHARSET"]) && strtolower($result) == "no") {
35 $ss = "a001 SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
36 fputs ($imapConnection, $ss);
37 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
39 unset($messagelist); $msgs=""; $c = 0;
41 #Keep going till we find the SEARCH responce
42 while ($c < count($readin)) {
44 #Check to see if a SEARCH Responce was recived
45 if (substr($readin[$c],0,9) == "* SEARCH ")
46 $messagelist = explode(" ",substr($readin[$c],9));
47 else if (isset($errors))
48 $errors = $errors.$readin[$c];
50 $errors = $readin[$c];
54 #If nothing is found * SEARCH should be the first error else echo errors
55 if (isset($errors) && strstr($errors,"* SEARCH")) {
56 echo "<br><CENTER>No Messages Found</CENTER>";
58 } else if (isset($errors)) {
59 echo "<!-- ".$errors." -->";
62 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
63 # exsitising code with a search true/false varible.
67 for ($q = 0; $q < count($messagelist); $q++
) {
68 $messagelist[$q] = trim($messagelist[$q]);
69 if ($mailbox == $sent_folder)
70 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
72 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
74 $from[$q] = $hdr->from
;
75 $date[$q] = $hdr->date
;
76 $subject[$q] = $hdr->subject
;
78 $priority[$q] = $hdr->priority
;
80 $size[$q] = $hdr->size
;
81 $type[$q] = $hdr->type0
;
82 $id[$q] = $messagelist[$q];
83 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
87 while ($j < count($messagelist)) {
88 $date[$j] = ereg_replace(" ", " ", $date[$j]);
89 $tmpdate = explode(" ", trim($date[$j]));
91 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
92 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
93 $messages[$j]["ID"] = $id[$j];
94 $messages[$j]["FROM"] = decodeHeader($from[$j]);
95 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
96 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
97 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
98 $messages[$j]["TO"] = decodeHeader($to[$j]);
99 $messages[$j]["PRIORITY"] = $priority[$j];
100 $messages[$j]["CC"] = $cc[$j];
101 $messages[$j]["SIZE"] = $size[$j];
102 $messages[$j]["TYPE0"] = $type[$j];
105 while ($num < count($flags[$j])) {
106 if ($flags[$j][$num] == "Deleted") {
107 $messages[$j]["FLAG_DELETED"] = true;
109 else if ($flags[$j][$num] == "Answered") {
110 $messages[$j]["FLAG_ANSWERED"] = true;
112 else if ($flags[$j][$num] == "Seen") {
113 $messages[$j]["FLAG_SEEN"] = true;
115 else if ($flags[$j][$num] == "Flagged") {
116 $messages[$j]["FLAG_FLAGGED"] = true;
123 /** Find and remove the ones that are deleted */
126 while ($j < count($messagelist)) {
127 if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) {
131 $msgs[$i] = $messages[$j];
138 // There's gotta be messages in the array for it to sort them.
140 if (count($messagelist) > 0) {
142 if (!isset ($msg)) { $msg = ""; }
143 mail_message_listing_beginning($imapConnection,
144 "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=".urlencode($search_where)."&what=".urlencode($search_what),
145 '', -1, '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
149 while ($j < count($msgs)) {
150 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
154 echo "</tr></td></table>";