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