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