+ $i = $unique_id[$j];
+ $messages[$i]['TIME_STAMP'] = getTimeStamp($tmpdate);
+ $messages[$i]['DATE_STRING'] =
+ getDateString($messages[$i]['TIME_STAMP']);
+ $messages[$i]['ID'] = $i;
+ $messages[$i]['FROM'] = decodeHeader($from[$j]);
+ $messages[$i]['FROM-SORT'] =
+ strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
+ $messages[$i]['SUBJECT'] = decodeHeader($subject[$j]);
+ $messages[$i]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
+ $messages[$i]['TO'] = decodeHeader($to[$j]);
+ $messages[$i]['PRIORITY'] = $priority[$j];
+ $messages[$i]['CC'] = $cc[$j];
+ $messages[$i]['SIZE'] = $size[$j];
+ $messages[$i]['TYPE0'] = $type[$j];
+ $messages[$i]['FLAG_DELETED'] = $flag_deleted[$j];
+ $messages[$i]['FLAG_ANSWERED'] = $flag_answered[$j];
+ $messages[$i]['FLAG_SEEN'] = $flag_seen[$j];
+ $messages[$i]['FLAG_FLAGGED'] = $flag_flagged[$j];
+
+
+ /*
+ * fix SUBJECT-SORT to remove Re:
+ * vedr|sv (Danish)
+ * re|aw (English)
+ *
+ * TODO: i18n should be incorporated here. E.g. we catch the ones
+ * we know about, but also define in i18n what the localized
+ * "Re: " is for this or that locale.
+ */
+ if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
+ $messages[$i]['SUBJECT-SORT'], $matches)){
+ $messages[$i]['SUBJECT-SORT'] = $matches[2];
+ }
+ $j++;
+ }
+ return $messages;
+}
+
+/* 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, $search=false) {
+ 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 html_tag( 'tr',
+ html_tag( 'td',
+ "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ",
+ 'center',
+ $color[4],
+ 'COLSPAN="' . count($index_order) . '"'
+ )
+ );
+ } 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>';
+
+ echo html_tag( 'table',
+ html_tag( 'tr',
+ html_tag( 'td',
+ html_tag( 'table',
+ html_tag( 'tr',
+ html_tag( 'td', $paginator_str ) .
+ html_tag( 'td', $msg_cnt_str, 'right' )
+ )
+ , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
+ )
+ , '', $color[4] )
+ , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
+
+
+ /* 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,
+ $lastTargetMailbox, $PHP_SELF;
+
+ $urlMailbox = urlencode($mailbox);
+
+ if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
+ $source_url = $regs[1];
+ } else {
+ $source_url = $PHP_SELF;
+ }
+
+
+ /*
+ * This is the beginning of the message list table.
+ * It wraps around all messages
+ */
+
+ echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
+ . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
+ html_tag( 'tr',
+ html_tag( 'td' ,
+ html_tag( 'table' ,
+ html_tag( 'tr',
+ html_tag( 'td', $paginator, 'left' ) .
+ html_tag( 'td', $msg_cnt_str, 'right' )
+ )
+ , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
+ , 'left', '', '' )
+ , '', $color[0] )
+ . html_tag( 'tr' ) . "\n"
+ . html_tag( 'td' ,'' , 'left', $color[0], '' )
+ . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
+ . html_tag( 'tr',
+ html_tag( 'td',
+ '<small> ' . _("Move Selected To:") . '</small>',
+ 'left',
+ '',
+ 'valign="middle" nowrap' ) .
+ html_tag( 'td',
+ '<small>' . _("Transform Selected Messages") . ': </small>',
+ 'right',
+ '',
+ 'nowrap' )
+ )
+ . html_tag( 'tr' ) ."\n"
+ . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' )
+ . ' <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(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
+ if( $box2 == 'INBOX' ) {
+ $box2 = _("INBOX");