From 406bc9c012c462e43e5074423e1a571fe6ac7470 Mon Sep 17 00:00:00 2001 From: "Aleksander Machniak (Kolab Systems)" Date: Thu, 18 Aug 2011 11:37:28 +0200 Subject: [PATCH] Unsubscribe from non-existent folders as core does (#247) --- plugins/kolab_folders/kolab_folders.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php index d3609708..de63a207 100644 --- a/plugins/kolab_folders/kolab_folders.php +++ b/plugins/kolab_folders/kolab_folders.php @@ -386,19 +386,35 @@ class kolab_folders extends rcube_plugin NULL, array('SUBSCRIBED')); // remove non-existent folders - if (is_array($a_folders)) { + if (is_array($a_folders) && $name = '*') { foreach ($a_folders as $idx => $folder) { if ($imap->conn->data['LIST'] && ($opts = $imap->conn->data['LIST'][$folder]) && in_array('\\NonExistent', $opts) ) { + $imap->conn->unsubscribe($folder); unset($a_folders[$idx]); - } + } } } } // retrieve list of folders from IMAP server using LSUB else { $a_folders = $imap->conn->listSubscribed($root, $name); + + // unsubscribe non-existent folders, remove from the list + if (is_array($a_folders) && $name == '*') { + foreach ($a_folders as $idx => $folder) { + if ($imap->conn->data['LIST'] && ($opts = $imap->conn->data['LIST'][$folder]) + && in_array('\\Noselect', $opts) + ) { + // Some servers returns \Noselect for existing folders + if (!$imap->mailbox_exists($folder)) { + $imap->conn->unsubscribe($folder); + unset($a_folders[$idx]); + } + } + } + } } return $a_folders;