From 6bfebc5e3205dea4bfffa1aa77776023fbfb2a1c Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 1 Mar 2018 21:01:01 +0100 Subject: [PATCH] Add sanity check when auto-unsubscribing non-existing folders --- program/lib/Roundcube/rcube_imap.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 1abbdb61c..d3c71eea3 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -2931,12 +2931,17 @@ class rcube_imap extends rcube_storage else { // unsubscribe non-existent folders, remove them from the list if (!empty($result) && $name == '*') { - $existing = $this->list_folders($root, $name); - $nonexisting = array_diff($result, $existing); - $result = array_diff($result, $nonexisting); + $existing = $this->list_folders($root, $name); - foreach ($nonexisting as $folder) { - $this->conn->unsubscribe($folder); + // Try to make sure the list of existing folders is not malformed, + // we don't want to unsubscribe existing folders on error + if (is_array($existing) && (!empty($root) || count($existing) > 1)) { + $nonexisting = array_diff($result, $existing); + $result = array_diff($result, $nonexisting); + + foreach ($nonexisting as $folder) { + $this->conn->unsubscribe($folder); + } } } }