* Added several hooks
[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 include('../src/validate.php');
15 include("../functions/page_header.php");
16 include("../functions/imap.php");
17 include("../functions/array.php");
18 include("../functions/tree.php");
19 include("../src/load_prefs.php");
20
21 /*
22 * Incoming values:
23 * $mailbox - selected mailbox from the form
24 */
25
26 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
27 $boxes = sqimap_mailbox_list ($imap_stream);
28 $dm = sqimap_get_delimiter($imap_stream);
29
30 if (substr($mailbox, -1) == $dm)
31 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
32 else
33 $mailbox_no_dm = $mailbox;
34
35 /** lets see if we CAN move folders to the trash.. otherwise,
36 ** just delete them **/
37
38 // Courier IMAP doesn't like subfolders of Trash
39 if (strtolower($imap_server_type) == "courier") {
40 $can_move_to_trash = false;
41 }
42
43 // If it's already a subfolder of trash, we'll have to delete it
44 else if(eregi("^".$trash_folder.".+", $mailbox)) {
45
46 $can_move_to_trash = false;
47
48 }
49
50 // Otherwise, check if trash folder exits and support sub-folders
51 else {
52 for ($i = 0; $i < count($boxes); $i++) {
53 if ($boxes[$i]["unformatted"] == $trash_folder) {
54 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
55 }
56 }
57 }
58
59 /** First create the top node in the tree **/
60 for ($i = 0;$i < count($boxes);$i++) {
61 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
62 $foldersTree[0]["value"] = $mailbox;
63 $foldersTree[0]["doIHaveChildren"] = false;
64 continue;
65 }
66 }
67 // Now create the nodes for subfolders of the parent folder
68 // You can tell that it is a subfolder by tacking the mailbox delimiter
69 // on the end of the $mailbox string, and compare to that.
70 $j = 0;
71 for ($i = 0;$i < count($boxes);$i++) {
72 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
73 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
74 }
75 }
76 // simpleWalkTreePre(0, $foldersTree);
77
78 /** Lets start removing the folders and messages **/
79 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
80 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
81 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
82 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
83 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
84 }
85
86 /** Log out this session **/
87 sqimap_logout($imap_stream);
88
89 $location = get_location();
90 header ("Location: $location/folders.php?success=delete");
91 /*
92 echo "<BR><BR><BR><CENTER><B>";
93 echo _("Folder Deleted!");
94 echo "</B><BR><BR>";
95 echo _("The folder has been successfully deleted.");
96 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
97 echo _("Click here");
98 echo "</A> ";
99 echo _("to continue.");
100 echo "</CENTER>";
101
102 echo "</BODY></HTML>";
103 */
104 ?>