You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by da...@apache.org on 2002/08/27 15:58:17 UTC
cvs commit: jakarta-james/proposals/imap/java/org/apache/james/imapserver/commands CommandTemplate.java UidCommand.java
danny 2002/08/27 06:58:16
Modified: proposals/imap/java/org/apache/james/imapserver/commands
CommandTemplate.java UidCommand.java
Log:
latest changes from sascha
Revision Changes Path
1.6 +199 -201 jakarta-james/proposals/imap/java/org/apache/james/imapserver/commands/CommandTemplate.java
Index: CommandTemplate.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap/java/org/apache/james/imapserver/commands/CommandTemplate.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CommandTemplate.java 9 Aug 2002 16:48:06 -0000 1.5
+++ CommandTemplate.java 27 Aug 2002 13:58:16 -0000 1.6
@@ -1,201 +1,199 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE file.
- */
-package org.apache.james.imapserver.commands;
-
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.AccessControlException;
-import org.apache.james.util.Assert;
-import org.apache.james.imapserver.*;
-
-import java.util.StringTokenizer;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-/**
- * Base Class for all Commands.
- *
- * @author <a href="mailto:sascha@kulawik.de">Sascha Kulawik</a>
- * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
- * @version 0.2 on 04 Aug 2002
- */
-
-abstract class CommandTemplate
- extends AbstractLogEnabled implements ImapCommand, ImapConstants
-{
- protected String commandName;
- private List args = new ArrayList();
-
- protected String getCommand()
- {
- return this.commandName;
- }
-
- /**
- * @return a List of <code>ImapArgument</code> objects.
- */
- protected List getArgs()
- {
- return this.args;
- }
-
- protected String getExpectedMessage()
- {
- StringBuffer msg = new StringBuffer( "<tag> " );
- msg.append( getCommand() );
-
- List args = getArgs();
- for ( Iterator iter = args.iterator(); iter.hasNext(); ) {
- msg.append( " " );
- ImapArgument arg = (ImapArgument) iter.next();
- msg.append( arg.format() );
- }
- return msg.toString();
- }
-
- /**
- * Template methods for handling command processing.
- */
- public boolean process( ImapRequest request, ImapSession session )
- {
- StringTokenizer tokens = request.getCommandLine();
-
- List args = getArgs();
- List argValues = new ArrayList();
-
- System.out.println("CommandTemplate.process command: '"+getCommand()+"'");
- for ( Iterator iter = args.iterator(); iter.hasNext(); ) {
- System.out.println("CommandTemplate.process ARGUMENT");
- Object o = iter.next();
- ImapArgument arg = (ImapArgument) o;
- try {
- argValues.add( arg.parse( tokens ) );
- }
- catch ( Exception e ) {
- String badMsg = e.getMessage() + ": Command should be " + getExpectedMessage();
- session.badResponse( badMsg );
- return true;
- }
- }
-
- if ( tokens.hasMoreTokens() ) {
- String badMsg = "Extra token found: Command should be " + getExpectedMessage();
- session.badResponse( badMsg );
- return true;
- }
- System.out.println("CommandTemplate.process starting doProcess");
- return doProcess( request, session, argValues );
-
- }
-
- protected abstract boolean doProcess( ImapRequest request, ImapSession session, List argValues );
-
- /**
- * By default, valid in any state (unless overridden by subclass.
- */
- public boolean validForState( ImapSessionState state )
- {
- return true;
- }
-
- protected void logCommand( ImapRequest request, ImapSession session )
- {
- getLogger().debug( request.getCommand() + " command completed for " +
- session.getRemoteHost() + "(" +
- session.getRemoteIP() + ")" );
- }
-
- protected ACLMailbox getMailbox( ImapSession session, String mailboxName, String command )
- {
- if ( session.getState() == ImapSessionState.SELECTED && session.getCurrentFolder().equals( mailboxName ) ) {
- return session.getCurrentMailbox();
- }
- else {
- try {
- return session.getImapHost().getMailbox( session.getCurrentUser(), mailboxName );
- }
- catch ( MailboxException me ) {
- if ( me.isRemote() ) {
- session.noResponse( "[REFERRAL " + me.getRemoteServer() + "]" + SP + "Remote mailbox" );
- }
- else {
- session.noResponse( command, "Unknown mailbox" );
- getLogger().info( "MailboxException in method getBox for user: "
- + session.getCurrentUser() + " mailboxName: " + mailboxName + " was "
- + me.getMessage() );
- }
- return null;
- }
- catch ( AccessControlException e ) {
- session.noResponse( command, "Unknown mailbox" );
- return null;
- }
- }
- }
-
- /** TODO - decode quoted strings properly, with escapes. */
- public static String readAstring( StringTokenizer tokens )
- {
- if ( ! tokens.hasMoreTokens() ) {
- throw new RuntimeException( "Not enough tokens" );
- }
- String token = tokens.nextToken();
- Assert.isTrue( token.length() > 0 );
-
- StringBuffer astring = new StringBuffer( token );
-
- if ( astring.charAt(0) == '\"' ) {
- while ( astring.length() == 1 ||
- astring.charAt( astring.length() - 1 ) != '\"' ) {
- if ( tokens.hasMoreTokens() ) {
- astring.append( tokens.nextToken() );
- }
- else {
- throw new RuntimeException( "Missing closing quote" );
- }
- }
- astring.deleteCharAt( 0 );
- astring.deleteCharAt( astring.length() - 1 );
- }
-
- return astring.toString();
- }
-
- public String decodeAstring( String rawAstring )
- {
-
- if ( rawAstring.length() == 0 ) {
- return rawAstring;
- }
-
- if ( rawAstring.startsWith( "\"" ) ) {
- //quoted string
- if ( rawAstring.endsWith( "\"" ) ) {
- if ( rawAstring.length() == 2 ) {
- return new String(); //ie blank
- }
- else {
- return rawAstring.substring( 1, rawAstring.length() - 1 );
- }
- }
- else {
- getLogger().error( "Quoted string with no closing quote." );
- return null;
- }
- }
- else {
- //atom
- return rawAstring;
- }
- }
-
- public void setArgs( List args )
- {
- this.args = args;
- }
-}
+/*
+ * Copyright (C) The Apache Software Foundation. All rights reserved.
+ *
+ * This software is published under the terms of the Apache Software License
+ * version 1.1, a copy of which has been included with this distribution in
+ * the LICENSE file.
+ */
+package org.apache.james.imapserver.commands;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.AccessControlException;
+import org.apache.james.util.Assert;
+import org.apache.james.imapserver.*;
+
+import java.util.StringTokenizer;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * Base Class for all Commands.
+ *
+ * @author <a href="mailto:sascha@kulawik.de">Sascha Kulawik</a>
+ * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
+ * @version 0.2 on 04 Aug 2002
+ */
+
+abstract class CommandTemplate
+ extends AbstractLogEnabled implements ImapCommand, ImapConstants
+{
+ protected String commandName;
+ private List args = new ArrayList();
+
+ protected String getCommand()
+ {
+ return this.commandName;
+ }
+
+ /**
+ * @return a List of <code>ImapArgument</code> objects.
+ */
+ protected List getArgs()
+ {
+ return this.args;
+ }
+
+ protected String getExpectedMessage()
+ {
+ StringBuffer msg = new StringBuffer( "<tag> " );
+ msg.append( getCommand() );
+
+ List args = getArgs();
+ for ( Iterator iter = args.iterator(); iter.hasNext(); ) {
+ msg.append( " " );
+ ImapArgument arg = (ImapArgument) iter.next();
+ msg.append( arg.format() );
+ }
+ return msg.toString();
+ }
+
+ /**
+ * Template methods for handling command processing.
+ */
+ public boolean process( ImapRequest request, ImapSession session )
+ {
+ StringTokenizer tokens = request.getCommandLine();
+
+ List args = getArgs();
+ List argValues = new ArrayList();
+
+ System.out.println("CommandTemplate.process command: '"+getCommand()+"'");
+ for ( Iterator iter = args.iterator(); iter.hasNext(); ) {
+ System.out.println("CommandTemplate.process ARGUMENT");
+ Object o = iter.next();
+ ImapArgument arg = (ImapArgument) o;
+ try {
+ argValues.add( arg.parse( tokens ) );
+ }
+ catch ( Exception e ) {
+ String badMsg = e.getMessage() + ": Command should be " + getExpectedMessage();
+ session.badResponse( badMsg );
+ return true;
+ }
+ }
+
+ if ( tokens.hasMoreTokens() ) {
+ String badMsg = "Extra token found: Command should be " + getExpectedMessage();
+ session.badResponse( badMsg );
+ return true;
+ }
+ System.out.println("CommandTemplate.process starting doProcess");
+ return doProcess( request, session, argValues );
+
+ }
+
+ protected abstract boolean doProcess( ImapRequest request, ImapSession session, List argValues );
+
+ /**
+ * By default, valid in any state (unless overridden by subclass.
+ */
+ public boolean validForState( ImapSessionState state )
+ {
+ return true;
+ }
+
+ protected void logCommand( ImapRequest request, ImapSession session )
+ {
+ getLogger().debug( request.getCommand() + " command completed for " +
+ session.getRemoteHost() + "(" +
+ session.getRemoteIP() + ")" );
+ }
+
+ protected ACLMailbox getMailbox( ImapSession session, String mailboxName, String command )
+ {
+ if ( session.getState() == ImapSessionState.SELECTED && session.getCurrentFolder().equals( mailboxName ) ) {
+ return session.getCurrentMailbox();
+ }
+ else {
+ try {
+ return session.getImapHost().getMailbox( session.getCurrentUser(), mailboxName );
+ } catch ( MailboxException me ) {
+ if ( me.isRemote() ) {
+ session.noResponse( "[REFERRAL " + me.getRemoteServer() + "]" + SP + "Remote mailbox" );
+ } else {
+ session.noResponse( command, "Unknown mailbox" );
+ getLogger().info( "MailboxException in method getBox for user: "
+ + session.getCurrentUser() + " mailboxName: " + mailboxName + " was "
+ + me.getMessage() );
+ }
+ return null;
+ }
+ catch ( AccessControlException e ) {
+ session.noResponse( command, "Unknown mailbox" );
+ return null;
+ }
+ }
+ }
+
+ /** TODO - decode quoted strings properly, with escapes. */
+ public static String readAstring( StringTokenizer tokens )
+ {
+ if ( ! tokens.hasMoreTokens() ) {
+ throw new RuntimeException( "Not enough tokens" );
+ }
+ String token = tokens.nextToken();
+ Assert.isTrue( token.length() > 0 );
+
+ StringBuffer astring = new StringBuffer( token );
+
+ if ( astring.charAt(0) == '\"' ) {
+ while ( astring.length() == 1 ||
+ astring.charAt( astring.length() - 1 ) != '\"' ) {
+ if ( tokens.hasMoreTokens() ) {
+ astring.append( tokens.nextToken() );
+ }
+ else {
+ throw new RuntimeException( "Missing closing quote" );
+ }
+ }
+ astring.deleteCharAt( 0 );
+ astring.deleteCharAt( astring.length() - 1 );
+ }
+
+ return astring.toString();
+ }
+
+ public String decodeAstring( String rawAstring )
+ {
+
+ if ( rawAstring.length() == 0 ) {
+ return rawAstring;
+ }
+
+ if ( rawAstring.startsWith( "\"" ) ) {
+ //quoted string
+ if ( rawAstring.endsWith( "\"" ) ) {
+ if ( rawAstring.length() == 2 ) {
+ return new String(); //ie blank
+ }
+ else {
+ return rawAstring.substring( 1, rawAstring.length() - 1 );
+ }
+ }
+ else {
+ getLogger().error( "Quoted string with no closing quote." );
+ return null;
+ }
+ }
+ else {
+ //atom
+ return rawAstring;
+ }
+ }
+
+ public void setArgs( List args )
+ {
+ this.args = args;
+ }
+}
1.5 +63 -63 jakarta-james/proposals/imap/java/org/apache/james/imapserver/commands/UidCommand.java
Index: UidCommand.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap/java/org/apache/james/imapserver/commands/UidCommand.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- UidCommand.java 9 Aug 2002 16:48:07 -0000 1.4
+++ UidCommand.java 27 Aug 2002 13:58:16 -0000 1.5
@@ -1,63 +1,63 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE file.
- */
-package org.apache.james.imapserver.commands;
-
-import org.apache.james.imapserver.*;
-import org.apache.james.util.Assert;
-
-import java.util.StringTokenizer;
-import java.util.List;
-
-/**
- * Implements the UID Command for calling Commands with the fixed UID
- *
- * @author <a href="mailto:sascha@kulawik.de">Sascha Kulawik</a>
- * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
- * @version 0.2 on 04 Aug 2002
- */
-class UidCommand implements ImapCommand
-{
- public boolean validForState( ImapSessionState state )
- {
- return ( state == ImapSessionState.SELECTED );
- }
-
- public boolean process( ImapRequest request, ImapSession session )
- {
- // StringTokenizer commandLine = new java.util.StringTokenizer(request.getCommandRaw());
- StringTokenizer commandLine = request.getCommandLine();
- int arguments = commandLine.countTokens();
- // StringTokenizer commandLine = request.getCommandLine();
- String command = request.getCommand();
-
- StringTokenizer txt = new java.util.StringTokenizer(request.getCommandRaw());
- System.out.println("UidCommand.process: #args="+txt.countTokens());
- while (txt.hasMoreTokens()) {
- System.out.println("UidCommand.process: arg='"+txt.nextToken()+"'");
- }
- if ( arguments < 3 ) {
- session.badResponse( "rawcommand='"+request.getCommandRaw()+"' #args="+request.arguments()+" Command should be <tag> <UID> <command> <command parameters>" );
- return true;
- }
- String uidCommand = commandLine.nextToken();
- System.out.println("UidCommand.uidCommand="+uidCommand);
- System.out.println("UidCommand.session="+session.getClass().getName());
- ImapCommand cmd = session.getImapCommand( uidCommand );
- System.out.println("UidCommand.cmd="+cmd);
- System.out.println("UidCommand.cmd="+cmd.getClass().getName());
- if ( cmd instanceof CommandFetch || cmd instanceof CommandStore || cmd instanceof CopyCommand) {
- // As in RFC2060 also the COPY Command is valid for UID Command
- request.setCommand( uidCommand );
- ((ImapRequestImpl)request).setUseUIDs( true );
- cmd.process( request, session );
- } else {
- session.badResponse( "Invalid UID secondary command." );
- }
- return true;
- }
-}
+/*
+ * Copyright (C) The Apache Software Foundation. All rights reserved.
+ *
+ * This software is published under the terms of the Apache Software License
+ * version 1.1, a copy of which has been included with this distribution in
+ * the LICENSE file.
+ */
+package org.apache.james.imapserver.commands;
+
+import org.apache.james.imapserver.*;
+import org.apache.james.util.Assert;
+
+import java.util.StringTokenizer;
+import java.util.List;
+
+/**
+ * Implements the UID Command for calling Commands with the fixed UID
+ *
+ * @author <a href="mailto:sascha@kulawik.de">Sascha Kulawik</a>
+ * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
+ * @version 0.2 on 04 Aug 2002
+ */
+class UidCommand implements ImapCommand
+{
+ public boolean validForState( ImapSessionState state )
+ {
+ return ( state == ImapSessionState.SELECTED );
+ }
+
+ public boolean process( ImapRequest request, ImapSession session )
+ {
+ // StringTokenizer commandLine = new java.util.StringTokenizer(request.getCommandRaw());
+ StringTokenizer commandLine = request.getCommandLine();
+ int arguments = commandLine.countTokens();
+ // StringTokenizer commandLine = request.getCommandLine();
+ String command = request.getCommand();
+
+ StringTokenizer txt = new java.util.StringTokenizer(request.getCommandRaw());
+ System.out.println("UidCommand.process: #args="+txt.countTokens());
+ while (txt.hasMoreTokens()) {
+ System.out.println("UidCommand.process: arg='"+txt.nextToken()+"'");
+ }
+ if ( arguments < 3 ) {
+ session.badResponse( "rawcommand='"+request.getCommandRaw()+"' #args="+request.arguments()+" Command should be <tag> <UID> <command> <command parameters>" );
+ return true;
+ }
+ String uidCommand = commandLine.nextToken();
+ System.out.println("UidCommand.uidCommand="+uidCommand);
+ System.out.println("UidCommand.session="+session.getClass().getName());
+ ImapCommand cmd = session.getImapCommand( uidCommand );
+ System.out.println("UidCommand.cmd="+cmd);
+ System.out.println("UidCommand.cmd="+cmd.getClass().getName());
+ if ( cmd instanceof CommandFetch || cmd instanceof CommandStore || cmd instanceof CopyCommand) {
+ // As in RFC2060 also the COPY Command is valid for UID Command
+ request.setCommand( uidCommand );
+ ((ImapRequestImpl)request).setUseUIDs( true );
+ cmd.process( request, session );
+ } else {
+ session.badResponse( "Invalid UID secondary command." );
+ }
+ return true;
+ }
+}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>