Updating copyrights. Happy New Year.
[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 *
c0d96801 9 * @copyright 1999-2012 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
906f7e9f 37$imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0);
b7f83b61 38
32aa0074 39/* switch to the right function based on what the user selected */
40if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) {
32aa0074 41 switch ($action)
b7f83b61 42 {
32aa0074 43 case 'create':
199a9ab8 44
45 // first, validate security token
46 sm_validate_security_token($submitted_token, 3600, TRUE);
47
32aa0074 48 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
49 sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
50 sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
51 folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs);
52 $td_str = _("Created folder successfully.");
b7f83b61 53 break;
32aa0074 54 case 'rename':
55 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
56 break;
57 }
58 if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) {
59 sqgetGlobalVar('old_name', $old_name, SQ_POST);
60 folders_rename_getname($imapConnection, $delimiter, $old_name);
61 } else {
199a9ab8 62
63 // first, validate security token
64 sm_validate_security_token($submitted_token, 3600, TRUE);
65
32aa0074 66 sqgetGlobalVar('orig', $orig, SQ_POST);
67 sqgetGlobalVar('old_name', $old_name, SQ_POST);
68 folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name);
333daac7 69 $td_str = _("Renamed successfully.");
32aa0074 70 }
b7f83b61 71 break;
72 case 'delete':
32aa0074 73 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
74 break;
75 }
76 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
77 if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) {
199a9ab8 78
79 // first, validate security token
80 sm_validate_security_token($submitted_token, 3600, TRUE);
81
32aa0074 82 folders_delete_do($imapConnection, $delimiter, $folder_name);
83 $td_str = _("Deleted folder successfully.");
84 } else {
85 folders_delete_ask($imapConnection, $folder_name);
86 }
b7f83b61 87 break;
32aa0074 88 case 'subscribe':
199a9ab8 89
90 // first, validate security token
91 sm_validate_security_token($submitted_token, 3600, TRUE);
92
32aa0074 93 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
94 folders_subscribe($imapConnection, $folder_names);
95 $td_str = _("Subscribed successfully.");
b7f83b61 96 break;
32aa0074 97 case 'unsubscribe':
199a9ab8 98
99 // first, validate security token
100 sm_validate_security_token($submitted_token, 3600, TRUE);
101
32aa0074 102 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
103 folders_unsubscribe($imapConnection, $folder_names);
104 $td_str = _("Unsubscribed successfully.");
b7f83b61 105 break;
decb0c39 106 default:
6e515418 107// TODO: this is a new hook for plugin action processing that has not been TESTED.
108 $td_str = do_hook('folder_action', $action);
decb0c39 109 break;
f8a1ed5a 110 }
dcc1cc82 111
e634431a 112}
b7f83b61 113
301d1912 114if (isset($td_str)) {
115 $oTemplate->assign('note', htmlspecialchars($td_str));
116 $oTemplate->display('note.tpl');
117}
118
cedd503c 119$boxes = sqimap_mailbox_list($imapConnection,true);
e634431a 120
121/** CREATING FOLDERS **/
7f0a2c23 122
45f836eb 123$show_selected = array();
124$skip_folders = array();
7f0a2c23 125$server_type = strtolower($imap_server_type);
decb0c39 126
127// Special handling for courier
7f0a2c23 128if ( $server_type == 'courier' ) {
decb0c39 129 if ( $default_folder_prefix == 'INBOX.' ) {
130 // We don't need INBOX, since it is top folder
131 array_push($skip_folders, 'INBOX');
132 }
e498ebbd 133} elseif ( $server_type == 'bincimap' ) {
134 if ( $default_folder_prefix == 'INBOX/' ) {
135 // We don't need INBOX, since it is top folder
136 array_push($skip_folders, 'INBOX');
137 }
7f0a2c23 138}
139
140if ( $default_sub_of_inbox == false ) {
9829e1d8 141 $mbx_option_list = '<option selected="selected" value="">[ '._("None")." ]</option>\n";
e634431a 142} else {
9829e1d8 143 $mbx_option_list = '<option value="">[ '._("None")." ]</option>\n";
be2d5495 144 $show_selected = array('inbox');
145}
be2d5495 146
6e2ae264 147// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
91e0dccc 148// the arrays of folders to include or skip (assembled above),
59a8e3e8 149// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
150// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
9829e1d8 151$mbx_option_list .= sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
e634431a 152
0037f048 153
154/** count special folders **/
decb0c39 155foreach ($boxes as $index => $aBoxData) {
ceb7ad3c 156 if (isSpecialMailbox($aBoxData['unformatted'],false) &&
decb0c39 157 ! in_array($aBoxData['unformatted'],$skip_folders)) {
158 $skip_folders[] = $aBoxData['unformatted'];
5c4ff7bf 159 }
0037f048 160}
161
decb0c39 162/**
163 * Retrieve list of folders when special folders are excluded. Special folders
164 * should be unavailable in rename/delete/unsubscribe. Theoretically user can
5c4ff7bf 165 * modify form and perform these operations with special folders, but if user
166 * manages to delete/rename/unsubscribe special folder by hacking form...
decb0c39 167 *
168 * If script or program depends on special folder, they should not assume that
169 * folder is available.
170 *
171 * $filtered_folders contains empty string or html formated option list.
172 */
9829e1d8 173$rendel_folder_list = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
e634431a 174
50ed645b 175
301d1912 176$subbox_option_list = array();
50ed645b 177
9829e1d8 178if ($show_only_subscribed_folders && !$no_list_for_subscribe) {
decb0c39 179 // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed
301d1912 180
decb0c39 181 // TODO: use checkboxes instead of select options.
301d1912 182 // DONE Steve Brown 2006-08-08
50ed645b 183
9829e1d8 184 /** SUBSCRIBE TO FOLDERS **/
185 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
186
187 // here we filter out all boxes we're already subscribed to,
188 // so we keep only the unsubscribed ones.
189 foreach ($boxes_all as $box_a) {
190
301d1912 191 $use_folder = true;
192 foreach ( $boxes as $box ) {
193 if ($box_a['unformatted'] == $box['unformatted'] ||
194 $box_a['unformatted-dm'] == $folder_prefix ) {
195 $use_folder = false;
196 }
197 }
198
199 if ($use_folder) {
200 $box_enc = htmlspecialchars($box_a['unformatted-dm']);
201 $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
202 $subbox_option_list[] = array( 'Value' => $box_enc, 'Display' => $box_disp);
203 }
9829e1d8 204 }
e634431a 205}
e7db48af 206
32aa0074 207sqimap_logout($imapConnection);
a2b193bc 208
301d1912 209$oTemplate->assign('show_subfolders_option', $show_contain_subfolders_option);
210$oTemplate->assign('show_only_subscribed_folders', $show_only_subscribed_folders==1);
211$oTemplate->assign('no_list_for_subscribe', $no_list_for_subscribe);
212
9829e1d8 213$oTemplate->assign('mbx_option_list', $mbx_option_list);
9829e1d8 214$oTemplate->assign('rendel_folder_list', $rendel_folder_list);
215$oTemplate->assign('subbox_option_list', $subbox_option_list);
9829e1d8 216
217$oTemplate->display('folder_manip.tpl');
218
5c4ff7bf 219$oTemplate->display('footer.tpl');