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