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 ($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));
43 $errors = $errors.$readin[$c];
47 #If nothing is found * SEARCH should be the first error else echo errors
48 if (strstr($errors,"* SEARCH")) {
49 echo "<br><CENTER>No Messages Found</CENTER>";
52 echo "<!-- ".$errors." -->";
55 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
56 # exsitising code with a search true/false varible.
60 for ($q = 0; $q < count($messagelist); $q++
) {
61 $messagelist[$q] = trim($messagelist[$q]);
62 if ($mailbox == $sent_folder)
63 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], true);
65 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
67 $from[$q] = $hdr->from
;
68 $date[$q] = $hdr->date
;
69 $subject[$q] = $hdr->subject
;
71 $priority[$q] = $hdr->priority
;
73 $size[$q] = $hdr->size
;
74 $type[$q] = $hdr->type0
;
75 $id[$q] = $messagelist[$q];
76 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
80 while ($j < count($messagelist)) {
81 $date[$j] = ereg_replace(" ", " ", $date[$j]);
82 $tmpdate = explode(" ", trim($date[$j]));
84 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
85 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
86 $messages[$j]["ID"] = $id[$j];
87 $messages[$j]["FROM"] = decodeHeader($from[$j]);
88 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
89 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
90 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
91 $messages[$j]["TO"] = decodeHeader($to[$j]);
92 $messages[$j]["PRIORITY"] = $priority[$j];
93 $messages[$j]["CC"] = $cc[$j];
94 $messages[$j]["SIZE"] = $size[$j];
95 $messages[$j]["TYPE0"] = $type[$j];
98 while ($num < count($flags[$j])) {
99 if ($flags[$j][$num] == "Deleted") {
100 $messages[$j]["FLAG_DELETED"] = true;
102 else if ($flags[$j][$num] == "Answered") {
103 $messages[$j]["FLAG_ANSWERED"] = true;
105 else if ($flags[$j][$num] == "Seen") {
106 $messages[$j]["FLAG_SEEN"] = true;
108 else if ($flags[$j][$num] == "Flagged") {
109 $messages[$j]["FLAG_FLAGGED"] = true;
116 /** Find and remove the ones that are deleted */
119 while ($j < count($messagelist)) {
120 if ($messages[$j]["FLAG_DELETED"] == true) {
124 $msgs[$i] = $messages[$j];
131 // There's gotta be messages in the array for it to sort them.
133 if (count($messagelist) > 0) {
135 mail_message_listing_beginning($imapConnection,
136 "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=".urlencode($search_where)."&what=".urlencode($search_what),
137 '', -1, '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
141 while ($j < count($msgs)) {
142 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
146 echo "</tr></td></table>";