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 | |
cbbef3
|
8 |
| Copyright (C) 2005-2009, 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 |
|
a5897a
|
22 |
// WARNING: folder names in UI are encoded with RCMAIL_CHARSET |
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 |
{ |
a5897a
|
30 |
if ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST, false, 'UTF7-IMAP')) |
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 |
{ |
a5897a
|
37 |
if ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST, false, 'UTF7-IMAP')) |
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 |
{ |
a5897a
|
46 |
$name = trim(get_input_value('_name', RCUBE_INPUT_POST, FALSE, 'UTF7-IMAP')); |
32ac95
|
47 |
$create = $IMAP->create_mailbox($name, TRUE); |
A |
48 |
} |
|
49 |
|
f11541
|
50 |
if ($create && $OUTPUT->ajax_call) |
4e17e6
|
51 |
{ |
9490b7
|
52 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
681a59
|
53 |
$folderlist = $IMAP->list_unsubscribed(); |
A |
54 |
$index = array_search($create, $folderlist); |
a5897a
|
55 |
$before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; |
681a59
|
56 |
|
a5897a
|
57 |
$create = rcube_charset_convert($create, 'UTF7-IMAP'); |
9490b7
|
58 |
$foldersplit = explode($delimiter, $create); |
681a59
|
59 |
$display_create = str_repeat(' ', substr_count($create, $delimiter)) . $foldersplit[count($foldersplit)-1]; |
A |
60 |
|
|
61 |
$OUTPUT->command('add_folder_row', $create, $display_create, false, $before); |
4e17e6
|
62 |
} |
09c1a3
|
63 |
else if (!$create) |
4e17e6
|
64 |
{ |
f11541
|
65 |
$OUTPUT->show_message('errorsaving', 'error'); |
4e17e6
|
66 |
} |
c8c1e0
|
67 |
} |
S |
68 |
|
|
69 |
// rename a mailbox |
197601
|
70 |
else if ($RCMAIL->action=='rename-folder') |
c8c1e0
|
71 |
{ |
8d0758
|
72 |
if (!empty($_POST['_folder_oldname']) && !empty($_POST['_folder_newname'])) |
32ac95
|
73 |
{ |
681a59
|
74 |
$name_utf8 = trim(get_input_value('_folder_newname', RCUBE_INPUT_POST)); |
A |
75 |
$oldname_utf8 = get_input_value('_folder_oldname', RCUBE_INPUT_POST); |
a5897a
|
76 |
$name = rcube_charset_convert($name_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); |
A |
77 |
$oldname = rcube_charset_convert($oldname_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); |
681a59
|
78 |
|
A |
79 |
$rename = $IMAP->rename_mailbox($oldname, $name); |
32ac95
|
80 |
} |
A |
81 |
|
f11541
|
82 |
if ($rename && $OUTPUT->ajax_call) |
c8c1e0
|
83 |
{ |
681a59
|
84 |
$folderlist = $IMAP->list_unsubscribed(); |
9490b7
|
85 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
681a59
|
86 |
|
A |
87 |
$regexp = '/^' . preg_quote($rename . $delimiter, '/') . '/'; |
|
88 |
|
|
89 |
// subfolders |
|
90 |
for ($x=sizeof($folderlist)-1; $x>=0; $x--) |
|
91 |
{ |
|
92 |
if (preg_match($regexp, $folderlist[$x])) |
|
93 |
{ |
3e8bd7
|
94 |
$oldfolder = $oldname . $delimiter . preg_replace($regexp, '', $folderlist[$x]); |
681a59
|
95 |
$foldersplit = explode($delimiter, $folderlist[$x]); |
A |
96 |
$level = count($foldersplit) - 1; |
|
97 |
$display_rename = str_repeat(' ', $level) |
a5897a
|
98 |
. rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'); |
681a59
|
99 |
|
a5897a
|
100 |
$before = isset($folderlist[$x+1]) ? rcube_charset_convert($folderlist[$x+1], 'UTF7-IMAP') : false; |
681a59
|
101 |
|
a5897a
|
102 |
$OUTPUT->command('replace_folder_row', rcube_charset_convert($oldfolder, 'UTF7-IMAP'), |
A |
103 |
rcube_charset_convert($folderlist[$x], 'UTF7-IMAP'), $display_rename, $before); |
681a59
|
104 |
} |
A |
105 |
} |
|
106 |
|
9490b7
|
107 |
$foldersplit = explode($delimiter, $rename); |
6b79f7
|
108 |
$level = count($foldersplit) - 1; |
a5897a
|
109 |
$display_rename = str_repeat(' ', $level) . rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'); |
681a59
|
110 |
$index = array_search($rename, $folderlist); |
a5897a
|
111 |
$before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; |
09c1a3
|
112 |
|
a5897a
|
113 |
$OUTPUT->command('replace_folder_row', $oldname_utf8, rcube_charset_convert($rename, 'UTF7-IMAP'), $display_rename, $before); |
f11541
|
114 |
$OUTPUT->command('reset_folder_rename'); |
c8c1e0
|
115 |
} |
f11541
|
116 |
else if (!$rename && $OUTPUT->ajax_call) |
c8c1e0
|
117 |
{ |
f11541
|
118 |
$OUTPUT->command('reset_folder_rename'); |
T |
119 |
$OUTPUT->show_message('errorsaving', 'error'); |
c8c1e0
|
120 |
} |
S |
121 |
else if (!$rename) |
f11541
|
122 |
$OUTPUT->show_message('errorsaving', 'error'); |
4e17e6
|
123 |
} |
T |
124 |
|
|
125 |
// delete an existing IMAP mailbox |
197601
|
126 |
else if ($RCMAIL->action=='delete-folder') |
4e17e6
|
127 |
{ |
681a59
|
128 |
$a_mboxes = $IMAP->list_unsubscribed(); |
97a656
|
129 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
681a59
|
130 |
|
A |
131 |
$mboxes_utf8 = get_input_value('_mboxes', RCUBE_INPUT_POST); |
a5897a
|
132 |
$mboxes = rcube_charset_convert($mboxes_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); |
97a656
|
133 |
|
681a59
|
134 |
if ($mboxes) |
b3ce79
|
135 |
$deleted = $IMAP->delete_mailbox(array($mboxes)); |
4e17e6
|
136 |
|
f11541
|
137 |
if ($OUTPUT->ajax_call && $deleted) |
f9c107
|
138 |
{ |
681a59
|
139 |
$OUTPUT->command('remove_folder_row', $mboxes_utf8); |
97a656
|
140 |
foreach ($a_mboxes as $mbox) |
fa0152
|
141 |
{ |
681a59
|
142 |
if (preg_match('/^'. preg_quote($mboxes.$delimiter, '/') .'/', $mbox)) |
fa0152
|
143 |
{ |
a5897a
|
144 |
$OUTPUT->command('remove_folder_row', rcube_charset_convert($mbox, 'UTF7-IMAP')); |
fa0152
|
145 |
} |
T |
146 |
} |
f11541
|
147 |
$OUTPUT->show_message('folderdeleted', 'confirmation'); |
f9c107
|
148 |
} |
09c1a3
|
149 |
else if (!$deleted) |
1cded8
|
150 |
{ |
f11541
|
151 |
$OUTPUT->show_message('errorsaving', 'error'); |
1cded8
|
152 |
} |
4e17e6
|
153 |
} |
T |
154 |
|
09c1a3
|
155 |
if ($OUTPUT->ajax_call) |
A |
156 |
$OUTPUT->send(); |
4e17e6
|
157 |
|
T |
158 |
|
|
159 |
// build table with all folders listed by server |
|
160 |
function rcube_subscription_form($attrib) |
|
161 |
{ |
f11541
|
162 |
global $IMAP, $CONFIG, $OUTPUT; |
4e17e6
|
163 |
|
T |
164 |
list($form_start, $form_end) = get_form_tags($attrib, 'folders'); |
|
165 |
unset($attrib['form']); |
|
166 |
|
|
167 |
if (!$attrib['id']) |
|
168 |
$attrib['id'] = 'rcmSubscriptionlist'; |
|
169 |
|
3e8bd7
|
170 |
$table = new html_table(); |
4e17e6
|
171 |
|
T |
172 |
// add table header |
3e8bd7
|
173 |
$table->add_header('name', rcube_label('foldername')); |
T |
174 |
$table->add_header('msgcount', rcube_label('messagecount')); |
|
175 |
$table->add_header('subscribed', rcube_label('subscribed')); |
|
176 |
$table->add_header('rename', ' '); |
|
177 |
$table->add_header('delete', ' '); |
4e17e6
|
178 |
|
T |
179 |
|
|
180 |
// get folders from server |
4d4264
|
181 |
$IMAP->clear_cache('mailboxes'); |
T |
182 |
|
4e17e6
|
183 |
$a_unsubscribed = $IMAP->list_unsubscribed(); |
T |
184 |
$a_subscribed = $IMAP->list_mailboxes(); |
9490b7
|
185 |
$delimiter = $IMAP->get_hierarchy_delimiter(); |
3e8bd7
|
186 |
$a_js_folders = $seen_folders = $list_folders = array(); |
cbf1f3
|
187 |
|
3e8bd7
|
188 |
// pre-process folders list |
T |
189 |
foreach ($a_unsubscribed as $i => $folder) { |
|
190 |
$foldersplit = explode($delimiter, $folder); |
a5897a
|
191 |
$name = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP'); |
3e8bd7
|
192 |
$parent_folder = join($delimiter, $foldersplit); |
T |
193 |
$level = count($foldersplit); |
cbf1f3
|
194 |
|
0456f8
|
195 |
// add any necessary "virtual" parent folders |
A |
196 |
if ($parent_folder && !$seen[$parent_folder]) { |
|
197 |
for ($i=1; $i<=$level; $i++) { |
|
198 |
$ancestor_folder = join($delimiter, array_slice($foldersplit, 0, $i)); |
|
199 |
if ($ancestor_folder && !$seen[$ancestor_folder]++) { |
a5897a
|
200 |
$ancestor_name = rcube_charset_convert($foldersplit[$i-1], 'UTF7-IMAP'); |
0456f8
|
201 |
$list_folders[] = array('id' => $ancestor_folder, 'name' => $ancestor_name, 'level' => $i-1, 'virtual' => true); |
A |
202 |
} |
|
203 |
} |
3e8bd7
|
204 |
} |
T |
205 |
|
|
206 |
$list_folders[] = array('id' => $folder, 'name' => $name, 'level' => $level); |
|
207 |
$seen[$folder]++; |
|
208 |
} |
681a59
|
209 |
|
3e8bd7
|
210 |
$checkbox_subscribe = new html_checkbox(array( |
T |
211 |
'name' => '_subscribed[]', |
|
212 |
'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)", |
|
213 |
)); |
4e17e6
|
214 |
|
24053e
|
215 |
if (!empty($attrib['deleteicon'])) |
70087c
|
216 |
$del_button = html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))); |
4e17e6
|
217 |
else |
24053e
|
218 |
$del_button = rcube_label('delete'); |
4e17e6
|
219 |
|
24053e
|
220 |
if (!empty($attrib['renameicon'])) |
70087c
|
221 |
$edit_button = html::img(array('src' => $CONFIG['skin_path'] . $attrib['renameicon'], 'alt' => rcube_label('rename'))); |
24053e
|
222 |
else |
731590
|
223 |
$edit_button = rcube_label('rename'); |
4e17e6
|
224 |
|
3e8bd7
|
225 |
// create list of available folders |
T |
226 |
foreach ($list_folders as $i => $folder) { |
|
227 |
$idx = $i + 1; |
|
228 |
$subscribed = in_array($folder['id'], $a_subscribed); |
0456f8
|
229 |
$protected = ($CONFIG['protect_default_folders'] == true && in_array($folder['id'], $CONFIG['default_imap_folders'])); |
3e8bd7
|
230 |
$classes = array($i%2 ? 'even' : 'odd'); |
T |
231 |
$folder_js = JQ($folder['id']); |
|
232 |
$display_folder = str_repeat(' ', $folder['level']) . ($protected ? rcmail_localize_foldername($folder['id']) : $folder['name']); |
a5897a
|
233 |
$folder_utf8 = rcube_charset_convert($folder['id'], 'UTF7-IMAP'); |
3e8bd7
|
234 |
|
T |
235 |
if ($folder['virtual']) |
|
236 |
$classes[] = 'virtual'; |
|
237 |
|
|
238 |
$table->add_row(array('id' => 'rcmrow'.$idx, 'class' => join(' ', $classes))); |
|
239 |
|
|
240 |
$table->add('name', Q($display_folder)); |
|
241 |
$table->add('msgcount', ($folder['virtual'] ? '' : $IMAP->messagecount($folder['id']))); |
0456f8
|
242 |
$table->add('subscribed', ($protected || $folder['virtual']) ? ($subscribed ? ' •' : ' ') : |
3e8bd7
|
243 |
$checkbox_subscribe->show(($subscribed ? $folder_utf8 : ''), array('value' => $folder_utf8))); |
T |
244 |
|
|
245 |
// add rename and delete buttons |
0456f8
|
246 |
if (!$protected && !$folder['virtual']) { |
3e8bd7
|
247 |
$table->add('rename', html::a(array('href' => "#rename", 'title' => rcube_label('renamefolder')), $edit_button)); |
T |
248 |
$table->add('delete', html::a(array('href' => "#delete", 'title' => rcube_label('deletefolder')), $del_button)); |
4e17e6
|
249 |
} |
3e8bd7
|
250 |
else { |
de2e0b
|
251 |
$table->add('rename', ' '); |
A |
252 |
$table->add('delete', ' '); |
3e8bd7
|
253 |
} |
T |
254 |
|
0456f8
|
255 |
$a_js_folders['rcmrow'.$idx] = array($folder_utf8, $display_folder, $protected || $folder['virtual']); |
3e8bd7
|
256 |
} |
4e17e6
|
257 |
|
cc97ea
|
258 |
rcmail::get_instance()->plugins->exec_hook('manage_folders', array('table'=>$table)); |
4e17e6
|
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 |
701b9a
|
349 |
$OUTPUT->add_label('deletefolderconfirm','addsubfolderhint','forbiddencharacter','folderdeleting','folderrenaming','foldercreating','foldermoving'); |
1cded8
|
350 |
|
f11541
|
351 |
$OUTPUT->send('managefolders'); |
c8c1e0
|
352 |
?> |