59177427 |
1 | <?php |
895905c0 |
2 | |
ef870322 |
3 | /** |
4 | ** folders_delete.php |
5 | ** |
895905c0 |
6 | ** Copyright (c) 1999-2001 The SquirrelMail development team |
ef870322 |
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 |
245a6892 |
11 | ** |
12 | ** $Id$ |
ef870322 |
13 | **/ |
14 | |
ff8a98e7 |
15 | require_once('../src/validate.php'); |
16 | require_once('../functions/imap.php'); |
17 | require_once('../functions/array.php'); |
18 | require_once('../functions/tree.php'); |
2a32fc83 |
19 | |
97dd6a62 |
20 | /* |
21 | * Incoming values: |
22 | * $mailbox - selected mailbox from the form |
23 | */ |
24 | |
e1469126 |
25 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
97dd6a62 |
26 | $boxes = sqimap_mailbox_list ($imap_stream); |
525b7ae6 |
27 | global $delimiter; |
cdee225a |
28 | |
525b7ae6 |
29 | if (substr($mailbox, -1) == $delimiter) |
abddc974 |
30 | $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); |
31 | else |
32 | $mailbox_no_dm = $mailbox; |
d92b6f31 |
33 | |
2c1dc652 |
34 | /** lets see if we CAN move folders to the trash.. otherwise, |
35 | ** just delete them **/ |
b140c154 |
36 | |
37 | // Courier IMAP doesn't like subfolders of Trash |
2c1dc652 |
38 | if (strtolower($imap_server_type) == "courier") { |
2c1dc652 |
39 | $can_move_to_trash = false; |
b140c154 |
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 { |
2c1dc652 |
51 | for ($i = 0; $i < count($boxes); $i++) { |
52 | if ($boxes[$i]["unformatted"] == $trash_folder) { |
e54e0b89 |
53 | $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']); |
813eba2f |
54 | } |
55 | } |
d92b6f31 |
56 | } |
54e3c1d8 |
57 | |
97dd6a62 |
58 | /** First create the top node in the tree **/ |
59 | for ($i = 0;$i < count($boxes);$i++) { |
abddc974 |
60 | if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) { |
97dd6a62 |
61 | $foldersTree[0]["value"] = $mailbox; |
62 | $foldersTree[0]["doIHaveChildren"] = false; |
63 | continue; |
54e3c1d8 |
64 | } |
97dd6a62 |
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++) { |
525b7ae6 |
71 | if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) { |
abddc974 |
72 | addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree); |
54e3c1d8 |
73 | } |
8c7dfc99 |
74 | } |
abddc974 |
75 | // simpleWalkTreePre(0, $foldersTree); |
b40316f9 |
76 | |
97dd6a62 |
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 **/ |
525b7ae6 |
79 | walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox); |
97dd6a62 |
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 | |
54e3c1d8 |
85 | /** Log out this session **/ |
97dd6a62 |
86 | sqimap_logout($imap_stream); |
b40316f9 |
87 | |
1195c340 |
88 | $location = get_location(); |
89 | header ("Location: $location/folders.php?success=delete"); |
90 | /* |
aff57ea5 |
91 | echo "<BR><BR><BR><CENTER><B>"; |
92 | echo _("Folder Deleted!"); |
93 | echo "</B><BR><BR>"; |
94 | echo _("The folder has been successfully deleted."); |
9f2215a1 |
95 | echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>"; |
aff57ea5 |
96 | echo _("Click here"); |
bd8bf491 |
97 | echo "</A> "; |
aff57ea5 |
98 | echo _("to continue."); |
aae41ae9 |
99 | echo "</CENTER>"; |
91f999f6 |
100 | |
f8f9bed9 |
101 | echo "</BODY></HTML>"; |
1195c340 |
102 | */ |
525b7ae6 |
103 | ?> |