6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
12 if (defined('mailbox_display_php'))
14 define('mailbox_display_php', true);
16 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
18 global $color, $msgs, $msort;
20 global $message_highlight_list;
23 $color_string = $color[4];
24 if ($GLOBALS['alt_index_colors']) {
25 if (!isset($GLOBALS["row_count"])) {
26 $GLOBALS["row_count"] = 0;
28 $GLOBALS["row_count"]++
;
29 if ($GLOBALS["row_count"] %
2) {
30 if (!isset($color[12])) $color[12] = "#EAEAEA";
31 $color_string = $color[12];
37 $senderName = sqimap_find_displayable_name($msg['FROM']);
38 $urlMailbox = urlencode($mailbox);
39 $subject = processSubject($msg['SUBJECT']);
43 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
45 $flag = "<font color=$color[2]>";
46 $flag_end = '</font>';
53 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
63 if ($mailbox == $sent_folder)
73 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
75 $fontstr = "<font color=\"$color[9]\">";
76 $fontstr_end = '</font>';
84 for ($i=0; $i < count($message_highlight_list); $i++
) {
85 if (trim($message_highlight_list[$i]['value']) != '') {
86 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
87 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
88 $hlt_color = $message_highlight_list[$i]['color'];
91 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
92 $hlt_color = $message_highlight_list[$i]['color'];
98 if (!isset($hlt_color))
99 $hlt_color = $color_string;
101 if ($where && $what) {
102 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
106 $checked = ' checked';
110 for ($i=1; $i <= count($index_order); $i++
) {
111 switch ($index_order[$i]) {
113 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
116 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
119 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
122 echo " <td bgcolor=$hlt_color>$bold";
123 if (! isset($search_stuff)) { $search_stuff = ''; }
124 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
125 do_hook("subject_link");
127 if ($subject != $msg['SUBJECT']) {
128 $title = get_html_translation_table(HTML_SPECIALCHARS
);
129 $title = array_flip($title);
130 $title = strtr($msg['SUBJECT'], $title);
131 $title = str_replace('"', "''", $title);
132 echo " title=\"$title\"";
134 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
138 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
139 if (isset($msg['FLAG_ANSWERED']) &&
140 $msg['FLAG_ANSWERED'] == true) {
144 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
145 echo "<font color=$color[8]>v</font>\n";
148 if ($msg['TYPE0'] == 'multipart') {
152 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
153 echo "<font color=$color[1]>!</font>\n";
156 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
157 echo "<font color=\"$color[1]\">D</font>\n";
161 if (!$stuff) echo " \n";
162 echo "</small></b></td>\n";
165 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
175 ** This function loops through a group of messages in the mailbox and shows them
177 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
178 global $msgs, $msort;
180 global $message_highlight_list;
181 global $auto_expunge;
183 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
184 sqimap_mailbox_select($imapConnection, $mailbox);
186 $issent = ($mailbox == $sent_folder);
189 if ($numMessages >= 1) {
191 $id = range(1, $numMessages);
193 // if it's not sorted
194 if ($startMessage +
($show_num - 1) < $numMessages) {
195 $endMessage = $startMessage +
($show_num-1);
197 $endMessage = $numMessages;
200 if ($endMessage < $startMessage) {
201 $startMessage = $startMessage - $show_num;
202 if ($startMessage < 1)
206 $real_startMessage = $numMessages - $startMessage +
1;
207 $real_endMessage = $numMessages - $startMessage - $show_num +
2;
208 if ($real_endMessage <= 0)
209 $real_endMessage = 1;
210 $id = array_reverse(range($real_endMessage, $real_startMessage));
213 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
214 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
215 foreach ($msgs_list as $hdr) {
216 $from[] = $hdr->from
;
217 $date[] = $hdr->date
;
218 $subject[] = $hdr->subject
;
220 $priority[] = $hdr->priority
;
222 $size[] = $hdr->size
;
223 $type[] = $hdr->type0
;
229 $end = $startMessage +
$show_num - 1;
230 if ($numMessages < $show_num)
231 $end_loop = $numMessages;
232 elseif ($end > $numMessages)
233 $end_loop = $numMessages - $startMessage +
1;
235 $end_loop = $show_num;
240 while ($j < $end_loop) {
241 if (isset($date[$j])) {
242 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
243 $tmpdate = explode(' ', trim($date[$j]));
245 $tmpdate = $date = array("","","","","","");
248 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
249 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
250 $messages[$j]['ID'] = $id[$j];
251 $messages[$j]['FROM'] = decodeHeader($from[$j]);
252 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
253 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
254 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
255 $messages[$j]['TO'] = decodeHeader($to[$j]);
256 $messages[$j]['PRIORITY'] = $priority[$j];
257 $messages[$j]['CC'] = $cc[$j];
258 $messages[$j]['SIZE'] = $size[$j];
259 $messages[$j]['TYPE0'] = $type[$j];
261 # fix SUBJECT-SORT to remove Re:
262 $re_abbr = # Add more here!
263 'vedr|sv|' . # Danish
265 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
266 $messages[$j]['SUBJECT-SORT'] = $regs[2];
269 while ($num < count($flags[$j])) {
270 if ($flags[$j][$num] == 'Deleted') {
271 $messages[$j]['FLAG_DELETED'] = true;
273 elseif ($flags[$j][$num] == 'Answered') {
274 $messages[$j]['FLAG_ANSWERED'] = true;
276 elseif ($flags[$j][$num] == 'Seen') {
277 $messages[$j]['FLAG_SEEN'] = true;
279 elseif ($flags[$j][$num] == 'Flagged') {
280 $messages[$j]['FLAG_FLAGGED'] = true;
287 /* Only ignore messages flagged as deleted if we are using a
288 * trash folder or auto_expunge */
289 if (((isset($move_to_trash) && $move_to_trash)
290 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
292 /** Find and remove the ones that are deleted */
295 while ($j < $numMessages) {
296 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
300 $msgs[$i] = $messages[$j];
307 if (! isset($messages))
313 // There's gotta be messages in the array for it to sort them.
314 if ($numMessages > 0 && ! $use_cache) {
315 /** 0 = Date (up) 4 = Subject (up)
316 ** 1 = Date (dn) 5 = Subject (dn)
320 session_unregister("msgs");
321 if (($sort == 0) ||
($sort == 1))
322 $msort = array_cleave ($msgs, 'TIME_STAMP');
323 elseif (($sort == 2) ||
($sort == 3))
324 $msort = array_cleave ($msgs, 'FROM-SORT');
325 elseif (($sort == 4) ||
($sort == 5))
326 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
337 session_register('msort');
339 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
340 session_register('msgs');
343 // generic function to convert the msgs array into an HTML table
344 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
345 global $folder_prefix, $sent_folder;
346 global $imapServerAddress;
347 global $index_order, $real_endMessage, $real_startMessage, $checkall;
349 // if cache isn't already set, do it now
350 if (!session_is_registered('msgs'))
351 session_register('msgs');
352 if (!session_is_registered('msort'))
353 session_register('msort');
355 if ($startMessage +
($show_num - 1) < $numMessages) {
356 $endMessage = $startMessage +
($show_num-1);
358 $endMessage = $numMessages;
361 if ($endMessage < $startMessage) {
362 $startMessage = $startMessage - $show_num;
363 if ($startMessage < 1)
367 $nextGroup = $startMessage +
$show_num;
368 $prevGroup = $startMessage - $show_num;
369 $urlMailbox = urlencode($mailbox);
371 do_hook('mailbox_index_before');
374 if ($startMessage < $endMessage) {
375 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
376 } elseif ($startMessage == $endMessage) {
377 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
386 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
387 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
388 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
390 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
391 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
392 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
394 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
395 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
396 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
401 mail_message_listing_beginning($imapConnection,
402 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
403 $mailbox, $sort, $Message, $More, $startMessage);
405 $groupNum = $startMessage %
($show_num - 1);
406 $real_startMessage = $startMessage;
408 if ($endMessage - $startMessage < $show_num - 1) {
409 $endMessage = $endMessage - $startMessage +
1;
411 } else if ($startMessage > $show_num) {
412 $endMessage = $show_num;
417 $endVar = $endMessage +
1;
419 // loop through and display the info for each message.
420 $t = 0; // $t is used for the checkbox number
421 if ($numMessages == 0) { // if there's no messages in this folder
422 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
423 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
424 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
435 } while (isset ($key) && ($k < $i));
436 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
446 } while (isset ($key) && ($k < $i));
449 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
454 } while ($i && $i < $endVar);
456 echo '</TABLE></FORM>';
460 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
461 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
462 echo "$More</td><td align=right>\n";
463 if (!$startMessage) $startMessage=1;
464 ShowSelectAllLink($startMessage, $sort);
466 echo '</td></tr></table>';
468 echo '</table>'; /** End of message-list table */
470 do_hook('mailbox_index_after');
473 /* Displays the standard message list header.
474 * To finish the table, you need to do a "</table></table>";
475 * $moveURL is the URL to submit the delete/move form to
476 * $mailbox is the current mailbox
477 * $sort is the current sorting method (-1 for no sorting available [searches])
478 * $Message is a message that is centered on top of the list
479 * $More is a second line that is left aligned
481 function mail_message_listing_beginning($imapConnection, $moveURL,
482 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
484 global $color, $index_order, $auto_expunge, $move_to_trash;
485 global $checkall, $sent_folder;
486 $urlMailbox = urlencode($mailbox);
487 /** This is the beginning of the message list table. It wraps around all messages */
488 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
492 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
495 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
496 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
497 echo "$More</td><td align=right>\n";
498 ShowSelectAllLink($startMessage, $sort);
500 echo '</td></tr></table>';
503 /** The delete and move options */
504 echo "<TR><TD BGCOLOR=\"$color[0]\">";
506 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
507 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
509 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
512 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
513 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
515 $boxes = sqimap_mailbox_list($imapConnection);
516 for ($i = 0; $i < count($boxes); $i++
) {
517 if (!in_array("noselect", $boxes[$i]['flags'])) {
518 $box = $boxes[$i]['unformatted'];
519 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
520 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
523 echo ' </SELECT></SMALL></TT>';
524 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
526 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
527 if (! $auto_expunge) {
528 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
530 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
535 do_hook('mailbox_form_before');
538 echo "<TR><TD BGCOLOR=\"$color[0]\">";
539 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
540 if ($GLOBALS['alt_index_colors']) {
545 echo " BGCOLOR=\"$color[0]\">";
546 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
549 for ($i=1; $i <= count($index_order); $i++
) {
550 switch ($index_order[$i]) {
553 echo ' <TD WIDTH="1%"><B> </B></TD>';
557 if ($mailbox == $sent_folder)
558 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
560 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
561 ShowSortButton($sort, $mailbox, 2, 3);
566 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
567 ShowSortButton($sort, $mailbox, 0, 1);
572 echo ' <TD><B>'. _("Subject") .'</B> ';
573 ShowSortButton($sort, $mailbox, 4, 5);
578 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
585 function ShowSortButton($sort, $mailbox, $Up, $Down) {
586 if ($sort != $Up && $sort != $Down) {
587 $img = 'sort_none.gif';
589 } elseif ($sort == $Up) {
590 $img = 'up_pointer.gif';
593 $img = 'down_pointer.gif';
596 echo ' <a href="right_main.php?newsort=' . $which .
597 '&startMessage=1&mailbox=' . urlencode($mailbox) .
598 '"><IMG SRC="../images/' . $img .
599 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
602 function ShowSelectAllLink($startMessage, $sort)
604 global $checkall, $PHP_SELF, $what, $where, $mailbox;
606 // This code is from Philippe Mingo <mingo@rotedic.com>
609 <script language
="JavaScript">
611 function CheckAll() {
612 for (var i
= 0; i
< document
.messageList
.elements
.length
; i++
) {
613 if( document
.messageList
.elements
[i
].name
.substr( 0, 3 ) == 'msg') {
614 document
.messageList
.elements
[i
].checked
=
615 !(document
.messageList
.elements
[i
].checked
);
619 window
.document
.write('<a href="#" onClick="CheckAll();"><?php echo
620 _("Toggle All") ?></A>');
625 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
626 "&startMessage=$startMessage&sort=$sort&checkall=";
627 if (isset($checkall) && $checkall == '1')
631 if (isset($where) && isset($what))
632 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
634 if (isset($checkall) && $checkall == '1')
635 echo _("Unselect All");
637 echo _("Select All");
639 echo "</A>\n</noscript>\n";
642 function processSubject($subject)
644 // Shouldn't ever happen -- caught too many times in the IMAP functions
646 return _("(no subject)");
648 if (strlen($subject) <= 55)
651 $ent_strlen=strlen($subject);
654 // see if this is entities-encoded string
655 // If so, Iterate through the whole string, find out
656 // the real number of characters, and if more
657 // than 55, substr with an updated trim value.
658 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
659 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
661 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
662 $ent_strlen -= $ent_loc_end-$ent_loc;
663 $ent_offset = $ent_loc_end+
1;
666 if ($ent_strlen <= 55)
669 return substr($subject, 0, $trim_val) . '...';