Cleaning and bug-fix. Added base uri to read mail.
[squirrelmail.git] / src / folders_delete.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders_delete.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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
31require_once('../src/validate.php');
32require_once('../functions/imap.php');
33require_once('../functions/array.php');
34require_once('../functions/tree.php');
2a32fc83 35
97dd6a62 36 /*
37 * Incoming values:
38 * $mailbox - selected mailbox from the form
39 */
40
e1469126 41 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
97dd6a62 42 $boxes = sqimap_mailbox_list ($imap_stream);
525b7ae6 43 global $delimiter;
cdee225a 44
525b7ae6 45 if (substr($mailbox, -1) == $delimiter)
abddc974 46 $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1);
47 else
48 $mailbox_no_dm = $mailbox;
d92b6f31 49
2c1dc652 50 /** lets see if we CAN move folders to the trash.. otherwise,
51 ** just delete them **/
b140c154 52
53 // Courier IMAP doesn't like subfolders of Trash
2c1dc652 54 if (strtolower($imap_server_type) == "courier") {
2c1dc652 55 $can_move_to_trash = false;
b140c154 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 {
2c1dc652 67 for ($i = 0; $i < count($boxes); $i++) {
68 if ($boxes[$i]["unformatted"] == $trash_folder) {
e54e0b89 69 $can_move_to_trash = !in_array('noinferiors', $boxes[$i]['flags']);
813eba2f 70 }
71 }
d92b6f31 72 }
54e3c1d8 73
97dd6a62 74 /** First create the top node in the tree **/
75 for ($i = 0;$i < count($boxes);$i++) {
abddc974 76 if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
97dd6a62 77 $foldersTree[0]["value"] = $mailbox;
78 $foldersTree[0]["doIHaveChildren"] = false;
79 continue;
54e3c1d8 80 }
97dd6a62 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++) {
525b7ae6 87 if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
abddc974 88 addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
54e3c1d8 89 }
8c7dfc99 90 }
abddc974 91// simpleWalkTreePre(0, $foldersTree);
b40316f9 92
97dd6a62 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 **/
525b7ae6 95 walkTreeInPostOrderCreatingFoldersUnderTrash(0, $imap_stream, $foldersTree, $mailbox);
97dd6a62 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
54e3c1d8 101 /** Log out this session **/
97dd6a62 102 sqimap_logout($imap_stream);
b40316f9 103
1195c340 104 $location = get_location();
105 header ("Location: $location/folders.php?success=delete");
106 /*
aff57ea5 107 echo "<BR><BR><BR><CENTER><B>";
108 echo _("Folder Deleted!");
109 echo "</B><BR><BR>";
110 echo _("The folder has been successfully deleted.");
9f2215a1 111 echo "<BR><A HREF=\"webmail.php?right_frame=folders.php\" TARGET=_top>";
aff57ea5 112 echo _("Click here");
bd8bf491 113 echo "</A> ";
aff57ea5 114 echo _("to continue.");
aae41ae9 115 echo "</CENTER>";
91f999f6 116
f8f9bed9 117 echo "</BODY></HTML>";
1195c340 118 */
525b7ae6 119?>