6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
11 $mailbox_display_php = true;
13 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
15 global $color, $msgs, $msort;
17 global $message_highlight_list;
22 $senderName = sqimap_find_displayable_name($msg["FROM"]);
23 $urlMailbox = urlencode($mailbox);
24 $subject = trim($msg["SUBJECT"]);
26 $subject = _("(no subject)");
30 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
31 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
32 if ($mailbox == $sent_folder) { $italic = "<i>"; $italic_end = "</i>"; }
33 if ($msg["FLAG_DELETED"]) { $fontstr = "<font color=\"$color[9]\">"; $fontstr_end = "</font>"; }
35 for ($i=0; $i < count($message_highlight_list); $i++
) {
36 if (trim($message_highlight_list[$i]["value"]) != "") {
37 if ($message_highlight_list[$i]["match_type"] == "to_cc") {
38 if (strpos("^^".strtolower($msg["TO"]), strtolower($message_highlight_list[$i]["value"])) ||
strpos("^^".strtolower($msg["CC"]), strtolower($message_highlight_list[$i]["value"]))) {
39 $hlt_color = $message_highlight_list[$i]["color"];
42 } else if (strpos("^^".strtolower($msg[strtoupper($message_highlight_list[$i]["match_type"])]),strtolower($message_highlight_list[$i]["value"]))) {
43 $hlt_color = $message_highlight_list[$i]["color"];
50 $hlt_color = $color[4];
52 if ($where && $what) {
53 $search_stuff = "&where=".urlencode($where)."&what=".urlencode($what);
57 $checked = " checked";
61 for ($i=1; $i <= count($index_order); $i++
) {
62 switch ($index_order[$i]) {
64 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
67 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
70 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
73 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";
77 echo " <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
78 if ($msg["FLAG_ANSWERED"] == true) {
82 if ($msg["TYPE0"] == "multipart") {
86 if (ereg("(1|2)",substr($msg["PRIORITY"],0,1))) {
87 echo "<font color=$color[1]>!</font>\n";
90 if ($msg["FLAG_DELETED"]) {
91 echo "<font color=\"$color[1]\">D</font>\n";
95 if (!$stuff) echo " \n";
96 echo "</small></b></td>\n";
99 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
109 ** This function loops through a group of messages in the mailbox and shows them
111 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
112 global $msgs, $msort;
114 global $message_highlight_list;
115 global $auto_expunge;
117 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
118 sqimap_mailbox_select($imapConnection, $mailbox);
122 if ($numMessages >= 1) {
124 for ($q = 0; $q < $numMessages; $q++
) {
125 if($mailbox == $sent_folder)
126 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
128 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
130 $from[$q] = $hdr->from
;
131 $date[$q] = $hdr->date
;
132 $subject[$q] = $hdr->subject
;
134 $priority[$q] = $hdr->priority
;
136 $size[$q] = $hdr->size
;
137 $type[$q] = $hdr->type0
;
138 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
142 // if it's not sorted
143 if ($startMessage +
($show_num - 1) < $numMessages) {
144 $endMessage = $startMessage +
($show_num-1);
146 $endMessage = $numMessages;
149 if ($endMessage < $startMessage) {
150 $startMessage = $startMessage - $show_num;
151 if ($startMessage < 1)
156 $real_startMessage = $numMessages - $startMessage +
1;
157 $real_endMessage = $numMessages - $startMessage - $show_num;
158 if ($real_endMessage <= 0)
159 $real_endMessage = 1;
162 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
163 if($mailbox == $sent_folder)
164 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
166 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
168 $from[$j] = $hdr->from
;
169 $date[$j] = $hdr->date
;
170 $subject[$j] = $hdr->subject
;
172 $priority[$j] = $hdr->priority
;
174 $size[$j] = $hdr->size
;
175 $type[$j] = $hdr->type0
;
176 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
185 $end = $startMessage +
$show_num - 1;
190 $date[$j] = ereg_replace(" ", " ", $date[$j]);
191 $tmpdate = explode(" ", trim($date[$j]));
193 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
194 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
195 $messages[$j]["ID"] = $id[$j];
196 $messages[$j]["FROM"] = decodeHeader($from[$j]);
197 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
198 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
199 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
200 $messages[$j]["TO"] = decodeHeader($to[$j]);
201 $messages[$j]["PRIORITY"] = $priority[$j];
202 $messages[$j]["CC"] = $cc[$j];
203 $messages[$j]["SIZE"] = $size[$j];
204 $messages[$j]["TYPE0"] = $type[$j];
206 # fix SUBJECT-SORT to remove Re:
207 $re_abbr = # Add more here!
208 "vedr|sv|" . # Danish
210 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
211 $messages[$j]['SUBJECT-SORT'] = $regs[2];
214 while ($num < count($flags[$j])) {
215 if ($flags[$j][$num] == "Deleted") {
216 $messages[$j]["FLAG_DELETED"] = true;
218 elseif ($flags[$j][$num] == "Answered") {
219 $messages[$j]["FLAG_ANSWERED"] = true;
221 elseif ($flags[$j][$num] == "Seen") {
222 $messages[$j]["FLAG_SEEN"] = true;
224 elseif ($flags[$j][$num] == "Flagged") {
225 $messages[$j]["FLAG_FLAGGED"] = true;
232 /* Only ignore messages flagged as deleted if we are using a
233 * trash folder or auto_expunge */
234 if (($move_to_trash ||
$auto_expunge) && $sort != 6)
236 /** Find and remove the ones that are deleted */
239 while ($j < $numMessages) {
240 if ($messages[$j]["FLAG_DELETED"] == true) {
244 $msgs[$i] = $messages[$j];
255 // There's gotta be messages in the array for it to sort them.
256 if ($numMessages > 0 && ! $use_cache) {
257 /** 0 = Date (up) 4 = Subject (up)
258 ** 1 = Date (dn) 5 = Subject (dn)
262 session_unregister("msgs");
263 if (($sort == 0) ||
($sort == 1))
264 $msort = array_cleave ($msgs, "TIME_STAMP");
265 if (($sort == 2) ||
($sort == 3))
266 $msort = array_cleave ($msgs, "FROM-SORT");
267 if (($sort == 4) ||
($sort == 5))
268 $msort = array_cleave ($msgs, "SUBJECT-SORT");
279 session_register("msort");
281 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
282 session_register("msgs");
285 // generic function to convert the msgs array into an HTML table
286 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
287 global $folder_prefix, $sent_folder;
288 global $imapServerAddress;
289 global $index_order, $real_endMessage, $real_startMessage, $checkall;
291 // if cache isn't already set, do it now
292 if (!session_is_registered("msgs"))
293 session_register("msgs");
294 if (!session_is_registered("msort"))
295 session_register("msort");
297 if ($startMessage +
($show_num - 1) < $numMessages) {
298 $endMessage = $startMessage +
($show_num-1);
300 $endMessage = $numMessages;
303 if ($endMessage < $startMessage) {
304 $startMessage = $startMessage - $show_num;
305 if ($startMessage < 1)
309 $nextGroup = $startMessage +
$show_num;
310 $prevGroup = $startMessage - $show_num;
311 $urlMailbox = urlencode($mailbox);
313 do_hook("mailbox_index_before");
316 if ($startMessage < $endMessage) {
317 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
318 } elseif ($startMessage == $endMessage) {
319 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
328 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
329 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
330 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
332 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
333 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
334 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
336 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
337 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
338 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
341 mail_message_listing_beginning($imapConnection,
342 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
343 $mailbox, $sort, $Message, $More, $startMessage);
345 $groupNum = $startMessage %
($show_num - 1);
346 $real_startMessage = $startMessage;
348 if ($endMessage - $startMessage < $show_num - 1) {
349 $endMessage = $endMessage - $startMessage +
1;
351 } else if ($startMessage > $show_num) {
352 $endMessage = $show_num;
357 $endVar = $endMessage +
1;
359 // loop through and display the info for each message.
360 $t = 0; // $t is used for the checkbox number
361 if ($numMessages == 0) { // if there's no messages in this folder
362 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
363 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
364 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
374 } while (isset ($key) && ($k < $i));
375 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
384 } while (isset ($key) && ($k < $i));
387 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
392 } while ($i && $i < $endVar);
398 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
399 echo "<table width=100% cellpadding=0 cellspacing=0 border=0><tr><td>";
400 echo "$More</td><td align=right>\n";
401 if (!$startMessage) $startMessage=1;
402 if ( $checkall == "1")
403 echo "\n<A HREF=\"right_main.php?mailbox=$mailbox&startMessage=$real_startMessage&sort=$sort\">" . _("Unselect All") . "</A>\n";
405 echo "\n<A HREF=\"right_main.php?mailbox=$mailbox&startMessage=$real_startMessage&sort=$sort&checkall=1\">" . _("Select All") . "</A>\n";
407 echo "</td></tr></table>";
409 echo "</table>"; /** End of message-list table */
411 do_hook("mailbox_index_after");
414 /* Displays the standard message list header.
415 * To finish the table, you need to do a "</table></table>";
416 * $moveURL is the URL to submit the delete/move form to
417 * $mailbox is the current mailbox
418 * $sort is the current sorting method (-1 for no sorting available [searches])
419 * $Message is a message that is centered on top of the list
420 * $More is a second line that is left aligned
422 function mail_message_listing_beginning($imapConnection, $moveURL,
423 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
425 global $color, $index_order, $auto_expunge, $move_to_trash;
427 $urlMailbox = urlencode($mailbox);
429 /** This is the beginning of the message list table. It wraps around all messages */
430 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
434 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
437 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
438 echo "<table width=100% cellpadding=0 cellspacing=0 border=0><tr><td>";
439 echo "$More</td><td align=right>\n";
440 if ( $checkall == "1")
441 echo "\n<A HREF=\"right_main.php?mailbox=$mailbox&startMessage=$startMessage&sort=$sort\">" . _("Unselect All") . "</A>\n";
443 echo "\n<A HREF=\"right_main.php?mailbox=$mailbox&startMessage=$startMessage&sort=$sort&checkall=1\">" . _("Select All") . "</A>\n";
445 echo "</td></tr></table>";
448 /** The delete and move options */
449 echo "<TR><TD BGCOLOR=\"$color[0]\">";
451 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
452 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
454 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
457 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
458 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
460 $boxes = sqimap_mailbox_list($imapConnection);
461 for ($i = 0; $i < count($boxes); $i++
) {
462 if ($boxes[$i]["flags"][0] != "noselect" &&
463 $boxes[$i]["flags"][1] != "noselect" &&
464 $boxes[$i]["flags"][2] != "noselect") {
465 $box = $boxes[$i]["unformatted"];
466 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
467 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
470 echo " </SELECT></SMALL></TT>";
471 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
473 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
474 if (! $move_to_trash && ! $auto_expunge) {
475 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT NAME=\"expungeButton\" VALUE=\"". _("Expunge") ."\"> ". _("mailbox") ."</SMALL></NOBR> \n";
477 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
482 do_hook("mailbox_form_before");
485 echo "<TR><TD BGCOLOR=\"$color[0]\">";
486 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
487 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
489 $urlMailbox=urlencode($mailbox);
492 for ($i=1; $i <= count($index_order); $i++
) {
493 switch ($index_order[$i]) {
496 echo " <TD WIDTH=1%><B> </B></TD>";
500 if ($mailbox == $sent_folder)
501 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
503 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
506 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";
508 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";
510 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";
515 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
517 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";
519 echo " <A HREF=\"right_main.php?newsort=6&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
521 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";
523 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";
528 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
530 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";
532 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";
534 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";
539 echo " <TD WIDTH=1%><b>" . _("Size")."</b></TD>\n";