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