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