b449bc4bfd32545818ebcc7ee39ab2a7271c19ba
6 ** Copyright (c) 1999-2001 The SquirrelMail development team
7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
9 ** Deltes folders from the IMAP server.
10 ** Called from the folders.php
15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/array.php');
18 require_once('../functions/tree.php');
22 * $mailbox - selected mailbox from the form
25 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
26 $boxes = sqimap_mailbox_list ($imap_stream);
29 if (substr($mailbox, -1) == $delimiter)
30 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
32 $mailbox_no_dm = $mailbox;
34 /** lets see if we CAN move folders to the trash.. otherwise,
35 ** just delete them **/
37 // Courier IMAP doesn't like subfolders of Trash
38 if (strtolower($imap_server_type) == "courier") {
39 $can_move_to_trash = false;
42 // If it's already a subfolder of trash, we'll have to delete it
43 else if(eregi("^".$trash_folder.".+", $mailbox)) {
45 $can_move_to_trash = false;
49 // Otherwise, check if trash folder exits and support sub-folders
51 for ($i = 0; $i < count($boxes); $i++
) {
52 if ($boxes[$i]["unformatted"] == $trash_folder) {
53 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
58 /** First create the top node in the tree **/
59 for ($i = 0;$i < count($boxes);$i++
) {
60 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
61 $foldersTree[0]["value"] = $mailbox;
62 $foldersTree[0]["doIHaveChildren"] = false;
66 // Now create the nodes for subfolders of the parent folder
67 // You can tell that it is a subfolder by tacking the mailbox delimiter
68 // on the end of the $mailbox string, and compare to that.
70 for ($i = 0;$i < count($boxes);$i++
) {
71 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
72 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
75 // simpleWalkTreePre(0, $foldersTree);
77 /** Lets start removing the folders and messages **/
78 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
79 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
80 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
81 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
82 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
85 /** Log out this session **/
86 sqimap_logout($imap_stream);
88 $location = get_location();
89 header ("Location: $location/folders.php?success=delete");
91 echo "<BR><BR><BR><CENTER><B>";
92 echo _("Folder Deleted!");
94 echo _("The folder has been successfully deleted.");
95 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
98 echo _("to continue.");
101 echo "</BODY></HTML>";