b449bc4bfd32545818ebcc7ee39ab2a7271c19ba
[squirrelmail.git] / src / folders_delete.php
1 <?php
2
3 /**
4 ** folders_delete.php
5 **
6 ** Copyright (c) 1999-2001 The SquirrelMail development team
7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 **
9 ** Deltes folders from the IMAP server.
10 ** Called from the folders.php
11 **
12 ** $Id$
13 **/
14
15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/array.php');
18 require_once('../functions/tree.php');
19
20 /*
21 * Incoming values:
22 * $mailbox - selected mailbox from the form
23 */
24
25 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
26 $boxes = sqimap_mailbox_list ($imap_stream);
27 global $delimiter;
28
29 if (substr($mailbox, -1) == $delimiter)
30 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
31 else
32 $mailbox_no_dm = $mailbox;
33
34 /** lets see if we CAN move folders to the trash.. otherwise,
35 ** just delete them **/
36
37 // Courier IMAP doesn't like subfolders of Trash
38 if (strtolower($imap_server_type) == "courier") {
39 $can_move_to_trash = false;
40 }
41
42 // If it's already a subfolder of trash, we'll have to delete it
43 else if(eregi("^".$trash_folder.".+", $mailbox)) {
44
45 $can_move_to_trash = false;
46
47 }
48
49 // Otherwise, check if trash folder exits and support sub-folders
50 else {
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']);
54 }
55 }
56 }
57
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;
63 continue;
64 }
65 }
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.
69 $j = 0;
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);
73 }
74 }
75 // simpleWalkTreePre(0, $foldersTree);
76
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);
83 }
84
85 /** Log out this session **/
86 sqimap_logout($imap_stream);
87
88 $location = get_location();
89 header ("Location: $location/folders.php?success=delete");
90 /*
91 echo "<BR><BR><BR><CENTER><B>";
92 echo _("Folder Deleted!");
93 echo "</B><BR><BR>";
94 echo _("The folder has been successfully deleted.");
95 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
96 echo _("Click here");
97 echo "</A> ";
98 echo _("to continue.");
99 echo "</CENTER>";
100
101 echo "</BODY></HTML>";
102 */
103 ?>