source: github/program/steps/settings/save_folder.inc @ 67975b9

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 67975b9 was 67975b9, checked in by alecpl <alec@…>, 2 years ago
  • Improved namespace roots handling in folder manager
  • Property mode set to 100644
File size: 6.1 KB
Line 
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-2009, The Roundcube Dev Team                       |
9 | Licensed under the GNU GPL                                            |
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();
37$options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array();
38
39// Folder name checks
40if ($options['protected'] || $options['norename']) {
41}
42else if (!strlen($name)) {
43    $error = rcube_label('cannotbeempty');
44}
45else if (mb_strlen($name) > 128) {
46    $error = rcube_label('nametoolong');
47}
48else {
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
58if ($error) {
59    $OUTPUT->command('display_message', $error, 'error');
60}
61else {
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 = $RCMAIL->imap->mod_mailbox($name, 'in');
70    }
71
72    $folder['name']     = $name_imap;
73    $folder['oldname']  = $old_imap;
74    $folder['class']    = '';
75    $folder['options']  = $options;
76    $folder['settings'] = array(
77        // List view mode: 0-list, 1-threads
78        'view_mode'   => (int) get_input_value('_viewmode', RCUBE_INPUT_POST),
79        'sort_column' => get_input_value('_sortcol', RCUBE_INPUT_POST),
80        'sort_order'  => get_input_value('_sortord', RCUBE_INPUT_POST),
81    );
82}
83
84// create a new mailbox
85if (!$error && !strlen($old)) {
86
87    $folder['subscribe'] = true;
88
89    $plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder));
90
91    $folder = $plugin['record'];
92
93    if (!$plugin['abort']) {
94        $created = $IMAP->create_mailbox($folder['name'], $folder['subscribe']);
95    }
96    else {
97        $created = $plugin['result'];
98    }
99
100    if ($created) {
101        // Save folder settings
102        if (isset($_POST['_viewmode'])) {
103            $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
104
105            if ($_POST['_viewmode'])
106                $a_threaded[$folder['name']] = true;
107            else
108                unset($a_threaded[$folder['name']]);
109
110            $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
111        }
112
113        rcmail_update_folder_row($folder['name'], null, $folder['subscribe'], $folder['class']);
114        $OUTPUT->show_message('foldercreated', 'confirmation');
115        // reset folder preview frame
116        $OUTPUT->command('subscription_select');
117        $OUTPUT->send('iframe');
118    }
119    else {
120        // show error message
121        $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
122    }
123}
124
125// update a mailbox
126else if (!$error) {
127    $plugin = $RCMAIL->plugins->exec_hook('folder_update', array('record' => $folder));
128
129    $folder = $plugin['record'];
130    $rename = ($folder['oldname'] != $folder['name']);
131
132    if (!$plugin['abort']) {
133        if ($rename) {
134            $updated = $RCMAIL->imap->rename_mailbox($folder['oldname'], $folder['name']);
135        }
136        else {
137            $updated = true;
138        }
139    }
140    else {
141        $updated = $plugin['result'];
142    }
143
144    if ($updated) {
145        // Update folder settings,
146        if (isset($_POST['_viewmode'])) {
147            $a_threaded = (array) $RCMAIL->config->get('message_threading', array());
148
149            // In case of name change update names of childrens in settings
150            if ($rename) {
151                $oldprefix  = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/';
152                foreach ($a_threaded as $key => $val) {
153                    if ($key == $folder['oldname']) {
154                        unset($a_threaded[$key]);
155                    }
156                    else if (preg_match($oldprefix, $key)) {
157                        unset($a_threaded[$key]);
158                            $a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = true;
159                    }
160                }
161            }
162            if ($_POST['_viewmode'])
163                $a_threaded[$folder['name']] = true;
164            else
165                unset($a_threaded[$folder['name']]);
166
167            $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded));
168        }
169
170        $OUTPUT->show_message('folderupdated', 'confirmation');
171        if ($rename) {
172            rcmail_update_folder_row($folder['name'], $folder['oldname'], $folder['subscribe'], $folder['class']);
173            $OUTPUT->send('iframe');
174        }
175    }
176    else {
177        // show error message
178        $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
179    }
180}
181
182rcmail_overwrite_action('edit-folder');
Note: See TracBrowser for help on using the repository browser.