59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * folders_delete.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
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 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
35586184 |
17 | |
86725763 |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/imap.php'); |
21 | require_once(SM_PATH . 'functions/array.php'); |
22 | require_once(SM_PATH . 'functions/tree.php'); |
23 | require_once(SM_PATH . 'functions/display_messages.php'); |
2a32fc83 |
24 | |
1c52ba77 |
25 | /* |
26 | * Incoming values: |
27 | * $mailbox - selected mailbox from the form |
28 | */ |
29 | |
0037f048 |
30 | if ($mailbox == '') { |
31 | displayPageHeader($color, 'None'); |
32 | echo "<html><body bgcolor=$color[4]>"; |
33 | plain_error_message(_("You have not selected a folder to delete. Please do so.")."<BR><A HREF=\"../src/folders.php\">"._("Click here to go back")."</A>.", $color); |
34 | exit; |
35 | } |
36 | |
37 | |
1c52ba77 |
38 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
39 | $boxes = sqimap_mailbox_list ($imap_stream); |
4e85a37f |
40 | global $delimiter, $delete_folder; |
1c52ba77 |
41 | |
42 | if (substr($mailbox, -1) == $delimiter) |
43 | $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); |
44 | else |
45 | $mailbox_no_dm = $mailbox; |
46 | |
47 | /** lets see if we CAN move folders to the trash.. otherwise, |
2c1dc652 |
48 | ** just delete them **/ |
b140c154 |
49 | |
0037f048 |
50 | /* Courier IMAP doesn't like subfolders of Trash */ |
1c52ba77 |
51 | if (strtolower($imap_server_type) == "courier") { |
52 | $can_move_to_trash = false; |
53 | } |
b140c154 |
54 | |
0037f048 |
55 | /* If global options say we can't move it into Trash */ |
4e85a37f |
56 | else if(isset($delete_folder) && $delete_folder == true) { |
57 | $can_move_to_trash = false; |
58 | } |
59 | |
0037f048 |
60 | /* If it's already a subfolder of trash, we'll have to delete it */ |
1c52ba77 |
61 | else if(eregi("^".$trash_folder.".+", $mailbox)) { |
b140c154 |
62 | |
1c52ba77 |
63 | $can_move_to_trash = false; |
b140c154 |
64 | |
1c52ba77 |
65 | } |
b140c154 |
66 | |
0037f048 |
67 | /* Otherwise, check if trash folder exits and support sub-folders */ |
1c52ba77 |
68 | else { |
69 | for ($i = 0; $i < count($boxes); $i++) { |
70 | if ($boxes[$i]["unformatted"] == $trash_folder) { |
e54e0b89 |
71 | $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']); |
1c52ba77 |
72 | } |
73 | } |
74 | } |
75 | |
76 | /** First create the top node in the tree **/ |
77 | for ($i = 0;$i < count($boxes);$i++) { |
78 | if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) { |
79 | $foldersTree[0]["value"] = $mailbox; |
80 | $foldersTree[0]["doIHaveChildren"] = false; |
81 | continue; |
82 | } |
83 | } |
0037f048 |
84 | /* Now create the nodes for subfolders of the parent folder |
85 | You can tell that it is a subfolder by tacking the mailbox delimiter |
86 | on the end of the $mailbox string, and compare to that. */ |
1c52ba77 |
87 | $j = 0; |
88 | for ($i = 0;$i < count($boxes);$i++) { |
89 | if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) { |
90 | addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree); |
91 | } |
92 | } |
0037f048 |
93 | /* simpleWalkTreePre(0, $foldersTree); */ |
b40316f9 |
94 | |
1c52ba77 |
95 | /** Lets start removing the folders and messages **/ |
96 | if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/ |
97 | walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox); |
98 | walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); |
99 | } else { /** if they do NOT wish to move messages to the trash (or cannot)**/ |
100 | walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); |
101 | } |
102 | |
103 | /** Log out this session **/ |
104 | sqimap_logout($imap_stream); |
105 | |
106 | $location = get_location(); |
107 | header ("Location: $location/folders.php?success=delete"); |
108 | /* |
109 | echo "<BR><BR><BR><CENTER><B>"; |
110 | echo _("Folder Deleted!"); |
111 | echo "</B><BR><BR>"; |
112 | echo _("The folder has been successfully deleted."); |
113 | echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>"; |
114 | echo _("Click here"); |
115 | echo "</A> "; |
116 | echo _("to continue."); |
117 | echo "</CENTER>"; |
118 | |
119 | echo "</BODY></HTML>"; |
120 | */ |
525b7ae6 |
121 | ?> |