Usability terminolofy change.
[squirrelmail.git] / src / folders_delete.php
1 <?php
2
3 /**
4 * folders_delete.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development 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 /*****************************************************************/
16 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18 /*** + Base level indent should begin at left margin, as ***/
19 /*** the require_once below looks. ***/
20 /*** + All identation should consist of four space blocks ***/
21 /*** + Tab characters are evil. ***/
22 /*** + all comments should use "slash-star ... star-slash" ***/
23 /*** style -- no pound characters, no slash-slash style ***/
24 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
26 /*** + Please use ' instead of ", when possible. Note " ***/
27 /*** should always be used in _( ) function calls. ***/
28 /*** Thank you for your help making the SM code more readable. ***/
29 /*****************************************************************/
30
31 require_once('../src/validate.php');
32 require_once('../functions/imap.php');
33 require_once('../functions/array.php');
34 require_once('../functions/tree.php');
35
36 /*
37 * Incoming values:
38 * $mailbox - selected mailbox from the form
39 */
40
41 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
42 $boxes = sqimap_mailbox_list ($imap_stream);
43 global $delimiter;
44
45 if (substr($mailbox, -1) == $delimiter)
46 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
47 else
48 $mailbox_no_dm = $mailbox;
49
50 /** lets see if we CAN move folders to the trash.. otherwise,
51 ** just delete them **/
52
53 // Courier IMAP doesn't like subfolders of Trash
54 if (strtolower($imap_server_type) == "courier") {
55 $can_move_to_trash = false;
56 }
57
58 // If it's already a subfolder of trash, we'll have to delete it
59 else if(eregi("^".$trash_folder.".+", $mailbox)) {
60
61 $can_move_to_trash = false;
62
63 }
64
65 // Otherwise, check if trash folder exits and support sub-folders
66 else {
67 for ($i = 0; $i < count($boxes); $i++) {
68 if ($boxes[$i]["unformatted"] == $trash_folder) {
69 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
70 }
71 }
72 }
73
74 /** First create the top node in the tree **/
75 for ($i = 0;$i < count($boxes);$i++) {
76 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
77 $foldersTree[0]["value"] = $mailbox;
78 $foldersTree[0]["doIHaveChildren"] = false;
79 continue;
80 }
81 }
82 // Now create the nodes for subfolders of the parent folder
83 // You can tell that it is a subfolder by tacking the mailbox delimiter
84 // on the end of the $mailbox string, and compare to that.
85 $j = 0;
86 for ($i = 0;$i < count($boxes);$i++) {
87 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
88 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
89 }
90 }
91 // simpleWalkTreePre(0, $foldersTree);
92
93 /** Lets start removing the folders and messages **/
94 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
95 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
96 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
97 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
98 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
99 }
100
101 /** Log out this session **/
102 sqimap_logout($imap_stream);
103
104 $location = get_location();
105 header ("Location: $location/folders.php?success=delete");
106 /*
107 echo "<BR><BR><BR><CENTER><B>";
108 echo _("Folder Deleted!");
109 echo "</B><BR><BR>";
110 echo _("The folder has been successfully deleted.");
111 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
112 echo _("Click here");
113 echo "</A> ";
114 echo _("to continue.");
115 echo "</CENTER>";
116
117 echo "</BODY></HTML>";
118 */
119 ?>