4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_folder.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland |
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 4304 2010-12-03 10:58:40Z 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 $special = (strlen($old_imap) && in_array($old_imap, (array) $RCMAIL->config->get('default_imap_folders')));
38 $protected = ($special && $RCMAIL->config->get('protect_default_folders'));
44 else if (!strlen($name)) {
45 $error = rcube_label('cannotbeempty');
47 else if (mb_strlen($name) > 128) {
48 $error = rcube_label('nametoolong');
51 // these characters are problematic e.g. when used in LIST/LSUB
52 foreach (array($delimiter, '%', '*') as $char) {
53 if (strpos($name, $delimiter) !== false) {
54 $error = rcube_label('forbiddencharacter') . " ($char)";
61 $OUTPUT->command('display_message', $error, 'error');
65 $name_imap = $old_imap;
67 else if (strlen($path)) {
68 $name_imap = $path . $delimiter . $name_imap;
71 $folder['name'] = $name_imap;
72 $folder['oldname'] = $old_imap;
73 $folder['settings'] = array(
74 // List view mode: 0-list, 1-threads
75 'view_mode' => (int) get_input_value('_viewmode', RCUBE_INPUT_POST),
76 'sort_column' => get_input_value('_sortcol', RCUBE_INPUT_POST),
77 'sort_order' => get_input_value('_sortord', RCUBE_INPUT_POST),
81 // create a new mailbox
82 if (!$error && !strlen($old)) {
84 $plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder));
86 $folder = $plugin['record'];
88 if (!$plugin['abort']) {
89 $created = $IMAP->create_mailbox($folder['name'], TRUE);
92 $created = $plugin['result'];
96 // Save folder settings
97 if (isset($_POST['_viewmode'])) {
98 $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
100 if ($_POST['_viewmode'])
101 $a_threaded[$folder['name']] = true;
103 unset($a_threaded[$folder['name']]);
105 $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
108 $OUTPUT->show_message('foldercreated', 'confirmation');
109 $OUTPUT->command('reload', 250);
110 $OUTPUT->send('iframe');
113 // show error message
114 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
120 $plugin = $RCMAIL->plugins->exec_hook('folder_update', array('record' => $folder));
122 $folder = $plugin['record'];
123 $rename = ($folder['oldname'] != $folder['name']);
125 if (!$plugin['abort']) {
127 $updated = $RCMAIL->imap->rename_mailbox($folder['oldname'], $folder['name']);
134 $updated = $plugin['result'];
138 // Update folder settings,
139 if (isset($_POST['_viewmode'])) {
140 $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
142 // In case of name change update names of childrens in settings
144 $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
145 $oldprefix = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/';
146 foreach ($a_threaded as $key => $val) {
147 if ($key == $folder['oldname']) {
148 unset($a_threaded[$key]);
150 else if (preg_match($oldprefix, $key)) {
151 unset($a_threaded[$key]);
152 $a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = true;
156 if ($_POST['_viewmode'])
157 $a_threaded[$folder['name']] = true;
159 unset($a_threaded[$folder['name']]);
161 $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
164 $OUTPUT->show_message('folderupdated', 'confirmation');
166 $OUTPUT->command('reload', 250);
167 $OUTPUT->send('iframe');
171 // show error message
172 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
176 rcmail_overwrite_action('edit-folder');