Last options commit for the evening. This one is dedicated to my wife and her colorfu...
[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
ff8a98e7 14 require_once('../src/validate.php');
15 require_once('../functions/imap.php');
16 require_once('../functions/array.php');
17 require_once('../functions/tree.php');
2a32fc83 18
97dd6a62 19 /*
20 * Incoming values:
21 * $mailbox - selected mailbox from the form
22 */
23
e1469126 24 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
97dd6a62 25 $boxes = sqimap_mailbox_list ($imap_stream);
26 $dm = sqimap_get_delimiter($imap_stream);
cdee225a 27
abddc974 28 if (substr($mailbox, -1) == $dm)
29 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
30 else
31 $mailbox_no_dm = $mailbox;
d92b6f31 32
2c1dc652 33 /** lets see if we CAN move folders to the trash.. otherwise,
34 ** just delete them **/
b140c154 35
36 // Courier IMAP doesn't like subfolders of Trash
2c1dc652 37 if (strtolower($imap_server_type) == "courier") {
2c1dc652 38 $can_move_to_trash = false;
b140c154 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 {
2c1dc652 50 for ($i = 0; $i < count($boxes); $i++) {
51 if ($boxes[$i]["unformatted"] == $trash_folder) {
e54e0b89 52 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
813eba2f 53 }
54 }
d92b6f31 55 }
54e3c1d8 56
97dd6a62 57 /** First create the top node in the tree **/
58 for ($i = 0;$i < count($boxes);$i++) {
abddc974 59 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
97dd6a62 60 $foldersTree[0]["value"] = $mailbox;
61 $foldersTree[0]["doIHaveChildren"] = false;
62 continue;
54e3c1d8 63 }
97dd6a62 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++) {
abddc974 70 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
abddc974 71 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
54e3c1d8 72 }
8c7dfc99 73 }
abddc974 74// simpleWalkTreePre(0, $foldersTree);
b40316f9 75
97dd6a62 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
54e3c1d8 84 /** Log out this session **/
97dd6a62 85 sqimap_logout($imap_stream);
b40316f9 86
1195c340 87 $location = get_location();
88 header ("Location: $location/folders.php?success=delete");
89 /*
aff57ea5 90 echo "<BR><BR><BR><CENTER><B>";
91 echo _("Folder Deleted!");
92 echo "</B><BR><BR>";
93 echo _("The folder has been successfully deleted.");
9f2215a1 94 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
aff57ea5 95 echo _("Click here");
bd8bf491 96 echo "</A> ";
aff57ea5 97 echo _("to continue.");
aae41ae9 98 echo "</CENTER>";
91f999f6 99
f8f9bed9 100 echo "</BODY></HTML>";
1195c340 101 */
ff8a98e7 102?>