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