this is a fix for the LSUB with a % when getting the folder list. This makes the...
[squirrelmail.git] / functions / mailbox_display.php
index e016737b253cd656b271827745f706c3e5d85c68..ceed2dc4cc29fe05438c302f126c53768b004016 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 require_once('../functions/strings.php');
+require_once('../functions/imap_utf7_decode_local.php');
 
 /* Default value for page_selector_max. */
 define('PG_SEL_MAX', 10);
@@ -31,7 +32,7 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
     $server_sort_order, /* sort value when using server-sorting */
     $row_count,
        $allow_server_sort; /* enable/disable server-side sorting */
-  $color_string = $color[4];
+    $color_string = $color[4];
   
   if ($GLOBALS['alt_index_colors']) {
     if (!isset($row_count)) {
@@ -190,11 +191,11 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
          $stuff = true;
        }
        if ($default_use_priority) {
-         if ( ($msg['PRIORITY'][0] == 1) || ($msg['PRIORITY'][0] == 2) ) {
+         if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
            echo "<font color=\"$color[1]\">!</font>\n";
            $stuff = true;
          }
-         if ($msg['PRIORITY'][0] == 5) {
+         if ($msg['PRIORITY'] == 5) {
            echo "<font color=\"$color[8]\">?</font>\n";
            $stuff = true;
          }
@@ -412,8 +413,9 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
        }
        $num++;
       }
-      $j++;
 */
+      $j++;
+
     }
 
     /*
@@ -494,125 +496,142 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
 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;
+                               
+    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');
     }
-  }
-
-  $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&amp;mailbox=$urlMailbox"
-    . "&amp;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;
+    if (!session_is_registered('msort')) {
+        session_register('msort');
     }
-  }
-  $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>&nbsp;</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;
+    
+    if ($start_msg + ($show_num - 1) < $num_msgs){
+        $end_msg = $start_msg + ($show_num - 1);
     } else {
-      $i = 1;
+        $end_msg = $num_msgs;
     }
-    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";
+    
+    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&amp;mailbox=$urlMailbox"
+             . "&amp;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>&nbsp;</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>';
+    $html->flush(
+         $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, array( 'align' => 'right' ) ) 
+                        )
+                    , array( 'bgcolor'=> $color[4],
+                             'width' => '100%',
+                             'cellpadding' => 1,
+                             'cellspacing' => 1 ) )
+                )
+            , array( 'bgcolor' => $color[4] ) )
+         , array( 'bgcolor' => $color[9],
+                  'width' => '100%',
+                  'cellpadding' => 1,
+                  'cellspacing' => 1 ) )
+    );
+         
+    /* End of message-list table */
+    
+    do_hook('mailbox_index_after');
+    echo "</TABLE></FORM>\n";
 }
 
 /*
@@ -625,6 +644,7 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg,
  * $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 = '', 
@@ -632,14 +652,16 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
                                         $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;
+    $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 "<FORM name=messageList method=post action=\"$moveURL\">\n"
+  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\" "
@@ -650,7 +672,7 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
     . "  </TR></TABLE>\n"
     . '</TD></TR>'
     . "<TR><TD BGCOLOR=\"$color[0]\">\n"
-    . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0"
+    . "<TABLE BGCOLOR=\"$color[0]\" BORDER=0 cellpadding=0 "
     . "cellspacing=0 width=\"100%\">\n"
     . "   <TR>\n"
     . "      <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
@@ -669,11 +691,16 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
   foreach ($boxes as $boxes_part) {
     if (!in_array('noselect', $boxes_part['flags'])) {
       $box = $boxes_part['unformatted'];
-      $box2 = str_replace(' ', '&nbsp;', $boxes_part['unformatted-disp']);
+      $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
       if( $box2 == 'INBOX' ) {
        $box2 = _("INBOX");
       }
-      echo "         <OPTION VALUE=\"$box\">$box2</option>\n";
+      if ($lastTargetMailbox == $box) {
+        echo "       <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
+      }
+      else {
+        echo "         <OPTION VALUE=\"$box\">$box2</OPTION>\n";
+      }
     }
   }
   echo '         </SELECT></TT>&nbsp;'
@@ -697,15 +724,15 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
   if ($allow_thread_sort == TRUE) {
     if ($thread_sort_messages == 1 ) {
       $set_thread = 2;
-      $thread_name = 'Unthread View';
+      $thread_name = _("Unthread View");
     } 
        elseif ($thread_sort_messages == 0) {
       $set_thread = 1;
-      $thread_name = 'Thread View';
+      $thread_name = _("Thread View");
     }
     echo   '<tr><td>&nbsp;<a href=' . "$base_uri" . 'src/right_main.php?sort=' 
       . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
-      . '&mailbox=' . urlencode($mailbox) . '><small>' . _("$thread_name")
+      . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
       . '</a></small>&nbsp;</td></tr>';
   }
 
@@ -795,7 +822,7 @@ function ShowSortButton($sort, $mailbox, $Up, $Down) {
   echo ' <a href="right_main.php?newsort=' . $which
     . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
     . '"><IMG SRC="../images/' . $img
-    . '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
+    . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
 }
 
 function get_selectall_link($start_msg, $sort) {