diff -Naur squirrelmail-1.5.1.orig/functions/imap_mailbox.php squirrelmail-1.5.1/functions/imap_mailbox.php
--- squirrelmail-1.5.1.orig/functions/imap_mailbox.php	2007-10-13 06:49:32.160213750 -0700
+++ squirrelmail-1.5.1/functions/imap_mailbox.php	2007-10-13 07:10:29.731878609 -0700
@@ -38,7 +38,7 @@
 class mailboxes {
     var $mailboxname_full = '', $mailboxname_sub= '', $is_noselect = false, $is_noinferiors = false,
         $is_special = false, $is_root = false, $is_inbox = false, $is_sent = false,
-        $is_trash = false, $is_draft = false,  $mbxs = array(),
+        $is_trash = false, $is_draft = false, $is_spam = false, $is_nonspam = false,  $mbxs = array(),
         $unseen = false, $total = false, $recent = false;
 
     function addMbx($mbx, $delimiter, $start, $specialfirst) {
@@ -219,7 +219,7 @@
 
 /**
  * Defines special mailboxes: given a mailbox name, it checks if this is a
- * "special" one: INBOX, Trash, Sent or Draft.
+ * "special" one: INBOX, Trash, Sent, Spam, NonSpam or Draft.
  *
  * Since 1.2.5 function includes special_mailbox hook.<br>
  * Since 1.4.3 hook supports more than one plugin.
@@ -229,7 +229,7 @@
  */
 function isSpecialMailbox( $box ) {
     $ret = ( (strtolower($box) == 'inbox') ||
-             isTrashMailbox($box) || isSentMailbox($box) || isDraftMailbox($box) );
+             isTrashMailbox($box) || isSentMailbox($box) || isDraftMailbox($box) || isSpamMailbox($box)  || isNonSpamMailbox($box) );
 
     if ( !$ret ) {
         $ret = boolean_hook_function('special_mailbox',$box,1);
@@ -274,6 +274,26 @@
 }
 
 /**
+ * Detects if mailbox is a Spam folder or subfolder of Spam
+ * @param string $box mailbox name
+ * @return bool whether this is a Spam folder
+ */
+function isSpamMailbox($box) {
+   global $spam_folder;
+   return ( $box == $spam_folder || isBoxBelow($box, $spam_folder) );
+}
+
+/**
+  * Detects if mailbox is a NonSpam folder or subfolder of NonSpam
+  * @param string $box mailbox name
+  * @return bool whether this is a NonSpam folder
+  */
+function isNonSpamMailbox($box) {
+   global $nonspam_folder;
+   return ( $box == $nonspam_folder || isBoxBelow($box, $nonspam_folder) );
+}
+
+/**
  * Expunges a mailbox
  *
  * WARNING: Select mailbox before calling this function.
@@ -1081,6 +1101,7 @@
 function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
     global $data_dir, $username, $list_special_folders_first,
            $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
+	   $spam_folder, $nonspam_folder,
            $move_to_trash, $move_to_sent, $save_as_draft,
            $delimiter, $imap_server_type;
 
@@ -1120,6 +1141,8 @@
             $mbx->is_special |= ($mbx->is_trash = isTrashMailbox($mailbox));
             $mbx->is_special |= ($mbx->is_sent = isSentMailbox($mailbox));
             $mbx->is_special |= ($mbx->is_draft = isDraftMailbox($mailbox));
+            $mbx->is_special |= ($mbx->is_draft = isSpamMailbox($mailbox));
+            $mbx->is_special |= ($mbx->is_draft = isNonSpamMailbox($mailbox));
 
             if (!$mbx->is_special)
                 $mbx->is_special = boolean_hook_function('special_mailbox', $mailbox, 1);
