+ }
+ session_register('msort');
+ } elseif ($thread_sort_messages == 1 || $allow_server_sort == 'true') {
+ $msort = $msgs;
+ session_unregister('msgs');
+ session_register('msort');
+ }
+ displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
+ $msort, $mailbox, $sort, $color,$show_num);
+ /**
+ * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
+ */
+ session_register('msgs');
+}
+
+/* Generic function to convert the msgs array into an HTML table. */
+function displayMessageArray($imapConnection, $num_msgs, $start_msg,
+ &$msgs, $msort, $mailbox, $sort, $color,
+ $show_num) {
+ global $folder_prefix, $sent_folder,
+ $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
+ $index_order, $real_endMessage, $real_startMessage, $checkall,
+ $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
+
+ /* If cache isn't already set, do it now. */
+ if (!session_is_registered('msgs')) {
+ session_register('msgs');
+ }
+ if (!session_is_registered('msort')) {
+ session_register('msort');
+ }
+
+ if ($start_msg + ($show_num - 1) < $num_msgs){
+ $end_msg = $start_msg + ($show_num - 1);
+ } else {
+ $end_msg = $num_msgs;
+ }
+
+ if ($end_msg < $start_msg) {
+ $start_msg = $start_msg - $show_num;
+ if ($start_msg < 1) {
+ $start_msg = 1;
+ }
+ }
+
+ $urlMailbox = urlencode($mailbox);
+
+ do_hook('mailbox_index_before');
+
+ $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
+ $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
+ $num_msgs, $show_num, $sort);
+
+ if (!isset($msg)) {
+ $msg = '';
+ }
+
+ /* get indent level for subject display */
+ if ($thread_sort_messages == 1 ) {
+ $indent_array = get_parent_level($imapConnection);
+ }
+ $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
+ . "&startMessage=$start_msg";
+ mail_message_listing_beginning($imapConnection, $fstring,
+ $mailbox, $sort, $msg_cnt_str,
+ $paginator_str, $start_msg);
+
+ $groupNum = $start_msg % ($show_num - 1);
+ $real_startMessage = $start_msg;
+ if ($sort == 6) {
+ if ($end_msg - $start_msg < $show_num - 1) {
+ $end_msg = $end_msg - $start_msg + 1;
+ $start_msg = 1;
+ } else if ($start_msg > $show_num) {
+ $end_msg = $show_num;
+ $start_msg = 1;
+ }
+ }
+ $endVar = $end_msg + 1;
+
+ /*
+ * Loop through and display the info for each message.
+ * ($t is used for the checkbox number)
+ */
+ $t = 0;
+ if ($num_msgs == 0) {
+ /* if there's no messages in this folder */
+ echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
+ . count($index_order) . ">\n"
+ . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
+ . "</B><BR> </CENTER>\n"
+ . "</TD></TR>";
+ } elseif ($start_msg == $end_msg) {
+ /* if there's only one message in the box, handle it differently. */
+ if ($sort != 6){
+ $i = $start_msg;
+ } else {
+ $i = 1;
+ }
+ reset($msort);
+ $k = 0;
+ do {
+ $key = key($msort);
+ next($msort);
+ $k++;
+ } while (isset ($key) && ($k < $i));
+ printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
+ $real_startMessage, 0, 0);
+ } else {
+ $i = $start_msg;
+ reset($msort);
+ $k = 0;
+ do {
+ $key = key($msort);
+ next($msort);
+ $k++;
+ } while (isset ($key) && ($k < $i));
+ do {
+ printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
+ $sort, $real_startMessage, 0, 0);
+ $key = key($msort);
+ $t++;
+ $i++;
+ next($msort);
+ } while ($i && $i < $endVar);
+ }
+
+ echo '</table>'
+ . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
+ . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
+ . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
+ . "cellspacing=0><tr><td>$paginator_str</td>"
+ . "<td align=right>$msg_cnt_str</td></tr></table>"
+ . "</td></tr></table>";
+ /* End of message-list table */
+
+ do_hook('mailbox_index_after');
+ echo "</TABLE></FORM>\n";
+}
+
+/*
+ * Displays the standard message list header. To finish the table,
+ * you need to do a "</table></table>";
+ *
+ * $moveURL is the URL to submit the delete/move form to
+ * $mailbox is the current mailbox
+ * $sort is the current sorting method (-1 for no sorting available [searches])
+ * $Message is a message that is centered on top of the list
+ * $More is a second line that is left aligned
+ */
+function mail_message_listing_beginning ($imapConnection, $moveURL,
+ $mailbox = '', $sort = -1,
+ $msg_cnt_str = '',
+ $paginator = ' ',
+ $start_msg = 1) {
+ global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
+ $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
+ $allow_thread_sort, $allow_server_sort, $server_sort_order;
+ $urlMailbox = urlencode($mailbox);
+
+ /*
+ * This is the beginning of the message list table.
+ * It wraps around all messages
+ */
+ echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
+ . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
+ . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
+ . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
+ . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
+ . " <TD ALIGN=LEFT>$paginator\n";
+
+ echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
+ . " </TR></TABLE>\n"
+ . '</TD></TR>'
+ . "<TR><TD BGCOLOR=\"$color[0]\">\n"
+ . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0"
+ . "cellspacing=0 width=\"100%\">\n"
+ . " <TR>\n"
+ . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
+ . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n"
+ . " </TD>\n"
+ . " <TD ALIGN=RIGHT NOWRAP>\n"
+ . ' <SMALL> ' . _("Transform Selected Messages")
+ . ": </SMALL><BR>\n"
+ . " </TD>\n"
+ . " </TR>\n"
+ . " <TR>\n"
+ . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
+ . ' <SMALL> <TT><SELECT NAME="targetMailbox">';
+
+ $boxes = sqimap_mailbox_list($imapConnection);
+ foreach ($boxes as $boxes_part) {
+ if (!in_array('noselect', $boxes_part['flags'])) {
+ $box = $boxes_part['unformatted'];
+ $box2 = str_replace(' ', ' ', $boxes_part['unformatted-disp']);
+ if( $box2 == 'INBOX' ) {
+ $box2 = _("INBOX");