Disable the show images stuff while reading html messages.
[squirrelmail.git] / functions / imap_search.php
1 <?php
2
3 /**
4 * imap_search.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * IMAP search routines
10 *
11 * $Id$
12 */
13
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');
19
20 function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$color, $search_position = '') {
21
22 global $msgs, $message_highlight_list, $squirrelmail_language, $languages, $index_order;
23 global $pos;
24
25 $pos = $search_position;
26
27 $urlMailbox = urlencode($mailbox);
28
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\"";
33 } else {
34 $ss .= "SEARCH ALL $search_where \"$search_what\"";
35 }
36
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);
42 }
43
44 unset($messagelist); $msgs=""; $c = 0;
45
46 /* Keep going till we find the SEARCH responce */
47 while ($c < count( $readin )) {
48
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];
54 else
55 $errors = $readin[$c];
56 $c++;
57 }
58
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>';
62 return;
63 } else if (isset($errors)) {
64 echo "<!-- ".$errors." -->";
65 }
66
67 /*
68 HACKED CODED FROM ANOTHER FUNCTION, Could Probably dump this and mondify
69 exsitising code with a search true/false varible.
70 */
71
72 global $sent_folder;
73 for ($q = 0; $q < count($messagelist); $q++) {
74 $id[$q] = trim($messagelist[$q]);
75 }
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) {
80 $from[] = $hdr->from;
81 $date[] = $hdr->date;
82 $subject[] = $hdr->subject;
83 $to[] = $hdr->to;
84 $priority[] = $hdr->priority;
85 $cc[] = $hdr->cc;
86 $size[] = $hdr->size;
87 $type[] = $hdr->type0;
88 }
89
90 $j = 0;
91 while ($j < count($messagelist)) {
92 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
93 $tmpdate = explode(" ", trim($date[$j]));
94
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];
107
108 $num = 0;
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;
118 }
119 $num++;
120 }
121 $j++;
122 }
123
124 /* Find and remove the ones that are deleted */
125 $i = 0;
126 $j = 0;
127 while ($j < count($messagelist)) {
128 if (isset($messages[$j]["FLAG_DELETED"]) && $messages[$j]["FLAG_DELETED"] == true) {
129 $j++;
130 continue;
131 }
132 $msgs[$i] = $messages[$j];
133
134 $i++;
135 $j++;
136 }
137 $numMessages = $i;
138
139 /* There's gotta be messages in the array for it to sort them. */
140
141 if (count($messagelist) > 0) {
142 $j=0;
143 if (!isset ($msg)) {
144 $msg = '';
145 }
146
147 mail_message_listing_beginning( $imapConnection,
148 "move_messages.php?msg=$msg&mailbox=$urlMailbox&pos=$pos&where=" . urlencode($search_where) . "&what=".urlencode($search_what),
149 $mailbox,
150 -1,
151 '<b>' . _("Found") . ' ' . count($messagelist) . ' ' . _("messages") . '</b>',
152 get_selectall_link($start_msg, $sort) );
153
154
155 while ($j < count($msgs)) {
156 printMessageInfo($imapConnection, $msgs[$j]["ID"], 0, $j, $mailbox, '', 0, $search_where, $search_what);
157 $j++;
158 }
159 echo '</table></td></tr></table></form>';
160
161 }
162 }
163
164 ?>