Fixed the issue where inbox showed up in the lsub response with a \NoSelect
[squirrelmail.git] / functions / imap_mailbox.php
index 8d5b957e52c2da4dcd9e371dbe7ab92e642514d0..a5a6277c7c6a2b28f3d18e021c3e27bcac0af244 100755 (executable)
@@ -812,15 +812,31 @@ function sqimap_mailbox_tree($imap_stream) {
         $has_inbox = false;
 
         for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
-            if (preg_match("/^\*\s+LSUB\s+(.*)\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
+            if (preg_match("/^\*\s+LSUB.*\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
                $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
-                $has_inbox = true;
+                // in case of an unsubscribed inbox an imap server can
+                // return the inbox in the lsub results with a \NoSelect 
+                // flag.
+                if (!preg_match("/\*\s+LSUB\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) {
+                    $has_inbox = true;
+                } else {
+                    // remove the result and request it again  with a list
+                    // response at a later stage.
+                    unset($lsub_ary[$i]);
+                }
                 break;
             }
         }
 
         if ($has_inbox == false) {
-            $lsub_ary[] = '* LSUB () NIL INBOX';
+            // do a list request for inbox because we should always show
+            // inbox even if the user isn't subscribed to it.
+            $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
+                                             true, $response, $message);
+            $inbox_ary = compact_mailboxes_response($inbox_ary);
+            if (count($inbox_ary)) {
+                $lsub_ary[] = $inbox_ary[0];
+            }
         }
 
         /*
@@ -979,7 +995,7 @@ function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
 }
 
 function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
-   if (strtoupper($mbx_tree->mailboxname_sub) == 'INBOX')
+   if (strtoupper($mbx_tree->mailboxname_full) == 'INBOX')
        $mbx_tree->mailboxname_sub = _("INBOX");
    else
        $mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);