From 7fe3811c65a7c63154f03610e289a6d196f3ae2e Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 18 Jan 2012 06:10:46 -0500
Subject: [PATCH] Changed license to GNU GPLv3+ with exceptions for skins and plugins

---
 program/steps/settings/save_folder.inc |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/program/steps/settings/save_folder.inc b/program/steps/settings/save_folder.inc
index 70aad6d..b7b0e6b 100644
--- a/program/steps/settings/save_folder.inc
+++ b/program/steps/settings/save_folder.inc
@@ -6,7 +6,10 @@
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
  | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
- | Licensed under the GNU GPL                                            |
+ |                                                                       |
+ | Licensed under the GNU General Public License version 3 or            |
+ | any later version with exceptions for skins & plugins.                |
+ | See the README file for a full license statement.                     |
  |                                                                       |
  | PURPOSE:                                                              |
  |   Provide functionality to create/edit a folder                       |
@@ -22,7 +25,7 @@
 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
 
 // init IMAP connection
-$RCMAIL->imap_connect();
+$STORAGE = $RCMAIL->get_storage();
 
 
 $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
@@ -33,8 +36,8 @@
 $old_imap  = rcube_charset_convert($old, RCMAIL_CHARSET, 'UTF7-IMAP');
 // $path is in UTF7-IMAP already
 
-$delimiter = $IMAP->get_hierarchy_delimiter();
-$options = strlen($old_imap) ? rcube_folder_options($old_imap) : array();
+$delimiter = $STORAGE->get_hierarchy_delimiter();
+$options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array();
 
 // Folder name checks
 if ($options['protected'] || $options['norename']) {
@@ -65,9 +68,26 @@
     else if (strlen($path)) {
         $name_imap = $path . $delimiter . $name_imap;
     }
+    else {
+        $name_imap = $STORAGE->mod_folder($name_imap, 'in');
+    }
+}
 
+// Check access rights to the parent folder
+if (!$error && strlen($path) && (!strlen($old_imap) || $old_imap != $name_imap)) {
+    $parent_opts = $STORAGE->folder_info($path);
+    if ($parent_opts['namespace'] != 'personal'
+        && (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts)))
+    ) {
+        $error = rcube_label('parentnotwritable');
+    }
+}
+
+if (!$error) {
     $folder['name']     = $name_imap;
     $folder['oldname']  = $old_imap;
+    $folder['class']    = '';
+    $folder['options']  = $options;
     $folder['settings'] = array(
         // List view mode: 0-list, 1-threads
         'view_mode'   => (int) get_input_value('_viewmode', RCUBE_INPUT_POST),
@@ -79,12 +99,14 @@
 // create a new mailbox
 if (!$error && !strlen($old)) {
 
+    $folder['subscribe'] = true;
+
     $plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder));
 
     $folder = $plugin['record'];
 
     if (!$plugin['abort']) {
-        $created = $IMAP->create_mailbox($folder['name'], TRUE);
+        $created = $STORAGE->create_folder($folder['name'], $folder['subscribe']);
     }
     else {
         $created = $plugin['result'];
@@ -103,8 +125,10 @@
             $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
         }
 
+        rcmail_update_folder_row($folder['name'], null, $folder['subscribe'], $folder['class']);
         $OUTPUT->show_message('foldercreated', 'confirmation');
-        $OUTPUT->command('reload', 250);
+        // reset folder preview frame
+        $OUTPUT->command('subscription_select');
         $OUTPUT->send('iframe');
     }
     else {
@@ -122,7 +146,7 @@
 
     if (!$plugin['abort']) {
         if ($rename) {
-            $updated = $RCMAIL->imap->rename_mailbox($folder['oldname'], $folder['name']);
+            $updated = $STORAGE->rename_folder($folder['oldname'], $folder['name']);
         }
         else {
             $updated = true;
@@ -160,7 +184,7 @@
 
         $OUTPUT->show_message('folderupdated', 'confirmation');
         if ($rename) {
-            $OUTPUT->command('reload', 250);
+            rcmail_update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']);
             $OUTPUT->send('iframe');
         }
     }

--
Gitblit v1.9.1