37205c861efc4491b96a974bcea63522e14f73f4
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
14 require_once('../functions/imap.php');
15 require_once('../functions/date.php');
16 require_once('../functions/array.php');
17 require_once('../functions/mailbox_display.php');
18 require_once('../functions/mime.php');
20 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color, $search_position = '', $search_all, $count_all) {
22 global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
25 $pos = $search_position;
27 $urlMailbox = urlencode($mailbox);
30 Construct the Search QuERY
32 account for multiple search terms
35 $multi_search = array ();
36 $search_what = ereg_replace("[ ]{2,}", ' ', $search_what);
37 $multi_search = split (' ', $search_what);
38 if (count($multi_search)==1) {
39 $search_string = $search_where . ' ' . '"' . $multi_search[0] . '"';
43 $count = count($multi_search);
44 for ($x=0;$x<$count;$x++
) {
45 $search_string = $search_string . ' ' . $search_where . ' "' . $multi_search[$x] . '" ';
48 $search_string = trim($search_string);
50 /* now use $search_string in the imap search */
52 if (isset($languages[$squirrelmail_language]['CHARSET']) &&
53 $languages[$squirrelmail_language]['CHARSET']) {
54 $ss = "SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_string";
56 $ss .= "SEARCH ALL $search_string\"";
59 /* Read Data Back From IMAP */
60 $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
61 if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') {
62 // $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"";
63 $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_string";
64 $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
71 /* Keep going till we find the SEARCH responce */
72 while ($c < count( $readin )) {
74 /* Check to see if a SEARCH Responce was recived */
75 if (substr($readin[$c],0,9) == "* SEARCH ")
76 $messagelist = explode(" ",substr($readin[$c],9));
77 else if (isset($errors))
78 $errors = $errors.$readin[$c];
80 $errors = $readin[$c];
84 /* If nothing is found * SEARCH should be the first error else echo errors */
85 if (isset($errors) && strstr($errors,"* SEARCH")) {
86 if ($search_all != "all") {
87 echo '<br><CENTER>' . _("No Messages Found") . '</CENTER>';
94 else if (isset($errors)) {
95 echo "<!-- ".$errors." -->";
99 HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
100 exsitising code with a search true/false varible.
104 for ($q = 0; $q < count($messagelist); $q++
) {
105 $id[$q] = trim($messagelist[$q]);
107 $issent = ($mailbox == $sent_folder);
108 $hdr_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
109 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
110 foreach ($hdr_list as $hdr) {
111 $from[] = $hdr->from
;
112 $date[] = $hdr->date
;
113 $subject[] = $hdr->subject
;
115 $priority[] = $hdr->priority
;
117 $size[] = $hdr->size
;
118 $type[] = $hdr->type0
;
122 while ($j < count($messagelist)) {
123 $date[$j] = str_replace(' ', ' ', $date[$j]);
124 $tmpdate = explode(" ", trim($date[$j]));
126 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
127 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
128 $messages[$j]["ID"] = $id[$j];
129 $messages[$j]["FROM"] = decodeHeader($from[$j]);
130 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
131 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
132 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
133 $messages[$j]["TO"] = decodeHeader($to[$j]);
134 $messages[$j]["PRIORITY"] = $priority[$j];
135 $messages[$j]["CC"] = $cc[$j];
136 $messages[$j]["SIZE"] = $size[$j];
137 $messages[$j]["TYPE0"] = $type[$j];
140 while ($num < count($flags[$j])) {
141 if ($flags[$j][$num] == 'Deleted') {
142 $messages[$j]['FLAG_DELETED'] = true;
143 } else if ($flags[$j][$num] == 'Answered') {
144 $messages[$j]['FLAG_ANSWERED'] = true;
145 } else if ($flags[$j][$num] == 'Seen') {
146 $messages[$j]['FLAG_SEEN'] = true;
147 } else if ($flags[$j][$num] == 'Flagged') {
148 $messages[$j]['FLAG_FLAGGED'] = true;
155 /* Find and remove the ones that are deleted */
158 while ($j < count($messagelist)) {
159 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED']) {
163 $msgs[$i] = $messages[$j];
170 /* There's gotta be messages in the array for it to sort them. */
172 if (count($messagelist) > 0) {
177 if ($search_all != 'all') {
178 if ( !isset( $start_msg ) ) {
181 if ( !isset( $sort ) ) {
184 mail_message_listing_beginning( $imapConnection,
185 "move_messages.php?msg=$msg&mailbox=$urlMailbox&pos=$pos&where=" . urlencode($search_where) . "&what=".urlencode($search_what),
188 '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b></tr><tr>'.
189 get_selectall_link($start_msg, $sort));
192 mail_message_listing_beginning( $imapConnection,
193 "move_messages.php?msg=$msg&mailbox=$urlMailbox&pos=$pos&where=" . urlencode($search_where) . "&what=".urlencode($search_what),
196 '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b></tr><tr>');
198 echo '<b><big>' . _("Folder:") . " $mailbox</big></b>";
199 while ($j < count($msgs)) {
200 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what);
204 echo '</table></td></tr></table></form>';
205 $count_all = count($msgs);