Fixed problem with lines mistakenly wrapping when resuming a draft mail.
[squirrelmail.git] / src / folders_delete.php
1 <?php
2 /**
3 ** folders_delete.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Deltes folders from the IMAP server.
9 ** Called from the folders.php
10 **
11 ** $Id$
12 **/
13
14 require_once('../src/validate.php');
15 require_once('../functions/imap.php');
16 require_once('../functions/array.php');
17 require_once('../functions/tree.php');
18
19 /*
20 * Incoming values:
21 * $mailbox - selected mailbox from the form
22 */
23
24 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
25 $boxes = sqimap_mailbox_list ($imap_stream);
26 $dm = sqimap_get_delimiter($imap_stream);
27
28 if (substr($mailbox, -1) == $dm)
29 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
30 else
31 $mailbox_no_dm = $mailbox;
32
33 /** lets see if we CAN move folders to the trash.. otherwise,
34 ** just delete them **/
35
36 // Courier IMAP doesn't like subfolders of Trash
37 if (strtolower($imap_server_type) == "courier") {
38 $can_move_to_trash = false;
39 }
40
41 // If it's already a subfolder of trash, we'll have to delete it
42 else if(eregi("^".$trash_folder.".+", $mailbox)) {
43
44 $can_move_to_trash = false;
45
46 }
47
48 // Otherwise, check if trash folder exits and support sub-folders
49 else {
50 for ($i = 0; $i < count($boxes); $i++) {
51 if ($boxes[$i]["unformatted"] == $trash_folder) {
52 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
53 }
54 }
55 }
56
57 /** First create the top node in the tree **/
58 for ($i = 0;$i < count($boxes);$i++) {
59 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
60 $foldersTree[0]["value"] = $mailbox;
61 $foldersTree[0]["doIHaveChildren"] = false;
62 continue;
63 }
64 }
65 // Now create the nodes for subfolders of the parent folder
66 // You can tell that it is a subfolder by tacking the mailbox delimiter
67 // on the end of the $mailbox string, and compare to that.
68 $j = 0;
69 for ($i = 0;$i < count($boxes);$i++) {
70 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
71 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
72 }
73 }
74 // simpleWalkTreePre(0, $foldersTree);
75
76 /** Lets start removing the folders and messages **/
77 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
78 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
79 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
80 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
81 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
82 }
83
84 /** Log out this session **/
85 sqimap_logout($imap_stream);
86
87 $location = get_location();
88 header ("Location: $location/folders.php?success=delete");
89 /*
90 echo "<BR><BR><BR><CENTER><B>";
91 echo _("Folder Deleted!");
92 echo "</B><BR><BR>";
93 echo _("The folder has been successfully deleted.");
94 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
95 echo _("Click here");
96 echo "</A> ";
97 echo _("to continue.");
98 echo "</CENTER>";
99
100 echo "</BODY></HTML>";
101 */
102 ?>