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 | * |
b7f83b61 |
9 | * Deletes folders from the IMAP server. |
35586184 |
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'); |
86725763 |
21 | require_once(SM_PATH . 'functions/tree.php'); |
22 | require_once(SM_PATH . 'functions/display_messages.php'); |
b7f83b61 |
23 | require_once(SM_PATH . 'functions/html.php'); |
2a32fc83 |
24 | |
1c52ba77 |
25 | /* |
b7f83b61 |
26 | * Incoming values: |
27 | * $mailbox - selected mailbox from the form |
28 | */ |
1c52ba77 |
29 | |
a32985a5 |
30 | /* globals */ |
31 | $username = $_SESSION['username']; |
32 | $key = $_COOKIE['key']; |
33 | $delimiter = $_SESSION['delimiter']; |
34 | $onetimepad = $_SESSION['onetimepad']; |
35 | |
36 | $mailbox = $_POST['mailbox']; |
37 | |
38 | /* end globals */ |
39 | |
0037f048 |
40 | if ($mailbox == '') { |
41 | displayPageHeader($color, 'None'); |
b7f83b61 |
42 | |
43 | plain_error_message(_("You have not selected a folder to delete. Please do so."). |
44 | '<BR><A HREF="../src/folders.php">'._("Click here to go back").'</A>.', $color); |
45 | exit; |
46 | } |
47 | |
48 | if (isset($_POST['backingout'])) { |
49 | $location = get_location(); |
50 | header ("Location: $location/folders.php"); |
0037f048 |
51 | exit; |
52 | } |
53 | |
b7f83b61 |
54 | if(!isset($_POST['confirmed'])) { |
55 | displayPageHeader($color, 'None'); |
56 | |
57 | echo '<br>' . |
58 | html_tag( 'table', '', 'center', '', 'width="95%" border="0"' ) . |
59 | html_tag( 'tr', |
60 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[0] ) |
61 | ) . |
62 | html_tag( 'tr' ) . |
63 | html_tag( 'td', '', 'center', $color[4] ) . |
334a77f8 |
64 | sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)). |
b7f83b61 |
65 | '<FORM ACTION="folders_delete.php" METHOD="POST"><p>'. |
66 | |
67 | '<INPUT TYPE=HIDDEN NAME="mailbox" VALUE="'.$mailbox."\">\n" . |
68 | '<INPUT TYPE=SUBMIT NAME="confirmed" VALUE="'._("Yes")."\">\n". |
69 | '<INPUT TYPE=SUBMIT NAME="backingout" VALUE="'._("No")."\">\n". |
70 | '</p></FORM><BR></td></tr></table>'; |
71 | |
72 | exit; |
73 | } |
0037f048 |
74 | |
1c52ba77 |
75 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
b7f83b61 |
76 | |
1c52ba77 |
77 | $boxes = sqimap_mailbox_list ($imap_stream); |
b7f83b61 |
78 | $numboxes = count($boxes); |
79 | |
a32985a5 |
80 | global $delete_folder; |
1c52ba77 |
81 | |
82 | if (substr($mailbox, -1) == $delimiter) |
83 | $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); |
84 | else |
85 | $mailbox_no_dm = $mailbox; |
86 | |
87 | /** lets see if we CAN move folders to the trash.. otherwise, |
2c1dc652 |
88 | ** just delete them **/ |
b140c154 |
89 | |
b7f83b61 |
90 | /* Courier IMAP doesn't like subfolders of Trash |
91 | * If global options say we can't move it into Trash |
92 | * If it's already a subfolder of trash, we'll have to delete it */ |
93 | if (strtolower($imap_server_type) == 'courier' || |
94 | (isset($delete_folder) && $delete_folder) || |
95 | eregi('^'.$trash_folder.'.+', $mailbox) ) |
96 | { |
97 | $can_move_to_trash = FALSE; |
1c52ba77 |
98 | } |
b140c154 |
99 | |
0037f048 |
100 | /* Otherwise, check if trash folder exits and support sub-folders */ |
1c52ba77 |
101 | else { |
b7f83b61 |
102 | for ($i = 0; $i < $numboxes; $i++) { |
103 | if ($boxes[$i]['unformatted'] == $trash_folder) { |
e54e0b89 |
104 | $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']); |
1c52ba77 |
105 | } |
106 | } |
107 | } |
108 | |
109 | /** First create the top node in the tree **/ |
b7f83b61 |
110 | for ($i = 0; $i < $numboxes; $i++) { |
111 | if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen($boxes[$i]['unformatted-dm']) == strlen($mailbox))) { |
112 | $foldersTree[0]['value'] = $mailbox; |
113 | $foldersTree[0]['doIHaveChildren'] = false; |
1c52ba77 |
114 | continue; |
115 | } |
116 | } |
b7f83b61 |
117 | |
0037f048 |
118 | /* Now create the nodes for subfolders of the parent folder |
119 | You can tell that it is a subfolder by tacking the mailbox delimiter |
120 | on the end of the $mailbox string, and compare to that. */ |
b7f83b61 |
121 | for ($i = 0; $i < $numboxes; $i++) { |
122 | if (substr($boxes[$i]['unformatted'], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) { |
123 | addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree); |
1c52ba77 |
124 | } |
125 | } |
b40316f9 |
126 | |
1c52ba77 |
127 | /** Lets start removing the folders and messages **/ |
128 | if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/ |
129 | walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox); |
130 | walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); |
131 | } else { /** if they do NOT wish to move messages to the trash (or cannot)**/ |
132 | walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree); |
133 | } |
134 | |
135 | /** Log out this session **/ |
136 | sqimap_logout($imap_stream); |
137 | |
138 | $location = get_location(); |
139 | header ("Location: $location/folders.php?success=delete"); |
b7f83b61 |
140 | |
525b7ae6 |
141 | ?> |