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) {
22 global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
24 $urlMailbox = urlencode($mailbox);
25 $isid = sqimap_session_id();
27 /* Construct the Search QuERY */
29 if (isset($languages[$squirrelmail_language]['CHARSET']) &&
30 $languages[$squirrelmail_language]['CHARSET']) {
31 $ss .= " SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\"\r\n";
33 $ss .= " SEARCH ALL $search_where \"$search_what\"\r\n";
35 fputs($imapConnection,$ss);
37 /* Read Data Back From IMAP */
38 $readin = sqimap_read_data ($imapConnection, $isid, false, $result, $message);
39 if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') {
40 $ss = $isid . " SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
41 fputs ($imapConnection, $ss);
42 $readin = sqimap_read_data ($imapConnection, $isid, true, $result, $message);
45 unset($messagelist); $msgs=""; $c = 0;
47 /* Keep going till we find the SEARCH responce */
48 while ($c < count( $readin )) {
50 /* Check to see if a SEARCH Responce was recived */
51 if (substr($readin[$c],0,9) == "* SEARCH ")
52 $messagelist = explode(" ",substr($readin[$c],9));
53 else if (isset($errors))
54 $errors = $errors.$readin[$c];
56 $errors = $readin[$c];
60 /* If nothing is found * SEARCH should be the first error else echo errors */
61 if (isset($errors) && strstr($errors,"* SEARCH")) {
62 echo '<br><CENTER>' . _("No Messages Found") . '</CENTER>';
64 } else if (isset($errors)) {
65 echo "<!-- ".$errors." -->";
69 HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
70 exsitising code with a search true/false varible.
74 for ($q = 0; $q < count($messagelist); $q++
) {
75 $id[$q] = trim($messagelist[$q]);
77 $issent = ($mailbox == $sent_folder);
78 $hdr_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
79 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
80 foreach ($hdr_list as $hdr) {
83 $subject[] = $hdr->subject
;
85 $priority[] = $hdr->priority
;
88 $type[] = $hdr->type0
;
92 while ($j < count($messagelist)) {
93 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
94 $tmpdate = explode(" ", trim($date[$j]));
96 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
97 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
98 $messages[$j]["ID"] = $id[$j];
99 $messages[$j]["FROM"] = decodeHeader($from[$j]);
100 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
101 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
102 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
103 $messages[$j]["TO"] = decodeHeader($to[$j]);
104 $messages[$j]["PRIORITY"] = $priority[$j];
105 $messages[$j]["CC"] = $cc[$j];
106 $messages[$j]["SIZE"] = $size[$j];
107 $messages[$j]["TYPE0"] = $type[$j];
110 while ($num < count($flags[$j])) {
111 if ($flags[$j][$num] == 'Deleted') {
112 $messages[$j]['FLAG_DELETED'] = true;
113 } else if ($flags[$j][$num] == 'Answered') {
114 $messages[$j]['FLAG_ANSWERED'] = true;
115 } else if ($flags[$j][$num] == 'Seen') {
116 $messages[$j]['FLAG_SEEN'] = true;
117 } else if ($flags[$j][$num] == 'Flagged') {
118 $messages[$j]['FLAG_FLAGGED'] = true;
125 /* Find and remove the ones that are deleted */
128 while ($j < count($messagelist)) {
129 if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) {
133 $msgs[$i] = $messages[$j];
140 /* There's gotta be messages in the array for it to sort them. */
142 if (count($messagelist) > 0) {
144 if (!isset ($msg)) { $msg = ""; }
146 mail_message_listing_beginning( $imapConnection,
147 "move_messages.php?msg=$msg&mailbox=$urlMailbox&where=" . urlencode($search_where) . "&what=".urlencode($search_what),
150 '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
151 get_selectall_link($start_msg, $sort) );
154 while ($j < count($msgs)) {
155 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what);
158 echo '</table></td></tr></table></form>';