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 = '') {
22 global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
25 $pos = $search_position;
27 $urlMailbox = urlencode($mailbox);
29 /* Construct the Search QuERY */
30 if (isset($languages[$squirrelmail_language]['CHARSET']) &&
31 $languages[$squirrelmail_language]['CHARSET']) {
32 $ss = "SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\"";
34 $ss .= "SEARCH ALL $search_where \"$search_what\"";
37 /* Read Data Back From IMAP */
38 $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
39 if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') {
40 $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"";
41 $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
44 unset($messagelist); $msgs=""; $c = 0;
46 /* Keep going till we find the SEARCH responce */
47 while ($c < count( $readin )) {
49 /* Check to see if a SEARCH Responce was recived */
50 if (substr($readin[$c],0,9) == "* SEARCH ")
51 $messagelist = explode(" ",substr($readin[$c],9));
52 else if (isset($errors))
53 $errors = $errors.$readin[$c];
55 $errors = $readin[$c];
59 /* If nothing is found * SEARCH should be the first error else echo errors */
60 if (isset($errors) && strstr($errors,"* SEARCH")) {
61 echo '<br><CENTER>' . _("No Messages Found") . '</CENTER>';
63 } else if (isset($errors)) {
64 echo "<!-- ".$errors." -->";
68 HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
69 exsitising code with a search true/false varible.
73 for ($q = 0; $q < count($messagelist); $q++
) {
74 $id[$q] = trim($messagelist[$q]);
76 $issent = ($mailbox == $sent_folder);
77 $hdr_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
78 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
79 foreach ($hdr_list as $hdr) {
82 $subject[] = $hdr->subject
;
84 $priority[] = $hdr->priority
;
87 $type[] = $hdr->type0
;
91 while ($j < count($messagelist)) {
92 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
93 $tmpdate = explode(" ", trim($date[$j]));
95 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
96 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
97 $messages[$j]["ID"] = $id[$j];
98 $messages[$j]["FROM"] = decodeHeader($from[$j]);
99 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
100 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
101 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
102 $messages[$j]["TO"] = decodeHeader($to[$j]);
103 $messages[$j]["PRIORITY"] = $priority[$j];
104 $messages[$j]["CC"] = $cc[$j];
105 $messages[$j]["SIZE"] = $size[$j];
106 $messages[$j]["TYPE0"] = $type[$j];
109 while ($num < count($flags[$j])) {
110 if ($flags[$j][$num] == 'Deleted') {
111 $messages[$j]['FLAG_DELETED'] = true;
112 } else if ($flags[$j][$num] == 'Answered') {
113 $messages[$j]['FLAG_ANSWERED'] = true;
114 } else if ($flags[$j][$num] == 'Seen') {
115 $messages[$j]['FLAG_SEEN'] = true;
116 } else if ($flags[$j][$num] == 'Flagged') {
117 $messages[$j]['FLAG_FLAGGED'] = true;
124 /* Find and remove the ones that are deleted */
127 while ($j < count($messagelist)) {
128 if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) {
132 $msgs[$i] = $messages[$j];
139 /* There's gotta be messages in the array for it to sort them. */
141 if (count($messagelist) > 0) {
147 mail_message_listing_beginning( $imapConnection,
148 "move_messages.php?msg=$msg&mailbox=$urlMailbox&pos=$pos&where=" . urlencode($search_where) . "&what=".urlencode($search_what),
151 '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
152 get_selectall_link($start_msg, $sort) );
155 while ($j < count($msgs)) {
156 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what);
159 echo '</table></td></tr></table></form>';