KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * Implements the command for searching after Mails.
33  *
34  * @version 0.2 on 04 Aug 2002
35  */

36
37 class SearchCommand extends AuthenticatedSelectedStateCommand
38 {
39     public SearchCommand()
40     {
41         System.out.println("*SEARCH*: <init>");
42         this.commandName = "SEARCH";
43
44         this.getArgs().add( new AstringArgument( "search1" ) );
45         this.getArgs().add( new AstringArgument( "search2" ) );
46     }
47
48     protected boolean doProcess( ImapRequest request, ImapSession session, List JavaDoc argValues )
49     {
50         String JavaDoc command = this.commandName;
51
52         String JavaDoc search1 = (String JavaDoc) argValues.get( 0 );
53         String JavaDoc search2 = (String JavaDoc) argValues.get( 1 );
54
55         System.out.println("*SEARCH*: got arg1: "+ search1);
56         System.out.println("*SEARCH*: got arg2: "+ search2);
57         
58         System.out.println("*SEARCH*: currentMailbox:"+request.getCurrentMailbox().getName());
59         
60         session.getOut().print( UNTAGGED + SP + command.toUpperCase());
61         getLogger().debug( UNTAGGED + SP + command.toUpperCase());
62         if (request.getCurrentMailbox().matchesName("inbox")) {
63             session.getOut().print( SP + "1" );
64             getLogger().debug( SP + "1" );
65         }
66         session.getOut().println();
67
68         session.okResponse( command );
69
70         if ( session.getState() == ImapSessionState.SELECTED ) {
71             session.checkSize();
72             session.checkExpunge();
73         }
74         return true;
75     }
76 }
77
Popular Tags