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