KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
23
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * Create Command for creating some new mailboxes.
29  *
30  * @version 0.2 on 04 Aug 2002
31  */

32
33 class CreateCommand extends AuthenticatedSelectedStateCommand
34 {
35     public CreateCommand()
36     {
37         this.commandName = "CREATE";
38         this.getArgs().add( new AstringArgument( "mailbox" ) );
39     }
40
41     protected boolean doProcess( ImapRequest request, ImapSession session, List JavaDoc argValues )
42     {
43         String JavaDoc command = this.commandName;
44         String JavaDoc folder = (String JavaDoc) argValues.get( 0 );
45
46         try {
47             if ( session.getCurrentFolder() == folder ) {
48                 session.noResponse( command, "Folder exists and is selected." );
49                 return true;
50             }
51             System.out.println("CreteCommand FOLDERNAME: "+folder);
52             ACLMailbox target = session.getImapHost().createMailbox( session.getCurrentUser(), folder );
53             session.okResponse( command );
54             session.getImapHost().releaseMailbox( session.getCurrentUser(), target );
55         }
56         catch ( AccessControlException ace ) {
57             session.noResponse( command, "No such mailbox." );
58             session.logACE( ace );
59             return true;
60         }
61         catch ( MailboxException mbe ) {
62             if ( mbe.isRemote() ) {
63                 session.noResponse( "[REFERRAL "
64                             + mbe.getRemoteServer() + "]"
65                             + SP + "Wrong server. Try remote." );
66             }
67             else {
68                 session.noResponse( mbe.getStatus() );
69             }
70             return true;
71         }
72         catch ( AuthorizationException aze ) {
73             session.noResponse( command, "You do not have the rights to create mailbox: "
74                                  + folder );
75             return true;
76         }
77         if ( session.getState() == ImapSessionState.SELECTED ) {
78             session.checkSize();
79             session.checkExpunge();
80         }
81         return true;
82     }
83 }
84
Popular Tags