\n";
+}
+
+/*
+ * This function loops through a group of messages in the mailbox
+ * and shows them to the user.
+ */
+function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
+ $start_msg, $sort, $color, $show_num,
+ $use_cache) {
+ global $msgs, $msort,
+ $sent_folder, $draft_folder,
+ $message_highlight_list,
+ $auto_expunge, $thread_sort_messages, $allow_server_sort,
+ $data_dir, $username, $server_sort_order;
+
+ /* if $start_msg is lower than $num_msgs, we probably deleted all messages
+ * in the last page. We need to re-adjust the start_msg
+ */
- for ($i=0; $i < count($message_highlight_list); $i++) {
- if (trim($message_highlight_list[$i]['value']) != '') {
- if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
- if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
- $hlt_color = $message_highlight_list[$i]['color'];
- continue;
- }
- } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
- $hlt_color = $message_highlight_list[$i]['color'];
- continue;
- }
- }
- }
+ if($start_msg > $num_msgs) {
+ $start_msg -= $show_num;
+ if($start_msg < 1) {
+ $start_msg = 1;
+ }
+ }
- if (!isset($hlt_color)) {
- $hlt_color = $color_string;
+ /* This code and the next if() block check for
+ * server-side sorting methods. The $id array is
+ * formatted and $sort is set to 6 to disable
+ * SM internal sorting
+ */
+ if ($thread_sort_messages == 1) {
+ $id = get_thread_sort($imapConnection);
+ if ($id == 'no') {
+ echo '
Thread sorting is not'.
+ ' supported by your IMAP server. Please report this'.
+ ' to the system administrator.
";
- /** End of message-list table */
-
- do_hook('mailbox_index_after');
- echo "\n";
- }
-
- /**
- * Displays the standard message list header. To finish the table,
- * you need to do a "";
- *
- * $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
+ }
+ 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, $html;
+
+ /* 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)
*/
- 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;
- global $checkall, $sent_folder, $draft_folder;
- $urlMailbox = urlencode($mailbox);
-
- /****************************************************
- * This is the beginning of the message list table. *
- * It wraps around all messages *
- ****************************************************/
- echo "
\n";
-
- echo "
";
- echo "
\n";
- echo "
$paginator
\n";
- echo '
' . get_selectall_link($start_msg, $sort) . "
\n";
- echo "
$msg_cnt_str
\n";
- echo "
\n";
- echo "
";
-
- /** The delete and move options */
- echo "
";
-
- echo "\n
\n";
+}
+
+/*
+ * Displays the standard message list header. To finish the table,
+ * you need to do a "";
+ *
+ * $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,
+ $lastTargetMailbox;
+
+ $urlMailbox = urlencode($mailbox);
+
+ /*
+ * This is the beginning of the message list table.
+ * It wraps around all messages
+ */
+ echo "