From 3870bec7ff891677fd848df8d027171acf921420 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 26 Oct 2010 09:44:39 -0400
Subject: [PATCH] - Add support for selection options from LIST-EXTENDED extension (RFC 5258)                                                                 - Don't list subscribed but non-existent folders (#1486225) - Fix \Noselect handling performance (#1487082)

---
 program/include/rcube_imap.php |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 556441d..a4b18c9 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -2816,8 +2816,27 @@
             $a_folders = $data['folders'];
         }
         else {
-            // retrieve list of folders from IMAP server
-            $a_folders = $this->conn->listSubscribed($this->mod_mailbox($root), $filter);
+            // Server supports LIST-EXTENDED, we can use selection options
+            if ($this->get_capability('LIST-EXTENDED')) {
+                // This will also set mailbox options, LSUB doesn't do that
+                $a_folders = $this->conn->listMailboxes($this->mod_mailbox($root), $filter,
+                    NULL, array('SUBSCRIBED'));
+
+                // remove non-existent folders
+                if (is_array($a_folders)) {
+                    foreach ($a_folders as $idx => $folder) {
+                        if ($this->conn->data['LIST'] && ($opts = $this->conn->data['LIST'][$folder])
+                            && in_array('\\NonExistent', $opts)
+                        ) {
+                            unset($a_folders[$idx]);
+                        } 
+                    }
+                }
+            }
+            // retrieve list of folders from IMAP server using LSUB
+            else {
+                $a_folders = $this->conn->listSubscribed($this->mod_mailbox($root), $filter);
+            }
         }
 
         if (!is_array($a_folders) || !sizeof($a_folders))
@@ -3121,13 +3140,15 @@
 
 
     /**
-     * Gets folder options from LIST/LSUB response, e.g. \Noselect, \Noinferiors
+     * Gets folder options from LIST response, e.g. \Noselect, \Noinferiors
      *
      * @param string $mbox_name Folder name
+     * @param bool   $force     Set to True if options should be refreshed
+     *                          Options are available after LIST command only
      *
      * @return array Options list
      */
-    function mailbox_options($mbox_name)
+    function mailbox_options($mbox_name, $force=false)
     {
         $mbox = $this->mod_mailbox($mbox_name);
 
@@ -3136,7 +3157,12 @@
         }
 
         if (!is_array($this->conn->data['LIST']) || !is_array($this->conn->data['LIST'][$mbox])) {
-            $this->conn->listMailboxes($this->mod_mailbox(''), $mbox_name);
+            if ($force) {
+                $this->conn->listMailboxes($this->mod_mailbox(''), $mbox_name);
+            }
+            else {
+                return array();
+            }
         }
 
         $opts = $this->conn->data['LIST'][$mbox];

--
Gitblit v1.9.1