summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2012-10-26 11:44:57 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2012-10-26 11:44:57 (GMT)
commit04793bfaf39a7b25d99d2600b069c0f3aab21571 (patch)
tree1f4f516f1aa24bdae15027e6b525d0d6a4b7e3d1
parent12e2d2ea4a2cdebdcc153cfba643cf8fc0d7eef2 (diff)
downloadroundcubemail-plugins-kolab-04793bfaf39a7b25d99d2600b069c0f3aab21571.tar.gz
Improvements in default folders creation procedure
-rw-r--r--plugins/kolab_folders/kolab_folders.php65
1 files changed, 21 insertions, 44 deletions
diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php
index 28d78bf..80389f6 100644
--- a/plugins/kolab_folders/kolab_folders.php
+++ b/plugins/kolab_folders/kolab_folders.php
@@ -348,7 +348,7 @@ class kolab_folders extends rcube_plugin
*
* @return boolean True on success
*/
- function set_folder_type($folder, $type='mail')
+ function set_folder_type($folder, $type = 'mail')
{
return kolab_storage::set_folder_type($folder, $type);
}
@@ -404,25 +404,12 @@ class kolab_folders extends rcube_plugin
$namespace = $storage->get_namespace();
$defaults = array();
$need_update = false;
-
- if (!is_array($folderdata)) {
- $folderdata = $storage->get_metadata('*', kolab_storage::CTYPE_KEY);
-
- if (!is_array($folderdata)) {
- return;
- }
-
- // "Flattenize" metadata array to become a name->type hash
- $folderdata = array_map('implode', $folderdata);
- }
+ $prefix = '';
// Find personal namespace prefix
if (is_array($namespace['personal']) && count($namespace['personal']) == 1) {
$prefix = $namespace['personal'][0][0];
}
- else {
- $prefix = '';
- }
$this->load_config();
@@ -443,45 +430,35 @@ class kolab_folders extends rcube_plugin
}
}
- // find default folders
- foreach ($defaults as $type => $foldername) {
- // folder exists, do nothing
- if (!empty($folderdata[$foldername])) {
- continue;
- }
+ if (empty($defaults)) {
+ return;
+ }
- // special case, need to set type only
- if ($foldername == 'INBOX' || $type == 'mail.inbox') {
- $this->set_folder_type($foldername, 'mail.inbox');
- continue;
+ if (!is_array($folderdata)) {
+ $folderdata = $storage->get_metadata('*', array(kolab_storage::CTYPE_KEY_PRIVATE, kolab_storage::CTYPE_KEY));
+
+ if (!is_array($folderdata)) {
+ return;
}
+ $folderdata = array_map(array('kolab_storage', 'folder_select_metadata'), $folderdata);
+ }
+
+ // find default folders
+ foreach ($defaults as $type => $foldername) {
// get all folders of specified type
- $folders = array_intersect($folderdata, array($type));
- unset($folders[0]);
-
- // find folders in personal namespace
- foreach ($folders as $folder) {
- if ($folder) {
- foreach (array('shared', 'other') as $nskey) {
- if (!empty($namespace[$nskey])) {
- foreach ($namespace[$nskey] as $ns) {
- if ($ns[0] && substr($folder, 0, strlen($ns[0])) == $ns[0]) {
- continue 3;
- }
- }
- }
- }
- }
+ $_folders = array_intersect($folderdata, array($type));
- // got folder in personal namespace
- continue 2;
+ // default folder found
+ if (!empty($_folders)) {
+ continue;
}
list($type1, $type2) = explode('.', $type);
+ $exists = !empty($folderdata[$foldername]) || $foldername == 'INBOX';
// create folder
- if ($type1 != 'mail' || !$storage->folder_exists($foldername)) {
+ if (!$exists && !$storage->folder_exists($foldername)) {
$storage->create_folder($foldername, $type1 == 'mail');
}