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 width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
116 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
119 echo " <td nowrap width=1% 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 ">$flag$subject$flag_end</a>$bold_end</td>\n";
130 echo " <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
131 if (isset($msg['FLAG_ANSWERED']) &&
132 $msg['FLAG_ANSWERED'] == true) {
136 if ($msg['TYPE0'] == 'multipart') {
140 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
141 echo "<font color=$color[1]>!</font>\n";
144 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
145 echo "<font color=\"$color[1]\">D</font>\n";
149 if (!$stuff) echo " \n";
150 echo "</small></b></td>\n";
153 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
163 ** This function loops through a group of messages in the mailbox and shows them
165 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
166 global $msgs, $msort;
168 global $message_highlight_list;
169 global $auto_expunge;
171 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
172 sqimap_mailbox_select($imapConnection, $mailbox);
176 if ($numMessages >= 1) {
178 for ($q = 0; $q < $numMessages; $q++
) {
179 if($mailbox == $sent_folder)
180 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
182 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
184 $from[$q] = $hdr->from
;
185 $date[$q] = $hdr->date
;
186 $subject[$q] = $hdr->subject
;
188 $priority[$q] = $hdr->priority
;
190 $size[$q] = $hdr->size
;
191 $type[$q] = $hdr->type0
;
192 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
196 // if it's not sorted
197 if ($startMessage +
($show_num - 1) < $numMessages) {
198 $endMessage = $startMessage +
($show_num-1);
200 $endMessage = $numMessages;
203 if ($endMessage < $startMessage) {
204 $startMessage = $startMessage - $show_num;
205 if ($startMessage < 1)
210 $real_startMessage = $numMessages - $startMessage +
1;
211 $real_endMessage = $numMessages - $startMessage - $show_num;
212 if ($real_endMessage <= 0)
213 $real_endMessage = 1;
216 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
217 if($mailbox == $sent_folder)
218 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
220 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
222 $from[$j] = $hdr->from
;
223 $date[$j] = $hdr->date
;
224 $subject[$j] = $hdr->subject
;
226 $priority[$j] = $hdr->priority
;
228 $size[$j] = $hdr->size
;
229 $type[$j] = $hdr->type0
;
230 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
239 $end = $startMessage +
$show_num - 1;
240 if ($numMessages < $show_num)
241 $end_loop = $numMessages;
242 elseif ($end > $numMessages)
243 $end_loop = $numMessages - $startMessage +
1;
245 $end_loop = $show_num;
250 while ($j < $end_loop) {
251 if (isset($date[$j])) {
252 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
253 $tmpdate = explode(' ', trim($date[$j]));
255 $tmpdate = $date = array("","","","","","");
258 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
259 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
260 $messages[$j]['ID'] = $id[$j];
261 $messages[$j]['FROM'] = decodeHeader($from[$j]);
262 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
263 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
264 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
265 $messages[$j]['TO'] = decodeHeader($to[$j]);
266 $messages[$j]['PRIORITY'] = $priority[$j];
267 $messages[$j]['CC'] = $cc[$j];
268 $messages[$j]['SIZE'] = $size[$j];
269 $messages[$j]['TYPE0'] = $type[$j];
271 # fix SUBJECT-SORT to remove Re:
272 $re_abbr = # Add more here!
273 '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 if (($sort == 2) ||
($sort == 3))
334 $msort = array_cleave ($msgs, 'FROM-SORT');
335 if (($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;
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";
396 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
397 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
398 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
400 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
401 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
402 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
404 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
405 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
406 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
411 mail_message_listing_beginning($imapConnection,
412 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
413 $mailbox, $sort, $Message, $More, $startMessage);
415 $groupNum = $startMessage %
($show_num - 1);
416 $real_startMessage = $startMessage;
418 if ($endMessage - $startMessage < $show_num - 1) {
419 $endMessage = $endMessage - $startMessage +
1;
421 } else if ($startMessage > $show_num) {
422 $endMessage = $show_num;
427 $endVar = $endMessage +
1;
429 // loop through and display the info for each message.
430 $t = 0; // $t is used for the checkbox number
431 if ($numMessages == 0) { // if there's no messages in this folder
432 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
433 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
434 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
445 } while (isset ($key) && ($k < $i));
446 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
456 } while (isset ($key) && ($k < $i));
459 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
464 } while ($i && $i < $endVar);
470 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
471 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
472 echo "$More</td><td align=right>\n";
473 if (!$startMessage) $startMessage=1;
474 ShowSelectAllLink($startMessage, $sort);
476 echo '</td></tr></table>';
478 echo '</table>'; /** End of message-list table */
480 do_hook('mailbox_index_after');
483 /* Displays the standard message list header.
484 * To finish the table, you need to do a "</table></table>";
485 * $moveURL is the URL to submit the delete/move form to
486 * $mailbox is the current mailbox
487 * $sort is the current sorting method (-1 for no sorting available [searches])
488 * $Message is a message that is centered on top of the list
489 * $More is a second line that is left aligned
491 function mail_message_listing_beginning($imapConnection, $moveURL,
492 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
494 global $color, $index_order, $auto_expunge, $move_to_trash;
495 global $checkall, $sent_folder;
496 $urlMailbox = urlencode($mailbox);
497 /** This is the beginning of the message list table. It wraps around all messages */
498 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
502 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
505 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
506 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
507 echo "$More</td><td align=right>\n";
508 ShowSelectAllLink($startMessage, $sort);
510 echo '</td></tr></table>';
513 /** The delete and move options */
514 echo "<TR><TD BGCOLOR=\"$color[0]\">";
516 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
517 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
519 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
522 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
523 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
525 $boxes = sqimap_mailbox_list($imapConnection);
526 for ($i = 0; $i < count($boxes); $i++
) {
527 if (!in_array("noselect", $boxes[$i]['flags'])) {
528 $box = $boxes[$i]['unformatted'];
529 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
530 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
533 echo ' </SELECT></SMALL></TT>';
534 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
536 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
537 if (! $auto_expunge) {
538 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
540 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
545 do_hook('mailbox_form_before');
548 echo "<TR><TD BGCOLOR=\"$color[0]\">";
549 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
550 if ($GLOBALS['alt_index_colors']) {
555 echo " BGCOLOR=\"$color[0]\">";
556 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
558 $urlMailbox=urlencode($mailbox);
561 for ($i=1; $i <= count($index_order); $i++
) {
562 switch ($index_order[$i]) {
565 echo ' <TD WIDTH="1%"><B> </B></TD>';
569 if ($mailbox == $sent_folder)
570 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
572 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
575 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
577 echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
579 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
584 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
586 echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
588 echo " <A HREF=\"right_main.php?newsort=6&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
590 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
592 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
597 echo ' <TD><B>'. _("Subject") ."</B>\n";
599 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
601 echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
603 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
608 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
615 function ShowSelectAllLink($startMessage, $sort)
617 global $checkall, $PHP_SELF, $what, $where, $mailbox;
619 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
620 "&startMessage=$startMessage&sort=$sort&";
621 if ( isset($checkall) && $checkall == '1')
625 if (isset($where) && isset($what))
626 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
628 if (isset($checkall) && $checkall == '1')
629 echo _("Unselect All");
631 echo _("Select All");
635 function processSubject($subject)
637 // Shouldn't ever happen -- caught too many times in the IMAP functions
639 return _("(no subject)");
641 if (strlen($subject) <= 55)
644 $ent_strlen=strlen($subject);
647 // see if this is entities-encoded string
648 // If so, Iterate through the whole string, find out
649 // the real number of characters, and if more
650 // than 55, substr with an updated trim value.
651 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
652 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
654 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
655 $ent_strlen -= $ent_loc_end-$ent_loc;
656 $ent_offset = $ent_loc_end+
1;
659 if ($ent_strlen <= 55)
662 return substr($subject, 0, $trim_val) . '...';