Added html_top and html_bottom hooks to read_body for compression plugin
[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 global $index_order;
18
19 $msg = $msgs[$key];
20
21 $senderName = sqimap_find_displayable_name($msg["FROM"]);
22 $urlMailbox = urlencode($mailbox);
23 $subject = trim($msg["SUBJECT"]);
24 if ($subject == "")
25 $subject = _("(no subject)");
26
27 echo "<TR>\n";
28
29 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
30 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
31 if ($mailbox == $sent_folder) { $italic = "<i>"; $italic_end = "</i>"; }
32
33 for ($i=0; $i < count($message_highlight_list); $i++) {
34 if (trim($message_highlight_list[$i]["value"]) != "") {
35 if ($message_highlight_list[$i]["match_type"] == "to_cc") {
36 if (strpos("^^".strtolower($msg["TO"]), strtolower($message_highlight_list[$i]["value"])) || strpos("^^".strtolower($msg["CC"]), strtolower($message_highlight_list[$i]["value"]))) {
37 $hlt_color = $message_highlight_list[$i]["color"];
38 continue;
39 }
40 } else if (strpos("^^".strtolower($msg[strtoupper($message_highlight_list[$i]["match_type"])]),strtolower($message_highlight_list[$i]["value"]))) {
41 $hlt_color = $message_highlight_list[$i]["color"];
42 continue;
43 }
44 }
45 }
46
47 if (!$hlt_color)
48 $hlt_color = $color[4];
49
50 if ($where && $what) {
51 $search_stuff = "&where=".urlencode($where)."&what=".urlencode($what);
52 }
53
54 for ($i=1; $i <= count($index_order); $i++) {
55 switch ($index_order[$i]) {
56 case 1: # checkbox
57 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
58 break;
59 case 2: # from
60 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$senderName$flag_end$bold_end$italic_end</td>\n";
61 break;
62 case 3: # date
63 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag".$msg["DATE_STRING"]."$flag_end$bold_end</center></td>\n";
64 break;
65 case 4: # subject
66 echo " <td bgcolor=$hlt_color>$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";
67 break;
68 case 5: # flags
69 $stuff = false;
70 echo " <td bgcolor=$hlt_color width=1%><b><small>\n";
71 if ($msg["FLAG_ANSWERED"] == true) {
72 echo "A\n";
73 $stuff = true;
74 }
75 if ($msg["TYPE0"] == "multipart") {
76 echo "+\n";
77 $stuff = true;
78 }
79 if (ereg("(1|2)",substr($msg["PRIORITY"],0,1))) {
80 echo "<font color=$color[1]>!</font>\n";
81 $stuff = true;
82 }
83 if (!$stuff) echo "&nbsp;\n";
84 echo "</small></b></td>\n";
85 break;
86 case 6: # size
87 echo " <td bgcolor=$hlt_color width=1%>$bold".show_readable_size($msg['SIZE'])."$bold_end</td>\n";
88 break;
89 }
90 }
91
92
93 echo "</tr>\n";
94 }
95
96 /**
97 ** This function loops through a group of messages in the mailbox and shows them
98 **/
99 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
100 global $msgs, $msort;
101 global $sent_folder;
102 global $message_highlight_list;
103 global $auto_expunge;
104
105 if ($auto_expunge) {
106 sqimap_mailbox_expunge($imapConnection, $mailbox);
107 sqimap_mailbox_select($imapConnection, $mailbox);
108 }
109
110 if (!$use_cache) {
111 if ($numMessages >= 1) {
112 for ($q = 0; $q < $numMessages; $q++) {
113 if ($mailbox == $sent_folder)
114 $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
115 else
116 $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
117
118 $from[$q] = $hdr->from;
119 $date[$q] = $hdr->date;
120 $subject[$q] = $hdr->subject;
121 $to[$q] = $hdr->to;
122 $priority[$q] = $hdr->priority;
123 $cc[$q] = $hdr->cc;
124 $size[$q] = $hdr->size;
125 $type[$q] = $hdr->type0;
126
127 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
128 }
129 }
130
131 $j = 0;
132 while ($j < $numMessages) {
133 $date[$j] = ereg_replace(" ", " ", $date[$j]);
134 $tmpdate = explode(" ", trim($date[$j]));
135
136 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
137 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
138 $messages[$j]["ID"] = $j+1;
139 $messages[$j]["FROM"] = decodeHeader($from[$j]);
140 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
141 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
142 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
143 $messages[$j]["TO"] = decodeHeader($to[$j]);
144 $messages[$j]["PRIORITY"] = $priority[$j];
145 $messages[$j]["CC"] = $cc[$j];
146 $messages[$j]["SIZE"] = $size[$j];
147 $messages[$j]["TYPE0"] = $type[$j];
148
149 # fix SUBJECT-SORT to remove Re:
150 $re_abbr = # Add more here!
151 "vedr|sv|" . # Danish
152 "re|aw"; # English
153 if (eregi("^($re_abbr):[ ]*(.*)$",
154 $messages[$j]['SUBJECT-SORT'], $regs))
155 $messages[$j]['SUBJECT-SORT'] = $regs[2];
156
157 $num = 0;
158 while ($num < count($flags[$j])) {
159 if ($flags[$j][$num] == "Deleted") {
160 $messages[$j]["FLAG_DELETED"] = true;
161 }
162 else if ($flags[$j][$num] == "Answered") {
163 $messages[$j]["FLAG_ANSWERED"] = true;
164 }
165 else if ($flags[$j][$num] == "Seen") {
166 $messages[$j]["FLAG_SEEN"] = true;
167 }
168 else if ($flags[$j][$num] == "Flagged") {
169 $messages[$j]["FLAG_FLAGGED"] = true;
170 }
171 $num++;
172 }
173 $j++;
174 }
175
176 /** Find and remove the ones that are deleted */
177 $i = 0;
178 $j = 0;
179 while ($j < $numMessages) {
180 if ($messages[$j]["FLAG_DELETED"] == true) {
181 $j++;
182 continue;
183 }
184 $msgs[$i] = $messages[$j];
185
186 $i++;
187 $j++;
188 }
189 $numMessages = $i;
190 }
191
192 // There's gotta be messages in the array for it to sort them.
193 if (($numMessages > 0) && (!$use_cache)) {
194 /** 0 = Date (up) 4 = Subject (up)
195 ** 1 = Date (dn) 5 = Subject (dn)
196 ** 2 = Name (up)
197 ** 3 = Name (dn)
198 **/
199 session_unregister("msgs");
200 if (($sort == 0) || ($sort == 1))
201 $msort = array_cleave ($msgs, "TIME_STAMP");
202 if (($sort == 2) || ($sort == 3))
203 $msort = array_cleave ($msgs, "FROM-SORT");
204 if (($sort == 4) || ($sort == 5))
205 $msort = array_cleave ($msgs, "SUBJECT-SORT");
206
207 if(($sort % 2) == 1) {
208 asort($msort);
209 } else {
210 arsort($msort);
211 }
212 session_register("msort");
213 }
214 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
215 session_register("msgs");
216 }
217
218 // generic function to convert the msgs array into an HTML table
219 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
220 global $folder_prefix, $sent_folder;
221 global $imapServerAddress;
222 global $index_order;
223
224 // if cache isn't already set, do it now
225 if (!session_is_registered("msgs"))
226 session_register("msgs");
227 if (!session_is_registered("msort"))
228 session_register("msort");
229
230
231 if ($startMessage + ($show_num - 1) < $numMessages) {
232 $endMessage = $startMessage + ($show_num-1);
233 } else {
234 $endMessage = $numMessages;
235 }
236
237 if ($endMessage < $startMessage) {
238 $startMessage = $startMessage - $show_num;
239 if ($startMessage < 1)
240 $startMessage = 1;
241 }
242
243 $nextGroup = $startMessage + $show_num;
244 $prevGroup = $startMessage - $show_num;
245 $urlMailbox = urlencode($mailbox);
246
247 do_hook("mailbox_index_before");
248
249 $Message = '';
250 if ($startMessage < $endMessage) {
251 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
252 } else if ($startMessage == $endMessage) {
253 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
254 }
255
256 $More = '';
257 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
258 $More = "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
259 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
260 }
261 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
262 $More = "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
263 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
264 }
265 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
266 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
267 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
268 }
269
270 mail_message_listing_beginning($imapConnection,
271 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
272 $mailbox, $sort, $Message, $More);
273
274
275 // loop through and display the info for each message.
276 $t = 0; // $t is used for the checkbox number
277 if ($numMessages == 0) { // if there's no messages in this folder
278 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
279 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
280 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
281 $i = $startMessage;
282 reset($msort);
283 do {
284 $key = key($msort);
285 next($msort);
286 $k++;
287 } while (isset ($key) && ($k < $i));
288 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
289 } else {
290 $i = $startMessage;
291 reset($msort);
292 do {
293 $key = key($msort);
294 next($msort);
295 $k++;
296 } while (isset ($key) && ($k < $i));
297
298 do {
299 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
300 $key = key($msort);
301 $t++;
302 $i++;
303 next($msort);
304 } while ($i < ($endMessage+1));
305 }
306 echo "</TABLE>";
307
308 echo "</td></tr>\n";
309
310 if ($More)
311 {
312 echo "<TR BGCOLOR=\"$color[4]\"><TD>$More</td></tr>\n";
313 }
314 echo "</table>"; /** End of message-list table */
315
316 do_hook("mailbox_index_after");
317 }
318
319 /* Displays the standard message list header.
320 * To finish the table, you need to do a "</table></table>";
321 * $moveURL is the URL to submit the delete/move form to
322 * $mailbox is the current mailbox
323 * $sort is the current sorting method (-1 for no sorting available [searches])
324 * $Message is a message that is centered on top of the list
325 * $More is a second line that is left aligned
326 */
327 function mail_message_listing_beginning($imapConnection, $moveURL,
328 $mailbox = '', $sort = -1, $Message = '', $More = '')
329 {
330 global $color, $index_order;
331
332 /** This is the beginning of the message list table. It wraps around all messages */
333 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
334
335 if ($Message)
336 {
337 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
338 }
339
340 if ($More)
341 {
342 echo "<TR BGCOLOR=\"$color[4]\"><TD>$More</td></tr>\n";
343 }
344
345 /** The delete and move options */
346 echo "<TR><TD BGCOLOR=\"$color[0]\">";
347
348 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
349 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
350 echo " <TR>\n";
351 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
352 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
353 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
354
355 $boxes = sqimap_mailbox_list($imapConnection);
356 for ($i = 0; $i < count($boxes); $i++) {
357 if ($boxes[$i]["flags"][0] != "noselect" &&
358 $boxes[$i]["flags"][1] != "noselect" &&
359 $boxes[$i]["flags"][2] != "noselect") {
360 $box = $boxes[$i]["unformatted"];
361 $box2 = replace_spaces($boxes[$i]["formatted"]);
362 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
363 }
364 }
365 echo " </SELECT></SMALL></TT>";
366 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
367 echo " </TD>\n";
368 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
369 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
370 echo " </TD>\n";
371 echo " </TR>\n";
372
373 echo "</TABLE>\n";
374 do_hook("mailbox_form_before");
375 echo "</TD></TR>";
376
377 echo "<TR><TD BGCOLOR=\"$color[0]\">";
378 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
379 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
380
381 // Print the headers
382 for ($i=1; $i <= count($index_order); $i++) {
383 switch ($index_order[$i]) {
384 case 1: # checkbox
385 case 5: # flags
386 echo " <TD WIDTH=1%><B>&nbsp;</B></TD>";
387 break;
388
389 case 2: # from
390 if ($mailbox == $sent_folder)
391 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
392 else
393 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
394
395 if ($sort == 2)
396 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";
397 else if ($sort == 3)
398 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";
399 else if ($sort != -1)
400 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";
401 break;
402
403 case 3: # date
404 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
405 if ($sort == 0)
406 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";
407 else if ($sort == 1)
408 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";
409 else if ($sort != -1)
410 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";
411 break;
412
413 case 4: # subject
414 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
415 if ($sort == 4)
416 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";
417 else if ($sort == 5)
418 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";
419 else if ($sort != -1)
420 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";
421 break;
422
423 case 6: # size
424 echo " <TD WIDTH=1%><b>" . _("Size")."</b></TD>\n";
425 break;
426 }
427 }
428 echo "</TR>\n";
429 }
430 ?>