updated docs
[squirrelmail.git] / functions / mailbox_display.php
index ddbb61298993fa2fd523b8449f0325b4419712ee..a4823676e6bab7fa0a30aff1fcb57c89c9a23a4a 100644 (file)
@@ -9,7 +9,9 @@
     **  $Id$
     **/
 
-   $mailbox_display_php = true;
+   if (defined('mailbox_display_php'))
+       return;
+   define('mailbox_display_php', true);
 
    function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
       global $checkall;
       global $message_highlight_list;
       global $index_order;
 
+      $color_string = $color[4];
+      if ($GLOBALS['alt_index_colors']) {
+          if (!isset($GLOBALS["row_count"])) {
+            $GLOBALS["row_count"] = 0;
+          }
+          $GLOBALS["row_count"]++;
+          if ($GLOBALS["row_count"] % 2) {
+          if (!isset($color[12])) $color[12] = "#EAEAEA";
+            $color_string = $color[12];
+          }
+      }
+
       $msg = $msgs[$key];
 
       $senderName = sqimap_find_displayable_name($msg['FROM']);
       $urlMailbox = urlencode($mailbox);
-      $subject = trim($msg['SUBJECT']);
-      if ($subject == '')
-         $subject = _("(no subject)");
+      $subject = processSubject($msg['SUBJECT']);
 
       echo "<TR>\n";
 
@@ -84,7 +96,7 @@
       }
 
       if (!isset($hlt_color))
-         $hlt_color = $color[4];
+         $hlt_color = $color_string;
 
       if ($where && $what) {
          $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
                    if (! isset($search_stuff)) { $search_stuff = ''; }
                echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
                do_hook("subject_link");
-               echo ">$flag";
-               if (strlen($subject) > 55){
-                 $ent_strlen=strlen($subject);
-                 $trim_val=50;
-                 // see if this is entities-encoded string
-                 if (is_int(strpos($subject, "&#"))){
-                   // Yes. Iterate through the whole string, find out
-                   // the real number of characters, and if more
-                   // than 55, substr with an updated trim value.
-                   $ent_offset=0;
-                   $ent_count=0;
-                   do {
-                     $ent_loc = strpos($subject, "&#", $ent_offset);
-                     $ent_loc_end = strpos($subject, ";", $ent_offset);
-                     if ($ent_loc_end){
-                       $trim_val += ($ent_loc_end-$ent_loc)+1;
-                       $ent_strlen -= $ent_loc_end-$ent_loc;
-                       $ent_offset = $ent_loc_end+1;
-                       $ent_count++;
-                     } else $ent_loc=false;
-                   } while (is_int($ent_loc));
-                 }
-                 if ($ent_strlen>55) echo substr($subject, 0, $trim_val) . '...';
-                else echo $subject;
-               } else echo $subject;
-               
-              echo "$flag_end</a>$bold_end</td>\n";
+               echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
                break;
             case 5: # flags
                $stuff = false;
             $end = $startMessage + $show_num - 1;
             if ($numMessages < $show_num)
                 $end_loop = $numMessages;
-            else
+            elseif ($end > $numMessages)
+               $end_loop = $numMessages - $startMessage + 1;
+           else
                 $end_loop = $show_num;
          } else {
             $end = $numMessages;
             $end_loop = $end;
          }
-         if ($end > $numMessages) $end = $numMessages;
          while ($j < $end_loop) {
             if (isset($date[$j])) {
                 $date[$j] = ereg_replace('  ', ' ', $date[$j]);
       global $color, $index_order, $auto_expunge, $move_to_trash;
       global $checkall, $sent_folder;
       $urlMailbox = urlencode($mailbox);
-
          /** This is the beginning of the message list table.  It wraps around all messages */
       echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
 
       for ($i = 0; $i < count($boxes); $i++) {
          if (!in_array("noselect", $boxes[$i]['flags'])) {
             $box = $boxes[$i]['unformatted'];
-            $box2 = replace_spaces($boxes[$i]['unformatted-disp']);
+            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
             echo "         <OPTION VALUE=\"$box\">$box2</option>\n";
          }
       }
       echo '</TD></TR>';
 
       echo "<TR><TD BGCOLOR=\"$color[0]\">";
-      echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
+      echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
+      if ($GLOBALS['alt_index_colors']) {
+        echo "0";
+      } else {
+        echo "1";
+      }
+      echo " BGCOLOR=\"$color[0]\">";
       echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
 
       $urlMailbox=urlencode($mailbox);
                break;
                
             case 4: # subject
-               echo '   <TD WIDTH=%><B>'. _("Subject") ."</B>\n";
+               echo '   <TD><B>'. _("Subject") ."</B>\n";
                if ($sort == 4)
                  echo "   <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
                elseif ($sort == 5)
            echo _("Select All");
        echo "</A>\n";
    }
-   
+
+   function processSubject($subject)
+   {
+      // Shouldn't ever happen -- caught too many times in the IMAP functions
+      if ($subject == '')
+          return _("(no subject)");
+         
+      if (strlen($subject) <= 55)
+          return $subject;
+         
+      $ent_strlen=strlen($subject);
+      $trim_val=50;
+      $ent_offset=0;
+      // see if this is entities-encoded string
+      // If so, Iterate through the whole string, find out
+      // the real number of characters, and if more
+      // than 55, substr with an updated trim value.
+      while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
+             ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
+      {
+        $trim_val += ($ent_loc_end-$ent_loc)+1;
+        $ent_strlen -= $ent_loc_end-$ent_loc;
+        $ent_offset = $ent_loc_end+1;
+      }
+      
+      if ($ent_strlen <= 55)
+          return $subject;
+
+      return substr($subject, 0, $trim_val) . '...';
+   }
+
 ?>