4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_folder.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Provide functionality to create/edit a folder |
14 +-----------------------------------------------------------------------+
15 | Author: Aleksander Machniak <alec@alec.pl> |
16 +-----------------------------------------------------------------------+
18 $Id: save_folder.inc 5096 2011-08-19 08:07:05Z alec $
22 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
24 // init IMAP connection
25 $RCMAIL->imap_connect();
28 $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
29 $old = trim(get_input_value('_mbox', RCUBE_INPUT_POST, true));
30 $path = trim(get_input_value('_parent', RCUBE_INPUT_POST, true));
32 $name_imap = rcube_charset_convert($name, RCMAIL_CHARSET, 'UTF7-IMAP');
33 $old_imap = rcube_charset_convert($old, RCMAIL_CHARSET, 'UTF7-IMAP');
34 // $path is in UTF7-IMAP already
36 $delimiter = $IMAP->get_hierarchy_delimiter();
37 $options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array();
40 if ($options['protected'] || $options['norename']) {
42 else if (!strlen($name)) {
43 $error = rcube_label('cannotbeempty');
45 else if (mb_strlen($name) > 128) {
46 $error = rcube_label('nametoolong');
49 // these characters are problematic e.g. when used in LIST/LSUB
50 foreach (array($delimiter, '%', '*') as $char) {
51 if (strpos($name, $delimiter) !== false) {
52 $error = rcube_label('forbiddencharacter') . " ($char)";
59 $OUTPUT->command('display_message', $error, 'error');
62 if ($options['protected'] || $options['norename']) {
63 $name_imap = $old_imap;
65 else if (strlen($path)) {
66 $name_imap = $path . $delimiter . $name_imap;
69 $name_imap = $RCMAIL->imap->mod_mailbox($name_imap, 'in');
73 // Check access rights to the parent folder
74 if (!$error && strlen($path) && (!strlen($old_imap) || $old_imap != $name_imap)) {
75 $parent_opts = $RCMAIL->imap->mailbox_info($path);
76 if ($parent_opts['namespace'] != 'personal'
77 && (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts)))
79 $error = rcube_label('parentnotwritable');
84 $folder['name'] = $name_imap;
85 $folder['oldname'] = $old_imap;
86 $folder['class'] = '';
87 $folder['options'] = $options;
88 $folder['settings'] = array(
89 // List view mode: 0-list, 1-threads
90 'view_mode' => (int) get_input_value('_viewmode', RCUBE_INPUT_POST),
91 'sort_column' => get_input_value('_sortcol', RCUBE_INPUT_POST),
92 'sort_order' => get_input_value('_sortord', RCUBE_INPUT_POST),
96 // create a new mailbox
97 if (!$error && !strlen($old)) {
99 $folder['subscribe'] = true;
101 $plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder));
103 $folder = $plugin['record'];
105 if (!$plugin['abort']) {
106 $created = $IMAP->create_mailbox($folder['name'], $folder['subscribe']);
109 $created = $plugin['result'];
113 // Save folder settings
114 if (isset($_POST['_viewmode'])) {
115 $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
117 if ($_POST['_viewmode'])
118 $a_threaded[$folder['name']] = true;
120 unset($a_threaded[$folder['name']]);
122 $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
125 rcmail_update_folder_row($folder['name'], null, $folder['subscribe'], $folder['class']);
126 $OUTPUT->show_message('foldercreated', 'confirmation');
127 // reset folder preview frame
128 $OUTPUT->command('subscription_select');
129 $OUTPUT->send('iframe');
132 // show error message
133 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
139 $plugin = $RCMAIL->plugins->exec_hook('folder_update', array('record' => $folder));
141 $folder = $plugin['record'];
142 $rename = ($folder['oldname'] != $folder['name']);
144 if (!$plugin['abort']) {
146 $updated = $RCMAIL->imap->rename_mailbox($folder['oldname'], $folder['name']);
153 $updated = $plugin['result'];
157 // Update folder settings,
158 if (isset($_POST['_viewmode'])) {
159 $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
161 // In case of name change update names of childrens in settings
163 $oldprefix = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/';
164 foreach ($a_threaded as $key => $val) {
165 if ($key == $folder['oldname']) {
166 unset($a_threaded[$key]);
168 else if (preg_match($oldprefix, $key)) {
169 unset($a_threaded[$key]);
170 $a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = true;
174 if ($_POST['_viewmode'])
175 $a_threaded[$folder['name']] = true;
177 unset($a_threaded[$folder['name']]);
179 $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
182 $OUTPUT->show_message('folderupdated', 'confirmation');
184 rcmail_update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']);
185 $OUTPUT->send('iframe');
189 // show error message
190 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
194 rcmail_overwrite_action('edit-folder');