| 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 © 1999-2005 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 | * Path for SquirrelMail required files. |
| 18 | * @ignore |
| 19 | */ |
| 20 | define('SM_PATH','../'); |
| 21 | |
| 22 | /* SquirrelMail required files. */ |
| 23 | require_once(SM_PATH . 'include/validate.php'); |
| 24 | require_once(SM_PATH . 'functions/imap.php'); |
| 25 | require_once(SM_PATH . 'functions/folder_manip.php'); |
| 26 | require_once(SM_PATH . 'functions/plugin.php'); |
| 27 | require_once(SM_PATH . 'functions/html.php'); |
| 28 | require_once(SM_PATH . 'functions/forms.php'); |
| 29 | |
| 30 | displayPageHeader($color, 'None'); |
| 31 | |
| 32 | /* get globals we may need */ |
| 33 | |
| 34 | sqgetGlobalVar('username', $username, SQ_SESSION); |
| 35 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
| 36 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 37 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
| 38 | |
| 39 | sqgetGlobalVar('smaction', $action, SQ_POST); |
| 40 | |
| 41 | /* end of get globals */ |
| 42 | |
| 43 | echo '<br />' . |
| 44 | html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . |
| 45 | html_tag( 'tr' ) . |
| 46 | html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' . |
| 47 | html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . |
| 48 | html_tag( 'tr' ) . |
| 49 | html_tag( 'td', '', 'center', $color[4] ); |
| 50 | |
| 51 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
| 52 | |
| 53 | /* switch to the right function based on what the user selected */ |
| 54 | if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) { |
| 55 | |
| 56 | switch ($action) |
| 57 | { |
| 58 | case 'create': |
| 59 | sqgetGlobalVar('folder_name', $folder_name, SQ_POST); |
| 60 | sqgetGlobalVar('subfolder', $subfolder, SQ_POST); |
| 61 | sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST); |
| 62 | folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs); |
| 63 | $td_str = _("Created folder successfully."); |
| 64 | break; |
| 65 | case 'rename': |
| 66 | if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) { |
| 67 | break; |
| 68 | } |
| 69 | if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) { |
| 70 | sqgetGlobalVar('old_name', $old_name, SQ_POST); |
| 71 | folders_rename_getname($imapConnection, $delimiter, $old_name); |
| 72 | } else { |
| 73 | sqgetGlobalVar('orig', $orig, SQ_POST); |
| 74 | sqgetGlobalVar('old_name', $old_name, SQ_POST); |
| 75 | folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name); |
| 76 | $td_str = _("Renamed successfully."); |
| 77 | } |
| 78 | break; |
| 79 | case 'delete': |
| 80 | if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) { |
| 81 | break; |
| 82 | } |
| 83 | sqgetGlobalVar('folder_name', $folder_name, SQ_POST); |
| 84 | if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) { |
| 85 | folders_delete_do($imapConnection, $delimiter, $folder_name); |
| 86 | $td_str = _("Deleted folder successfully."); |
| 87 | } else { |
| 88 | folders_delete_ask($imapConnection, $folder_name); |
| 89 | } |
| 90 | break; |
| 91 | case 'subscribe': |
| 92 | sqgetGlobalVar('folder_names', $folder_names, SQ_POST); |
| 93 | folders_subscribe($imapConnection, $folder_names); |
| 94 | $td_str = _("Subscribed successfully."); |
| 95 | break; |
| 96 | case 'unsubscribe': |
| 97 | sqgetGlobalVar('folder_names', $folder_names, SQ_POST); |
| 98 | folders_unsubscribe($imapConnection, $folder_names); |
| 99 | $td_str = _("Unsubscribed successfully."); |
| 100 | break; |
| 101 | default: |
| 102 | // TODO: add hook for plugin action processing. |
| 103 | $td_str = ''; |
| 104 | break; |
| 105 | } |
| 106 | |
| 107 | // if there are any messages, output them. |
| 108 | if ( !empty($td_str) ) { |
| 109 | echo html_tag( 'table', |
| 110 | html_tag( 'tr', |
| 111 | html_tag( 'td', '<b>' . $td_str . "</b><br />\n" . |
| 112 | '<a href="../src/left_main.php" target="left">' . |
| 113 | _("refresh folder list") . '</a>' , |
| 114 | 'center' ) |
| 115 | ) , |
| 116 | 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | echo "\n<br />"; |
| 121 | |
| 122 | $boxes = sqimap_mailbox_list($imapConnection,true); |
| 123 | |
| 124 | /** CREATING FOLDERS **/ |
| 125 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
| 126 | html_tag( 'tr', |
| 127 | html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) |
| 128 | ) . |
| 129 | html_tag( 'tr' ) . |
| 130 | html_tag( 'td', '', 'center', $color[0] ) . |
| 131 | addForm('folders.php', 'post', 'cf'). |
| 132 | addHidden('smaction','create'). |
| 133 | addInput('folder_name', '', 25). |
| 134 | "<br />\n". _("as a subfolder of"). '<br />'. |
| 135 | "<tt><select name=\"subfolder\">\n"; |
| 136 | |
| 137 | $show_selected = array(); |
| 138 | $skip_folders = array(); |
| 139 | $server_type = strtolower($imap_server_type); |
| 140 | |
| 141 | // Special handling for courier |
| 142 | if ( $server_type == 'courier' ) { |
| 143 | /** |
| 144 | * If we use courier, we should hide system trash folder |
| 145 | * FIXME: (tokul) Who says that courier does not allow storing folders in |
| 146 | * INBOX.Trash or inbox.trash? Can't reproduce it 3.0.8. This entry is |
| 147 | * useless, because in_array() check is case sensitive and INBOX is in |
| 148 | * upper case. |
| 149 | */ |
| 150 | array_push($skip_folders, 'inbox.trash'); |
| 151 | |
| 152 | if ( $default_folder_prefix == 'INBOX.' ) { |
| 153 | // We don't need INBOX, since it is top folder |
| 154 | array_push($skip_folders, 'INBOX'); |
| 155 | } |
| 156 | } elseif ( $server_type == 'bincimap' ) { |
| 157 | if ( $default_folder_prefix == 'INBOX/' ) { |
| 158 | // We don't need INBOX, since it is top folder |
| 159 | array_push($skip_folders, 'INBOX'); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if ( $default_sub_of_inbox == false ) { |
| 164 | echo '<option selected="selected" value="">[ '._("None")." ]</option>\n"; |
| 165 | } else { |
| 166 | echo '<option value="">[ '._("None")." ]</option>\n"; |
| 167 | $show_selected = array('inbox'); |
| 168 | } |
| 169 | |
| 170 | // Call sqimap_mailbox_option_list, using existing connection to IMAP server, |
| 171 | // the arrays of folders to include or skip (assembled above), |
| 172 | // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders. |
| 173 | // use the long format to show subfolders in an intelligible way if parent is missing (special folder) |
| 174 | echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true); |
| 175 | |
| 176 | echo "</select></tt>\n"; |
| 177 | if ($show_contain_subfolders_option) { |
| 178 | echo '<br />'. |
| 179 | addCheckBox('contain_subs', FALSE, '1') .' ' |
| 180 | . _("Let this folder contain subfolders") |
| 181 | . '<br />'; |
| 182 | } |
| 183 | echo "<input type=\"submit\" value=\""._("Create")."\" />\n"; |
| 184 | echo "</form></td></tr>\n"; |
| 185 | |
| 186 | echo html_tag( 'tr', |
| 187 | html_tag( 'td', ' ', 'left', $color[4] ) |
| 188 | ) ."\n"; |
| 189 | |
| 190 | /** count special folders **/ |
| 191 | foreach ($boxes as $index => $aBoxData) { |
| 192 | if (isSpecialMailbox($aBoxData['unformatted']) && |
| 193 | ! in_array($aBoxData['unformatted'],$skip_folders)) { |
| 194 | $skip_folders[] = $aBoxData['unformatted']; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Retrieve list of folders when special folders are excluded. Special folders |
| 200 | * should be unavailable in rename/delete/unsubscribe. Theoretically user can |
| 201 | * modify form and perform these operations with special folders, but if user |
| 202 | * manages to delete/rename/unsubscribe special folder by hacking form... |
| 203 | * |
| 204 | * If script or program depends on special folder, they should not assume that |
| 205 | * folder is available. |
| 206 | * |
| 207 | * $filtered_folders contains empty string or html formated option list. |
| 208 | */ |
| 209 | $filtered_folders = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); |
| 210 | |
| 211 | /** RENAMING FOLDERS **/ |
| 212 | echo html_tag( 'tr', |
| 213 | html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) |
| 214 | ) . |
| 215 | html_tag( 'tr' ) . |
| 216 | html_tag( 'td', '', 'center', $color[0] ); |
| 217 | |
| 218 | /* show only if we have folders to rename */ |
| 219 | if (! empty($filtered_folders)) { |
| 220 | echo addForm('folders.php') |
| 221 | . addHidden('smaction', 'rename') |
| 222 | . "<tt><select name=\"old_name\">\n" |
| 223 | . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; |
| 224 | |
| 225 | // use existing IMAP connection, we have no special values to show, |
| 226 | // but we do include values to skip. Use the pre-created $boxes to save an IMAP query. |
| 227 | // send NULL for the flag - ALL folders are eligible for rename! |
| 228 | // use long format to make sure folder names make sense when parents may be missing. |
| 229 | echo $filtered_folders; |
| 230 | |
| 231 | echo "</select></tt>\n". |
| 232 | '<input type="submit" value="'. |
| 233 | _("Rename"). |
| 234 | "\" />\n". |
| 235 | "</form></td></tr>\n"; |
| 236 | } else { |
| 237 | echo _("No folders found") . '<br /><br /></td></tr>'; |
| 238 | } |
| 239 | |
| 240 | echo html_tag( 'tr', |
| 241 | html_tag( 'td', ' ', 'left', $color[4] ) |
| 242 | ) ."\n"; |
| 243 | |
| 244 | /** DELETING FOLDERS **/ |
| 245 | echo html_tag( 'tr', |
| 246 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) |
| 247 | ) . |
| 248 | html_tag( 'tr' ) . |
| 249 | html_tag( 'td', '', 'center', $color[0] ); |
| 250 | |
| 251 | /* show only if we have folders to delete */ |
| 252 | if (!empty($filtered_folders)) { |
| 253 | echo addForm('folders.php') |
| 254 | . addHidden('smaction', 'delete') |
| 255 | . "<tt><select name=\"folder_name\">\n" |
| 256 | . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; |
| 257 | |
| 258 | // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist) |
| 259 | // use long format to make sure folder names make sense when parents may be missing. |
| 260 | echo $filtered_folders; |
| 261 | |
| 262 | echo "</select></tt>\n" |
| 263 | . '<input type="submit" value="' |
| 264 | . _("Delete") |
| 265 | . "\" />\n" |
| 266 | . "</form></td></tr>\n"; |
| 267 | } else { |
| 268 | echo _("No folders found") . "<br /><br /></td></tr>"; |
| 269 | } |
| 270 | |
| 271 | echo html_tag( 'tr', |
| 272 | html_tag( 'td', ' ', 'left', $color[4] ) |
| 273 | ) ."</table>\n"; |
| 274 | |
| 275 | |
| 276 | if ($show_only_subscribed_folders) { |
| 277 | // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed |
| 278 | // TODO: use checkboxes instead of select options. |
| 279 | |
| 280 | /** UNSUBSCRIBE FOLDERS **/ |
| 281 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
| 282 | html_tag( 'tr', |
| 283 | html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) |
| 284 | ) . |
| 285 | html_tag( 'tr' ) . |
| 286 | html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
| 287 | |
| 288 | if (!empty($filtered_folders)) { |
| 289 | echo addForm('folders.php') |
| 290 | . addHidden('smaction', 'unsubscribe') |
| 291 | . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n" |
| 292 | . $filtered_folders |
| 293 | . "</select></tt><br /><br />\n" |
| 294 | . '<input type="submit" value="' |
| 295 | . _("Unsubscribe") |
| 296 | . "\" />\n" |
| 297 | . "</form></td>\n"; |
| 298 | } else { |
| 299 | echo _("No folders were found to unsubscribe from.") . '</td>'; |
| 300 | } |
| 301 | |
| 302 | /** SUBSCRIBE TO FOLDERS **/ |
| 303 | echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
| 304 | if(!$no_list_for_subscribe) { |
| 305 | $boxes_all = sqimap_mailbox_list_all ($imapConnection); |
| 306 | |
| 307 | $subboxes = array(); |
| 308 | // here we filter out all boxes we're already subscribed to, |
| 309 | // so we keep only the unsubscribed ones. |
| 310 | foreach ($boxes_all as $box_a) { |
| 311 | |
| 312 | $use_folder = true; |
| 313 | foreach ( $boxes as $box ) { |
| 314 | if ($box_a['unformatted'] == $box['unformatted'] || |
| 315 | $box_a['unformatted-dm'] == $folder_prefix ) { |
| 316 | $use_folder = false; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | if ($use_folder == true) { |
| 321 | $box_enc = htmlspecialchars($box_a['unformatted-dm']); |
| 322 | $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp'])); |
| 323 | $subboxes[$box_enc] = $box_disp; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | if ( count($subboxes) > 0 ) { |
| 328 | echo addForm('folders.php') |
| 329 | . addHidden('smaction', 'subscribe') |
| 330 | . '<tt><select name="folder_names[]" multiple="multiple" size="8">'; |
| 331 | |
| 332 | foreach($subboxes as $subbox_enc => $subbox_disp) { |
| 333 | echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n"; |
| 334 | } |
| 335 | |
| 336 | echo '</select></tt><br /><br />' |
| 337 | . '<input type="submit" value="'. _("Subscribe") . "\" />\n" |
| 338 | . "</form></td></tr></table><br />\n"; |
| 339 | } else { |
| 340 | echo _("No folders were found to subscribe to.") . '</td></tr></table>'; |
| 341 | } |
| 342 | } else { |
| 343 | /* don't perform the list action -- this is much faster */ |
| 344 | echo addForm('folders.php') |
| 345 | . addHidden('smaction', 'subscribe') |
| 346 | . _("Subscribe to:") . '<br />' |
| 347 | . '<tt><input type="text" name="folder_names[]" size="35" />' |
| 348 | . '<input type="submit" value="'. _("Subscribe") . "\" />\n" |
| 349 | . "</form></td></tr></table><br />\n"; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | do_hook('folders_bottom'); |
| 354 | sqimap_logout($imapConnection); |
| 355 | |
| 356 | ?> |
| 357 | </td></tr> |
| 358 | </table> |
| 359 | </td></tr> |
| 360 | </table> |
| 361 | </body></html> |