plugins/kolab_folders
Aleksander Machniak
machniak at kolabsys.com
Tue Oct 29 16:05:15 CET 2013
plugins/kolab_folders/kolab_folders.php | 52 +++++++++++++++++++++++++-------
1 file changed, 41 insertions(+), 11 deletions(-)
New commits:
commit dfd761f4b920ff0fd6748fe18caa6c67b5e0f4b9
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Tue Oct 29 16:04:02 2013 +0100
Re-write code to create/subscribe/activate default kolab folders
with some performance improvements and proper event/task folders activation (Bug #1667)
diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php
index 0677b41..6de4ed3 100644
--- a/plugins/kolab_folders/kolab_folders.php
+++ b/plugins/kolab_folders/kolab_folders.php
@@ -26,8 +26,9 @@ class kolab_folders extends rcube_plugin
{
public $task = '?(?!login).*';
- public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy');
+ public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy');
public $mail_types = array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail');
+ public $act_types = array('event', 'task');
private $rc;
private static $instance;
@@ -86,7 +87,7 @@ class kolab_folders extends rcube_plugin
// Create default folders
if ($args['root'] == '' && $args['name'] = '*') {
- $this->create_default_folders($folders, $args['filter'], $folderdata);
+ $this->create_default_folders($folders, $args['filter'], $folderdata, $args['mode'] == 'LSUB');
}
$args['folders'] = $folders;
@@ -476,7 +477,7 @@ class kolab_folders extends rcube_plugin
/**
* Creates default folders if they doesn't exist
*/
- private function create_default_folders(&$folders, $filter, $folderdata = null)
+ private function create_default_folders(&$folders, $filter, $folderdata = null, $lsub = false)
{
$storage = $this->rc->get_storage();
$namespace = $storage->get_namespace();
@@ -530,25 +531,54 @@ class kolab_folders extends rcube_plugin
}
list($type1, $type2) = explode('.', $type);
- $exists = !empty($folderdata[$foldername]) || $foldername == 'INBOX';
+
+ $activate = in_array($type1, $this->act_types);
+ $exists = false;
+ $result = false;
+
+ // check if folder exists
+ if (!empty($folderdata[$foldername]) || $foldername == 'INBOX') {
+ $exists = true;
+ }
+ else if ((!$filter || $filter == $type1) && in_array($foldername, $folders)) {
+ // this assumes also that subscribed folder exists
+ $exists = true;
+ }
+ else {
+ $exists = $storage->folder_exists($foldername);
+ }
// create folder
- if (!$exists && !$storage->folder_exists($foldername)) {
- $storage->create_folder($foldername);
- $storage->subscribe($foldername);
+ if (!$exists) {
+ $exists = $storage->create_folder($foldername);
}
- // set type
- $result = $this->set_folder_type($foldername, $type);
+ // set type + subscribe + activate
+ if ($exists) {
+ if ($result = kolab_storage::set_folder_type($foldername, $type)) {
+ // check if folder is subscribed
+ if ((!$filter || $filter == $type1) && $lsub && in_array($foldername, $folders)) {
+ // already subscribed
+ $subscribed = true;
+ }
+ else {
+ $subscribed = $storage->subscribe($foldername);
+ }
+
+ // activate folder
+ if ($activate) {
+ kolab_storage::set_state($foldername, true);
+ }
+ }
+ }
// add new folder to the result
- if ($result && (!$filter || $filter == $type1)) {
+ if ($result && (!$filter || $filter == $type1) && (!$lsub || $subscribed)) {
$folders[] = $foldername;
}
}
}
-
/**
* Static getter for default folder of the given type
*
More information about the commits
mailing list