KickJava   Java API By Example, From Geeks To Geeks.

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


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.ImapRequest;
22 import org.apache.james.imapserver.ImapSession;
23 import org.apache.james.imapserver.ImapSessionState;
24 import org.apache.james.imapserver.MailboxException;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29
30 /**
31  * Implements the Status Command for getting the status of a Mailbox.
32  *
33  * @version 0.2 on 04 Aug 2002
34  */

35 class StatusCommand extends AuthenticatedSelectedStateCommand
36 {
37     public StatusCommand()
38     {
39         this.commandName = "STATUS";
40
41        // this.getArgs().add( "mailbox" );
42
// this.getArgs().add( "status data item" );
43
this.getArgs().add( new AstringArgument( "mailbox" ) );
44         this.getArgs().add( new ListArgument( "status data item" ) );
45     }
46
47     protected boolean doProcess( ImapRequest request, ImapSession session, List JavaDoc argValues )
48     {
49         String JavaDoc command = this.getCommand();
50
51         String JavaDoc folder = (String JavaDoc) argValues.get( 0 );
52         List JavaDoc dataNames = (List JavaDoc) argValues.get( 1 );
53
54         try {
55             String JavaDoc response = session.getImapHost().getMailboxStatus( session.getCurrentUser(), folder,
56                                                          dataNames );
57             session.untaggedResponse( " STATUS \"" + folder + "\" ("
58                                        + response + ")" );
59             session.okResponse( command );
60         }
61         catch ( MailboxException mbe ) {
62             if ( mbe.isRemote() ) {
63                 session.noResponse( command , "[REFERRAL "
64                                            + mbe.getRemoteServer() + "]"
65                                            + SP + "Wrong server. Try remote." );
66             }
67             else {
68                 session.noResponse( command, "No such mailbox" );
69             }
70             return true;
71         }
72         catch ( AccessControlException ace ) {
73             session.noResponse( command, "No such mailbox" );
74             session.logACE( ace );
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