From b6da0b76afb5697685c35b8584631294cfc7b12f Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 07 Dec 2011 05:41:15 -0500
Subject: [PATCH] - Remove deprecated global $IMAP variable usage (#1488148)

---
 program/steps/settings/save_folder.inc |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/program/steps/settings/save_folder.inc b/program/steps/settings/save_folder.inc
index 70aad6d..0fc090e 100644
--- a/program/steps/settings/save_folder.inc
+++ b/program/steps/settings/save_folder.inc
@@ -33,8 +33,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 = $RCMAIL->imap->get_hierarchy_delimiter();
+$options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array();
 
 // Folder name checks
 if ($options['protected'] || $options['norename']) {
@@ -65,9 +65,26 @@
     else if (strlen($path)) {
         $name_imap = $path . $delimiter . $name_imap;
     }
+    else {
+        $name_imap = $RCMAIL->imap->mod_mailbox($name_imap, 'in');
+    }
+}
 
+// Check access rights to the parent folder
+if (!$error && strlen($path) && (!strlen($old_imap) || $old_imap != $name_imap)) {
+    $parent_opts = $RCMAIL->imap->mailbox_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 +96,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 = $RCMAIL->imap->create_mailbox($folder['name'], $folder['subscribe']);
     }
     else {
         $created = $plugin['result'];
@@ -103,8 +122,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 {
@@ -160,7 +181,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