From 28ca8c28233668ce056453f0e09306e1b5a4e970 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 22 Sep 2013 15:50:44 -0600 Subject: [PATCH] Don't rely on mailbox name to determine special container labels --- imp/lib/Ftree.php | 39 +++++++++++++++++----------------- imp/lib/Ftree/Account/Imap.php | 16 +++++++++----- imp/lib/Ftree/Element.php | 7 ++++++ imp/lib/Mailbox.php | 22 +++++++++---------- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/imp/lib/Ftree.php b/imp/lib/Ftree.php index 61e6a81db5d..8bf0a4d6c79 100644 --- a/imp/lib/Ftree.php +++ b/imp/lib/Ftree.php @@ -35,19 +35,20 @@ class IMP_Ftree implements ArrayAccess, Countable, IteratorAggregate, Serializab { /* Constants for mailboxElt attributes. */ const ELT_NOSELECT = 1; - const ELT_NAMESPACE = 2; - const ELT_IS_OPEN = 4; - const ELT_IS_SUBSCRIBED = 8; - const ELT_NOINFERIORS = 16; - const ELT_IS_POLLED = 32; - const ELT_NOT_POLLED = 64; - const ELT_VFOLDER = 128; - const ELT_NONIMAP = 256; - const ELT_INVISIBLE = 512; - const ELT_NEED_SORT = 1024; - const ELT_REMOTE = 2048; - const ELT_REMOTE_AUTH = 4096; - const ELT_REMOTE_MBOX = 8192; + const ELT_NAMESPACE_OTHER = 2; + const ELT_NAMESPACE_SHARED = 4; + const ELT_IS_OPEN = 8; + const ELT_IS_SUBSCRIBED = 16; + const ELT_NOINFERIORS = 32; + const ELT_IS_POLLED = 64; + const ELT_NOT_POLLED = 128; + const ELT_VFOLDER = 256; + const ELT_NONIMAP = 512; + const ELT_INVISIBLE = 1024; + const ELT_NEED_SORT = 2048; + const ELT_REMOTE = 4096; + const ELT_REMOTE_AUTH = 8192; + const ELT_REMOTE_MBOX = 16384; /* The string used to indicate the base of the tree. This must include * null since this is the only 7-bit character not allowed in IMAP @@ -55,10 +56,6 @@ class IMP_Ftree implements ArrayAccess, Countable, IteratorAggregate, Serializab * IMAP mailbox). */ const BASE_ELT = "base\0"; - /* Defines used with namespace display. */ - const SHARED_KEY = "shared\0"; - const OTHER_KEY = "other\0"; - /** * Account sources. * @@ -485,8 +482,12 @@ public function getAttribute($type, $name) $attr = self::ELT_INVISIBLE; break; - case 'namespace': - $attr = self::ELT_NAMESPACE; + case 'namespace_other': + $attr = self::ELT_NAMESPACE_OTHER; + break; + + case 'namespace_shared': + $attr = self::ELT_NAMESPACE_SHARED; break; case 'needsort': diff --git a/imp/lib/Ftree/Account/Imap.php b/imp/lib/Ftree/Account/Imap.php index a7108b35b54..b6c3db9d1ee 100644 --- a/imp/lib/Ftree/Account/Imap.php +++ b/imp/lib/Ftree/Account/Imap.php @@ -24,6 +24,10 @@ */ class IMP_Ftree_Account_Imap extends IMP_Ftree_Account { + /* Defines used with namespace display. */ + const OTHER_KEY = "other\0"; + const SHARED_KEY = "shared\0"; + /** */ public function __get($name) @@ -55,17 +59,19 @@ public function getList($query = null) switch ($val['type']) { case Horde_Imap_Client::NS_OTHER: - $type = IMP_Ftree::OTHER_KEY; + $attr = IMP_Ftree::ELT_NAMESPACE_OTHER; + $type = self::OTHER_KEY; break; case Horde_Imap_Client::NS_SHARED: - $type = IMP_Ftree::SHARED_KEY; + $attr = IMP_Ftree::ELT_NAMESPACE_SHARED; + $type = self::SHARED_KEY; break; } if (!is_null($type)) { $out[$type] = array( - 'a' => IMP_Ftree::ELT_NOSELECT | IMP_Ftree::ELT_NAMESPACE | IMP_Ftree::ELT_NONIMAP, + 'a' => $attr | IMP_Ftree::ELT_NOSELECT | IMP_Ftree::ELT_NONIMAP, 'v' => $type ); } @@ -118,8 +124,8 @@ public function getList($query = null) case Horde_Imap_Client::NS_SHARED: if ($prefs->getValue('tree_view')) { $parent = $ns_info['type'] - ? IMP_Ftree::OTHER_KEY - : IMP_Ftree::SHARED_KEY; + ? self::OTHER_KEY + : self::SHARED_KEY; } break; } diff --git a/imp/lib/Ftree/Element.php b/imp/lib/Ftree/Element.php index 68e87963817..1245d0f0eb7 100644 --- a/imp/lib/Ftree/Element.php +++ b/imp/lib/Ftree/Element.php @@ -33,6 +33,10 @@ * @property-read boolean $namespace True if this is a namespace container * element. * @property-read array $namespace_info Namespace info. + * @property-read boolean $namespace_other True if this is an 'Other' + * namespace. + * @property-read boolean $namespace_shared True if this is a 'Shared' + * namespace. * @property boolean $needsort True if this level needs a sort. * @property-read boolean $nochildren True if this element doesn't allow * children. @@ -116,6 +120,9 @@ public function __get($name) case 'mbox_ob': return IMP_Mailbox::get($this->_id); + case 'namespace': + return ($this->namespace_other || $this->namespace_shared); + case 'namespace_info': return $this->mbox_ob->imp_imap->getNamespace($this->_id); diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index 672a80fbc5c..9516194dc7c 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -1638,18 +1638,16 @@ protected function _getDisplay($notranslate = false) } /* Handle special container mailboxes. */ - switch ($this->_mbox) { - case IMP_Ftree::OTHER_KEY: - return _("Other Users"); - - case IMP_Ftree_Account_Remote::REMOTE_KEY: - return _("Remote Accounts"); - - case IMP_Ftree::SHARED_KEY: - return _("Shared"); - - case IMP_Ftree_Account_Vfolder::VFOLDER_KEY: - return _("Virtual Folders"); + if (($elt = $this->tree_elt) && $elt->nonimap && $elt->container) { + if ($elt->remote) { + return _("Remote Accounts"); + } elseif ($elt->vfolder) { + return _("Virtual Folders"); + } elseif ($elt->namespace_other) { + return _("Other Users"); + } elseif ($elt->namespace_shared) { + return _("Shared"); + } } /* Handle remote mailboxes. */