fixed some more quoting problems with searching and message highlighting
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
11 $mailbox_display_php = true;
12
13 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
14 global $color, $msgs, $msort;
15 global $sent_folder;
16 global $message_highlight_list;
17
18 $msg = $msgs[$key];
19
20 $senderName = sqimap_find_displayable_name($msg["FROM"]);
21 $urlMailbox = urlencode($mailbox);
22 $subject = trim(stripslashes($msg["SUBJECT"]));
23 echo "<TR>\n";
24
25 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
26 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
27 if ($mailbox == $sent_folder) { $italic = "<i>"; $italic_end = "</i>"; }
28
29 for ($i=0; $i < count($message_highlight_list); $i++) {
30 if (trim($message_highlight_list[$i]["value"]) != "") {
31 if ($message_highlight_list[$i]["match_type"] == "to_cc") {
32 if (strpos("^^".$msg["TO"], $message_highlight_list[$i]["value"]) || strpos("^^".$msg["CC"], $message_highlight_list[$i]["value"])) {
33 $hlt_color = $message_highlight_list[$i]["color"];
34 continue;
35 }
36 } else if (strpos("^^".$msg[strtoupper($message_highlight_list[$i]["match_type"])],$message_highlight_list[$i]["value"])) {
37 $hlt_color = $message_highlight_list[$i]["color"];
38 continue;
39 }
40 }
41 }
42
43 if (!$hlt_color)
44 $hlt_color = $color[4];
45
46 if ($where && $what) {
47 $search_stuff = "&where=".urlencode($where)."&what=".urlencode($what);
48 }
49
50 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
51 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$senderName$flag_end$bold_end$italic_end</td>\n";
52 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag".$msg["DATE_STRING"]."$flag_end$bold_end</center></td>\n";
53 if ($msg["FLAG_ANSWERED"] == true) echo " <td bgcolor=$hlt_color width=1%><b><small>A</small></b></td>";
54 elseif (ereg("(1|2)",substr($msg["PRIORITY"],0,1))) echo " <td bgcolor=$hlt_color width=1%><b><small><font color=$color[1]>!</font></small></b></td>";
55 else echo " <td bgcolor=$hlt_color width=1%>&nbsp;</td>";
56 echo " <td bgcolor=$hlt_color width=%>$bold<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\">$flag$subject$flag_end</a>$bold_end</td>\n";
57
58 echo "</tr>\n";
59 }
60
61 /**
62 ** This function loops through a group of messages in the mailbox and shows them
63 **/
64 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
65 global $msgs, $msort;
66 global $sent_folder;
67 global $message_highlight_list;
68
69 if (!$use_cache) {
70 if ($numMessages >= 1) {
71 for ($q = 0; $q < $numMessages; $q++) {
72 if ($mailbox == $sent_folder)
73 $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
74 else
75 $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
76
77 $from[$q] = $hdr->from;
78 $date[$q] = $hdr->date;
79 $subject[$q] = $hdr->subject;
80 $to[$q] = $hdr->to;
81 $priority[$q] = $hdr->priority;
82 $cc[$q] = $hdr->cc;
83
84 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
85 }
86 }
87
88 $j = 0;
89 while ($j < $numMessages) {
90 $date[$j] = ereg_replace(" ", " ", $date[$j]);
91 $tmpdate = explode(" ", trim($date[$j]));
92
93 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
94 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
95 $messages[$j]["ID"] = $j+1;
96 $messages[$j]["FROM"] = decodeHeader($from[$j]);
97 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
98 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
99 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
100 $messages[$j]["TO"] = decodeHeader($to[$j]);
101 $messages[$j]["PRIORITY"] = $priority[$j];
102 $messages[$j]["CC"] = $cc[$j];
103
104 # fix SUBJECT-SORT to remove Re:
105 if (substr($messages[$j]["SUBJECT-SORT"], 0, 3) == "re:" ||
106 substr($messages[$j]["SUBJECT-SORT"], 0, 3) == "aw:")
107 $messages[$j]["SUBJECT-SORT"] = trim(substr($messages[$j]["SUBJECT-SORT"], 3));
108
109 $num = 0;
110 while ($num < count($flags[$j])) {
111 if ($flags[$j][$num] == "Deleted") {
112 $messages[$j]["FLAG_DELETED"] = true;
113 }
114 else if ($flags[$j][$num] == "Answered") {
115 $messages[$j]["FLAG_ANSWERED"] = true;
116 }
117 else if ($flags[$j][$num] == "Seen") {
118 $messages[$j]["FLAG_SEEN"] = true;
119 }
120 else if ($flags[$j][$num] == "Flagged") {
121 $messages[$j]["FLAG_FLAGGED"] = true;
122 }
123 $num++;
124 }
125 $j++;
126 }
127
128 /** Find and remove the ones that are deleted */
129 $i = 0;
130 $j = 0;
131 while ($j < $numMessages) {
132 if ($messages[$j]["FLAG_DELETED"] == true) {
133 $j++;
134 continue;
135 }
136 $msgs[$i] = $messages[$j];
137
138 $i++;
139 $j++;
140 }
141 $numMessages = $i;
142 }
143
144 // There's gotta be messages in the array for it to sort them.
145 if (($numMessages > 0) && (!$use_cache)) {
146 /** 0 = Date (up) 4 = Subject (up)
147 ** 1 = Date (dn) 5 = Subject (dn)
148 ** 2 = Name (up)
149 ** 3 = Name (dn)
150 **/
151 session_unregister("msgs");
152 if (($sort == 0) || ($sort == 1))
153 $msort = array_cleave ($msgs, "TIME_STAMP");
154 if (($sort == 2) || ($sort == 3))
155 $msort = array_cleave ($msgs, "FROM-SORT");
156 if (($sort == 4) || ($sort == 5))
157 $msort = array_cleave ($msgs, "SUBJECT-SORT");
158
159 if(($sort % 2) == 1) {
160 asort($msort);
161 } else {
162 arsort($msort);
163 }
164 session_register("msort");
165 }
166 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
167 session_register("msgs");
168 }
169
170 // generic function to convert the msgs array into an HTML table
171 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
172 global $folder_prefix, $sent_folder;
173 global $imapServerAddress;
174
175 // if cache isn't already set, do it now
176 if (!session_is_registered("msgs"))
177 session_register("msgs");
178 if (!session_is_registered("msort"))
179 session_register("msort");
180
181
182 if ($startMessage + ($show_num - 1) < $numMessages) {
183 $endMessage = $startMessage + ($show_num-1);
184 } else {
185 $endMessage = $numMessages;
186 }
187
188 if ($endMessage < $startMessage) {
189 $startMessage = $startMessage - $show_num;
190 if ($startMessage < 1)
191 $startMessage = 1;
192 }
193
194 $nextGroup = $startMessage + $show_num;
195 $prevGroup = $startMessage - $show_num;
196 $urlMailbox = urlencode($mailbox);
197
198 do_hook("mailbox_index_before");
199 /** This is the beginning of the message list table. It wraps around all messages */
200 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
201
202 if ($startMessage < $endMessage) {
203 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
204 echo "<CENTER>". _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")</CENTER>\n";
205 echo "</TD></TR>\n";
206 } else if ($startMessage == $endMessage) {
207 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
208 echo "<CENTER>". _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")</CENTER>\n";
209 echo "</TD></TR>\n";
210 }
211
212 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
213 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
214 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
215 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
216 }
217 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
218 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
219 echo "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
220 }
221 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
222 echo "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
223 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
224 }
225 echo "</TD></TR>\n";
226
227 /** The delete and move options */
228 echo "<TR><TD BGCOLOR=\"$color[0]\">";
229
230 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage\">";
231 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0>\n";
232 echo " <TR>\n";
233 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
234 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
235 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
236
237 $boxes = sqimap_mailbox_list($imapConnection);
238 for ($i = 0; $i < count($boxes); $i++) {
239 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
240 $box = $boxes[$i]["unformatted"];
241 $box2 = replace_spaces($boxes[$i]["formatted"]);
242 echo " <OPTION VALUE=\"$box\">$box2\n";
243 }
244 }
245 echo " </SELECT></SMALL></TT>";
246 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
247
248 echo " </TD>\n";
249 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
250 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
251 echo " </TD>";
252 echo " </TR>\n";
253
254 echo "</TABLE>\n\n\n";
255 echo "</TD></TR>";
256
257 echo "<TR><TD BGCOLOR=\"$color[0]\">";
258 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
259 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
260 echo " <TD WIDTH=1%><B>&nbsp;</B></TD>";
261 /** FROM HEADER **/
262 if ($mailbox == $sent_folder)
263 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
264 else
265 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
266
267 if ($sort == 2)
268 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
269 else if ($sort == 3)
270 echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
271 else
272 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
273 /** DATE HEADER **/
274 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
275 if ($sort == 0)
276 echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
277 else if ($sort == 1)
278 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
279 else
280 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
281 echo " <TD WIDTH=1%>&nbsp;</TD>\n";
282 /** SUBJECT HEADER **/
283 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
284 if ($sort == 4)
285 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
286 else if ($sort == 5)
287 echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
288 else
289 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
290
291 echo "</TR>";
292
293
294 // loop through and display the info for each message.
295 $t = 0; // $t is used for the checkbox number
296 if ($numMessages == 0) { // if there's no messages in this folder
297 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=5><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
298 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
299 $i = $startMessage;
300 reset($msort);
301 do {
302 $key = key($msort);
303 next($msort);
304 $k++;
305 } while (isset ($key) && ($k < $i));
306 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
307 } else {
308 $i = $startMessage;
309 reset($msort);
310 do {
311 $key = key($msort);
312 next($msort);
313 $k++;
314 } while (isset ($key) && ($k < $i));
315
316 do {
317 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
318 $key = key($msort);
319 $t++;
320 $i++;
321 next($msort);
322 } while ($i < ($endMessage+1));
323 }
324 echo "</FORM></TABLE>";
325
326 echo "</TABLE>\n";
327 echo "</TD></TR>\n";
328
329 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
330 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
331 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A> | \n";
332 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
333 }
334 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
335 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A> | \n";
336 echo "<FONT COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
337 }
338 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
339 echo "<FONT COLOR=\"$color[9]\">" . _("Previous"). "</FONT> | \n";
340 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
341 }
342 echo "</TD></TR></table>"; /** End of message-list table */
343
344 do_hook("mailbox_index_after");
345 }
346 ?>