From 01fd6db764532e05af05e946c67747cbb08ee0bb Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 20 Nov 2009 16:38:29 -0700 Subject: [PATCH] IMP_Imap_Tree fixes. _subscribed and _fulllist have mailbox names in the keys, not the values. LSUB does not return a list of existing subscribed mailboxes - it only returns a list of subscribed mailboxes. Need to intersect this list with LIST output to get the list of actual existing subscribed mailboxes. --- imp/lib/Imap/Tree.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index 456a472cb..2aea73090 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -288,8 +288,16 @@ class IMP_Imap_Tree { if ($showunsub && !is_null($this->_fulllist)) { return $this->_fulllist; - } elseif (!$showunsub && !is_null($this->_subscribed)) { - return array_keys($this->_subscribed); + } elseif (!$showunsub) { + if (is_null($this->_subscribed)) { + /* The subscribed list MAY contain mailboxes that do not + * currently exist on the server. See RFC 3501 [6.3.9]. So + * we need to grab the list of existing mailboxes using LIST + * and intersect against the LSUB list. */ + $this->_getList(true); + } else { + return $this->_subscribed; + } } /* INBOX must always appear. */ @@ -298,14 +306,16 @@ class IMP_Imap_Tree foreach ($this->_namespaces as $key => $val) { try { $names = array_merge($names, $GLOBALS['imp_imap']->ob()->listMailboxes($key . '*', $showunsub ? Horde_Imap_Client::MBOX_ALL : Horde_Imap_Client::MBOX_SUBSCRIBED, array('flat' => true))); - if ($showunsub) { - $this->_fulllist = $names; - } else { - $this->_subscribed = $names; - } } catch (Horde_Imap_Client_Exception $e) {} } + if ($showunsub) { + $this->_fulllist = array_flip($names); + } else { + $names = array_intersect($names, array_keys($this->_fulllist)); + $this->_subscribed = array_flip($names); + } + return $names; } @@ -845,7 +855,7 @@ class IMP_Imap_Tree /* Delete the entry from the folder list cache(s). */ foreach (array('_subscribed', '_fulllist') as $var) { if (!is_null($this->$var)) { - $this->$var = array_values(array_diff($this->$var, array($id))); + unset($this->$var[$id]); } } @@ -1174,7 +1184,7 @@ class IMP_Imap_Tree /* Add the list of polled mailboxes from the prefs. */ if ($GLOBALS['prefs']->getValue('nav_poll_all')) { - $navPollList = array_flip($this->_getList(true)); + $navPollList = $this->_getList(true); } else { $navPollList = @unserialize($GLOBALS['prefs']->getValue('nav_poll')); } -- 2.11.0