Fix variable name typo
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
35586184 2/**
3 * folders.php
4 *
35586184 5 * Handles all interaction between the user and the other folder
6 * scripts which do most of the work. Also handles the Special
7 * Folders.
8 *
c4faef33 9 * @copyright 1999-2020 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
14
ebd2391c 15/** This is the folders page */
16define('PAGE_NAME', 'folders');
17
30967a1e 18/**
202bcbcc 19 * Include the SquirrelMail initialization file.
30967a1e 20 */
202bcbcc 21require('../include/init.php');
86725763 22
23/* SquirrelMail required files. */
202bcbcc 24require_once(SM_PATH . 'functions/imap_general.php');
32aa0074 25require_once(SM_PATH . 'functions/folder_manip.php');
62366261 26require_once(SM_PATH . 'functions/forms.php');
d3cdb279 27
876fdb60 28displayPageHeader($color);
aa42fbfb 29
a32985a5 30/* get globals we may need */
f38b7cf0 31sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
32aa0074 32sqgetGlobalVar('smaction', $action, SQ_POST);
199a9ab8 33sqgetGlobalVar('smtoken', $submitted_token, SQ_POST, '');
a32985a5 34
35/* end of get globals */
36
a9805897 37global $imap_stream_options; // in case not defined in config
38$imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
b7f83b61 39
32aa0074 40/* switch to the right function based on what the user selected */
41if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) {
32aa0074 42 switch ($action)
b7f83b61 43 {
32aa0074 44 case 'create':
199a9ab8 45
46 // first, validate security token
2cefa62a 47 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 48
32aa0074 49 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
50 sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
51 sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
52 folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs);
53 $td_str = _("Created folder successfully.");
b7f83b61 54 break;
32aa0074 55 case 'rename':
56 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
57 break;
58 }
59 if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) {
60 sqgetGlobalVar('old_name', $old_name, SQ_POST);
61 folders_rename_getname($imapConnection, $delimiter, $old_name);
62 } else {
199a9ab8 63
64 // first, validate security token
2cefa62a 65 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 66
32aa0074 67 sqgetGlobalVar('orig', $orig, SQ_POST);
68 sqgetGlobalVar('old_name', $old_name, SQ_POST);
69 folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name);
333daac7 70 $td_str = _("Renamed successfully.");
32aa0074 71 }
b7f83b61 72 break;
73 case 'delete':
32aa0074 74 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
75 break;
76 }
77 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
78 if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) {
199a9ab8 79
80 // first, validate security token
2cefa62a 81 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 82
32aa0074 83 folders_delete_do($imapConnection, $delimiter, $folder_name);
84 $td_str = _("Deleted folder successfully.");
85 } else {
86 folders_delete_ask($imapConnection, $folder_name);
87 }
b7f83b61 88 break;
32aa0074 89 case 'subscribe':
199a9ab8 90
91 // first, validate security token
2cefa62a 92 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 93
32aa0074 94 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
95 folders_subscribe($imapConnection, $folder_names);
96 $td_str = _("Subscribed successfully.");
b7f83b61 97 break;
32aa0074 98 case 'unsubscribe':
199a9ab8 99
100 // first, validate security token
2cefa62a 101 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 102
32aa0074 103 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
104 folders_unsubscribe($imapConnection, $folder_names);
105 $td_str = _("Unsubscribed successfully.");
b7f83b61 106 break;
decb0c39 107 default:
6e515418 108// TODO: this is a new hook for plugin action processing that has not been TESTED.
109 $td_str = do_hook('folder_action', $action);
decb0c39 110 break;
f8a1ed5a 111 }
dcc1cc82 112
e634431a 113}
b7f83b61 114
301d1912 115if (isset($td_str)) {
3047e291 116 $oTemplate->assign('note', sm_encode_html_special_chars($td_str));
301d1912 117 $oTemplate->display('note.tpl');
118}
119
cedd503c 120$boxes = sqimap_mailbox_list($imapConnection,true);
e634431a 121
122/** CREATING FOLDERS **/
7f0a2c23 123
45f836eb 124$show_selected = array();
125$skip_folders = array();
7f0a2c23 126$server_type = strtolower($imap_server_type);
decb0c39 127
128// Special handling for courier
7f0a2c23 129if ( $server_type == 'courier' ) {
decb0c39 130 if ( $default_folder_prefix == 'INBOX.' ) {
131 // We don't need INBOX, since it is top folder
132 array_push($skip_folders, 'INBOX');
133 }
e498ebbd 134} elseif ( $server_type == 'bincimap' ) {
135 if ( $default_folder_prefix == 'INBOX/' ) {
136 // We don't need INBOX, since it is top folder
137 array_push($skip_folders, 'INBOX');
138 }
7f0a2c23 139}
140
141if ( $default_sub_of_inbox == false ) {
9829e1d8 142 $mbx_option_list = '<option selected="selected" value="">[ '._("None")." ]</option>\n";
e634431a 143} else {
9829e1d8 144 $mbx_option_list = '<option value="">[ '._("None")." ]</option>\n";
be2d5495 145 $show_selected = array('inbox');
146}
be2d5495 147
6e2ae264 148// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
91e0dccc 149// the arrays of folders to include or skip (assembled above),
59a8e3e8 150// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
151// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
9829e1d8 152$mbx_option_list .= sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
e634431a 153
0037f048 154
155/** count special folders **/
decb0c39 156foreach ($boxes as $index => $aBoxData) {
ceb7ad3c 157 if (isSpecialMailbox($aBoxData['unformatted'],false) &&
decb0c39 158 ! in_array($aBoxData['unformatted'],$skip_folders)) {
159 $skip_folders[] = $aBoxData['unformatted'];
5c4ff7bf 160 }
0037f048 161}
162
decb0c39 163/**
164 * Retrieve list of folders when special folders are excluded. Special folders
165 * should be unavailable in rename/delete/unsubscribe. Theoretically user can
5c4ff7bf 166 * modify form and perform these operations with special folders, but if user
167 * manages to delete/rename/unsubscribe special folder by hacking form...
decb0c39 168 *
169 * If script or program depends on special folder, they should not assume that
170 * folder is available.
171 *
172 * $filtered_folders contains empty string or html formated option list.
173 */
9829e1d8 174$rendel_folder_list = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
e634431a 175
50ed645b 176
301d1912 177$subbox_option_list = array();
50ed645b 178
9829e1d8 179if ($show_only_subscribed_folders && !$no_list_for_subscribe) {
decb0c39 180 // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed
301d1912 181
decb0c39 182 // TODO: use checkboxes instead of select options.
301d1912 183 // DONE Steve Brown 2006-08-08
50ed645b 184
9829e1d8 185 /** SUBSCRIBE TO FOLDERS **/
186 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
187
188 // here we filter out all boxes we're already subscribed to,
189 // so we keep only the unsubscribed ones.
190 foreach ($boxes_all as $box_a) {
191
301d1912 192 $use_folder = true;
193 foreach ( $boxes as $box ) {
194 if ($box_a['unformatted'] == $box['unformatted'] ||
195 $box_a['unformatted-dm'] == $folder_prefix ) {
196 $use_folder = false;
197 }
198 }
199
200 if ($use_folder) {
3047e291 201 $box_enc = sm_encode_html_special_chars($box_a['unformatted-dm']);
202 $box_disp = sm_encode_html_special_chars(imap_utf7_decode_local($box_a['unformatted-disp']));
301d1912 203 $subbox_option_list[] = array( 'Value' => $box_enc, 'Display' => $box_disp);
204 }
9829e1d8 205 }
e634431a 206}
e7db48af 207
32aa0074 208sqimap_logout($imapConnection);
a2b193bc 209
301d1912 210$oTemplate->assign('show_subfolders_option', $show_contain_subfolders_option);
211$oTemplate->assign('show_only_subscribed_folders', $show_only_subscribed_folders==1);
212$oTemplate->assign('no_list_for_subscribe', $no_list_for_subscribe);
213
9829e1d8 214$oTemplate->assign('mbx_option_list', $mbx_option_list);
9829e1d8 215$oTemplate->assign('rendel_folder_list', $rendel_folder_list);
216$oTemplate->assign('subbox_option_list', $subbox_option_list);
9829e1d8 217
218$oTemplate->display('folder_manip.tpl');
219
5c4ff7bf 220$oTemplate->display('footer.tpl');