Hebrew step 2
[squirrelmail.git] / functions / mailbox_display.php
index b727d456d35a35b5a1bc8e88c5e5e32ccc99bd94..13f185a37b5b08af6bdf10579da967d8d823c806 100644 (file)
@@ -13,6 +13,8 @@
  */
 
 require_once('../functions/strings.php');
+require_once('../functions/imap_utf7_decode_local.php');
+require_once('../functions/html.php');
 
 /* Default value for page_selector_max. */
 define('PG_SEL_MAX', 10);
@@ -161,8 +163,10 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
       case 4: /* subject */
        echo "   <td bgcolor=\"$hlt_color\">$bold";
        if ($thread_sort_messages == 1) {
-         echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg["ID"]]);
-       }
+      if (isset($indent_array[$msg["ID"]])) {
+           echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg["ID"]]);
+         }
+    }
        echo "<a href=\"read_body.php?mailbox=$urlMailbox&amp;passed_id="
          . $msg["ID"] 
          . "&amp;startMessage=$start_msg&amp;show_more=0$search_stuff\"";
@@ -188,11 +192,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;
          }
@@ -229,6 +233,17 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
     $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
+    */
+
+   if($start_msg > $num_msgs) {
+       $start_msg -= $show_num;
+       if($start_msg < 1) {
+         $start_msg = 1;
+       }
+   }
+
   /* 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 
@@ -239,8 +254,8 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
   if ($id == 'no') {
       echo '<b><small><center><font color=red>Thread sorting is not'.
              ' supported by your IMAP server.<br>Please report this'.
-             'to the system administrator.</center></small></b>';
-     $thread_sort_messages == 0; 
+             ' to the system administrator.</center></small></b>';
+     $thread_sort_messages = 0; 
     $id = array();
   }
   else {
@@ -259,11 +274,11 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
     $server_sort_order = $sort;
     $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
   if ($id == 'no') {
-    echo '<b><small><center><font color=red>Server-side sorting '.
-       'is not supported by your IMAP server.<br>Please report this'.
+    echo '<b><small><center><font color=red>Server-side sorting'.
+       ' is not supported by your IMAP server.<br>Please report this'.
        ' to the system administrator.</center></small></b>';
     $sort = $server_sort_order;
-         $allow_server_sort = false;
+         $allow_server_sort = FALSE;
          $id = array();
        }
        else {
@@ -312,7 +327,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
        $id = array_reverse(range($real_endMessage, $real_startMessage));
       }
       $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
-      $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
+//      $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
       if (sizeof($msgs_list)){
        foreach ($msgs_list as $hdr) {
          $from[] = $hdr->from;
@@ -323,6 +338,10 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
          $cc[] = $hdr->cc;
          $size[] = $hdr->size;
          $type[] = $hdr->type0;
+         $flag_deleted[] = $hdr->flag_deleted;
+         $flag_answered[] = $hdr->flag_answered;
+         $flag_seen[] = $hdr->flag_seen;
+         $flag_flagged[] = $hdr->flag_flagged;
        }
       }
     }
@@ -362,6 +381,11 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       $messages[$j]['CC'] = $cc[$j];
       $messages[$j]['SIZE'] = $size[$j];
       $messages[$j]['TYPE0'] = $type[$j];
+      $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
+      $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
+      $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
+      $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
+
       
       /*
        * fix SUBJECT-SORT to remove Re:
@@ -376,7 +400,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
                     $messages[$j]['SUBJECT-SORT'], $matches)){
        $messages[$j]['SUBJECT-SORT'] = $matches[2];
       }
-      
+/*      
       $num = 0;
       while ($num < count($flags[$j])) {
        if ($flags[$j][$num] == 'Deleted') {
@@ -390,7 +414,9 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
        }
        $num++;
       }
+*/
       $j++;
+
     }
 
     /*
@@ -580,11 +606,12 @@ function displayMessageArray($imapConnection, $num_msgs, $start_msg,
   }
   
   echo '</table>'
-    . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
-    . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
+    . html_tag( '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>"
+    . html_tag( 'td', 'right' ) . "$msg_cnt_str</td></tr></table>"
     . "</td></tr></table>";
   /* End of message-list table */
   
@@ -602,6 +629,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 = '', 
@@ -609,14 +637,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\" "
@@ -627,7 +657,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"
@@ -646,11 +676,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;'
@@ -670,19 +705,19 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
     . "</TD>\n"
     . "   </TR>\n";
 
-/* draws thread sorting links */
+  /* draws thread sorting links */
   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>';
   }
 
@@ -719,21 +754,21 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
       } else {
        echo '   <TD WIDTH="25%"><B>' . _("From") . '</B>';
       }
-      if ($thread_sort_messages != 1) {
+      if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
        ShowSortButton($sort, $mailbox, 2, 3);
       }
       echo "</TD>\n";
       break;
     case 3: /* date */
       echo '   <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
-      if ($thread_sort_messages != 1) {
+      if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
        ShowSortButton($sort, $mailbox, 0, 1);
       }
       echo "</TD>\n";
       break;
     case 4: /* subject */
       echo '   <TD><B>' . _("Subject") . '</B> ';
-      if ($thread_sort_messages != 1) {
+      if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
        ShowSortButton($sort, $mailbox, 4, 5);
       }
       echo "</TD>\n";
@@ -772,7 +807,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) {
@@ -814,10 +849,6 @@ function get_selectall_link($start_msg, $sort) {
        . '&amp;what=' . urlencode($what);
     }
     
-    if ($PG_SHOWNUM == 999999) {
-      $result .= '&amp;PG_SHOWNUM=999999';
-    }
-    
     $result .= "\">";
     
     if (isset($checkall) && ($checkall == '1')) {
@@ -1025,14 +1056,14 @@ function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
        }
       }
   } else if ($PG_SHOWNUM == 999999) {
-    $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
-      . "&amp;startMessage=1&amp;mailbox=$box\" TARGET=\"right\">"
-      . _("Paginate") . '</A>' . $spc;
+    $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
+      . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
+      . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
   }
 
   /* If necessary, compute the 'show all' string. */
   if (($prv_str != '') || ($nxt_str != '')) {
-    $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
+    $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
       . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
       . "TARGET=\"right\">" . _("Show All") . '</A>';
   }