diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php index 43f9c720..62b7796a 100644 --- a/plugins/libkolab/lib/kolab_storage.php +++ b/plugins/libkolab/lib/kolab_storage.php @@ -72,11 +72,11 @@ class kolab_storage */ public static function get_folders($type) { - $folders = array(); + $folders = $folderdata = array(); if (self::setup()) { - foreach ((array)self::list_folders('', '*', $type) as $foldername) { - $folders[$foldername] = new kolab_storage_folder($foldername, self::$imap); + foreach ((array)self::list_folders('', '*', $type, false, $folderdata) as $foldername) { + $folders[$foldername] = new kolab_storage_folder($foldername, $folderdata[$foldername]); } } @@ -92,7 +92,7 @@ class kolab_storage */ public static function get_folder($folder) { - return self::setup() ? new kolab_storage_folder($folder, self::$imap) : null; + return self::setup() ? new kolab_storage_folder($folder) : null; } @@ -110,7 +110,7 @@ class kolab_storage $folder = null; foreach ((array)self::list_folders('', '*', $type) as $foldername) { if (!$folder) - $folder = new kolab_storage_folder($foldername, self::$imap); + $folder = new kolab_storage_folder($foldername); else $folder->set_folder($foldername); @@ -384,10 +384,11 @@ class kolab_storage * @param string Optional name pattern * @param string Data type to list folders for (contact,distribution-list,event,task,note,mail) * @param string Enable to return subscribed folders only + * @param array Will be filled with folder-types data * * @return array List of folders */ - public static function list_folders($root = '', $mbox = '*', $filter = null, $subscribed = false) + public static function list_folders($root = '', $mbox = '*', $filter = null, $subscribed = false, &$folderdata = array()) { if (!self::setup()) { return null; @@ -412,14 +413,14 @@ class kolab_storage return array(); } - $regexp = '/^' . preg_quote($filter, '/') . '(\..+)?$/'; + $folderdata = array_map('implode', $folderdata); + $regexp = '/^' . preg_quote($filter, '/') . '(\..+)?$/'; // In some conditions we can skip LIST command (?) if ($subscribed == false && $filter != 'mail' && $prefix == '*') { - foreach ($folderdata as $idx => $folder) { - $type = $folder[self::CTYPE_KEY]; + foreach ($folderdata as $folder => $type) { if (!preg_match($regexp, $type)) { - unset($folderdata[$idx]); + unset($folderdata[$folder]); } } return array_keys($folderdata); @@ -440,7 +441,7 @@ class kolab_storage // Filter folders list foreach ($folders as $idx => $folder) { - $type = !empty($folderdata[$folder]) ? $folderdata[$folder][self::CTYPE_KEY] : null; + $type = $folderdata[$folder]; if ($filter == 'mail' && empty($type)) { continue; diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php index d6919064..ffbbb5d1 100644 --- a/plugins/libkolab/lib/kolab_storage_folder.php +++ b/plugins/libkolab/lib/kolab_storage_folder.php @@ -54,30 +54,34 @@ class kolab_storage_folder /** * Default constructor */ - function __construct($name, $imap = null) + function __construct($name, $type = null) { - $this->imap = is_object($imap) ? $imap : rcube::get_instance()->get_storage(); + $this->imap = rcube::get_instance()->get_storage(); $this->imap->set_options(array('skip_deleted' => true)); $this->cache = new kolab_storage_cache($this); - $this->set_folder($name); + $this->set_folder($name, $type); } /** - * Set the IMAP folder name this instance connects to + * Set the IMAP folder this instance connects to * * @param string The folder name/path + * @param string Optional folder type if known */ - public function set_folder($name) + public function set_folder($name, $type = null) { - $this->name = $name; + if (!$type) { + $metadata = $this->imap->get_metadata($name, array(kolab_storage::CTYPE_KEY)); + $type = $metadata[$this->name][kolab_storage::CTYPE_KEY]; + } + + $this->name = $name; + $this->type_annotation = $type; + $this->type = reset(explode('.', $type)); + $this->resource_uri = null; + $this->imap->set_folder($this->name); - - $metadata = $this->imap->get_metadata($this->name, array(kolab_storage::CTYPE_KEY)); - $this->type_annotation = $metadata[$this->name][kolab_storage::CTYPE_KEY]; - $this->type = reset(explode('.', $this->type_annotation)); - $this->resource_uri = null; - $this->cache->set_folder($this); }