Correct changes of "" to ''.
[squirrelmail.git] / functions / imap_search.php
1 <?php
2 /******************************************************************
3 ** IMAP SEARCH ROUTIES
4 ** $Id$
5 *****************************************************************/
6 if (!isset($imap_php))
7 include("../functions/imap.php");
8 if (!isset($date_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");
16
17 $imap_search_php = true;
18
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);
22
23 # Construct the Search QuERY
24
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";
27 } else {
28 $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
29 }
30 fputs($imapConnection,$ss);
31
32 # Read Data Back From IMAP
33 $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
34 unset($messagelist); $msgs=""; $c = 0;
35
36 #Keep going till we find the SEARCH responce
37 while ($c < count($readin)) {
38
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];
44 else
45 $errors = $readin[$c];
46 $c++;
47 }
48
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>";
52 return;
53 } else if (isset($errors)) {
54 echo "<!-- ".$errors." -->";
55 }
56
57 # HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
58 # exsitising code with a search true/false varible.
59
60
61 global $sent_folder;
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);
66 else
67 $hdr = sqimap_get_small_header ($imapConnection, $messagelist[$q], false);
68
69 $from[$q] = $hdr->from;
70 $date[$q] = $hdr->date;
71 $subject[$q] = $hdr->subject;
72 $to[$q] = $hdr->to;
73 $priority[$q] = $hdr->priority;
74 $cc[$q] = $hdr->cc;
75 $size[$q] = $hdr->size;
76 $type[$q] = $hdr->type0;
77 $id[$q] = $messagelist[$q];
78 $flags[$q] = sqimap_get_flags ($imapConnection, $messagelist[$q]);
79 }
80
81 $j = 0;
82 while ($j < count($messagelist)) {
83 $date[$j] = ereg_replace(" ", " ", $date[$j]);
84 $tmpdate = explode(" ", trim($date[$j]));
85
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];
98
99 $num = 0;
100 while ($num < count($flags[$j])) {
101 if ($flags[$j][$num] == "Deleted") {
102 $messages[$j]["FLAG_DELETED"] = true;
103 }
104 else if ($flags[$j][$num] == "Answered") {
105 $messages[$j]["FLAG_ANSWERED"] = true;
106 }
107 else if ($flags[$j][$num] == "Seen") {
108 $messages[$j]["FLAG_SEEN"] = true;
109 }
110 else if ($flags[$j][$num] == "Flagged") {
111 $messages[$j]["FLAG_FLAGGED"] = true;
112 }
113 $num++;
114 }
115 $j++;
116 }
117
118 /** Find and remove the ones that are deleted */
119 $i = 0;
120 $j = 0;
121 while ($j < count($messagelist)) {
122 if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) {
123 $j++;
124 continue;
125 }
126 $msgs[$i] = $messages[$j];
127
128 $i++;
129 $j++;
130 }
131 $numMessages = $i;
132
133 // There's gotta be messages in the array for it to sort them.
134
135 if (count($messagelist) > 0) {
136 $j=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>',
141 '&nbsp;');
142
143
144 while ($j < count($msgs)) {
145 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, "", 0, $search_where, $search_what);
146 $j++;
147 }
148 echo "</table>";
149 echo "</tr></td></table>";
150 }
151 }
152
153 ?>