- fixed and improved wordWrap
[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
12 session_start();
13
14 /*
15 * Incoming values:
16 * $mailbox - selected mailbox from the form
17 */
18
19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($page_header_php))
24 include("../functions/page_header.php");
25 if (!isset($imap_php))
26 include("../functions/imap.php");
27 if (!isset($array_php))
28 include("../functions/array.php");
29 if (!isset($tree_php))
30 include("../functions/tree.php");
31
32 include("../src/load_prefs.php");
33
34
35 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
36 $boxes = sqimap_mailbox_list ($imap_stream);
37 $dm = sqimap_get_delimiter($imap_stream);
38 $mailbox = sqStripSlashes($mailbox);
39
40 if (substr($mailbox, -1) == $dm)
41 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
42 else
43 $mailbox_no_dm = $mailbox;
44
45 /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
46 for ($i = 0; $i < count($boxes); $i++) {
47 if ($boxes[$i]["unformatted"] == $trash_folder) {
48 $can_move_to_trash = true;
49 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
50 if (strtolower($boxes[$i]["flags"][$j]) == "noinferiors")
51 $can_move_to_trash = false;
52 }
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 ?>