Improve listing of user folders: also list them if one has access to a child folder

This commit is contained in:
Thomas Bruederli 2014-05-15 11:57:12 +02:00
parent 701c3391fe
commit df08826c03
2 changed files with 40 additions and 24 deletions

View file

@ -298,6 +298,24 @@ class kolab_storage
} }
/**
* Return the (first) path of the requested IMAP namespace
*
* @param string Namespace name (personal, shared, other)
* @return string IMAP root path for that namespace
*/
public static function namespace_root($name)
{
foreach ((array)self::$imap->get_namespace($name) as $paths) {
if (strlen($paths[0]) > 1) {
return $paths[0];
}
}
return '/';
}
/** /**
* Deletes IMAP folder * Deletes IMAP folder
* *
@ -868,14 +886,10 @@ class kolab_storage
{ {
$_folders = array(); $_folders = array();
$delim = self::$imap->get_hierarchy_delimiter(); $delim = self::$imap->get_hierarchy_delimiter();
$other_ns = self::$imap->get_namespace('other'); $other_ns = rtrim(self::namespace_root('other'), $delim);
$tree = new kolab_storage_virtual_folder('', '<root>', ''); // create tree root $tree = new kolab_storage_virtual_folder('', '<root>', ''); // create tree root
$refs = array('' => $tree); $refs = array('' => $tree);
if (is_array($other_ns)) {
$other_ns = rtrim($other_ns[0][0], '/');
}
foreach ($folders as $idx => $folder) { foreach ($folders as $idx => $folder) {
$path = explode($delim, $folder->name); $path = explode($delim, $folder->name);
array_pop($path); array_pop($path);
@ -894,7 +908,11 @@ class kolab_storage
array_pop($path); array_pop($path);
$parent_parent = join($delim, $path); $parent_parent = join($delim, $path);
if (!$refs[$parent]) { if (!$refs[$parent]) {
if ($parent_parent == $other_ns) { if ($folder->type && self::folder_type($parent) == $folder->type) {
$refs[$parent] = new kolab_storage_folder($parent, $folder->type);
$refs[$parent]->parent = $parent_parent;
}
else if ($parent_parent == $other_ns) {
$refs[$parent] = new kolab_storage_user_folder($parent, $parent_parent); $refs[$parent] = new kolab_storage_user_folder($parent, $parent_parent);
} }
else { else {
@ -1314,12 +1332,11 @@ class kolab_storage
$results = self::$ldap->search(array('cn','mail','alias'), $query, $mode, $required, $limit); $results = self::$ldap->search(array('cn','mail','alias'), $query, $mode, $required, $limit);
// resolve to IMAP folder name // resolve to IMAP folder name
$other_ns = self::$imap->get_namespace('other'); $root = self::namespace_root('other');
$user_attrib = rcube::get_instance()->config->get('kolab_auth_login', 'mail'); $user_attrib = rcube::get_instance()->config->get('kolab_auth_login', 'mail');
array_walk($results, function(&$user, $dn) use ($other_ns, $user_attrib) { array_walk($results, function(&$user, $dn) use ($root, $user_attrib) {
list($localpart, $domain) = explode('@', $user[$user_attrib]); list($localpart, $domain) = explode('@', $user[$user_attrib]);
$root = $other_ns[0][0];
$user['kolabtargetfolder'] = $root . $localpart; $user['kolabtargetfolder'] = $root . $localpart;
}); });
@ -1346,11 +1363,7 @@ class kolab_storage
if (!empty($user[$user_attrib])) { if (!empty($user[$user_attrib])) {
list($mbox) = explode('@', $user[$user_attrib]); list($mbox) = explode('@', $user[$user_attrib]);
$other_ns = self::$imap->get_namespace('other'); $other_ns = self::namespace_root('other');
if (is_array($other_ns)) {
$other_ns = $other_ns[0][0];
}
$folders = self::list_folders($other_ns . $mbox, '*', $type, $subscribed, $folderdata); $folders = self::list_folders($other_ns . $mbox, '*', $type, $subscribed, $folderdata);
} }
@ -1363,7 +1376,7 @@ class kolab_storage
* *
* @param boolean Enable to return subscribed folders only (null to use configured subscription mode) * @param boolean Enable to return subscribed folders only (null to use configured subscription mode)
* *
* @return array List of Kolab_Folder objects (folder names in UTF7-IMAP) * @return array List of kolab_storage_user_folder objects
*/ */
public static function get_user_folders($subscribed) public static function get_user_folders($subscribed)
{ {
@ -1371,19 +1384,15 @@ class kolab_storage
if (self::setup()) { if (self::setup()) {
$delimiter = self::$imap->get_hierarchy_delimiter(); $delimiter = self::$imap->get_hierarchy_delimiter();
$other_ns = self::$imap->get_namespace('other'); $other_ns = rtrim(self::namespace_root('other'), $delimiter);
if (is_array($other_ns)) { $path_len = count(explode($delimiter, $other_ns));
$other_ns = rtrim($other_ns[0][0], $delimiter);
$other_depth = count(explode($delimiter, $other_ns));
}
foreach ((array)self::list_folders($other_ns, '*', '', $subscribed) as $foldername) { foreach ((array)self::list_folders($other_ns, '*', '', $subscribed) as $foldername) {
// truncate folder path to top-level folders of the 'other' namespace
$path = explode($delimiter, $foldername); $path = explode($delimiter, $foldername);
$depth = count($path) - $other_depth; $foldername = join($delimiter, array_slice($path, 0, $path_len + 1));
array_pop($path);
// only list top-level folders of the 'other' namespace if (!$folders[$foldername]) {
if ($depth == 1) {
$folders[$foldername] = new kolab_storage_user_folder($foldername, $other_ns); $folders[$foldername] = new kolab_storage_user_folder($foldername, $other_ns);
} }
} }

View file

@ -24,6 +24,12 @@
*/ */
class kolab_storage_folder class kolab_storage_folder
{ {
/**
* Folder identifier
* @var string
*/
public $id;
/** /**
* The folder name. * The folder name.
* @var string * @var string
@ -89,6 +95,7 @@ class kolab_storage_folder
$this->default = $suffix == 'default'; $this->default = $suffix == 'default';
$this->name = $name; $this->name = $name;
$this->resource_uri = null; $this->resource_uri = null;
$this->id = kolab_storage::folder_id($name);
// get a new cache instance of folder type changed // get a new cache instance of folder type changed
if (!$this->cache || $type != $oldtype) if (!$this->cache || $type != $oldtype)