commit | author | age
|
af3c04
|
1 |
<?php |
A |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/settings/save_folder.inc | |
|
6 |
| | |
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2005-2009, The Roundcube Dev Team | |
af3c04
|
9 |
| Licensed under the GNU GPL | |
A |
10 |
| | |
|
11 |
| PURPOSE: | |
|
12 |
| Provide functionality to create/edit a folder | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Aleksander Machniak <alec@alec.pl> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
|
22 |
// WARNING: folder names in UI are encoded with RCMAIL_CHARSET |
|
23 |
|
|
24 |
// init IMAP connection |
|
25 |
$RCMAIL->imap_connect(); |
|
26 |
|
|
27 |
|
|
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)); |
|
31 |
|
|
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 |
|
35 |
|
|
36 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
254d5e
|
37 |
$options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array(); |
af3c04
|
38 |
|
A |
39 |
// Folder name checks |
bbce3e
|
40 |
if ($options['protected'] || $options['norename']) { |
af3c04
|
41 |
} |
A |
42 |
else if (!strlen($name)) { |
|
43 |
$error = rcube_label('cannotbeempty'); |
|
44 |
} |
|
45 |
else if (mb_strlen($name) > 128) { |
|
46 |
$error = rcube_label('nametoolong'); |
|
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, $delimiter) !== false) { |
|
52 |
$error = rcube_label('forbiddencharacter') . " ($char)"; |
|
53 |
break; |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
|
c6c99c
|
58 |
// Check access rights to the parent folder |
A |
59 |
if (!$error && strlen($path)) { |
|
60 |
$parent_opts = $RCMAIL->imap->mailbox_info($path); |
|
61 |
if ($parent_opts['namespace'] != 'personal' |
|
62 |
&& (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts))) |
|
63 |
) { |
|
64 |
$error = rcube_label('parentnotwritable'); |
|
65 |
} |
|
66 |
} |
|
67 |
|
af3c04
|
68 |
if ($error) { |
A |
69 |
$OUTPUT->command('display_message', $error, 'error'); |
|
70 |
} |
|
71 |
else { |
bbce3e
|
72 |
if ($options['protected'] || $options['norename']) { |
af3c04
|
73 |
$name_imap = $old_imap; |
A |
74 |
} |
|
75 |
else if (strlen($path)) { |
|
76 |
$name_imap = $path . $delimiter . $name_imap; |
|
77 |
} |
d08333
|
78 |
else { |
f6eb1e
|
79 |
$name_imap = $RCMAIL->imap->mod_mailbox($name_imap, 'in'); |
d08333
|
80 |
} |
af3c04
|
81 |
|
A |
82 |
$folder['name'] = $name_imap; |
|
83 |
$folder['oldname'] = $old_imap; |
1a0343
|
84 |
$folder['class'] = ''; |
67975b
|
85 |
$folder['options'] = $options; |
af3c04
|
86 |
$folder['settings'] = array( |
A |
87 |
// List view mode: 0-list, 1-threads |
|
88 |
'view_mode' => (int) get_input_value('_viewmode', RCUBE_INPUT_POST), |
|
89 |
'sort_column' => get_input_value('_sortcol', RCUBE_INPUT_POST), |
|
90 |
'sort_order' => get_input_value('_sortord', RCUBE_INPUT_POST), |
|
91 |
); |
|
92 |
} |
|
93 |
|
|
94 |
// create a new mailbox |
|
95 |
if (!$error && !strlen($old)) { |
|
96 |
|
1a0343
|
97 |
$folder['subscribe'] = true; |
A |
98 |
|
af3c04
|
99 |
$plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder)); |
A |
100 |
|
|
101 |
$folder = $plugin['record']; |
|
102 |
|
|
103 |
if (!$plugin['abort']) { |
1a0343
|
104 |
$created = $IMAP->create_mailbox($folder['name'], $folder['subscribe']); |
af3c04
|
105 |
} |
A |
106 |
else { |
|
107 |
$created = $plugin['result']; |
|
108 |
} |
|
109 |
|
|
110 |
if ($created) { |
|
111 |
// Save folder settings |
|
112 |
if (isset($_POST['_viewmode'])) { |
|
113 |
$a_threaded = (array) $RCMAIL->config->get('message_threading', array()); |
|
114 |
|
|
115 |
if ($_POST['_viewmode']) |
|
116 |
$a_threaded[$folder['name']] = true; |
|
117 |
else |
|
118 |
unset($a_threaded[$folder['name']]); |
|
119 |
|
|
120 |
$RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); |
|
121 |
} |
1a0343
|
122 |
|
A |
123 |
rcmail_update_folder_row($folder['name'], null, $folder['subscribe'], $folder['class']); |
af3c04
|
124 |
$OUTPUT->show_message('foldercreated', 'confirmation'); |
1a0343
|
125 |
// reset folder preview frame |
A |
126 |
$OUTPUT->command('subscription_select'); |
af3c04
|
127 |
$OUTPUT->send('iframe'); |
A |
128 |
} |
|
129 |
else { |
|
130 |
// show error message |
|
131 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
// update a mailbox |
|
136 |
else if (!$error) { |
|
137 |
$plugin = $RCMAIL->plugins->exec_hook('folder_update', array('record' => $folder)); |
|
138 |
|
|
139 |
$folder = $plugin['record']; |
|
140 |
$rename = ($folder['oldname'] != $folder['name']); |
|
141 |
|
|
142 |
if (!$plugin['abort']) { |
|
143 |
if ($rename) { |
|
144 |
$updated = $RCMAIL->imap->rename_mailbox($folder['oldname'], $folder['name']); |
|
145 |
} |
|
146 |
else { |
|
147 |
$updated = true; |
|
148 |
} |
|
149 |
} |
|
150 |
else { |
|
151 |
$updated = $plugin['result']; |
|
152 |
} |
|
153 |
|
|
154 |
if ($updated) { |
|
155 |
// Update folder settings, |
|
156 |
if (isset($_POST['_viewmode'])) { |
|
157 |
$a_threaded = (array) $RCMAIL->config->get('message_threading', array()); |
|
158 |
|
|
159 |
// In case of name change update names of childrens in settings |
|
160 |
if ($rename) { |
|
161 |
$oldprefix = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/'; |
|
162 |
foreach ($a_threaded as $key => $val) { |
|
163 |
if ($key == $folder['oldname']) { |
|
164 |
unset($a_threaded[$key]); |
|
165 |
} |
|
166 |
else if (preg_match($oldprefix, $key)) { |
|
167 |
unset($a_threaded[$key]); |
|
168 |
$a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = true; |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
if ($_POST['_viewmode']) |
|
173 |
$a_threaded[$folder['name']] = true; |
|
174 |
else |
|
175 |
unset($a_threaded[$folder['name']]); |
|
176 |
|
|
177 |
$RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); |
|
178 |
} |
|
179 |
|
|
180 |
$OUTPUT->show_message('folderupdated', 'confirmation'); |
|
181 |
if ($rename) { |
1a0343
|
182 |
rcmail_update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']); |
af3c04
|
183 |
$OUTPUT->send('iframe'); |
A |
184 |
} |
|
185 |
} |
|
186 |
else { |
|
187 |
// show error message |
|
188 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
rcmail_overwrite_action('edit-folder'); |