Converted sm-1_0 to branch and sm-1_1 to trunk
[squirrelmail.git] / src / folders_delete.php
1 <?php
2 /**
3 ** folders_delete.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Deltes folders from the IMAP server.
9 ** Called from the folders.php
10 **
11 ** $Id$
12 **/
13
14 session_start();
15
16 /*
17 * Incoming values:
18 * $mailbox - selected mailbox from the form
19 */
20
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($config_php))
24 include("../config/config.php");
25 if (!isset($page_header_php))
26 include("../functions/page_header.php");
27 if (!isset($imap_php))
28 include("../functions/imap.php");
29 if (!isset($array_php))
30 include("../functions/array.php");
31 if (!isset($tree_php))
32 include("../functions/tree.php");
33
34 include("../src/load_prefs.php");
35
36
37 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38 $boxes = sqimap_mailbox_list ($imap_stream);
39 $dm = sqimap_get_delimiter($imap_stream);
40
41 if (substr($mailbox, -1) == $dm)
42 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
43 else
44 $mailbox_no_dm = $mailbox;
45
46 /** lets see if we CAN move folders to the trash.. otherwise,
47 ** just delete them **/
48
49 // Courier IMAP doesn't like subfolders of Trash
50 if (strtolower($imap_server_type) == "courier") {
51 $can_move_to_trash = false;
52 }
53
54 // If it's already a subfolder of trash, we'll have to delete it
55 else if(eregi("^".$trash_folder.".+", $mailbox)) {
56
57 $can_move_to_trash = false;
58
59 }
60
61 // Otherwise, check if trash folder exits and support sub-folders
62 else {
63 for ($i = 0; $i < count($boxes); $i++) {
64 if ($boxes[$i]["unformatted"] == $trash_folder) {
65 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
66 }
67 }
68 }
69
70 /** First create the top node in the tree **/
71 for ($i = 0;$i < count($boxes);$i++) {
72 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
73 $foldersTree[0]["value"] = $mailbox;
74 $foldersTree[0]["doIHaveChildren"] = false;
75 continue;
76 }
77 }
78 // Now create the nodes for subfolders of the parent folder
79 // You can tell that it is a subfolder by tacking the mailbox delimiter
80 // on the end of the $mailbox string, and compare to that.
81 $j = 0;
82 for ($i = 0;$i < count($boxes);$i++) {
83 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
84 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
85 }
86 }
87 // simpleWalkTreePre(0, $foldersTree);
88
89 /** Lets start removing the folders and messages **/
90 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
91 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
92 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
93 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
94 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
95 }
96
97 /** Log out this session **/
98 sqimap_logout($imap_stream);
99
100 $location = get_location();
101 header ("Location: $location/folders.php?success=delete");
102 /*
103 echo "<BR><BR><BR><CENTER><B>";
104 echo _("Folder Deleted!");
105 echo "</B><BR><BR>";
106 echo _("The folder has been successfully deleted.");
107 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
108 echo _("Click here");
109 echo "</A> ";
110 echo _("to continue.");
111 echo "</CENTER>";
112
113 echo "</BODY></HTML>";
114 */
115 ?>