--- program/steps/mail/func-orig.inc	2005-08-20 18:09:49.000000000 +0000
+++ program/steps/mail/func.inc	2005-09-13 04:32:30.000000000 +0000
@@ -92,10 +92,33 @@
       $foldername = rcube_label($folder_lc);
     else
       $foldername = $folder;
-        
-    if ($unread_count = $IMAP->messagecount($folder, 'UNSEEN'))
-      $foldername .= sprintf(' (%d)', $unread_count);
-      
+
+
+    # Replace the INBOX. part with nothing because INBOX. is worthless to people.
+    # We'll put this in the configuration file later and make it a regex ^INBOX. -mark@suso.org 2005-09-13
+    $foldername = str_replace('INBOX.','',$foldername);
+
+    if ($unread_count = $IMAP->messagecount($folder, 'UNSEEN')) {
+        # Code to shring the size of the folder name so that it fits within the folder menu.
+        # The maximum size of a folder menu field is about 16-17 characters. But this will vary.
+        # -mark@suso.org 2005-09-13
+
+        $first_foldername_part_length = 4;  # The part before the ~
+        $max_foldername_length = 17;        # The total max length that the string can be.
+        $foldername_length = strlen($foldername);
+        $unread_count_nodigits = strlen($unread_count);
+
+        if (($foldername_length + $unread_count_nodigits) > $max_foldername_length) {
+            $second_starting_location = $foldername_length - $max_foldername_length + $first_foldername_part_length + 1 + ($unread_count_nodigits ? 3 : 0) + $unread_count_nodigits;
+            $foldername = substr($foldername, 0, $first_foldername_part_length) . "~" . substr($foldername, $second_starting_location, strlen($foldername));
+        } else {
+            $foldername = $foldername;
+        }
+
+        $foldername .= sprintf(' (%d)', $unread_count);
+     
+    }
+ 
     // compose mailbox line
     if ($type=='select')
       $out .= sprintf('<option value="%s">%s</option>'."\n",
@@ -1098,4 +1121,4 @@
   }
   
   
-?>
\ No newline at end of file
+?>
