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 © 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 |
19 | require('../include/init.php'); |
86725763 |
20 | |
21 | /* SquirrelMail required files. */ |
202bcbcc |
22 | require_once(SM_PATH . 'functions/imap_general.php'); |
32aa0074 |
23 | require_once(SM_PATH . 'functions/folder_manip.php'); |
62366261 |
24 | require_once(SM_PATH . 'functions/forms.php'); |
d3cdb279 |
25 | |
e634431a |
26 | displayPageHeader($color, 'None'); |
aa42fbfb |
27 | |
a32985a5 |
28 | /* get globals we may need */ |
29 | |
f38b7cf0 |
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 | |
32aa0074 |
35 | sqgetGlobalVar('smaction', $action, SQ_POST); |
a32985a5 |
36 | |
37 | /* end of get globals */ |
38 | |
32aa0074 |
39 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
b7f83b61 |
40 | |
32aa0074 |
41 | /* switch to the right function based on what the user selected */ |
42 | if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) { |
b7f83b61 |
43 | |
32aa0074 |
44 | switch ($action) |
b7f83b61 |
45 | { |
32aa0074 |
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."); |
b7f83b61 |
52 | break; |
32aa0074 |
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); |
333daac7 |
64 | $td_str = _("Renamed successfully."); |
32aa0074 |
65 | } |
b7f83b61 |
66 | break; |
67 | case 'delete': |
32aa0074 |
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 | } |
b7f83b61 |
78 | break; |
32aa0074 |
79 | case 'subscribe': |
80 | sqgetGlobalVar('folder_names', $folder_names, SQ_POST); |
81 | folders_subscribe($imapConnection, $folder_names); |
82 | $td_str = _("Subscribed successfully."); |
b7f83b61 |
83 | break; |
32aa0074 |
84 | case 'unsubscribe': |
85 | sqgetGlobalVar('folder_names', $folder_names, SQ_POST); |
86 | folders_unsubscribe($imapConnection, $folder_names); |
87 | $td_str = _("Unsubscribed successfully."); |
b7f83b61 |
88 | break; |
decb0c39 |
89 | default: |
90 | // TODO: add hook for plugin action processing. |
91 | $td_str = ''; |
92 | break; |
f8a1ed5a |
93 | } |
dcc1cc82 |
94 | |
e634431a |
95 | } |
b7f83b61 |
96 | |
cedd503c |
97 | $boxes = sqimap_mailbox_list($imapConnection,true); |
e634431a |
98 | |
99 | /** CREATING FOLDERS **/ |
7f0a2c23 |
100 | |
45f836eb |
101 | $show_selected = array(); |
102 | $skip_folders = array(); |
7f0a2c23 |
103 | $server_type = strtolower($imap_server_type); |
decb0c39 |
104 | |
105 | // Special handling for courier |
7f0a2c23 |
106 | if ( $server_type == 'courier' ) { |
decb0c39 |
107 | /** |
108 | * If we use courier, we should hide system trash folder |
5c4ff7bf |
109 | * FIXME: (tokul) Who says that courier does not allow storing folders in |
110 | * INBOX.Trash or inbox.trash? Can't reproduce it 3.0.8. This entry is |
111 | * useless, because in_array() check is case sensitive and INBOX is in |
decb0c39 |
112 | * upper case. |
113 | */ |
114 | array_push($skip_folders, 'inbox.trash'); |
115 | |
116 | if ( $default_folder_prefix == 'INBOX.' ) { |
117 | // We don't need INBOX, since it is top folder |
118 | array_push($skip_folders, 'INBOX'); |
119 | } |
e498ebbd |
120 | } elseif ( $server_type == 'bincimap' ) { |
121 | if ( $default_folder_prefix == 'INBOX/' ) { |
122 | // We don't need INBOX, since it is top folder |
123 | array_push($skip_folders, 'INBOX'); |
124 | } |
7f0a2c23 |
125 | } |
126 | |
127 | if ( $default_sub_of_inbox == false ) { |
9829e1d8 |
128 | $mbx_option_list = '<option selected="selected" value="">[ '._("None")." ]</option>\n"; |
e634431a |
129 | } else { |
9829e1d8 |
130 | $mbx_option_list = '<option value="">[ '._("None")." ]</option>\n"; |
be2d5495 |
131 | $show_selected = array('inbox'); |
132 | } |
be2d5495 |
133 | |
6e2ae264 |
134 | // Call sqimap_mailbox_option_list, using existing connection to IMAP server, |
91e0dccc |
135 | // the arrays of folders to include or skip (assembled above), |
59a8e3e8 |
136 | // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders. |
137 | // use the long format to show subfolders in an intelligible way if parent is missing (special folder) |
9829e1d8 |
138 | $mbx_option_list .= sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true); |
e634431a |
139 | |
0037f048 |
140 | |
141 | /** count special folders **/ |
decb0c39 |
142 | foreach ($boxes as $index => $aBoxData) { |
143 | if (isSpecialMailbox($aBoxData['unformatted']) && |
144 | ! in_array($aBoxData['unformatted'],$skip_folders)) { |
145 | $skip_folders[] = $aBoxData['unformatted']; |
5c4ff7bf |
146 | } |
0037f048 |
147 | } |
148 | |
decb0c39 |
149 | /** |
150 | * Retrieve list of folders when special folders are excluded. Special folders |
151 | * should be unavailable in rename/delete/unsubscribe. Theoretically user can |
5c4ff7bf |
152 | * modify form and perform these operations with special folders, but if user |
153 | * manages to delete/rename/unsubscribe special folder by hacking form... |
decb0c39 |
154 | * |
155 | * If script or program depends on special folder, they should not assume that |
156 | * folder is available. |
157 | * |
158 | * $filtered_folders contains empty string or html formated option list. |
159 | */ |
9829e1d8 |
160 | $rendel_folder_list = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
e634431a |
161 | |
50ed645b |
162 | |
9829e1d8 |
163 | $subbox_option_list = ''; |
50ed645b |
164 | |
9829e1d8 |
165 | if ($show_only_subscribed_folders && !$no_list_for_subscribe) { |
decb0c39 |
166 | // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed |
167 | // TODO: use checkboxes instead of select options. |
50ed645b |
168 | |
9829e1d8 |
169 | /** SUBSCRIBE TO FOLDERS **/ |
170 | $boxes_all = sqimap_mailbox_list_all ($imapConnection); |
171 | |
172 | // here we filter out all boxes we're already subscribed to, |
173 | // so we keep only the unsubscribed ones. |
174 | foreach ($boxes_all as $box_a) { |
175 | |
176 | $use_folder = true; |
177 | foreach ( $boxes as $box ) { |
178 | if ($box_a['unformatted'] == $box['unformatted'] || |
179 | $box_a['unformatted-dm'] == $folder_prefix ) { |
180 | $use_folder = false; |
181 | } |
182 | } |
183 | |
184 | if ($use_folder) { |
185 | $box_enc = htmlspecialchars($box_a['unformatted-dm']); |
186 | $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp'])); |
187 | $subbox_option_list .= '<option value="' . $box_enc . '">'.$box_disp."</option>\n"; |
188 | } |
189 | } |
e634431a |
190 | } |
e7db48af |
191 | |
32aa0074 |
192 | sqimap_logout($imapConnection); |
a2b193bc |
193 | |
9829e1d8 |
194 | $oTemplate->assign('td_str', @$td_str); |
195 | $oTemplate->assign('color', $color); |
196 | $oTemplate->assign('mbx_option_list', $mbx_option_list); |
197 | $oTemplate->assign('show_contain_subfolders_option', $show_contain_subfolders_option); |
198 | $oTemplate->assign('show_only_subscribed_folders', $show_only_subscribed_folders); |
199 | $oTemplate->assign('rendel_folder_list', $rendel_folder_list); |
200 | $oTemplate->assign('subbox_option_list', $subbox_option_list); |
201 | $oTemplate->assign('no_list_for_subscribe', $no_list_for_subscribe); |
202 | |
203 | $oTemplate->display('folder_manip.tpl'); |
204 | |
5c4ff7bf |
205 | $oTemplate->display('footer.tpl'); |
9829e1d8 |
206 | |