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 ($msg['TYPE0'] == 'multipart') {
148 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
149 echo "<font color=$color[1]>!</font>\n";
152 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
153 echo "<font color=\"$color[1]\">D</font>\n";
157 if (!$stuff) echo " \n";
158 echo "</small></b></td>\n";
161 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
171 ** This function loops through a group of messages in the mailbox and shows them
173 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
174 global $msgs, $msort;
176 global $message_highlight_list;
177 global $auto_expunge;
179 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
180 sqimap_mailbox_select($imapConnection, $mailbox);
182 $issent = ($mailbox == $sent_folder);
185 if ($numMessages >= 1) {
187 $id = range(1, $numMessages);
189 // if it's not sorted
190 if ($startMessage +
($show_num - 1) < $numMessages) {
191 $endMessage = $startMessage +
($show_num-1);
193 $endMessage = $numMessages;
196 if ($endMessage < $startMessage) {
197 $startMessage = $startMessage - $show_num;
198 if ($startMessage < 1)
202 $real_startMessage = $numMessages - $startMessage +
1;
203 $real_endMessage = $numMessages - $startMessage - $show_num +
2;
204 if ($real_endMessage <= 0)
205 $real_endMessage = 1;
206 $id = array_reverse(range($real_endMessage, $real_startMessage));
209 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
210 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
211 foreach ($msgs_list as $hdr) {
212 $from[] = $hdr->from
;
213 $date[] = $hdr->date
;
214 $subject[] = $hdr->subject
;
216 $priority[] = $hdr->priority
;
218 $size[] = $hdr->size
;
219 $type[] = $hdr->type0
;
225 $end = $startMessage +
$show_num - 1;
226 if ($numMessages < $show_num)
227 $end_loop = $numMessages;
228 elseif ($end > $numMessages)
229 $end_loop = $numMessages - $startMessage +
1;
231 $end_loop = $show_num;
236 while ($j < $end_loop) {
237 if (isset($date[$j])) {
238 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
239 $tmpdate = explode(' ', trim($date[$j]));
241 $tmpdate = $date = array("","","","","","");
244 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
245 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
246 $messages[$j]['ID'] = $id[$j];
247 $messages[$j]['FROM'] = decodeHeader($from[$j]);
248 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
249 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
250 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
251 $messages[$j]['TO'] = decodeHeader($to[$j]);
252 $messages[$j]['PRIORITY'] = $priority[$j];
253 $messages[$j]['CC'] = $cc[$j];
254 $messages[$j]['SIZE'] = $size[$j];
255 $messages[$j]['TYPE0'] = $type[$j];
257 # fix SUBJECT-SORT to remove Re:
258 $re_abbr = # Add more here!
259 'vedr|sv|' . # Danish
261 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
262 $messages[$j]['SUBJECT-SORT'] = $regs[2];
265 while ($num < count($flags[$j])) {
266 if ($flags[$j][$num] == 'Deleted') {
267 $messages[$j]['FLAG_DELETED'] = true;
269 elseif ($flags[$j][$num] == 'Answered') {
270 $messages[$j]['FLAG_ANSWERED'] = true;
272 elseif ($flags[$j][$num] == 'Seen') {
273 $messages[$j]['FLAG_SEEN'] = true;
275 elseif ($flags[$j][$num] == 'Flagged') {
276 $messages[$j]['FLAG_FLAGGED'] = true;
283 /* Only ignore messages flagged as deleted if we are using a
284 * trash folder or auto_expunge */
285 if (((isset($move_to_trash) && $move_to_trash)
286 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
288 /** Find and remove the ones that are deleted */
291 while ($j < $numMessages) {
292 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
296 $msgs[$i] = $messages[$j];
303 if (! isset($messages))
309 // There's gotta be messages in the array for it to sort them.
310 if ($numMessages > 0 && ! $use_cache) {
311 /** 0 = Date (up) 4 = Subject (up)
312 ** 1 = Date (dn) 5 = Subject (dn)
316 session_unregister("msgs");
317 if (($sort == 0) ||
($sort == 1))
318 $msort = array_cleave ($msgs, 'TIME_STAMP');
319 elseif (($sort == 2) ||
($sort == 3))
320 $msort = array_cleave ($msgs, 'FROM-SORT');
321 elseif (($sort == 4) ||
($sort == 5))
322 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
333 session_register('msort');
335 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
336 session_register('msgs');
339 // generic function to convert the msgs array into an HTML table
340 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
341 global $folder_prefix, $sent_folder;
342 global $imapServerAddress;
343 global $index_order, $real_endMessage, $real_startMessage, $checkall;
345 // if cache isn't already set, do it now
346 if (!session_is_registered('msgs'))
347 session_register('msgs');
348 if (!session_is_registered('msort'))
349 session_register('msort');
351 if ($startMessage +
($show_num - 1) < $numMessages) {
352 $endMessage = $startMessage +
($show_num-1);
354 $endMessage = $numMessages;
357 if ($endMessage < $startMessage) {
358 $startMessage = $startMessage - $show_num;
359 if ($startMessage < 1)
363 $nextGroup = $startMessage +
$show_num;
364 $prevGroup = $startMessage - $show_num;
365 $urlMailbox = urlencode($mailbox);
367 do_hook('mailbox_index_before');
370 if ($startMessage < $endMessage) {
371 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
372 } elseif ($startMessage == $endMessage) {
373 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
382 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
383 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
384 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
386 elseif (($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 .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
390 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
391 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
392 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
397 mail_message_listing_beginning($imapConnection,
398 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
399 $mailbox, $sort, $Message, $More, $startMessage);
401 $groupNum = $startMessage %
($show_num - 1);
402 $real_startMessage = $startMessage;
404 if ($endMessage - $startMessage < $show_num - 1) {
405 $endMessage = $endMessage - $startMessage +
1;
407 } else if ($startMessage > $show_num) {
408 $endMessage = $show_num;
413 $endVar = $endMessage +
1;
415 // loop through and display the info for each message.
416 $t = 0; // $t is used for the checkbox number
417 if ($numMessages == 0) { // if there's no messages in this folder
418 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
419 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
420 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
431 } while (isset ($key) && ($k < $i));
432 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
442 } while (isset ($key) && ($k < $i));
445 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
450 } while ($i && $i < $endVar);
452 echo '</TABLE></FORM>';
456 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
457 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
458 echo "$More</td><td align=right>\n";
459 if (!$startMessage) $startMessage=1;
460 ShowSelectAllLink($startMessage, $sort);
462 echo '</td></tr></table>';
464 echo '</table>'; /** End of message-list table */
466 do_hook('mailbox_index_after');
469 /* Displays the standard message list header.
470 * To finish the table, you need to do a "</table></table>";
471 * $moveURL is the URL to submit the delete/move form to
472 * $mailbox is the current mailbox
473 * $sort is the current sorting method (-1 for no sorting available [searches])
474 * $Message is a message that is centered on top of the list
475 * $More is a second line that is left aligned
477 function mail_message_listing_beginning($imapConnection, $moveURL,
478 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
480 global $color, $index_order, $auto_expunge, $move_to_trash;
481 global $checkall, $sent_folder;
482 $urlMailbox = urlencode($mailbox);
483 /** This is the beginning of the message list table. It wraps around all messages */
484 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
488 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
491 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
492 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
493 echo "$More</td><td align=right>\n";
494 ShowSelectAllLink($startMessage, $sort);
496 echo '</td></tr></table>';
499 /** The delete and move options */
500 echo "<TR><TD BGCOLOR=\"$color[0]\">";
502 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
503 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
505 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
508 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
509 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
511 $boxes = sqimap_mailbox_list($imapConnection);
512 for ($i = 0; $i < count($boxes); $i++
) {
513 if (!in_array("noselect", $boxes[$i]['flags'])) {
514 $box = $boxes[$i]['unformatted'];
515 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
516 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
519 echo ' </SELECT></SMALL></TT>';
520 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
522 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
523 if (! $auto_expunge) {
524 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
526 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
531 do_hook('mailbox_form_before');
534 echo "<TR><TD BGCOLOR=\"$color[0]\">";
535 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
536 if ($GLOBALS['alt_index_colors']) {
541 echo " BGCOLOR=\"$color[0]\">";
542 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
545 for ($i=1; $i <= count($index_order); $i++
) {
546 switch ($index_order[$i]) {
549 echo ' <TD WIDTH="1%"><B> </B></TD>';
553 if ($mailbox == $sent_folder)
554 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
556 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
557 ShowSortButton($sort, $mailbox, 2, 3);
562 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
563 ShowSortButton($sort, $mailbox, 0, 1);
568 echo ' <TD><B>'. _("Subject") .'</B> ';
569 ShowSortButton($sort, $mailbox, 4, 5);
574 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
581 function ShowSortButton($sort, $mailbox, $Up, $Down) {
582 if ($sort != $Up && $sort != $Down) {
583 $img = 'sort_none.gif';
585 } elseif ($sort == $Up) {
586 $img = 'up_pointer.gif';
589 $img = 'down_pointer.gif';
592 echo ' <a href="right_main.php?newsort=' . $which .
593 '&startMessage=1&mailbox=' . urlencode($mailbox) .
594 '"><IMG SRC="../images/' . $img .
595 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
598 function ShowSelectAllLink($startMessage, $sort)
600 global $checkall, $PHP_SELF, $what, $where, $mailbox;
602 // This code is from Philippe Mingo <mingo@rotedic.com>
605 <script language
="JavaScript">
607 function CheckAll() {
608 for (var i
= 0; i
< document
.messageList
.elements
.length
; i++
) {
609 if( document
.messageList
.elements
[i
].name
.substr( 0, 3 ) == 'msg') {
610 document
.messageList
.elements
[i
].checked
=
611 !(document
.messageList
.elements
[i
].checked
);
615 window
.document
.write('<a href="#" onClick="CheckAll();"><?php echo
616 _("Toggle All") ?></A>');
621 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
622 "&startMessage=$startMessage&sort=$sort&checkall=";
623 if (isset($checkall) && $checkall == '1')
627 if (isset($where) && isset($what))
628 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
630 if (isset($checkall) && $checkall == '1')
631 echo _("Unselect All");
633 echo _("Select All");
635 echo "</A>\n</noscript>\n";
638 function processSubject($subject)
640 // Shouldn't ever happen -- caught too many times in the IMAP functions
642 return _("(no subject)");
644 if (strlen($subject) <= 55)
647 $ent_strlen=strlen($subject);
650 // see if this is entities-encoded string
651 // If so, Iterate through the whole string, find out
652 // the real number of characters, and if more
653 // than 55, substr with an updated trim value.
654 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
655 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
657 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
658 $ent_strlen -= $ent_loc_end-$ent_loc;
659 $ent_offset = $ent_loc_end+
1;
662 if ($ent_strlen <= 55)
665 return substr($subject, 0, $trim_val) . '...';