summaryrefslogtreecommitdiff
path: root/plugins/kolab_folders
diff options
context:
space:
mode:
authorAleksander Machniak (Kolab Systems) <machniak@kolabsys.com>2011-07-07 13:50:50 (GMT)
committerAleksander Machniak (Kolab Systems) <machniak@kolabsys.com>2011-07-07 13:50:50 (GMT)
commitfcbcab7f3676fd448b078825f7fa4395f3478c9d (patch)
treed5924c63f09634645ef7687fa2aab36b1ad6e151 /plugins/kolab_folders
parent4054953039ae9acef248207eed761086997cee4d (diff)
downloadroundcubemail-plugins-kolab-fcbcab7f3676fd448b078825f7fa4395f3478c9d.tar.gz
There can be only one default folder of specified type
Diffstat (limited to 'plugins/kolab_folders')
-rw-r--r--plugins/kolab_folders/kolab_folders.php78
-rw-r--r--plugins/kolab_folders/localization/en_US.inc2
-rw-r--r--plugins/kolab_folders/localization/pl_PL.inc1
3 files changed, 73 insertions, 8 deletions
diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php
index ae98b2f..059c5dd 100644
--- a/plugins/kolab_folders/kolab_folders.php
+++ b/plugins/kolab_folders/kolab_folders.php
@@ -25,8 +25,6 @@
class kolab_folders extends rcube_plugin
{
- public $task = '?(?!login).*';
-
public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact');
public $mail_types = array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail');
private $rc;
@@ -182,6 +180,8 @@ class kolab_folders extends rcube_plugin
// Get type of the folder or the parent
if (strlen($mbox)) {
list($ctype, $subtype) = $this->get_folder_type($mbox);
+ if (strlen($args['parent_name']) && $subtype == 'default')
+ $subtype = ''; // there can be only one
}
if (!$ctype) {
@@ -234,8 +234,23 @@ class kolab_folders extends rcube_plugin
return $args;
}
- // @TODO: There can be only one default folder of specified type. Add check for this.
+ // load translations
+ $this->add_texts('localization/', false);
+
+ // Skip folder creation/rename in core
+ // @TODO: Maybe we should provide folder_create_after and folder_update_after hooks?
+ // Using create_mailbox/rename_mailbox here looks bad
+ $args['abort'] = true;
+
+ // There can be only one default folder of specified type
if ($subtype == 'default') {
+ $default = $this->get_default_folder($ctype);
+
+ if ($default !== null && $old_mbox != $default) {
+ $args['result'] = false;
+ $args['message'] = $this->gettext('defaultfolderexists');
+ return $args;
+ }
}
// Subtype sanity-checks
else if ($subtype && ($ctype != 'mail' || !in_array($subtype, $this->mail_types))) {
@@ -277,11 +292,6 @@ class kolab_folders extends rcube_plugin
$args['record']['class'] = self::folder_class_name($ctype);
$args['record']['subscribe'] = $subscribe;
-
- // Skip folder creation/rename in core
- // @TODO: Maybe we should provide folder_create_after and folder_update_after hooks?
- // Using create_mailbox/rename_mailbox here looks bad
- $args['abort'] = true;
$args['result'] = $result;
return $args;
@@ -397,6 +407,58 @@ class kolab_folders extends rcube_plugin
}
/**
+ * Returns the name of default folder
+ *
+ * @param string $type Folder type
+ *
+ * @return string Folder name
+ */
+ function get_default_folder($type)
+ {
+ $folderdata = $this->get_folder_type_list('*');
+
+ if (!is_array($folderdata)) {
+ return null;
+ }
+
+ $type .= '.default';
+ $namespace = $this->rc->imap->get_namespace();
+ $delimiter = $this->rc->imap->get_hierarchy_delimiter();
+
+ foreach ($folderdata as $folder => $data) {
+ if ($data[kolab_folders::CTYPE_KEY] != $type) {
+ unset ($folderdata[$folder]);
+ continue;
+ }
+
+ // folder found, check if it is in personal namespace
+ $fname = $folder . $delimiter;
+
+ if (!empty($namespace['other'])) {
+ foreach ($namespace['other'] as $item) {
+ if ($item[0] === $fname) {
+ unset ($folderdata[$folder]);
+ continue 2;
+ }
+ }
+ }
+ if (!empty($namespace['shared'])) {
+ foreach ($namespace['shared'] as $item) {
+ if ($item[0] === $fname) {
+ unset ($folderdata[$folder]);
+ continue 2;
+ }
+ }
+ }
+
+ // There can be only one default folder of specified type
+ return $folder;
+ }
+
+ return null;
+ }
+
+ /**
* Returns CSS class name for specified folder type
*
* @param string $type Folder type
diff --git a/plugins/kolab_folders/localization/en_US.inc b/plugins/kolab_folders/localization/en_US.inc
index 79e2e80..86040eb 100644
--- a/plugins/kolab_folders/localization/en_US.inc
+++ b/plugins/kolab_folders/localization/en_US.inc
@@ -18,4 +18,6 @@ $labels['outbox'] = 'Outbox';
$labels['wastebasket'] = 'Trash';
$labels['junkemail'] = 'Junk';
+$messages['defaultfolderexists'] = 'There is already default folder of specified type';
+
?>
diff --git a/plugins/kolab_folders/localization/pl_PL.inc b/plugins/kolab_folders/localization/pl_PL.inc
index 6dd4772..8bd00e6 100644
--- a/plugins/kolab_folders/localization/pl_PL.inc
+++ b/plugins/kolab_folders/localization/pl_PL.inc
@@ -15,5 +15,6 @@ $labels['sentitems'] = 'Wysłane';
$labels['outbox'] = 'Wychodzące';
$labels['wastebasket'] = 'Kosz';
$labels['junkemail'] = 'Spam';
+$messages['defaultfolderexists'] = 'Folder domyślny dla podanego typu już istnieje';
?>