commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/settings/manage_folders.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
a8d23d
|
8 |
| Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Provide functionality to create/delete/rename folders | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
681a59
|
22 |
// WARNING: folder names in UI are encoded with UTF-8 |
a55606
|
23 |
|
c8c1e0
|
24 |
// init IMAP connection |
197601
|
25 |
$RCMAIL->imap_init(true); |
4e17e6
|
26 |
|
T |
27 |
// subscribe to one or more mailboxes |
197601
|
28 |
if ($RCMAIL->action=='subscribe') |
4e17e6
|
29 |
{ |
681a59
|
30 |
if ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST, false, 'UTF-7')) |
c5097c
|
31 |
$IMAP->subscribe(array($mbox)); |
4e17e6
|
32 |
} |
T |
33 |
|
|
34 |
// unsubscribe one or more mailboxes |
197601
|
35 |
else if ($RCMAIL->action=='unsubscribe') |
4e17e6
|
36 |
{ |
681a59
|
37 |
if ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST, false, 'UTF-7')) |
c5097c
|
38 |
$IMAP->unsubscribe(array($mbox)); |
4e17e6
|
39 |
} |
T |
40 |
|
|
41 |
// create a new mailbox |
197601
|
42 |
else if ($RCMAIL->action=='create-folder') |
4e17e6
|
43 |
{ |
8d0758
|
44 |
if (!empty($_POST['_name'])) |
32ac95
|
45 |
{ |
A |
46 |
$name = trim(get_input_value('_name', RCUBE_INPUT_POST, FALSE, 'UTF-7')); |
681a59
|
47 |
// #1485036 (RFC3501, 5.1.3) TODO: it should be done on read not on write |
32ac95
|
48 |
$name = str_replace('&-', '&', $name); |
A |
49 |
$create = $IMAP->create_mailbox($name, TRUE); |
|
50 |
} |
|
51 |
|
f11541
|
52 |
if ($create && $OUTPUT->ajax_call) |
4e17e6
|
53 |
{ |
9490b7
|
54 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
681a59
|
55 |
$folderlist = $IMAP->list_unsubscribed(); |
A |
56 |
$index = array_search($create, $folderlist); |
|
57 |
$before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF-7') : false; |
|
58 |
|
|
59 |
$create = rcube_charset_convert($create, 'UTF-7'); |
9490b7
|
60 |
$foldersplit = explode($delimiter, $create); |
681a59
|
61 |
$display_create = str_repeat(' ', substr_count($create, $delimiter)) . $foldersplit[count($foldersplit)-1]; |
A |
62 |
|
|
63 |
$OUTPUT->command('add_folder_row', $create, $display_create, false, $before); |
4e17e6
|
64 |
} |
09c1a3
|
65 |
else if (!$create) |
4e17e6
|
66 |
{ |
f11541
|
67 |
$OUTPUT->show_message('errorsaving', 'error'); |
4e17e6
|
68 |
} |
c8c1e0
|
69 |
} |
S |
70 |
|
|
71 |
// rename a mailbox |
197601
|
72 |
else if ($RCMAIL->action=='rename-folder') |
c8c1e0
|
73 |
{ |
8d0758
|
74 |
if (!empty($_POST['_folder_oldname']) && !empty($_POST['_folder_newname'])) |
32ac95
|
75 |
{ |
681a59
|
76 |
$name_utf8 = trim(get_input_value('_folder_newname', RCUBE_INPUT_POST)); |
A |
77 |
$oldname_utf8 = get_input_value('_folder_oldname', RCUBE_INPUT_POST); |
|
78 |
$name = rcube_charset_convert($name_utf8, 'UTF-8', 'UTF-7'); |
|
79 |
$oldname = rcube_charset_convert($oldname_utf8, 'UTF-8', 'UTF-7'); |
|
80 |
|
|
81 |
// #1485036 (RFC3501, 5.1.3) TODO: it should be done on read not on write |
32ac95
|
82 |
$name = str_replace('&-', '&', $name); |
681a59
|
83 |
|
A |
84 |
$rename = $IMAP->rename_mailbox($oldname, $name); |
32ac95
|
85 |
} |
A |
86 |
|
f11541
|
87 |
if ($rename && $OUTPUT->ajax_call) |
c8c1e0
|
88 |
{ |
681a59
|
89 |
$folderlist = $IMAP->list_unsubscribed(); |
9490b7
|
90 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
681a59
|
91 |
|
A |
92 |
$regexp = '/^' . preg_quote($rename . $delimiter, '/') . '/'; |
|
93 |
|
|
94 |
// subfolders |
|
95 |
for ($x=sizeof($folderlist)-1; $x>=0; $x--) |
|
96 |
{ |
|
97 |
if (preg_match($regexp, $folderlist[$x])) |
|
98 |
{ |
3e8bd7
|
99 |
$oldfolder = $oldname . $delimiter . preg_replace($regexp, '', $folderlist[$x]); |
681a59
|
100 |
$foldersplit = explode($delimiter, $folderlist[$x]); |
A |
101 |
$level = count($foldersplit) - 1; |
|
102 |
$display_rename = str_repeat(' ', $level) |
3e8bd7
|
103 |
. rcube_charset_convert($foldersplit[$level], 'UTF-7'); |
681a59
|
104 |
|
3e8bd7
|
105 |
$before = isset($folderlist[$x+1]) ? rcube_charset_convert($folderlist[$x+1], 'UTF-7') : false; |
681a59
|
106 |
|
3e8bd7
|
107 |
$OUTPUT->command('replace_folder_row', rcube_charset_convert($oldfolder, 'UTF-7'), |
T |
108 |
rcube_charset_convert($folderlist[$x], 'UTF-7'), $display_rename, $before); |
681a59
|
109 |
} |
A |
110 |
} |
|
111 |
|
9490b7
|
112 |
$foldersplit = explode($delimiter, $rename); |
6b79f7
|
113 |
$level = count($foldersplit) - 1; |
T |
114 |
$display_rename = str_repeat(' ', $level) . rcube_charset_convert($foldersplit[$level], 'UTF-7'); |
681a59
|
115 |
$index = array_search($rename, $folderlist); |
A |
116 |
$before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF-7') : false; |
09c1a3
|
117 |
|
3e8bd7
|
118 |
$OUTPUT->command('replace_folder_row', $oldname_utf8, rcube_charset_convert($rename, 'UTF-7'), $display_rename, $before); |
681a59
|
119 |
|
f11541
|
120 |
$OUTPUT->command('reset_folder_rename'); |
c8c1e0
|
121 |
} |
f11541
|
122 |
else if (!$rename && $OUTPUT->ajax_call) |
c8c1e0
|
123 |
{ |
f11541
|
124 |
$OUTPUT->command('reset_folder_rename'); |
T |
125 |
$OUTPUT->show_message('errorsaving', 'error'); |
c8c1e0
|
126 |
} |
S |
127 |
else if (!$rename) |
f11541
|
128 |
$OUTPUT->show_message('errorsaving', 'error'); |
4e17e6
|
129 |
} |
T |
130 |
|
|
131 |
// delete an existing IMAP mailbox |
197601
|
132 |
else if ($RCMAIL->action=='delete-folder') |
4e17e6
|
133 |
{ |
681a59
|
134 |
$a_mboxes = $IMAP->list_unsubscribed(); |
97a656
|
135 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
681a59
|
136 |
|
A |
137 |
$mboxes_utf8 = get_input_value('_mboxes', RCUBE_INPUT_POST); |
|
138 |
$mboxes = rcube_charset_convert($mboxes_utf8, 'UTF-8', 'UTF-7'); |
97a656
|
139 |
|
681a59
|
140 |
if ($mboxes) |
b3ce79
|
141 |
$deleted = $IMAP->delete_mailbox(array($mboxes)); |
4e17e6
|
142 |
|
f11541
|
143 |
if ($OUTPUT->ajax_call && $deleted) |
f9c107
|
144 |
{ |
681a59
|
145 |
$OUTPUT->command('remove_folder_row', $mboxes_utf8); |
97a656
|
146 |
foreach ($a_mboxes as $mbox) |
fa0152
|
147 |
{ |
681a59
|
148 |
if (preg_match('/^'. preg_quote($mboxes.$delimiter, '/') .'/', $mbox)) |
fa0152
|
149 |
{ |
681a59
|
150 |
$OUTPUT->command('remove_folder_row', rcube_charset_convert($mbox, 'UTF-7')); |
fa0152
|
151 |
} |
T |
152 |
} |
f11541
|
153 |
$OUTPUT->show_message('folderdeleted', 'confirmation'); |
f9c107
|
154 |
} |
09c1a3
|
155 |
else if (!$deleted) |
1cded8
|
156 |
{ |
f11541
|
157 |
$OUTPUT->show_message('errorsaving', 'error'); |
1cded8
|
158 |
} |
4e17e6
|
159 |
} |
T |
160 |
|
09c1a3
|
161 |
if ($OUTPUT->ajax_call) |
A |
162 |
$OUTPUT->send(); |
4e17e6
|
163 |
|
T |
164 |
|
|
165 |
// build table with all folders listed by server |
|
166 |
function rcube_subscription_form($attrib) |
|
167 |
{ |
f11541
|
168 |
global $IMAP, $CONFIG, $OUTPUT; |
4e17e6
|
169 |
|
T |
170 |
list($form_start, $form_end) = get_form_tags($attrib, 'folders'); |
|
171 |
unset($attrib['form']); |
|
172 |
|
|
173 |
if (!$attrib['id']) |
|
174 |
$attrib['id'] = 'rcmSubscriptionlist'; |
|
175 |
|
3e8bd7
|
176 |
$table = new html_table(); |
4e17e6
|
177 |
|
T |
178 |
// add table header |
3e8bd7
|
179 |
$table->add_header('name', rcube_label('foldername')); |
T |
180 |
$table->add_header('msgcount', rcube_label('messagecount')); |
|
181 |
$table->add_header('subscribed', rcube_label('subscribed')); |
|
182 |
$table->add_header('rename', ' '); |
|
183 |
$table->add_header('delete', ' '); |
4e17e6
|
184 |
|
T |
185 |
|
|
186 |
// get folders from server |
4d4264
|
187 |
$IMAP->clear_cache('mailboxes'); |
T |
188 |
|
4e17e6
|
189 |
$a_unsubscribed = $IMAP->list_unsubscribed(); |
T |
190 |
$a_subscribed = $IMAP->list_mailboxes(); |
9490b7
|
191 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
3e8bd7
|
192 |
$a_js_folders = $seen_folders = $list_folders = array(); |
T |
193 |
|
|
194 |
// pre-process folders list |
|
195 |
foreach ($a_unsubscribed as $i => $folder) { |
|
196 |
$foldersplit = explode($delimiter, $folder); |
|
197 |
$name = rcube_charset_convert(array_pop($foldersplit), 'UTF-7'); |
|
198 |
$parent_folder = join($delimiter, $foldersplit); |
|
199 |
$level = count($foldersplit); |
|
200 |
|
|
201 |
// add a "virtual" parent folder |
|
202 |
if ($parent_folder && !$seen[$parent_folder]++) { |
|
203 |
$parent_name = rcube_charset_convert($foldersplit[$level-1], 'UTF-7'); |
|
204 |
$list_folders[] = array('id' => $parent_folder, 'name' => $parent_name, 'level' => $level-1, 'virtual' => true); |
|
205 |
} |
|
206 |
|
|
207 |
$list_folders[] = array('id' => $folder, 'name' => $name, 'level' => $level); |
|
208 |
$seen[$folder]++; |
|
209 |
} |
681a59
|
210 |
|
3e8bd7
|
211 |
$checkbox_subscribe = new html_checkbox(array( |
T |
212 |
'name' => '_subscribed[]', |
|
213 |
'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)", |
|
214 |
)); |
4e17e6
|
215 |
|
24053e
|
216 |
if (!empty($attrib['deleteicon'])) |
3e8bd7
|
217 |
$del_button = html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'), 'border' => 0)); |
4e17e6
|
218 |
else |
24053e
|
219 |
$del_button = rcube_label('delete'); |
4e17e6
|
220 |
|
24053e
|
221 |
if (!empty($attrib['renameicon'])) |
3e8bd7
|
222 |
$edit_button = html::img(array('src' => $CONFIG['skin_path'] . $attrib['renameicon'], 'alt' => rcube_label('rename'), 'border' => 0)); |
24053e
|
223 |
else |
731590
|
224 |
$edit_button = rcube_label('rename'); |
4e17e6
|
225 |
|
3e8bd7
|
226 |
// create list of available folders |
T |
227 |
foreach ($list_folders as $i => $folder) { |
|
228 |
$idx = $i + 1; |
|
229 |
$subscribed = in_array($folder['id'], $a_subscribed); |
|
230 |
$protected = ($folder['virtual'] || ($CONFIG['protect_default_folders'] == true && in_array($folder['id'], $CONFIG['default_imap_folders']))); |
|
231 |
$classes = array($i%2 ? 'even' : 'odd'); |
|
232 |
$folder_js = JQ($folder['id']); |
|
233 |
$display_folder = str_repeat(' ', $folder['level']) . ($protected ? rcmail_localize_foldername($folder['id']) : $folder['name']); |
|
234 |
$folder_utf8 = rcube_charset_convert($folder['id'], 'UTF-7'); |
|
235 |
|
|
236 |
if ($folder['virtual']) |
|
237 |
$classes[] = 'virtual'; |
|
238 |
|
|
239 |
$table->add_row(array('id' => 'rcmrow'.$idx, 'class' => join(' ', $classes))); |
|
240 |
|
|
241 |
$table->add('name', Q($display_folder)); |
|
242 |
$table->add('msgcount', ($folder['virtual'] ? '' : $IMAP->messagecount($folder['id']))); |
|
243 |
$table->add('subscribed', $protected ? ($subscribed ? ' •' : ' -') : |
|
244 |
$checkbox_subscribe->show(($subscribed ? $folder_utf8 : ''), array('value' => $folder_utf8))); |
|
245 |
|
|
246 |
// add rename and delete buttons |
|
247 |
if (!$protected) { |
|
248 |
$table->add('rename', html::a(array('href' => "#rename", 'title' => rcube_label('renamefolder')), $edit_button)); |
|
249 |
$table->add('delete', html::a(array('href' => "#delete", 'title' => rcube_label('deletefolder')), $del_button)); |
4e17e6
|
250 |
} |
3e8bd7
|
251 |
else { |
T |
252 |
$table->add(null, ''); |
|
253 |
$table->add(null, ''); |
|
254 |
} |
|
255 |
|
|
256 |
$a_js_folders['rcmrow'.$idx] = array($folder_utf8, $display_folder, $protected); |
|
257 |
} |
4e17e6
|
258 |
|
T |
259 |
|
f11541
|
260 |
$OUTPUT->add_gui_object('subscriptionlist', $attrib['id']); |
T |
261 |
$OUTPUT->set_env('subscriptionrows', $a_js_folders); |
b0dbf3
|
262 |
$OUTPUT->set_env('defaultfolders', $CONFIG['default_imap_folders']); |
9490b7
|
263 |
$OUTPUT->set_env('delimiter', $delimiter); |
4e17e6
|
264 |
|
3e8bd7
|
265 |
return $form_start . $table->show($attrib) . $form_end; |
4e17e6
|
266 |
} |
T |
267 |
|
|
268 |
|
|
269 |
function rcube_create_folder_form($attrib) |
|
270 |
{ |
a8d23d
|
271 |
global $OUTPUT; |
T |
272 |
|
4e17e6
|
273 |
list($form_start, $form_end) = get_form_tags($attrib, 'create-folder'); |
T |
274 |
unset($attrib['form']); |
|
275 |
|
a8d23d
|
276 |
if ($attrib['hintbox']) |
T |
277 |
$OUTPUT->add_gui_object('createfolderhint', $attrib['hintbox']); |
4e17e6
|
278 |
|
T |
279 |
// return the complete edit form as table |
|
280 |
$out = "$form_start\n"; |
|
281 |
|
47124c
|
282 |
$input = new html_inputfield(array('name' => '_folder_name')); |
4e17e6
|
283 |
$out .= $input->show(); |
T |
284 |
|
|
285 |
if (get_boolean($attrib['button'])) |
|
286 |
{ |
47124c
|
287 |
$button = new html_inputfield(array('type' => 'button', |
4e17e6
|
288 |
'value' => rcube_label('create'), |
f11541
|
289 |
'onclick' => JS_OBJECT_NAME.".command('create-folder',this.form)")); |
4e17e6
|
290 |
$out .= $button->show(); |
T |
291 |
} |
|
292 |
|
|
293 |
$out .= "\n$form_end"; |
|
294 |
|
|
295 |
return $out; |
|
296 |
} |
|
297 |
|
c8c1e0
|
298 |
function rcube_rename_folder_form($attrib) |
S |
299 |
{ |
f11541
|
300 |
global $CONFIG, $IMAP; |
c8c1e0
|
301 |
|
S |
302 |
list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder'); |
|
303 |
unset($attrib['form']); |
|
304 |
|
|
305 |
// return the complete edit form as table |
|
306 |
$out = "$form_start\n"; |
|
307 |
|
|
308 |
$a_unsubscribed = $IMAP->list_unsubscribed(); |
47124c
|
309 |
$select_folder = new html_select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder')); |
c8c1e0
|
310 |
|
S |
311 |
foreach ($a_unsubscribed as $i => $folder) |
|
312 |
{ |
|
313 |
if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders'])) |
|
314 |
continue; |
|
315 |
|
|
316 |
$select_folder->add($folder); |
|
317 |
} |
|
318 |
|
|
319 |
$out .= $select_folder->show(); |
|
320 |
|
|
321 |
$out .= " to "; |
47124c
|
322 |
$inputtwo = new html_inputfield(array('name' => '_folder_newname')); |
c8c1e0
|
323 |
$out .= $inputtwo->show(); |
S |
324 |
|
|
325 |
if (get_boolean($attrib['button'])) |
|
326 |
{ |
47124c
|
327 |
$button = new html_inputfield(array('type' => 'button', |
c8c1e0
|
328 |
'value' => rcube_label('rename'), |
f11541
|
329 |
'onclick' => JS_OBJECT_NAME.".command('rename-folder',this.form)")); |
c8c1e0
|
330 |
$out .= $button->show(); |
S |
331 |
} |
|
332 |
|
|
333 |
$out .= "\n$form_end"; |
a8d23d
|
334 |
|
c8c1e0
|
335 |
return $out; |
S |
336 |
} |
|
337 |
|
681a59
|
338 |
$OUTPUT->set_pagetitle(rcube_label('folders')); |
28c59f
|
339 |
$OUTPUT->include_script('list.js'); |
4e17e6
|
340 |
|
f11541
|
341 |
// register UI objects |
T |
342 |
$OUTPUT->add_handlers(array( |
|
343 |
'foldersubscription' => 'rcube_subscription_form', |
|
344 |
'createfolder' => 'rcube_create_folder_form', |
|
345 |
'renamefolder' => 'rcube_rename_folder_form' |
|
346 |
)); |
|
347 |
|
1cded8
|
348 |
// add some labels to client |
d93fc9
|
349 |
$OUTPUT->add_label('deletefolderconfirm','addsubfolderhint','forbiddencharacter','folderdeleting','folderrenaming','foldercreating'); |
1cded8
|
350 |
|
f11541
|
351 |
$OUTPUT->send('managefolders'); |
c8c1e0
|
352 |
?> |