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