Mercurial > hg > rc2
comparison program/steps/settings/save_folder.inc @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 +-----------------------------------------------------------------------+ | |
5 | program/steps/settings/save_folder.inc | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2005-2013, The Roundcube Dev Team | | |
9 | | | |
10 | Licensed under the GNU General Public License version 3 or | | |
11 | any later version with exceptions for skins & plugins. | | |
12 | See the README file for a full license statement. | | |
13 | | | |
14 | PURPOSE: | | |
15 | Provide functionality to create/edit a folder | | |
16 | | | |
17 +-----------------------------------------------------------------------+ | |
18 | Author: Aleksander Machniak <alec@alec.pl> | | |
19 +-----------------------------------------------------------------------+ | |
20 */ | |
21 | |
22 // WARNING: folder names in UI are encoded with RCUBE_CHARSET | |
23 | |
24 // init IMAP connection | |
25 $STORAGE = $RCMAIL->get_storage(); | |
26 | |
27 $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true)); | |
28 $path = rcube_utils::get_input_value('_parent', rcube_utils::INPUT_POST, true); | |
29 $old_imap = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST, true); | |
30 $name_imap = rcube_charset::convert($name, RCUBE_CHARSET, 'UTF7-IMAP'); | |
31 // $path is in UTF7-IMAP already | |
32 | |
33 $delimiter = $STORAGE->get_hierarchy_delimiter(); | |
34 $options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array(); | |
35 | |
36 // Folder name checks | |
37 if ($options['protected'] || $options['norename']) { | |
38 } | |
39 else if (!strlen($name)) { | |
40 $error = $RCMAIL->gettext('namecannotbeempty'); | |
41 } | |
42 else if (mb_strlen($name) > 128) { | |
43 $error = $RCMAIL->gettext('nametoolong'); | |
44 } | |
45 else if ($name[0] == '.' && $RCMAIL->config->get('imap_skip_hidden_folders')) { | |
46 $error = $RCMAIL->gettext('namedotforbidden'); | |
47 } | |
48 else { | |
49 // these characters are problematic e.g. when used in LIST/LSUB | |
50 foreach (array($delimiter, '%', '*') as $char) { | |
51 if (strpos($name, $char) !== false) { | |
52 $error = $RCMAIL->gettext('forbiddencharacter') . " ($char)"; | |
53 break; | |
54 } | |
55 } | |
56 } | |
57 | |
58 if ($error) { | |
59 $OUTPUT->command('display_message', $error, 'error'); | |
60 } | |
61 else { | |
62 if ($options['protected'] || $options['norename']) { | |
63 $name_imap = $old_imap; | |
64 } | |
65 else if (strlen($path)) { | |
66 $name_imap = $path . $delimiter . $name_imap; | |
67 } | |
68 else { | |
69 $name_imap = $STORAGE->mod_folder($name_imap, 'in'); | |
70 } | |
71 } | |
72 | |
73 // Check access rights to the parent folder | |
74 if (!$error && strlen($path) && (!strlen($old_imap) || $old_imap != $name_imap) | |
75 && $STORAGE->get_capability('ACL') | |
76 ) { | |
77 $parent_opts = $STORAGE->folder_info($path); | |
78 if ($parent_opts['namespace'] != 'personal' | |
79 && (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts['rights']))) | |
80 ) { | |
81 $error = $RCMAIL->gettext('parentnotwritable'); | |
82 } | |
83 } | |
84 | |
85 if ($error) { | |
86 $OUTPUT->command('display_message', $error, 'error'); | |
87 } | |
88 else { | |
89 $folder['name'] = $name_imap; | |
90 $folder['oldname'] = $old_imap; | |
91 $folder['class'] = ''; | |
92 $folder['options'] = $options; | |
93 $folder['settings'] = array( | |
94 // List view mode: 0-list, 1-threads | |
95 'view_mode' => (int) rcube_utils::get_input_value('_viewmode', rcube_utils::INPUT_POST), | |
96 'sort_column' => rcube_utils::get_input_value('_sortcol', rcube_utils::INPUT_POST), | |
97 'sort_order' => rcube_utils::get_input_value('_sortord', rcube_utils::INPUT_POST), | |
98 ); | |
99 } | |
100 | |
101 // create a new mailbox | |
102 if (!$error && !strlen($old_imap)) { | |
103 $folder['subscribe'] = true; | |
104 | |
105 $plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder)); | |
106 | |
107 $folder = $plugin['record']; | |
108 | |
109 if (!$plugin['abort']) { | |
110 $created = $STORAGE->create_folder($folder['name'], $folder['subscribe']); | |
111 } | |
112 else { | |
113 $created = $plugin['result']; | |
114 } | |
115 | |
116 if ($created) { | |
117 // Save folder settings | |
118 if (isset($_POST['_viewmode'])) { | |
119 $a_threaded = (array) $RCMAIL->config->get('message_threading', array()); | |
120 | |
121 $a_threaded[$folder['name']] = (bool) $_POST['_viewmode']; | |
122 | |
123 $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); | |
124 } | |
125 | |
126 rcmail_update_folder_row($folder['name'], null, $folder['subscribe'], $folder['class']); | |
127 | |
128 $OUTPUT->show_message('foldercreated', 'confirmation'); | |
129 // reset folder preview frame | |
130 $OUTPUT->command('subscription_select'); | |
131 $OUTPUT->send('iframe'); | |
132 } | |
133 else { | |
134 // show error message | |
135 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error', null, false); | |
136 } | |
137 } | |
138 // update a mailbox | |
139 else if (!$error) { | |
140 $plugin = $RCMAIL->plugins->exec_hook('folder_update', array('record' => $folder)); | |
141 | |
142 $folder = $plugin['record']; | |
143 $rename = ($folder['oldname'] != $folder['name']); | |
144 | |
145 if (!$plugin['abort']) { | |
146 if ($rename) { | |
147 $updated = $STORAGE->rename_folder($folder['oldname'], $folder['name']); | |
148 } | |
149 else { | |
150 $updated = true; | |
151 } | |
152 } | |
153 else { | |
154 $updated = $plugin['result']; | |
155 } | |
156 | |
157 if ($updated) { | |
158 // Update folder settings, | |
159 if (isset($_POST['_viewmode'])) { | |
160 $a_threaded = (array) $RCMAIL->config->get('message_threading', array()); | |
161 | |
162 // In case of name change update names of childrens in settings | |
163 if ($rename) { | |
164 $oldprefix = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/'; | |
165 foreach ($a_threaded as $key => $val) { | |
166 if ($key == $folder['oldname']) { | |
167 unset($a_threaded[$key]); | |
168 } | |
169 else if (preg_match($oldprefix, $key)) { | |
170 unset($a_threaded[$key]); | |
171 $a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = $val; | |
172 } | |
173 } | |
174 } | |
175 | |
176 $a_threaded[$folder['name']] = (bool) $_POST['_viewmode']; | |
177 | |
178 $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); | |
179 } | |
180 | |
181 $OUTPUT->show_message('folderupdated', 'confirmation'); | |
182 $OUTPUT->set_env('folder', $folder['name']); | |
183 | |
184 if ($rename) { | |
185 // #1488692: update session | |
186 if ($_SESSION['mbox'] === $folder['oldname']) { | |
187 $_SESSION['mbox'] = $folder['name']; | |
188 } | |
189 rcmail_update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']); | |
190 $OUTPUT->send('iframe'); | |
191 } | |
192 else if (!empty($folder['class'])) { | |
193 rcmail_update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']); | |
194 } | |
195 } | |
196 else { | |
197 // show error message | |
198 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error', null, false); | |
199 } | |
200 } | |
201 | |
202 $RCMAIL->overwrite_action('edit-folder'); |