Sigh... I guess global search and replace in emacs doesn't work QUITE as
[squirrelmail.git] / functions / mailbox_display.php
index 5458024c0e42052311a3e7009f7bde8c2a6287e4..5a0929857d2334c8c6d9272ee33507e0d075f73c 100644 (file)
@@ -190,11 +190,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;
          }
@@ -231,6 +231,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 
@@ -241,8 +252,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 {
@@ -257,15 +268,15 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       }
   }
 
-  if ($allow_server_sort == 'true' && $thread_sort_messages != 1) {
+  if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
     $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 {
@@ -292,7 +303,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       if ($sort < 6 ) {
        $id = range(1, $num_msgs);
       } 
-      elseif ($thread_sort_messages != 1 && $allow_server_sort != 'true' && $sort == 6) {
+      elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
        /* if it's not sorted */
        if ($start_msg + ($show_num - 1) < $num_msgs){
          $end_msg = $start_msg + ($show_num - 1);
@@ -314,7 +325,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;
@@ -325,6 +336,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;
        }
       }
     }
@@ -364,6 +379,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:
@@ -378,7 +398,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') {
@@ -392,7 +412,9 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
        }
        $num++;
       }
+*/
       $j++;
+
     }
 
     /*
@@ -456,7 +478,7 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
       }
     }          
     session_register('msort');
-  } elseif ($thread_sort_messages == 1 || $allow_server_sort == 'true') {
+  } elseif ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
     $msort = $msgs;
     session_unregister('msgs');
     session_register('msort');
@@ -673,18 +695,18 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
     . "   </TR>\n";
 
   /* draws thread sorting links */
-  if ($allow_thread_sort == 'true') {
+  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>';
   }
 
@@ -705,7 +727,7 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
    * instead. but here we reset sort for a bit
    * since its easy
    */
-  if ($allow_server_sort == 'true') {
+  if ($allow_server_sort == TRUE) {
     $sort = $server_sort_order;
   }
   /* Print the headers. */
@@ -721,21 +743,21 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
       } else {
        echo '   <TD WIDTH="25%"><B>' . _("From") . '</B>';
       }
-      if ($allow_thread_sort != 'true' || $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 ($allow_thread_sort != 'true' || $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 ($allow_thread_sort != 'true' || $thread_sort_messages != 1) {
+      if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
        ShowSortButton($sort, $mailbox, 4, 5);
       }
       echo "</TD>\n";
@@ -748,7 +770,7 @@ function mail_message_listing_beginning ($imapConnection, $moveURL,
   /* if using server-sorting,
    * send sort back to 6
    */
-  if ($allow_server_sort == 'true') {
+  if ($allow_server_sort == TRUE) {
     $sort = 6;
   }
   echo "</TR>\n";