Skip to content

Commit

Permalink
Don't rely on mailbox name to determine special container labels
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Sep 24, 2013
1 parent db55f72 commit 28ca8c2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
39 changes: 20 additions & 19 deletions imp/lib/Ftree.php
Expand Up @@ -35,30 +35,27 @@ 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
* mailboxes (nulls allow us to sort by name but never conflict with an
* IMAP mailbox). */
const BASE_ELT = "base\0";

/* Defines used with namespace display. */
const SHARED_KEY = "shared\0";
const OTHER_KEY = "other\0";

/**
* Account sources.
*
Expand Down Expand Up @@ -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':
Expand Down
16 changes: 11 additions & 5 deletions imp/lib/Ftree/Account/Imap.php
Expand Up @@ -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)
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions imp/lib/Ftree/Element.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
22 changes: 10 additions & 12 deletions imp/lib/Mailbox.php
Expand Up @@ -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. */
Expand Down

0 comments on commit 28ca8c2

Please sign in to comment.