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 define( 'PG_SEL_MAX', 10 ); // Default value for page_selector_max
18 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
20 global $color, $msgs, $msort;
22 global $message_highlight_list;
25 $color_string = $color[4];
26 if ($GLOBALS['alt_index_colors']) {
27 if (!isset($GLOBALS["row_count"])) {
28 $GLOBALS["row_count"] = 0;
30 $GLOBALS["row_count"]++
;
31 if ($GLOBALS["row_count"] %
2) {
32 if (!isset($color[12])) $color[12] = '#EAEAEA';
33 $color_string = $color[12];
39 $senderName = sqimap_find_displayable_name($msg['FROM']);
40 if( $mailbox == _("None") ) {
41 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
42 $boxes = sqimap_mailbox_list($imapConnection);
43 // sqimap_logout($imapConnection);
44 $mailbox = $boxes[0]['unformatted'];
47 $urlMailbox = urlencode($mailbox);
48 $subject = processSubject($msg['SUBJECT']);
52 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
54 $flag = "<font color=$color[2]>";
55 $flag_end = '</font>';
62 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
72 if ($mailbox == $sent_folder)
82 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
84 $fontstr = "<font color=\"$color[9]\">";
85 $fontstr_end = '</font>';
93 for ($i=0; $i < count($message_highlight_list); $i++
) {
94 if (trim($message_highlight_list[$i]['value']) != '') {
95 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
96 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
97 $hlt_color = $message_highlight_list[$i]['color'];
100 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
101 $hlt_color = $message_highlight_list[$i]['color'];
107 if (!isset($hlt_color))
108 $hlt_color = $color_string;
110 if ($where && $what) {
111 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
115 $checked = ' checked';
119 for ($i=1; $i <= count($index_order); $i++
) {
120 switch ($index_order[$i]) {
122 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
125 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
128 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
131 echo " <td bgcolor=$hlt_color>$bold";
132 if (! isset($search_stuff)) { $search_stuff = ''; }
133 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
134 do_hook("subject_link");
136 if ($subject != $msg['SUBJECT']) {
137 $title = get_html_translation_table(HTML_SPECIALCHARS
);
138 $title = array_flip($title);
139 $title = strtr($msg['SUBJECT'], $title);
140 $title = str_replace('"', "''", $title);
141 echo " title=\"$title\"";
143 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
147 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
148 if (isset($msg['FLAG_ANSWERED']) &&
149 $msg['FLAG_ANSWERED'] == true) {
153 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
154 echo "<font color=$color[8]>v</font>\n";
157 if ($msg['TYPE0'] == 'multipart') {
161 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
162 echo "<font color=$color[1]>!</font>\n";
165 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
166 echo "<font color=\"$color[1]\">D</font>\n";
170 if (!$stuff) echo " \n";
171 echo "</small></b></td>\n";
174 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
184 ** This function loops through a group of messages in the mailbox and shows them
186 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
187 global $msgs, $msort;
189 global $message_highlight_list;
190 global $auto_expunge;
192 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
193 sqimap_mailbox_select($imapConnection, $mailbox);
195 $issent = ($mailbox == $sent_folder);
198 if ($numMessages >= 1) {
200 $id = range(1, $numMessages);
202 // if it's not sorted
203 if ($startMessage +
($show_num - 1) < $numMessages) {
204 $endMessage = $startMessage +
($show_num-1);
206 $endMessage = $numMessages;
209 if ($endMessage < $startMessage) {
210 $startMessage = $startMessage - $show_num;
211 if ($startMessage < 1)
215 $real_startMessage = $numMessages - $startMessage +
1;
216 $real_endMessage = $numMessages - $startMessage - $show_num +
2;
217 if ($real_endMessage <= 0)
218 $real_endMessage = 1;
219 $id = array_reverse(range($real_endMessage, $real_startMessage));
222 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
223 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
224 foreach ($msgs_list as $hdr) {
225 $from[] = $hdr->from
;
226 $date[] = $hdr->date
;
227 $subject[] = $hdr->subject
;
229 $priority[] = $hdr->priority
;
231 $size[] = $hdr->size
;
232 $type[] = $hdr->type0
;
238 $end = $startMessage +
$show_num - 1;
239 if ($numMessages < $show_num)
240 $end_loop = $numMessages;
241 elseif ($end > $numMessages)
242 $end_loop = $numMessages - $startMessage +
1;
244 $end_loop = $show_num;
249 while ($j < $end_loop) {
250 if (isset($date[$j])) {
251 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
252 $tmpdate = explode(' ', trim($date[$j]));
254 $tmpdate = $date = array("","","","","","");
257 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
258 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
259 $messages[$j]['ID'] = $id[$j];
260 $messages[$j]['FROM'] = decodeHeader($from[$j]);
261 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
262 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
263 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
264 $messages[$j]['TO'] = decodeHeader($to[$j]);
265 $messages[$j]['PRIORITY'] = $priority[$j];
266 $messages[$j]['CC'] = $cc[$j];
267 $messages[$j]['SIZE'] = $size[$j];
268 $messages[$j]['TYPE0'] = $type[$j];
270 # fix SUBJECT-SORT to remove Re:
271 $re_abbr = # Add more here!
272 'vedr|sv|' . # Danish
275 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
276 $messages[$j]['SUBJECT-SORT'] = $regs[2];
279 while ($num < count($flags[$j])) {
280 if ($flags[$j][$num] == 'Deleted') {
281 $messages[$j]['FLAG_DELETED'] = true;
283 elseif ($flags[$j][$num] == 'Answered') {
284 $messages[$j]['FLAG_ANSWERED'] = true;
286 elseif ($flags[$j][$num] == 'Seen') {
287 $messages[$j]['FLAG_SEEN'] = true;
289 elseif ($flags[$j][$num] == 'Flagged') {
290 $messages[$j]['FLAG_FLAGGED'] = true;
297 /* Only ignore messages flagged as deleted if we are using a
298 * trash folder or auto_expunge */
299 if (((isset($move_to_trash) && $move_to_trash)
300 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
302 /** Find and remove the ones that are deleted */
305 while ($j < $numMessages) {
306 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
310 $msgs[$i] = $messages[$j];
317 if (! isset($messages))
323 // There's gotta be messages in the array for it to sort them.
324 if ($numMessages > 0 && ! $use_cache) {
325 /** 0 = Date (up) 4 = Subject (up)
326 ** 1 = Date (dn) 5 = Subject (dn)
330 session_unregister("msgs");
331 if (($sort == 0) ||
($sort == 1))
332 $msort = array_cleave ($msgs, 'TIME_STAMP');
333 elseif (($sort == 2) ||
($sort == 3))
334 $msort = array_cleave ($msgs, 'FROM-SORT');
335 elseif (($sort == 4) ||
($sort == 5))
336 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
347 session_register('msort');
349 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
350 session_register('msgs');
353 // generic function to convert the msgs array into an HTML table
354 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
355 global $folder_prefix, $sent_folder;
356 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
357 global $index_order, $real_endMessage, $real_startMessage, $checkall;
359 // if cache isn't already set, do it now
360 if (!session_is_registered('msgs'))
361 session_register('msgs');
362 if (!session_is_registered('msort'))
363 session_register('msort');
365 if ($startMessage +
($show_num - 1) < $numMessages) {
366 $endMessage = $startMessage +
($show_num-1);
368 $endMessage = $numMessages;
371 if ($endMessage < $startMessage) {
372 $startMessage = $startMessage - $show_num;
373 if ($startMessage < 1)
377 $nextGroup = $startMessage +
$show_num;
378 $prevGroup = $startMessage - $show_num;
379 $urlMailbox = urlencode($mailbox);
381 do_hook('mailbox_index_before');
384 if ($startMessage < $endMessage) {
385 $Message = _("Viewing messages") .":<B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
386 } elseif ($startMessage == $endMessage) {
387 $Message = _("Viewing message") .":<B>$startMessage</B> ($numMessages " . _("total") . ")\n";
397 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
398 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
399 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
401 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
402 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
403 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
405 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
406 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
407 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
412 // Page selector block. Following code computes page links.
414 if( !getPref($data_dir, $username, 'page_selector') &&
415 $numMessages > $show_num ) {
416 $j = intval( $numMessages / $show_num ); // Max pages
417 $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
) );
418 if( $numMessages %
$show_num <> 0 )
420 $startMessage = min( $startMessage, $numMessages );
421 $p = intval( $startMessage / $show_num ) +
1;
425 $start = ( ($pg-1) * $show_num ) +
1;
426 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
427 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
430 $mMore .= "<b>$p</b> ";
434 $start = ( ($pg-1) * $show_num ) +
1;
435 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
436 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
444 mail_message_listing_beginning($imapConnection,
445 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
446 $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
448 $groupNum = $startMessage %
($show_num - 1);
449 $real_startMessage = $startMessage;
451 if ($endMessage - $startMessage < $show_num - 1) {
452 $endMessage = $endMessage - $startMessage +
1;
454 } else if ($startMessage > $show_num) {
455 $endMessage = $show_num;
460 $endVar = $endMessage +
1;
462 // loop through and display the info for each message.
463 $t = 0; // $t is used for the checkbox number
464 if ($numMessages == 0) { // if there's no messages in this folder
465 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
466 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
467 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
478 } while (isset ($key) && ($k < $i));
479 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
489 } while (isset ($key) && ($k < $i));
492 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
497 } while ($i && $i < $endVar);
500 echo "<TR BGCOLOR=\"$color[5]\"><TD colspan=5><table width=100%><tr ><td>$lMore$mMore$rMore</td><td align=right>$Message</td></tr></table></td></tr></table>";
501 /** End of message-list table */
503 do_hook('mailbox_index_after');
504 echo "</TABLE></FORM>\n";
507 /* Displays the standard message list header.
508 * To finish the table, you need to do a "</table></table>";
509 * $moveURL is the URL to submit the delete/move form to
510 * $mailbox is the current mailbox
511 * $sort is the current sorting method (-1 for no sorting available [searches])
512 * $Message is a message that is centered on top of the list
513 * $More is a second line that is left aligned
515 function mail_message_listing_beginning($imapConnection, $moveURL,
516 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
518 global $color, $index_order, $auto_expunge, $move_to_trash;
519 global $checkall, $sent_folder;
520 $urlMailbox = urlencode($mailbox);
522 /** This is the beginning of the message list table. It wraps around all messages */
523 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
525 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
527 /** The delete and move options */
528 echo "<TR><TD BGCOLOR=\"$color[0]\">";
530 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
531 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
534 echo "<tr bgcolor=\"$color[4]\"><td colspan=3>\n" .
535 "<table bgcolor=\"$color[4]\" cellpadding=2".
536 ' width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>' .
537 "$More</td><td align=right>";
538 ShowSelectAllLink($startMessage, $sort);
539 echo "</td></tr></table>\n</td></tr>";
542 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
543 ' <SMALL> ' . _("Move selected to:") . "</SMALL>\n" .
545 " <TD ALIGN=RIGHT NOWRAP>\n" .
546 ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n" .
550 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
551 ' <SMALL> <TT><SELECT NAME="targetMailbox">';
553 $boxes = sqimap_mailbox_list($imapConnection);
554 for ($i = 0; $i < count($boxes); $i++
) {
555 if (!in_array("noselect", $boxes[$i]['flags'])) {
556 $box = $boxes[$i]['unformatted'];
557 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
558 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
561 echo ' </SELECT></TT></SMALL>';
562 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
564 echo " <TD ALIGN=RIGHT NOWRAP> \n";
565 if (! $auto_expunge) {
566 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n";
569 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
570 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
571 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n";
576 do_hook('mailbox_form_before');
580 echo "<TR><TD BGCOLOR=\"$color[0]\">";
581 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
582 if ($GLOBALS['alt_index_colors']) {
587 echo " BGCOLOR=\"$color[0]\">";
588 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
591 for ($i=1; $i <= count($index_order); $i++
) {
592 switch ($index_order[$i]) {
595 echo ' <TD WIDTH="1%"><B> </B></TD>';
599 if ($mailbox == $sent_folder)
600 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
602 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
603 ShowSortButton($sort, $mailbox, 2, 3);
608 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
609 ShowSortButton($sort, $mailbox, 0, 1);
614 echo ' <TD><B>'. _("Subject") .'</B> ';
615 ShowSortButton($sort, $mailbox, 4, 5);
620 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
627 /* ----------------------------------------------------------------------- */
629 function ShowSortButton($sort, $mailbox, $Up, $Down) {
630 if ($sort != $Up && $sort != $Down) {
631 $img = 'sort_none.gif';
633 } elseif ($sort == $Up) {
634 $img = 'up_pointer.gif';
637 $img = 'down_pointer.gif';
640 echo ' <a href="right_main.php?newsort=' . $which .
641 '&startMessage=1&mailbox=' . urlencode($mailbox) .
642 '"><IMG SRC="../images/' . $img .
643 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
646 function ShowSelectAllLink($startMessage, $sort)
648 global $checkall, $PHP_SELF, $what, $where, $mailbox;
651 <script language
="JavaScript">
653 function CheckAll() {
654 for (var i
= 0; i
< document
.messageList
.elements
.length
; i++
) {
655 if( document
.messageList
.elements
[i
].type
== 'checkbox' ) {
656 document
.messageList
.elements
[i
].checked
=
657 !(document
.messageList
.elements
[i
].checked
);
661 window
.document
.write('<input type=button onClick="CheckAll();" value="<?php echo
662 _("Toggle All") ?>">');
667 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
668 "&startMessage=$startMessage&sort=$sort&checkall=";
669 if (isset($checkall) && $checkall == '1')
673 if (isset($where) && isset($what))
674 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
676 if (isset($checkall) && $checkall == '1')
677 echo _("Unselect All");
679 echo _("Select All");
681 echo "</A>\n</noscript>\n";
684 function processSubject($subject)
686 // Shouldn't ever happen -- caught too many times in the IMAP functions
688 return _("(no subject)");
690 if (strlen($subject) <= 55)
693 $ent_strlen=strlen($subject);
696 // see if this is entities-encoded string
697 // If so, Iterate through the whole string, find out
698 // the real number of characters, and if more
699 // than 55, substr with an updated trim value.
700 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
701 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
703 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
704 $ent_strlen -= $ent_loc_end-$ent_loc;
705 $ent_offset = $ent_loc_end+
1;
708 if ($ent_strlen <= 55)
711 return substr($subject, 0, $trim_val) . '...';