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");
126 echo " title=\"" . urlencode($msg['SUBJECT']) .
127 "\">$flag$subject$flag_end</a>$bold_end</td>\n";
131 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
132 if (isset($msg['FLAG_ANSWERED']) &&
133 $msg['FLAG_ANSWERED'] == true) {
137 if ($msg['TYPE0'] == 'multipart') {
141 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
142 echo "<font color=$color[1]>!</font>\n";
145 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
146 echo "<font color=\"$color[1]\">D</font>\n";
150 if (!$stuff) echo " \n";
151 echo "</small></b></td>\n";
154 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
164 ** This function loops through a group of messages in the mailbox and shows them
166 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
167 global $msgs, $msort;
169 global $message_highlight_list;
170 global $auto_expunge;
172 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
173 sqimap_mailbox_select($imapConnection, $mailbox);
175 $issent = ($mailbox == $sent_folder);
178 if ($numMessages >= 1) {
180 $id = range(1, $numMessages);
182 // if it's not sorted
183 if ($startMessage +
($show_num - 1) < $numMessages) {
184 $endMessage = $startMessage +
($show_num-1);
186 $endMessage = $numMessages;
189 if ($endMessage < $startMessage) {
190 $startMessage = $startMessage - $show_num;
191 if ($startMessage < 1)
195 $real_startMessage = $numMessages - $startMessage +
1;
196 $real_endMessage = $numMessages - $startMessage - $show_num +
2;
197 if ($real_endMessage <= 0)
198 $real_endMessage = 1;
199 $id = array_reverse(range($real_endMessage, $real_startMessage));
202 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
203 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
204 foreach ($msgs_list as $hdr) {
205 $from[] = $hdr->from
;
206 $date[] = $hdr->date
;
207 $subject[] = $hdr->subject
;
209 $priority[] = $hdr->priority
;
211 $size[] = $hdr->size
;
212 $type[] = $hdr->type0
;
218 $end = $startMessage +
$show_num - 1;
219 if ($numMessages < $show_num)
220 $end_loop = $numMessages;
221 elseif ($end > $numMessages)
222 $end_loop = $numMessages - $startMessage +
1;
224 $end_loop = $show_num;
229 while ($j < $end_loop) {
230 if (isset($date[$j])) {
231 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
232 $tmpdate = explode(' ', trim($date[$j]));
234 $tmpdate = $date = array("","","","","","");
237 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
238 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
239 $messages[$j]['ID'] = $id[$j];
240 $messages[$j]['FROM'] = decodeHeader($from[$j]);
241 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
242 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
243 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
244 $messages[$j]['TO'] = decodeHeader($to[$j]);
245 $messages[$j]['PRIORITY'] = $priority[$j];
246 $messages[$j]['CC'] = $cc[$j];
247 $messages[$j]['SIZE'] = $size[$j];
248 $messages[$j]['TYPE0'] = $type[$j];
250 # fix SUBJECT-SORT to remove Re:
251 $re_abbr = # Add more here!
252 'vedr|sv|' . # Danish
254 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
255 $messages[$j]['SUBJECT-SORT'] = $regs[2];
258 while ($num < count($flags[$j])) {
259 if ($flags[$j][$num] == 'Deleted') {
260 $messages[$j]['FLAG_DELETED'] = true;
262 elseif ($flags[$j][$num] == 'Answered') {
263 $messages[$j]['FLAG_ANSWERED'] = true;
265 elseif ($flags[$j][$num] == 'Seen') {
266 $messages[$j]['FLAG_SEEN'] = true;
268 elseif ($flags[$j][$num] == 'Flagged') {
269 $messages[$j]['FLAG_FLAGGED'] = true;
276 /* Only ignore messages flagged as deleted if we are using a
277 * trash folder or auto_expunge */
278 if (((isset($move_to_trash) && $move_to_trash)
279 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
281 /** Find and remove the ones that are deleted */
284 while ($j < $numMessages) {
285 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
289 $msgs[$i] = $messages[$j];
296 if (! isset($messages))
302 // There's gotta be messages in the array for it to sort them.
303 if ($numMessages > 0 && ! $use_cache) {
304 /** 0 = Date (up) 4 = Subject (up)
305 ** 1 = Date (dn) 5 = Subject (dn)
309 session_unregister("msgs");
310 if (($sort == 0) ||
($sort == 1))
311 $msort = array_cleave ($msgs, 'TIME_STAMP');
312 elseif (($sort == 2) ||
($sort == 3))
313 $msort = array_cleave ($msgs, 'FROM-SORT');
314 elseif (($sort == 4) ||
($sort == 5))
315 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
326 session_register('msort');
328 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
329 session_register('msgs');
332 // generic function to convert the msgs array into an HTML table
333 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
334 global $folder_prefix, $sent_folder;
335 global $imapServerAddress;
336 global $index_order, $real_endMessage, $real_startMessage, $checkall;
338 // if cache isn't already set, do it now
339 if (!session_is_registered('msgs'))
340 session_register('msgs');
341 if (!session_is_registered('msort'))
342 session_register('msort');
344 if ($startMessage +
($show_num - 1) < $numMessages) {
345 $endMessage = $startMessage +
($show_num-1);
347 $endMessage = $numMessages;
350 if ($endMessage < $startMessage) {
351 $startMessage = $startMessage - $show_num;
352 if ($startMessage < 1)
356 $nextGroup = $startMessage +
$show_num;
357 $prevGroup = $startMessage - $show_num;
358 $urlMailbox = urlencode($mailbox);
360 do_hook('mailbox_index_before');
363 if ($startMessage < $endMessage) {
364 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
365 } elseif ($startMessage == $endMessage) {
366 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
375 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
376 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
377 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
379 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
380 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
381 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
383 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
384 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
385 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
390 mail_message_listing_beginning($imapConnection,
391 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
392 $mailbox, $sort, $Message, $More, $startMessage);
394 $groupNum = $startMessage %
($show_num - 1);
395 $real_startMessage = $startMessage;
397 if ($endMessage - $startMessage < $show_num - 1) {
398 $endMessage = $endMessage - $startMessage +
1;
400 } else if ($startMessage > $show_num) {
401 $endMessage = $show_num;
406 $endVar = $endMessage +
1;
408 // loop through and display the info for each message.
409 $t = 0; // $t is used for the checkbox number
410 if ($numMessages == 0) { // if there's no messages in this folder
411 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
412 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
413 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
424 } while (isset ($key) && ($k < $i));
425 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
435 } while (isset ($key) && ($k < $i));
438 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
443 } while ($i && $i < $endVar);
445 echo '</TABLE></FORM>';
449 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
450 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
451 echo "$More</td><td align=right>\n";
452 if (!$startMessage) $startMessage=1;
453 ShowSelectAllLink($startMessage, $sort);
455 echo '</td></tr></table>';
457 echo '</table>'; /** End of message-list table */
459 do_hook('mailbox_index_after');
462 /* Displays the standard message list header.
463 * To finish the table, you need to do a "</table></table>";
464 * $moveURL is the URL to submit the delete/move form to
465 * $mailbox is the current mailbox
466 * $sort is the current sorting method (-1 for no sorting available [searches])
467 * $Message is a message that is centered on top of the list
468 * $More is a second line that is left aligned
470 function mail_message_listing_beginning($imapConnection, $moveURL,
471 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
473 global $color, $index_order, $auto_expunge, $move_to_trash;
474 global $checkall, $sent_folder;
475 $urlMailbox = urlencode($mailbox);
476 /** This is the beginning of the message list table. It wraps around all messages */
477 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
481 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
484 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
485 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
486 echo "$More</td><td align=right>\n";
487 ShowSelectAllLink($startMessage, $sort);
489 echo '</td></tr></table>';
492 /** The delete and move options */
493 echo "<TR><TD BGCOLOR=\"$color[0]\">";
495 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
496 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
498 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
501 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
502 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
504 $boxes = sqimap_mailbox_list($imapConnection);
505 for ($i = 0; $i < count($boxes); $i++
) {
506 if (!in_array("noselect", $boxes[$i]['flags'])) {
507 $box = $boxes[$i]['unformatted'];
508 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
509 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
512 echo ' </SELECT></SMALL></TT>';
513 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
515 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
516 if (! $auto_expunge) {
517 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
519 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
524 do_hook('mailbox_form_before');
527 echo "<TR><TD BGCOLOR=\"$color[0]\">";
528 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
529 if ($GLOBALS['alt_index_colors']) {
534 echo " BGCOLOR=\"$color[0]\">";
535 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
538 for ($i=1; $i <= count($index_order); $i++
) {
539 switch ($index_order[$i]) {
542 echo ' <TD WIDTH="1%"><B> </B></TD>';
546 if ($mailbox == $sent_folder)
547 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
549 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
550 ShowSortButton($sort, $mailbox, 2, 3);
555 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
556 ShowSortButton($sort, $mailbox, 0, 1);
561 echo ' <TD><B>'. _("Subject") .'</B> ';
562 ShowSortButton($sort, $mailbox, 4, 5);
567 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
574 function ShowSortButton($sort, $mailbox, $Up, $Down) {
575 if ($sort != $Up && $sort != $Down) {
576 $img = 'sort_none.gif';
578 } elseif ($sort == $Up) {
579 $img = 'up_pointer.gif';
582 $img = 'down_pointer.gif';
585 echo ' <a href="right_main.php?newsort=' . $which .
586 '&startMessage=1&mailbox=' . urlencode($mailbox) .
587 '"><IMG SRC="../images/' . $img .
588 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
591 function ShowSelectAllLink($startMessage, $sort)
593 global $checkall, $PHP_SELF, $what, $where, $mailbox;
595 // This code is from Philippe Mingo <mingo@rotedic.com>
598 <script language
="JavaScript">
600 function CheckAll() {
601 for (var i
= 0; i
< document
.messageList
.elements
.length
; i++
) {
602 if( document
.messageList
.elements
[i
].name
.substr( 0, 3 ) == 'msg') {
603 document
.messageList
.elements
[i
].checked
=
604 !(document
.messageList
.elements
[i
].checked
);
608 window
.document
.write('<a href="#" onClick="CheckAll();"><?php echo
609 _("Toggle All") ?></A>');
614 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
615 "&startMessage=$startMessage&sort=$sort&checkall=";
616 if (isset($checkall) && $checkall == '1')
620 if (isset($where) && isset($what))
621 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
623 if (isset($checkall) && $checkall == '1')
624 echo _("Unselect All");
626 echo _("Select All");
628 echo "</A>\n</noscript>\n";
631 function processSubject($subject)
633 // Shouldn't ever happen -- caught too many times in the IMAP functions
635 return _("(no subject)");
637 if (strlen($subject) <= 55)
640 $ent_strlen=strlen($subject);
643 // see if this is entities-encoded string
644 // If so, Iterate through the whole string, find out
645 // the real number of characters, and if more
646 // than 55, substr with an updated trim value.
647 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
648 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
650 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
651 $ent_strlen -= $ent_loc_end-$ent_loc;
652 $ent_offset = $ent_loc_end+
1;
655 if ($ent_strlen <= 55)
658 return substr($subject, 0, $trim_val) . '...';