KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > commands > DeleteCommand


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.imapserver.commands;
19
20 import org.apache.james.imapserver.AccessControlException;
21 import org.apache.james.imapserver.AuthorizationException;
22 import org.apache.james.imapserver.ImapRequest;
23 import org.apache.james.imapserver.ImapSession;
24 import org.apache.james.imapserver.ImapSessionState;
25 import org.apache.james.imapserver.MailboxException;
26
27 import java.util.StringTokenizer JavaDoc;
28 import java.util.List JavaDoc;
29
30 class DeleteCommand extends AuthenticatedSelectedStateCommand
31 {
32     public DeleteCommand()
33     {
34         this.commandName = "DELETE";
35
36         this.getArgs().add( new AstringArgument( "mailbox" ) );
37     }
38
39     public boolean doProcess( ImapRequest request, ImapSession session, List JavaDoc argValues )
40     {
41         String JavaDoc command = this.getCommand();
42
43         String JavaDoc folder = (String JavaDoc) argValues.get( 0 );
44
45         if ( session.getCurrentFolder().equals( folder ) ) {
46             session.noResponse( command, "You can't delete a folder while you have it selected." );
47             return true;
48         }
49         try {
50             if ( session.getImapHost().deleteMailbox( session.getCurrentUser(), folder ) ) {
51                 session.okResponse( command );
52             }
53             else {
54                 session.noResponse( command );
55                 getLogger().info( "Attempt to delete mailbox " + folder
56                                   + " by user " + session.getCurrentUser() + " failed." );
57             }
58             if ( session.getState() == ImapSessionState.SELECTED ) {
59                 session.checkSize();
60                 session.checkExpunge();
61             }
62             return true;
63         }
64         catch ( MailboxException mbe ) {
65             session.noResponse( command, mbe.getMessage() );
66             return true;
67         }
68         catch ( AuthorizationException aze ) {
69             session.noResponse( command, "You do not have the rights to delete mailbox: " + folder );
70             session.logAZE( aze );
71             return true;
72         }
73         catch ( AccessControlException ace ) {
74             session.noResponse( command, ace.getMessage() );
75             session.logACE( ace );
76             return true;
77         }
78     }
79 }
80
Popular Tags