1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| 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: |
| Handler for saving the create/edit folder form |
+-----------------------------------------------------------------------+
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_settings_folder_save extends rcmail_action_settings_folder_edit
{
protected static $mode = self::MODE_HTTP;
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
// WARNING: folder names in UI are encoded with RCUBE_CHARSET
$name = trim(rcube_utils::get_input_string('_name', rcube_utils::INPUT_POST, true));
$path = rcube_utils::get_input_string('_parent', rcube_utils::INPUT_POST, true);
$old_imap = rcube_utils::get_input_string('_mbox', rcube_utils::INPUT_POST, true);
$type = rcube_utils::get_input_string('_type', rcube_utils::INPUT_POST);
$name_imap = rcube_charset::convert($name, RCUBE_CHARSET, 'UTF7-IMAP');
// $path is in UTF7-IMAP already
// init IMAP connection
$rcmail = rcmail::get_instance();
$storage = $rcmail->get_storage();
$delimiter = $storage->get_hierarchy_delimiter();
$options = strlen($old_imap) ? self::folder_options($old_imap) : [];
$char = null;
// Folder name checks
if (!empty($options['protected']) || !empty($options['norename'])) {
// do nothing
}
else if (!strlen($name)) {
$error = $rcmail->gettext('namecannotbeempty');
}
else if (mb_strlen($name) > 128) {
$error = $rcmail->gettext('nametoolong');
}
else if ($name[0] == '.' && $rcmail->config->get('imap_skip_hidden_folders')) {
$error = $rcmail->gettext('namedotforbidden');
}
else if (!$storage->folder_validate($name, $char)) {
$error = $rcmail->gettext('forbiddencharacter') . " ($char)";
}
if (!empty($error)) {
$rcmail->output->command('display_message', $error, 'error');
}
else {
if (!empty($options['protected']) || !empty($options['norename'])) {
$name_imap = $old_imap;
}
else if (strlen($path)) {
$name_imap = $path . $delimiter . $name_imap;
}
else {
$name_imap = $storage->mod_folder($name_imap, 'in');
}
}
$dual_use_supported = $storage->get_capability(rcube_storage::DUAL_USE_FOLDERS);
$acl_supported = $storage->get_capability('ACL');
// Check access rights to the parent folder
if (empty($error) && $acl_supported && 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['rights'])))
) {
$error = $rcmail->gettext('parentnotwritable');
}
}
if (!empty($error)) {
$rcmail->output->command('display_message', $error, 'error');
$folder = null;
}
else {
$folder = [
'name' => $name_imap,
'oldname' => $old_imap,
'class' => '',
'options' => $options,
'settings' => [
// List view mode: 0-list, 1-threads
'view_mode' => (int) rcube_utils::get_input_string('_viewmode', rcube_utils::INPUT_POST),
'sort_column' => rcube_utils::get_input_string('_sortcol', rcube_utils::INPUT_POST),
'sort_order' => rcube_utils::get_input_string('_sortord', rcube_utils::INPUT_POST),
],
'subscribe' => false,
'noselect' => false,
];
}
// create a new mailbox
if (empty($error) && !strlen($old_imap)) {
$folder['subscribe'] = true;
// Server does not support both sub-folders and messages in a folder
// For folders that are supposed to contain other folders we will:
// - disable subscription
// - add a separator at the end to make them \NoSelect
if (!$dual_use_supported && $type == 'folder') {
$folder['subscribe'] = false;
$folder['noselect'] = true;
}
$plugin = $rcmail->plugins->exec_hook('folder_create', ['record' => $folder]);
$folder = $plugin['record'];
if (!$plugin['abort']) {
$created = $storage->create_folder($folder['name'], $folder['subscribe'], null, $folder['noselect']);
}
else {
$created = $plugin['result'];
}
if ($created) {
// Save folder settings
if (isset($_POST['_viewmode'])) {
$a_threaded = (array) $rcmail->config->get('message_threading', []);
$a_threaded[$folder['name']] = (bool) $_POST['_viewmode'];
$rcmail->user->save_prefs(['message_threading' => $a_threaded]);
}
self::update_folder_row($folder['name'], null, $folder['subscribe'], $folder['class']);
$rcmail->output->show_message('foldercreated', 'confirmation');
// reset folder preview frame
$rcmail->output->command('subscription_select');
$rcmail->output->send('iframe');
}
else {
// show error message
if (!empty($plugin['message'])) {
$rcmail->output->show_message($plugin['message'], 'error', null, false);
}
else {
self::display_server_error('errorsaving');
}
}
}
// update a mailbox
else if (empty($error)) {
$plugin = $rcmail->plugins->exec_hook('folder_update', ['record' => $folder]);
$folder = $plugin['record'];
$rename = $folder['oldname'] != $folder['name'];
if (!$plugin['abort']) {
if ($rename) {
$updated = $storage->rename_folder($folder['oldname'], $folder['name']);
}
else {
$updated = true;
}
}
else {
$updated = $plugin['result'];
}
if ($updated) {
// Update folder settings,
if (isset($_POST['_viewmode'])) {
$a_threaded = (array) $rcmail->config->get('message_threading', []);
// In case of name change update names of children in settings
if ($rename) {
$oldprefix = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/';
foreach ($a_threaded as $key => $val) {
if ($key == $folder['oldname']) {
unset($a_threaded[$key]);
}
else if (preg_match($oldprefix, $key)) {
unset($a_threaded[$key]);
$a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = $val;
}
}
}
$a_threaded[$folder['name']] = (bool) $_POST['_viewmode'];
$rcmail->user->save_prefs(['message_threading' => $a_threaded]);
}
$rcmail->output->show_message('folderupdated', 'confirmation');
$rcmail->output->set_env('folder', $folder['name']);
if ($rename) {
// #1488692: update session
if (isset($_SESSION['mbox']) && $_SESSION['mbox'] === $folder['oldname']) {
$_SESSION['mbox'] = $folder['name'];
}
self::update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']);
$rcmail->output->send('iframe');
}
else if (!empty($folder['class'])) {
self::update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']);
}
}
else {
// show error message
if (!empty($plugin['message'])) {
$rcmail->output->show_message($plugin['message'], 'error', null, false);
}
else {
self::display_server_error('errorsaving');
}
}
}
$rcmail->overwrite_action('edit-folder');
}
}
|