thomascube
2011-09-28 63d6e6dfc35e6d82c4a64f37c408794c163becd4
program/steps/settings/save_folder.inc
@@ -34,12 +34,10 @@
// $path is in UTF7-IMAP already
$delimiter = $IMAP->get_hierarchy_delimiter();
$special   = (strlen($old_imap) && in_array($old_imap, (array) $RCMAIL->config->get('default_imap_folders')));
$protected = ($special && $RCMAIL->config->get('protect_default_folders'));
$options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array();
// Folder name checks
if ($protected) {
if ($options['protected'] || $options['norename']) {
}
else if (!strlen($name)) {
    $error = rcube_label('cannotbeempty');
@@ -61,15 +59,32 @@
    $OUTPUT->command('display_message', $error, 'error');
}
else {
    if ($protected) {
    if ($options['protected'] || $options['norename']) {
        $name_imap = $old_imap;
    }
    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),
@@ -81,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 = $IMAP->create_mailbox($folder['name'], $folder['subscribe']);
    }
    else {
        $created = $plugin['result'];
@@ -105,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 {
@@ -141,7 +160,6 @@
            // In case of name change update names of childrens in settings
            if ($rename) {
                $delimiter  = $RCMAIL->imap->get_hierarchy_delimiter();
                $oldprefix  = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/';
                foreach ($a_threaded as $key => $val) {
                    if ($key == $folder['oldname']) {
@@ -163,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');
        }
    }