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 if( $mailbox == _("None") ) {
39 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40 $boxes = sqimap_mailbox_list($imapConnection);
41 // sqimap_logout($imapConnection);
42 $mailbox = $boxes[0]['unformatted'];
45 $urlMailbox = urlencode($mailbox);
46 $subject = processSubject($msg['SUBJECT']);
50 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
52 $flag = "<font color=$color[2]>";
53 $flag_end = '</font>';
60 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
70 if ($mailbox == $sent_folder)
80 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
82 $fontstr = "<font color=\"$color[9]\">";
83 $fontstr_end = '</font>';
91 for ($i=0; $i < count($message_highlight_list); $i++
) {
92 if (trim($message_highlight_list[$i]['value']) != '') {
93 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
94 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
95 $hlt_color = $message_highlight_list[$i]['color'];
98 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
99 $hlt_color = $message_highlight_list[$i]['color'];
105 if (!isset($hlt_color))
106 $hlt_color = $color_string;
108 if ($where && $what) {
109 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
113 $checked = ' checked';
117 for ($i=1; $i <= count($index_order); $i++
) {
118 switch ($index_order[$i]) {
120 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
123 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
126 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
129 echo " <td bgcolor=$hlt_color>$bold";
130 if (! isset($search_stuff)) { $search_stuff = ''; }
131 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
132 do_hook("subject_link");
134 if ($subject != $msg['SUBJECT']) {
135 $title = get_html_translation_table(HTML_SPECIALCHARS
);
136 $title = array_flip($title);
137 $title = strtr($msg['SUBJECT'], $title);
138 $title = str_replace('"', "''", $title);
139 echo " title=\"$title\"";
141 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
145 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
146 if (isset($msg['FLAG_ANSWERED']) &&
147 $msg['FLAG_ANSWERED'] == true) {
151 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
152 echo "<font color=$color[8]>v</font>\n";
155 if ($msg['TYPE0'] == 'multipart') {
159 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
160 echo "<font color=$color[1]>!</font>\n";
163 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
164 echo "<font color=\"$color[1]\">D</font>\n";
168 if (!$stuff) echo " \n";
169 echo "</small></b></td>\n";
172 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
182 ** This function loops through a group of messages in the mailbox and shows them
184 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
185 global $msgs, $msort;
187 global $message_highlight_list;
188 global $auto_expunge;
190 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
191 sqimap_mailbox_select($imapConnection, $mailbox);
193 $issent = ($mailbox == $sent_folder);
196 if ($numMessages >= 1) {
198 $id = range(1, $numMessages);
200 // if it's not sorted
201 if ($startMessage +
($show_num - 1) < $numMessages) {
202 $endMessage = $startMessage +
($show_num-1);
204 $endMessage = $numMessages;
207 if ($endMessage < $startMessage) {
208 $startMessage = $startMessage - $show_num;
209 if ($startMessage < 1)
213 $real_startMessage = $numMessages - $startMessage +
1;
214 $real_endMessage = $numMessages - $startMessage - $show_num +
2;
215 if ($real_endMessage <= 0)
216 $real_endMessage = 1;
217 $id = array_reverse(range($real_endMessage, $real_startMessage));
220 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
221 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
222 foreach ($msgs_list as $hdr) {
223 $from[] = $hdr->from
;
224 $date[] = $hdr->date
;
225 $subject[] = $hdr->subject
;
227 $priority[] = $hdr->priority
;
229 $size[] = $hdr->size
;
230 $type[] = $hdr->type0
;
236 $end = $startMessage +
$show_num - 1;
237 if ($numMessages < $show_num)
238 $end_loop = $numMessages;
239 elseif ($end > $numMessages)
240 $end_loop = $numMessages - $startMessage +
1;
242 $end_loop = $show_num;
247 while ($j < $end_loop) {
248 if (isset($date[$j])) {
249 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
250 $tmpdate = explode(' ', trim($date[$j]));
252 $tmpdate = $date = array("","","","","","");
255 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
256 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
257 $messages[$j]['ID'] = $id[$j];
258 $messages[$j]['FROM'] = decodeHeader($from[$j]);
259 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
260 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
261 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
262 $messages[$j]['TO'] = decodeHeader($to[$j]);
263 $messages[$j]['PRIORITY'] = $priority[$j];
264 $messages[$j]['CC'] = $cc[$j];
265 $messages[$j]['SIZE'] = $size[$j];
266 $messages[$j]['TYPE0'] = $type[$j];
268 # fix SUBJECT-SORT to remove Re:
269 $re_abbr = # Add more here!
270 'vedr|sv|' . # Danish
272 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
273 $messages[$j]['SUBJECT-SORT'] = $regs[2];
276 while ($num < count($flags[$j])) {
277 if ($flags[$j][$num] == 'Deleted') {
278 $messages[$j]['FLAG_DELETED'] = true;
280 elseif ($flags[$j][$num] == 'Answered') {
281 $messages[$j]['FLAG_ANSWERED'] = true;
283 elseif ($flags[$j][$num] == 'Seen') {
284 $messages[$j]['FLAG_SEEN'] = true;
286 elseif ($flags[$j][$num] == 'Flagged') {
287 $messages[$j]['FLAG_FLAGGED'] = true;
294 /* Only ignore messages flagged as deleted if we are using a
295 * trash folder or auto_expunge */
296 if (((isset($move_to_trash) && $move_to_trash)
297 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
299 /** Find and remove the ones that are deleted */
302 while ($j < $numMessages) {
303 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
307 $msgs[$i] = $messages[$j];
314 if (! isset($messages))
320 // There's gotta be messages in the array for it to sort them.
321 if ($numMessages > 0 && ! $use_cache) {
322 /** 0 = Date (up) 4 = Subject (up)
323 ** 1 = Date (dn) 5 = Subject (dn)
327 session_unregister("msgs");
328 if (($sort == 0) ||
($sort == 1))
329 $msort = array_cleave ($msgs, 'TIME_STAMP');
330 elseif (($sort == 2) ||
($sort == 3))
331 $msort = array_cleave ($msgs, 'FROM-SORT');
332 elseif (($sort == 4) ||
($sort == 5))
333 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
344 session_register('msort');
346 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
347 session_register('msgs');
350 // generic function to convert the msgs array into an HTML table
351 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
352 global $folder_prefix, $sent_folder;
353 global $imapServerAddress;
354 global $index_order, $real_endMessage, $real_startMessage, $checkall;
356 // if cache isn't already set, do it now
357 if (!session_is_registered('msgs'))
358 session_register('msgs');
359 if (!session_is_registered('msort'))
360 session_register('msort');
362 if ($startMessage +
($show_num - 1) < $numMessages) {
363 $endMessage = $startMessage +
($show_num-1);
365 $endMessage = $numMessages;
368 if ($endMessage < $startMessage) {
369 $startMessage = $startMessage - $show_num;
370 if ($startMessage < 1)
374 $nextGroup = $startMessage +
$show_num;
375 $prevGroup = $startMessage - $show_num;
376 $urlMailbox = urlencode($mailbox);
378 do_hook('mailbox_index_before');
381 if ($startMessage < $endMessage) {
382 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
383 } elseif ($startMessage == $endMessage) {
384 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
394 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
395 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
396 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
398 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
399 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
400 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
402 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
403 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
404 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
409 // Page selector block. Following code computes page links.
411 if( getPref($data_dir, $username, 'page_selector') && $numMessages > $show_num ) {
413 $j = intval( $numMessages / $show_num );
414 if( $numMessages %
$show_num <> 0 )
416 $startMessage = min( $startMessage, $numMessages );
417 for( $i = 0; $i < $j; $i++
) {
419 $start = ( ( $i * $show_num ) +
1 );
421 if( $startMessage >= $start &&
422 $startMessage < $start +
$show_num ) {
423 $mMore .= '<b>' . ($i+
1) . '</b> ';
425 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
426 "&mailbox=$urlMailbox\" TARGET=\"right\">" .
436 mail_message_listing_beginning($imapConnection,
437 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
438 $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
440 $groupNum = $startMessage %
($show_num - 1);
441 $real_startMessage = $startMessage;
443 if ($endMessage - $startMessage < $show_num - 1) {
444 $endMessage = $endMessage - $startMessage +
1;
446 } else if ($startMessage > $show_num) {
447 $endMessage = $show_num;
452 $endVar = $endMessage +
1;
454 // loop through and display the info for each message.
455 $t = 0; // $t is used for the checkbox number
456 if ($numMessages == 0) { // if there's no messages in this folder
457 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
458 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
459 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
470 } while (isset ($key) && ($k < $i));
471 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
481 } while (isset ($key) && ($k < $i));
484 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
489 } while ($i && $i < $endVar);
491 echo '</TABLE></FORM>';
495 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
496 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
497 echo "$lMore$mMore$rMore</td><td align=right>\n";
498 if (!$startMessage) $startMessage=1;
499 ShowSelectAllLink($startMessage, $sort);
501 echo '</td></tr></table></td></tr></table>'; /** End of message-list table */
503 do_hook('mailbox_index_after');
506 /* Displays the standard message list header.
507 * To finish the table, you need to do a "</table></table>";
508 * $moveURL is the URL to submit the delete/move form to
509 * $mailbox is the current mailbox
510 * $sort is the current sorting method (-1 for no sorting available [searches])
511 * $Message is a message that is centered on top of the list
512 * $More is a second line that is left aligned
514 function mail_message_listing_beginning($imapConnection, $moveURL,
515 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
517 global $color, $index_order, $auto_expunge, $move_to_trash;
518 global $checkall, $sent_folder;
519 $urlMailbox = urlencode($mailbox);
521 /** This is the beginning of the message list table. It wraps around all messages */
522 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
524 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
527 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
528 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
529 echo "$More</td><td align=right>\n";
530 ShowSelectAllLink($startMessage, $sort);
531 echo '</td></tr></table></td></tr>';
533 /** The delete and move options */
534 echo "<TR><TD BGCOLOR=\"$color[0]\">";
536 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
537 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
540 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER NOWRAP>\n";
541 echo ' <SMALL> ' . _("Move selected to:") . "</SMALL>\n";
543 echo " <TD> </TD>\n";
544 echo " <TD WIDTH=\"1%\" ALIGN=RIGHT NOWRAP>\n";
545 echo ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n";
549 echo " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n";
550 echo ' <SMALL> <TT><SELECT NAME="targetMailbox">';
552 $boxes = sqimap_mailbox_list($imapConnection);
553 for ($i = 0; $i < count($boxes); $i++
) {
554 if (!in_array("noselect", $boxes[$i]['flags'])) {
555 $box = $boxes[$i]['unformatted'];
556 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
557 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
560 echo ' </SELECT></TT></SMALL>';
561 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
563 echo " <TD> </TD>\n";
564 echo " <TD ALIGN=RIGHT NOWRAP> \n";
565 if (! $auto_expunge) {
566 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n";
568 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
569 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
570 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n";
574 do_hook('mailbox_form_before');
577 echo "<TR><TD BGCOLOR=\"$color[0]\">";
578 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
579 if ($GLOBALS['alt_index_colors']) {
584 echo " BGCOLOR=\"$color[0]\">";
585 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
588 for ($i=1; $i <= count($index_order); $i++
) {
589 switch ($index_order[$i]) {
592 echo ' <TD WIDTH="1%"><B> </B></TD>';
596 if ($mailbox == $sent_folder)
597 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
599 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
600 ShowSortButton($sort, $mailbox, 2, 3);
605 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
606 ShowSortButton($sort, $mailbox, 0, 1);
611 echo ' <TD><B>'. _("Subject") .'</B> ';
612 ShowSortButton($sort, $mailbox, 4, 5);
617 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
624 function ShowSortButton($sort, $mailbox, $Up, $Down) {
625 if ($sort != $Up && $sort != $Down) {
626 $img = 'sort_none.gif';
628 } elseif ($sort == $Up) {
629 $img = 'up_pointer.gif';
632 $img = 'down_pointer.gif';
635 echo ' <a href="right_main.php?newsort=' . $which .
636 '&startMessage=1&mailbox=' . urlencode($mailbox) .
637 '"><IMG SRC="../images/' . $img .
638 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
641 function ShowSelectAllLink($startMessage, $sort)
643 global $checkall, $PHP_SELF, $what, $where, $mailbox;
645 // This code is from Philippe Mingo <mingo@rotedic.com>
648 <script language
="JavaScript">
650 function CheckAll() {
651 for (var i
= 0; i
< document
.messageList
.elements
.length
; i++
) {
652 if( document
.messageList
.elements
[i
].name
.substr( 0, 3 ) == 'msg') {
653 document
.messageList
.elements
[i
].checked
=
654 !(document
.messageList
.elements
[i
].checked
);
658 window
.document
.write('<a href="#" onClick="CheckAll();"><?php echo
659 _("Toggle All") ?></A>');
664 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
665 "&startMessage=$startMessage&sort=$sort&checkall=";
666 if (isset($checkall) && $checkall == '1')
670 if (isset($where) && isset($what))
671 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
673 if (isset($checkall) && $checkall == '1')
674 echo _("Unselect All");
676 echo _("Select All");
678 echo "</A>\n</noscript>\n";
681 function processSubject($subject)
683 // Shouldn't ever happen -- caught too many times in the IMAP functions
685 return _("(no subject)");
687 if (strlen($subject) <= 55)
690 $ent_strlen=strlen($subject);
693 // see if this is entities-encoded string
694 // If so, Iterate through the whole string, find out
695 // the real number of characters, and if more
696 // than 55, substr with an updated trim value.
697 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
698 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
700 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
701 $ent_strlen -= $ent_loc_end-$ent_loc;
702 $ent_offset = $ent_loc_end+
1;
705 if ($ent_strlen <= 55)
708 return substr($subject, 0, $trim_val) . '...';