updated docs
[squirrelmail.git] / src / folders_delete.php
CommitLineData
59177427 1<?php
ef870322 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
245a6892 10 **
11 ** $Id$
ef870322 12 **/
13
f740c049 14 include('../src/validate.php');
15 include("../functions/strings.php");
16 include("../config/config.php");
17 include("../functions/page_header.php");
18 include("../functions/imap.php");
19 include("../functions/array.php");
20 include("../functions/tree.php");
21 include("../src/load_prefs.php");
2a32fc83 22
97dd6a62 23 /*
24 * Incoming values:
25 * $mailbox - selected mailbox from the form
26 */
27
e1469126 28 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
97dd6a62 29 $boxes = sqimap_mailbox_list ($imap_stream);
30 $dm = sqimap_get_delimiter($imap_stream);
cdee225a 31
abddc974 32 if (substr($mailbox, -1) == $dm)
33 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
34 else
35 $mailbox_no_dm = $mailbox;
d92b6f31 36
2c1dc652 37 /** lets see if we CAN move folders to the trash.. otherwise,
38 ** just delete them **/
b140c154 39
40 // Courier IMAP doesn't like subfolders of Trash
2c1dc652 41 if (strtolower($imap_server_type) == "courier") {
2c1dc652 42 $can_move_to_trash = false;
b140c154 43 }
44
45 // If it's already a subfolder of trash, we'll have to delete it
46 else if(eregi("^".$trash_folder.".+", $mailbox)) {
47
48 $can_move_to_trash = false;
49
50 }
51
52 // Otherwise, check if trash folder exits and support sub-folders
53 else {
2c1dc652 54 for ($i = 0; $i < count($boxes); $i++) {
55 if ($boxes[$i]["unformatted"] == $trash_folder) {
e54e0b89 56 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
813eba2f 57 }
58 }
d92b6f31 59 }
54e3c1d8 60
97dd6a62 61 /** First create the top node in the tree **/
62 for ($i = 0;$i < count($boxes);$i++) {
abddc974 63 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
97dd6a62 64 $foldersTree[0]["value"] = $mailbox;
65 $foldersTree[0]["doIHaveChildren"] = false;
66 continue;
54e3c1d8 67 }
97dd6a62 68 }
69 // Now create the nodes for subfolders of the parent folder
70 // You can tell that it is a subfolder by tacking the mailbox delimiter
71 // on the end of the $mailbox string, and compare to that.
72 $j = 0;
73 for ($i = 0;$i < count($boxes);$i++) {
abddc974 74 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
abddc974 75 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
54e3c1d8 76 }
8c7dfc99 77 }
abddc974 78// simpleWalkTreePre(0, $foldersTree);
b40316f9 79
97dd6a62 80 /** Lets start removing the folders and messages **/
81 if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
82 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $dm, $mailbox);
83 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
84 } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
85 walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
86 }
87
54e3c1d8 88 /** Log out this session **/
97dd6a62 89 sqimap_logout($imap_stream);
b40316f9 90
1195c340 91 $location = get_location();
92 header ("Location: $location/folders.php?success=delete");
93 /*
aff57ea5 94 echo "<BR><BR><BR><CENTER><B>";
95 echo _("Folder Deleted!");
96 echo "</B><BR><BR>";
97 echo _("The folder has been successfully deleted.");
9f2215a1 98 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
aff57ea5 99 echo _("Click here");
bd8bf491 100 echo "</A> ";
aff57ea5 101 echo _("to continue.");
aae41ae9 102 echo "</CENTER>";
91f999f6 103
f8f9bed9 104 echo "</BODY></HTML>";
1195c340 105 */
b40316f9 106?>