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 rd...@apache.org on 2007/02/10 08:35:29 UTC

svn commit: r505647 - in /james/server/sandbox/seda-imap/src: java/org/apache/james/imapserver/commands/ test/org/apache/james/imapserver/commands/

Author: rdonkin
Date: Fri Feb  9 23:35:28 2007
New Revision: 505647

URL: http://svn.apache.org/viewvc?view=rev&rev=505647
Log:
Perform state validation in process. Remove coupling between messages and commands.

Modified:
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ImapCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java
    james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java Fri Feb  9 23:35:28 2007
@@ -60,7 +60,7 @@
         MimeMessage message = parser.mimeMessage( request );
         parser.endLine( request );
         // TODO: use an object pool
-        final AppendCommandMessage result = new AppendCommandMessage(mailboxName, 
+        final AppendCommandMessage result = new AppendCommandMessage(this, mailboxName, 
                 flags, datetime, message, tag);
         return result;
     }
@@ -77,15 +77,15 @@
         return ARGS;
     }
 
-    private class AppendCommandMessage extends AbstractImapCommandMessage {
+    private static class AppendCommandMessage extends AbstractImapCommandMessage {
         private String mailboxName;
         private Flags flags;
         private Date datetime;
         private MimeMessage message;
                 
-        public AppendCommandMessage(String mailboxName, Flags flags, 
+        public AppendCommandMessage(ImapCommand command, String mailboxName, Flags flags, 
                 Date datetime, MimeMessage message, String tag) {
-            super(tag);
+            super(tag, command);
             this.mailboxName = mailboxName;
             this.flags = flags;
             this.datetime = datetime;
@@ -108,7 +108,7 @@
             return message;
         }
         
-        public ImapResponseMessage doProcess( final ImapSession session, String tag ) throws MailboxException {
+        public ImapResponseMessage doProcess( final ImapSession session, String tag, ImapCommand command ) throws MailboxException {
             ImapMailboxSession mailbox = null;
             try {
                 mailboxName=session.buildFullName(mailboxName);
@@ -126,7 +126,7 @@
                 // TODO why not TRYCREATE?
                 throw new MailboxException(e);
             }
-            return new CommandCompleteResponseMessage(false, AppendCommand.this, tag);
+            return new CommandCompleteResponseMessage(false, command, tag);
         }
     }
     

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java Fri Feb  9 23:35:28 2007
@@ -38,21 +38,21 @@
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         String authType = parser.astring( request );
         parser.endLine( request );        
-        final AuthenticateCommandMessage result = new AuthenticateCommandMessage(authType, tag);
+        final AuthenticateCommandMessage result = new AuthenticateCommandMessage(this, authType, tag);
         return result;
     }
 
-    private class AuthenticateCommandMessage extends AbstractImapCommandMessage {
+    private static class AuthenticateCommandMessage extends AbstractImapCommandMessage {
 
         private final String authType;
         
-        public AuthenticateCommandMessage(final String authType, final String tag) {
-            super(tag);
+        public AuthenticateCommandMessage(final ImapCommand command, final String authType, final String tag) {
+            super(tag, command);
             this.authType = authType;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
-            final CommandFailedResponseMessage result = new CommandFailedResponseMessage(AuthenticateCommand.this, 
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+            final CommandFailedResponseMessage result = new CommandFailedResponseMessage(command, 
                                 "Unsupported authentication mechanism '" + authType + "'", tag);
             return result;
         }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java Fri Feb  9 23:35:28 2007
@@ -40,7 +40,7 @@
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         parser.endLine( request );
-        final CapabilityCommandMessage result = new CapabilityCommandMessage(tag);
+        final CapabilityCommandMessage result = new CapabilityCommandMessage(this, tag);
         return result;
     }
 
@@ -70,14 +70,14 @@
         
     }
     
-    private class CapabilityCommandMessage extends AbstractImapCommandMessage {
+    private static class CapabilityCommandMessage extends AbstractImapCommandMessage {
 
-        public CapabilityCommandMessage(final String tag) {
-            super(tag);
+        public CapabilityCommandMessage(final ImapCommand command, final String tag) {
+            super(tag, command);
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
-            final CapabilityReponseMessage result = new CapabilityReponseMessage(CapabilityCommand.this, tag);
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+            final CapabilityReponseMessage result = new CapabilityReponseMessage(command, tag);
             return result;
         }
     }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java Fri Feb  9 23:35:28 2007
@@ -34,7 +34,7 @@
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         parser.endLine( request );
-        return new CompleteCommandMessage(false, tag);
+        return new CompleteCommandMessage(this, false, tag);
     }
 
     /** @see ImapCommand#getName */

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java Fri Feb  9 23:35:28 2007
@@ -55,13 +55,13 @@
         }
     }
     
-    private class CloseCommandMessage extends AbstractImapCommandMessage {
+    private static class CloseCommandMessage extends AbstractImapCommandMessage {
         
-        public CloseCommandMessage(final String tag) {
-            super(tag);
+        public CloseCommandMessage(final ImapCommand command, final String tag) {
+            super(tag, command);
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             ImapMailboxSession mailbox = session.getSelected().getMailbox();
             if ( session.getSelected().getMailbox().isWriteable() ) {
                 try {
@@ -71,14 +71,14 @@
                 }
             }
             session.deselect();
-            final CloseResponseMessage result = new CloseResponseMessage(CloseCommand.this, tag);
+            final CloseResponseMessage result = new CloseResponseMessage(command, tag);
             return result;
         }
     }
     
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         parser.endLine( request );
-        return new CloseCommandMessage(tag);
+        return new CloseCommandMessage(this, tag);
     }
 
     /** @see ImapCommand#getName */

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java Fri Feb  9 23:35:28 2007
@@ -105,6 +105,28 @@
         return message;
     }
 
+    
+    /**
+     * Provides a message which describes the expected format and arguments
+     * for this command. This is used to provide user feedback when a command
+     * request is malformed.
+     *
+     * @return A message describing the command protocol format.
+     */
+    public String getExpectedMessage()
+    {
+        StringBuffer syntax = new StringBuffer( "<tag> " );
+        syntax.append( getName() );
+
+        String args = getArgSyntax();
+        if ( args != null && args.length() > 0 ) {
+            syntax.append( " " );
+            syntax.append( args );
+        }
+
+        return syntax.toString();
+    }
+    
     /**
      * Parses a request into a command message
      * for later processing.
@@ -134,26 +156,6 @@
         responseMessage.encode(response, session);
     }
 
-    /**
-     * Provides a message which describes the expected format and arguments
-     * for this command. This is used to provide user feedback when a command
-     * request is malformed.
-     *
-     * @return A message describing the command protocol format.
-     */
-    protected String getExpectedMessage()
-    {
-        StringBuffer syntax = new StringBuffer( "<tag> " );
-        syntax.append( getName() );
-
-        String args = getArgSyntax();
-        if ( args != null && args.length() > 0 ) {
-            syntax.append( " " );
-            syntax.append( args );
-        }
-
-        return syntax.toString();
-    }
 
     /**
      * Provides the syntax for the command arguments if any. This value is used
@@ -165,7 +167,7 @@
      * @return The syntax for the command arguments, or <code>null</code> for
      *         commands without arguments.
      */
-    protected abstract String getArgSyntax();
+    public abstract String getArgSyntax();
 
 
     public CommandParser getParser()
@@ -173,11 +175,13 @@
         return parser;
     }
     
-    protected abstract class AbstractImapCommandMessage implements ImapCommandMessage {
+    protected abstract static class AbstractImapCommandMessage extends AbstractLogEnabled implements ImapCommandMessage {
         private final String tag;
+        private final ImapCommand command;
         
-        public AbstractImapCommandMessage(final String tag) {
+        public AbstractImapCommandMessage(final String tag, final ImapCommand command) {
             this.tag = tag;
+            this.command = command;
         }
         public ImapResponseMessage process(ImapSession session) {
             ImapResponseMessage result;
@@ -189,7 +193,7 @@
                 if (logger != null) {
                     logger.debug("error processing command ", e);
                 }
-                result = new CommandFailedResponseMessage( CommandTemplate.this, e.getResponseCode(), 
+                result = new CommandFailedResponseMessage( command, e.getResponseCode(), 
                         e.getMessage(), tag );
             }
             catch ( AuthorizationException e ) {
@@ -197,7 +201,7 @@
                     logger.debug("error processing command ", e);
                 }
                 String msg = "Authorization error: Lacking permissions to perform requested operation.";
-                result = new CommandFailedResponseMessage( CommandTemplate.this, null, 
+                result = new CommandFailedResponseMessage( command, null, 
                         msg, tag );
             }
             catch ( ProtocolException e ) {
@@ -205,7 +209,7 @@
                     logger.debug("error processing command ", e);
                 }
                 String msg = e.getMessage() + " Command should be '" +
-                        getExpectedMessage() + "'";
+                        command.getExpectedMessage() + "'";
                 result = new ErrorResponseMessage( msg, tag );
             }
             return result;
@@ -213,30 +217,30 @@
         
         final ImapResponseMessage doProcess(ImapSession session) throws MailboxException, AuthorizationException, ProtocolException {
             ImapResponseMessage result;
-            if ( !validForState( session.getState() ) ) {
+            if ( !command.validForState( session.getState() ) ) {
                 result = 
-                    new CommandFailedResponseMessage(CommandTemplate.this, 
+                    new CommandFailedResponseMessage(command, 
                             "Command not valid in this state", tag );
             } else {
-                result = doProcess( session, tag );
+                result = doProcess( session, tag, command );
             }
             return result;
         }
         
-        protected abstract ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException;
+        protected abstract ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException;
     }
     
-    protected class CompleteCommandMessage extends AbstractImapCommandMessage {
+    protected static class CompleteCommandMessage extends AbstractImapCommandMessage {
 
         private final boolean useUids;
         
-        public CompleteCommandMessage(final boolean useUids, final String tag) {
-            super(tag);
+        public CompleteCommandMessage(final ImapCommand command, final boolean useUids, final String tag) {
+            super(tag, command);
             this.useUids = useUids;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
-            final CommandCompleteResponseMessage result = new CommandCompleteResponseMessage(useUids, CommandTemplate.this, tag);
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+            final CommandCompleteResponseMessage result = new CommandCompleteResponseMessage(useUids, command, tag);
             return result;
         }
         

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java Fri Feb  9 23:35:28 2007
@@ -51,21 +51,21 @@
         return ARGS;
     }
 
-    private class CopyCommandMessage extends AbstractImapCommandMessage {
+    private static class CopyCommandMessage extends AbstractImapCommandMessage {
 
         private final IdRange[] idSet;
         private final String mailboxName;
         private final boolean useUids;
 
-        public CopyCommandMessage(final IdRange[] idSet, final String mailboxName, 
+        public CopyCommandMessage(final ImapCommand command, final IdRange[] idSet, final String mailboxName, 
                 final boolean useUids, final String tag) {
-            super(tag);
+            super(tag, command);
             this.idSet = idSet;
             this.mailboxName = mailboxName;
             this.useUids = useUids;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             ImapMailboxSession currentMailbox = session.getSelected().getMailbox();
             try {
                 String fullMailboxName = session.buildFullName(this.mailboxName);
@@ -82,7 +82,7 @@
                 throw new MailboxException(e);
             } 
             final CommandCompleteResponseMessage result = 
-                new CommandCompleteResponseMessage(useUids, CopyCommand.this, tag);
+                new CommandCompleteResponseMessage(useUids, command, tag);
             return result;
         }
     }
@@ -96,7 +96,7 @@
         String mailboxName = parser.mailbox( request );
         parser.endLine( request );
         final CopyCommandMessage result = 
-            new CopyCommandMessage(idSet, mailboxName, useUids, tag);
+            new CopyCommandMessage(this, idSet, mailboxName, useUids, tag);
         return result;
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java Fri Feb  9 23:35:28 2007
@@ -51,18 +51,18 @@
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         String mailboxName = parser.mailbox( request );
         parser.endLine( request );
-        final CreateCommandMessage result = new CreateCommandMessage(mailboxName, tag);
+        final CreateCommandMessage result = new CreateCommandMessage(this, mailboxName, tag);
         return result;
     }
 
-    private class CreateCommandMessage extends AbstractImapCommandMessage {
+    private static class CreateCommandMessage extends AbstractImapCommandMessage {
         private final String mailboxName;
-        public CreateCommandMessage(final String mailboxName, final String tag) {
-            super(tag);
+        public CreateCommandMessage(final ImapCommand command, final String mailboxName, final String tag) {
+            super(tag, command);
             this.mailboxName = mailboxName;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             try {
 
                 final String fullMailboxName=session.buildFullName(this.mailboxName);
@@ -70,7 +70,7 @@
             } catch (MailboxManagerException e) {
                throw new MailboxException(e);
             }
-            return new CommandCompleteResponseMessage(false, CreateCommand.this, tag);
+            return new CommandCompleteResponseMessage(false, command, tag);
         }
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java Fri Feb  9 23:35:28 2007
@@ -52,18 +52,18 @@
         String mailboxName = parser.mailbox( request );
         parser.endLine( request );
         final DeleteCommandMessage result = 
-            new DeleteCommandMessage( mailboxName, tag );
+            new DeleteCommandMessage( this, mailboxName, tag );
         return result;
     }
     
-    private class DeleteCommandMessage extends AbstractImapCommandMessage {
+    private static class DeleteCommandMessage extends AbstractImapCommandMessage {
         private final String mailboxName;
-        public DeleteCommandMessage(final String mailboxName, final String tag) {
-            super(tag);
+        public DeleteCommandMessage(final ImapCommand command, final String mailboxName, final String tag) {
+            super(tag, command);
             this.mailboxName = mailboxName;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             try {
                 final String fullMailboxName = session.buildFullName(this.mailboxName);
                 if (session.getSelected() != null) {
@@ -78,7 +78,7 @@
             }
 
             final CommandCompleteResponseMessage result = 
-                new CommandCompleteResponseMessage(false, DeleteCommand.this, tag);
+                new CommandCompleteResponseMessage(false, command, tag);
             return result;
         }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java Fri Feb  9 23:35:28 2007
@@ -53,25 +53,25 @@
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         parser.endLine( request );
-        final ExpungeCommandMessage result = new ExpungeCommandMessage(tag);
+        final ExpungeCommandMessage result = new ExpungeCommandMessage(this, tag);
         return result;
     }
     
-    private class ExpungeCommandMessage extends AbstractImapCommandMessage {
+    private static class ExpungeCommandMessage extends AbstractImapCommandMessage {
 
-        public ExpungeCommandMessage(final String tag) {
-            super(tag);
+        public ExpungeCommandMessage(final ImapCommand command, final String tag) {
+            super(tag, command);
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             ImapResponseMessage result;
             ImapMailboxSession mailbox = session.getSelected().getMailbox();
             if (!mailbox.isWriteable()) {
-                result = new CommandFailedResponseMessage(ExpungeCommand.this, "Mailbox selected read only.", tag );
+                result = new CommandFailedResponseMessage(command, "Mailbox selected read only.", tag );
             } else {
                 try {
                     mailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.NOTHING);
-                    result = new CommandCompleteResponseMessage(false, ExpungeCommand.this, tag);
+                    result = new CommandCompleteResponseMessage(false, command, tag);
                 } catch (MailboxManagerException e) {
                     throw new MailboxException(e);
                 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java Fri Feb  9 23:35:28 2007
@@ -63,245 +63,6 @@
 
     private FetchCommandParser parser = new FetchCommandParser();
 
-    private String outputMessage(FetchRequest fetch, MessageResult result,
-            ImapMailboxSession mailbox, boolean useUids)
-            throws MailboxException, ProtocolException {
-        // Check if this fetch will cause the "SEEN" flag to be set on this
-        // message
-        // If so, update the flags, and ensure that a flags response is included
-        // in the response.
-        try {
-            boolean ensureFlagsResponse = false;
-            if (fetch.isSetSeen()
-                    && !result.getFlags().contains(Flags.Flag.SEEN)) {
-                mailbox.setFlags(new Flags(Flags.Flag.SEEN), true, false,
-                        GeneralMessageSetImpl.oneUid(result.getUid()), null);
-                result.getFlags().add(Flags.Flag.SEEN);
-                ensureFlagsResponse = true;
-            }
-
-            StringBuffer response = new StringBuffer();
-
-            // FLAGS response
-            if (fetch.flags || ensureFlagsResponse) {
-                response.append(" FLAGS ");
-                response.append(MessageFlags.format(result.getFlags()));
-            }
-
-            // INTERNALDATE response
-            if (fetch.internalDate) {
-                response.append(" INTERNALDATE \"");
-                // TODO format properly
-                response.append(RFC822DateFormat.toString(result
-                        .getInternalDate())); // not right format
-                response.append("\"");
-
-            }
-
-            // RFC822.SIZE response
-            if (fetch.size) {
-                response.append(" RFC822.SIZE ");
-                response.append(result.getSize());
-            }
-
-            SimpleMessageAttributes attrs = new SimpleMessageAttributes(result
-                    .getMimeMessage(), getLogger());
-
-            // ENVELOPE response
-            if (fetch.envelope) {
-                response.append(" ENVELOPE ");
-                response.append(attrs.getEnvelope());
-            }
-
-            // BODY response
-            if (fetch.body) {
-                response.append(" BODY ");
-                response.append(attrs.getBodyStructure(false));
-            }
-
-            // BODYSTRUCTURE response
-            if (fetch.bodyStructure) {
-                response.append(" BODYSTRUCTURE ");
-                response.append(attrs.getBodyStructure(true));
-            }
-
-            // UID response
-            if (fetch.uid) {
-                response.append(" UID ");
-                response.append(result.getUid());
-            }
-
-            // BODY part responses.
-            Collection elements = fetch.getBodyElements();
-            for (Iterator iterator = elements.iterator(); iterator.hasNext();) {
-                BodyFetchElement fetchElement = (BodyFetchElement) iterator
-                        .next();
-                response.append(SP);
-                response.append(fetchElement.getResponseName());
-                response.append(SP);
-
-                // Various mechanisms for returning message body.
-                String sectionSpecifier = fetchElement.getParameters();
-
-                MimeMessage mimeMessage = result.getMimeMessage();
-                try {
-                    handleBodyFetch(mimeMessage, sectionSpecifier, response);
-                } catch (MessagingException e) {
-                    throw new MailboxException(e.getMessage(), e);
-                }
-            }
-
-            if (response.length() > 0) {
-                // Remove the leading " ".
-                return response.substring(1);
-            } else {
-                return "";
-            }
-        } catch (MailboxManagerException mme) {
-            throw new MailboxException(mme);
-        } catch (MessagingException me) {
-            throw new MailboxException(me);       
-        }
-    }
-
-
-    private void handleBodyFetch( MimeMessage mimeMessage,
-                                  String sectionSpecifier,
-                                  StringBuffer response )
-            throws ProtocolException, MessagingException
-    {
-        if ( sectionSpecifier.length() == 0 ) {
-            // TODO - need to use an InputStream from the response here.
-            ByteArrayOutputStream bout = new ByteArrayOutputStream();
-            try {
-                mimeMessage.writeTo(new CRLFOutputStream(bout));
-            }
-            catch ( IOException e ) {
-                throw new ProtocolException( "Error reading message source", e);
-            }
-            byte[] bytes = bout.toByteArray();
-            addLiteral( bytes, response );
-            // TODO JD maybe we've to add CRLF here
-            
-        }
-        else if ( sectionSpecifier.equalsIgnoreCase( "HEADER" ) ) {
-            Enumeration e = mimeMessage.getAllHeaderLines();
-            addHeaders( e, response );
-        }
-        else if ( sectionSpecifier.startsWith( "HEADER.FIELDS.NOT " ) ) {
-            String[] excludeNames = extractHeaderList( sectionSpecifier, "HEADER.FIELDS.NOT ".length() );
-            Enumeration e = mimeMessage.getNonMatchingHeaderLines( excludeNames );
-            addHeaders( e, response );
-        }
-        else if ( sectionSpecifier.startsWith( "HEADER.FIELDS " ) ) {
-            String[] includeNames = extractHeaderList( sectionSpecifier, "HEADER.FIELDS ".length() );
-            Enumeration e = mimeMessage.getMatchingHeaderLines( includeNames );
-            addHeaders( e, response );
-        }
-        else if ( sectionSpecifier.equalsIgnoreCase( "MIME" ) ) {
-            // TODO implement
-            throw new ProtocolException( "MIME not yet implemented." );
-        }
-        else if ( sectionSpecifier.equalsIgnoreCase( "TEXT" ) ) {
-            // TODO - need to use an InputStream from the response here.
-            // TODO - this is a hack. To get just the body content, I'm using a null
-            // input stream to take the headers. Need to have a way of ignoring headers.
-            ByteArrayOutputStream headerOut = new ByteArrayOutputStream();
-            ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
-            try {
-                // TODO James Trunk : Is this okay?
-                MimeMessageWrapper mmw=new MimeMessageWrapper(mimeMessage);
-                
-                mmw.writeTo(headerOut, bodyOut );
-                byte[] bytes = bodyOut.toByteArray();
-
-                addLiteral( bytes, response );
-
-            }
-            catch ( IOException e ) {
-                throw new ProtocolException( "Error reading message source", e);
-            }
-        }
-        else {
-            // Should be a part specifier followed by a section specifier.
-            // See if there's a leading part specifier.
-            // If so, get the number, get the part, and call this recursively.
-            int dotPos = sectionSpecifier.indexOf( '.' );
-            if ( dotPos == -1 ) {
-                throw new ProtocolException( "Malformed fetch attribute: " + sectionSpecifier );
-            }
-            int partNumber = Integer.parseInt( sectionSpecifier.substring( 0, dotPos ) );
-            String partSectionSpecifier = sectionSpecifier.substring( dotPos + 1 );
-
-            // TODO - get the MimePart of the mimeMessage, and call this method
-            // with the new partSectionSpecifier.
-//        MimeMessage part;
-//        handleBodyFetch( part, partSectionSpecifier, response );
-            throw new ProtocolException( "Mime parts not yet implemented for fetch." );
-        }
-
-    }
-
-    private void addLiteral( byte[] bytes, StringBuffer response )
-    {
-        response.append('{' );
-        response.append( bytes.length ); // TODO JD addLiteral: why was it  bytes.length +1 here?
-        response.append( '}' );
-        response.append( "\r\n" );
-
-        for ( int i = 0; i < bytes.length; i++ ) {
-            byte b = bytes[i];
-            response.append((char)b);
-        }
-    }
-
-    // TODO should do this at parse time.
-    private String[] extractHeaderList( String headerList, int prefixLen )
-    {
-        // Remove the trailing and leading ')('
-        String tmp = headerList.substring( prefixLen + 1, headerList.length() - 1 );
-        String[] headerNames = split( tmp, " " );
-        return headerNames;
-    }
-    
-    private String[] split(String value, String delimiter) {
-        ArrayList strings = new ArrayList();
-        int startPos = 0;
-        int delimPos;
-        while ( (delimPos = value.indexOf(delimiter, startPos) ) != -1) {
-            String sub = value.substring(startPos, delimPos);
-            strings.add(sub);
-            startPos = delimPos + 1;
-        }
-        String sub = value.substring(startPos);
-        strings.add(sub);
-        
-        return (String[]) strings.toArray(new String[0]);
-    }
-
-    private void addHeaders( Enumeration e, StringBuffer response )
-    {
-        List lines = new ArrayList();
-        int count = 0;
-        while (e.hasMoreElements()) {
-            String line = (String)e.nextElement();
-            count += line.length() + 2;
-            lines.add(line);
-        }
-        response.append( '{' );
-        response.append( count + 2 );
-        response.append( '}' );
-        response.append("\r\n");
-
-        Iterator lit = lines.iterator();
-        while (lit.hasNext()) {
-            String line = (String)lit.next();
-            response.append( line );
-            response.append( "\r\n" );
-        }
-        response.append("\r\n");
-    }
-
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -511,18 +272,18 @@
         FetchRequest fetch = parser.fetchRequest( request );
         parser.endLine( request );
         
-        final FetchCommandMessage result = new FetchCommandMessage(useUids, idSet, fetch, tag);
+        final FetchCommandMessage result = new FetchCommandMessage(this, useUids, idSet, fetch, tag);
         return result;
     }
     
-    private class FetchCommandMessage extends AbstractImapCommandMessage {
+    private static class FetchCommandMessage extends AbstractImapCommandMessage {
         private final boolean useUids;
         private final IdRange[] idSet;
         private final FetchRequest fetch;
 
-        public FetchCommandMessage(final boolean useUids, final IdRange[] idSet, 
+        public FetchCommandMessage(final ImapCommand command, final boolean useUids, final IdRange[] idSet, 
                 final FetchRequest fetch, String tag) {
-            super(tag);
+            super(tag, command);
             this.useUids = useUids;
             this.idSet = idSet;
             this.fetch = fetch;
@@ -532,10 +293,10 @@
         }
 
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             
             FetchResponseMessage result = 
-                new FetchResponseMessage(FetchCommand.this, useUids, tag);
+                new FetchResponseMessage(command, useUids, tag);
             // TODO only fetch needed results
             int resultToFetch = MessageResult.FLAGS | MessageResult.MIME_MESSAGE
                     | MessageResult.INTERNAL_DATE | MessageResult.MSN
@@ -557,6 +318,248 @@
                 }
             }
             return result;
+        }
+        
+
+        private String outputMessage(FetchRequest fetch, MessageResult result,
+                ImapMailboxSession mailbox, boolean useUids)
+                throws MailboxException, ProtocolException {
+            // Check if this fetch will cause the "SEEN" flag to be set on this
+            // message
+            // If so, update the flags, and ensure that a flags response is included
+            // in the response.
+            try {
+                boolean ensureFlagsResponse = false;
+                if (fetch.isSetSeen()
+                        && !result.getFlags().contains(Flags.Flag.SEEN)) {
+                    mailbox.setFlags(new Flags(Flags.Flag.SEEN), true, false,
+                            GeneralMessageSetImpl.oneUid(result.getUid()), null);
+                    result.getFlags().add(Flags.Flag.SEEN);
+                    ensureFlagsResponse = true;
+                }
+
+                StringBuffer response = new StringBuffer();
+
+                // FLAGS response
+                if (fetch.flags || ensureFlagsResponse) {
+                    response.append(" FLAGS ");
+                    response.append(MessageFlags.format(result.getFlags()));
+                }
+
+                // INTERNALDATE response
+                if (fetch.internalDate) {
+                    response.append(" INTERNALDATE \"");
+                    // TODO format properly
+                    response.append(RFC822DateFormat.toString(result
+                            .getInternalDate())); // not right format
+                    response.append("\"");
+
+                }
+
+                // RFC822.SIZE response
+                if (fetch.size) {
+                    response.append(" RFC822.SIZE ");
+                    response.append(result.getSize());
+                }
+
+                SimpleMessageAttributes attrs = new SimpleMessageAttributes(result
+                        .getMimeMessage(), getLogger());
+
+                // ENVELOPE response
+                if (fetch.envelope) {
+                    response.append(" ENVELOPE ");
+                    response.append(attrs.getEnvelope());
+                }
+
+                // BODY response
+                if (fetch.body) {
+                    response.append(" BODY ");
+                    response.append(attrs.getBodyStructure(false));
+                }
+
+                // BODYSTRUCTURE response
+                if (fetch.bodyStructure) {
+                    response.append(" BODYSTRUCTURE ");
+                    response.append(attrs.getBodyStructure(true));
+                }
+
+                // UID response
+                if (fetch.uid) {
+                    response.append(" UID ");
+                    response.append(result.getUid());
+                }
+
+                // BODY part responses.
+                Collection elements = fetch.getBodyElements();
+                for (Iterator iterator = elements.iterator(); iterator.hasNext();) {
+                    BodyFetchElement fetchElement = (BodyFetchElement) iterator
+                            .next();
+                    response.append(SP);
+                    response.append(fetchElement.getResponseName());
+                    response.append(SP);
+
+                    // Various mechanisms for returning message body.
+                    String sectionSpecifier = fetchElement.getParameters();
+
+                    MimeMessage mimeMessage = result.getMimeMessage();
+                    try {
+                        handleBodyFetch(mimeMessage, sectionSpecifier, response);
+                    } catch (MessagingException e) {
+                        throw new MailboxException(e.getMessage(), e);
+                    }
+                }
+
+                if (response.length() > 0) {
+                    // Remove the leading " ".
+                    return response.substring(1);
+                } else {
+                    return "";
+                }
+            } catch (MailboxManagerException mme) {
+                throw new MailboxException(mme);
+            } catch (MessagingException me) {
+                throw new MailboxException(me);       
+            }
+        }
+        
+
+
+
+        private void handleBodyFetch( MimeMessage mimeMessage,
+                                      String sectionSpecifier,
+                                      StringBuffer response )
+                throws ProtocolException, MessagingException
+        {
+            if ( sectionSpecifier.length() == 0 ) {
+                // TODO - need to use an InputStream from the response here.
+                ByteArrayOutputStream bout = new ByteArrayOutputStream();
+                try {
+                    mimeMessage.writeTo(new CRLFOutputStream(bout));
+                }
+                catch ( IOException e ) {
+                    throw new ProtocolException( "Error reading message source", e);
+                }
+                byte[] bytes = bout.toByteArray();
+                addLiteral( bytes, response );
+                // TODO JD maybe we've to add CRLF here
+                
+            }
+            else if ( sectionSpecifier.equalsIgnoreCase( "HEADER" ) ) {
+                Enumeration e = mimeMessage.getAllHeaderLines();
+                addHeaders( e, response );
+            }
+            else if ( sectionSpecifier.startsWith( "HEADER.FIELDS.NOT " ) ) {
+                String[] excludeNames = extractHeaderList( sectionSpecifier, "HEADER.FIELDS.NOT ".length() );
+                Enumeration e = mimeMessage.getNonMatchingHeaderLines( excludeNames );
+                addHeaders( e, response );
+            }
+            else if ( sectionSpecifier.startsWith( "HEADER.FIELDS " ) ) {
+                String[] includeNames = extractHeaderList( sectionSpecifier, "HEADER.FIELDS ".length() );
+                Enumeration e = mimeMessage.getMatchingHeaderLines( includeNames );
+                addHeaders( e, response );
+            }
+            else if ( sectionSpecifier.equalsIgnoreCase( "MIME" ) ) {
+                // TODO implement
+                throw new ProtocolException( "MIME not yet implemented." );
+            }
+            else if ( sectionSpecifier.equalsIgnoreCase( "TEXT" ) ) {
+                // TODO - need to use an InputStream from the response here.
+                // TODO - this is a hack. To get just the body content, I'm using a null
+                // input stream to take the headers. Need to have a way of ignoring headers.
+                ByteArrayOutputStream headerOut = new ByteArrayOutputStream();
+                ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
+                try {
+                    // TODO James Trunk : Is this okay?
+                    MimeMessageWrapper mmw=new MimeMessageWrapper(mimeMessage);
+                    
+                    mmw.writeTo(headerOut, bodyOut );
+                    byte[] bytes = bodyOut.toByteArray();
+
+                    addLiteral( bytes, response );
+
+                }
+                catch ( IOException e ) {
+                    throw new ProtocolException( "Error reading message source", e);
+                }
+            }
+            else {
+                // Should be a part specifier followed by a section specifier.
+                // See if there's a leading part specifier.
+                // If so, get the number, get the part, and call this recursively.
+                int dotPos = sectionSpecifier.indexOf( '.' );
+                if ( dotPos == -1 ) {
+                    throw new ProtocolException( "Malformed fetch attribute: " + sectionSpecifier );
+                }
+                int partNumber = Integer.parseInt( sectionSpecifier.substring( 0, dotPos ) );
+                String partSectionSpecifier = sectionSpecifier.substring( dotPos + 1 );
+
+                // TODO - get the MimePart of the mimeMessage, and call this method
+                // with the new partSectionSpecifier.
+//            MimeMessage part;
+//            handleBodyFetch( part, partSectionSpecifier, response );
+                throw new ProtocolException( "Mime parts not yet implemented for fetch." );
+            }
+
+        }
+
+        private void addLiteral( byte[] bytes, StringBuffer response )
+        {
+            response.append('{' );
+            response.append( bytes.length ); // TODO JD addLiteral: why was it  bytes.length +1 here?
+            response.append( '}' );
+            response.append( "\r\n" );
+
+            for ( int i = 0; i < bytes.length; i++ ) {
+                byte b = bytes[i];
+                response.append((char)b);
+            }
+        }
+
+        // TODO should do this at parse time.
+        private String[] extractHeaderList( String headerList, int prefixLen )
+        {
+            // Remove the trailing and leading ')('
+            String tmp = headerList.substring( prefixLen + 1, headerList.length() - 1 );
+            String[] headerNames = split( tmp, " " );
+            return headerNames;
+        }
+        
+        private String[] split(String value, String delimiter) {
+            ArrayList strings = new ArrayList();
+            int startPos = 0;
+            int delimPos;
+            while ( (delimPos = value.indexOf(delimiter, startPos) ) != -1) {
+                String sub = value.substring(startPos, delimPos);
+                strings.add(sub);
+                startPos = delimPos + 1;
+            }
+            String sub = value.substring(startPos);
+            strings.add(sub);
+            
+            return (String[]) strings.toArray(new String[0]);
+        }
+
+        private void addHeaders( Enumeration e, StringBuffer response )
+        {
+            List lines = new ArrayList();
+            int count = 0;
+            while (e.hasMoreElements()) {
+                String line = (String)e.nextElement();
+                count += line.length() + 2;
+                lines.add(line);
+            }
+            response.append( '{' );
+            response.append( count + 2 );
+            response.append( '}' );
+            response.append("\r\n");
+
+            Iterator lit = lines.iterator();
+            while (lit.hasNext()) {
+                String line = (String)lit.next();
+                response.append( line );
+                response.append( "\r\n" );
+            }
+            response.append("\r\n");
         }
     }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ImapCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ImapCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ImapCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ImapCommand.java Fri Feb  9 23:35:28 2007
@@ -56,4 +56,25 @@
     void process( ImapRequestLineReader request,
                   ImapResponse response,
                   ImapSession session, String tag );
+
+    /**
+     * Provides the syntax for the command arguments if any. This value is used
+     * to provide user feedback in the case of a malformed request.
+     *
+     * For commands which do not allow any arguments, <code>null</code> should
+     * be returned.
+     *
+     * @return The syntax for the command arguments, or <code>null</code> for
+     *         commands without arguments.
+     */
+    String getArgSyntax();
+    
+    /**
+     * Provides a message which describes the expected format and arguments
+     * for this command. This is used to provide user feedback when a command
+     * request is malformed.
+     *
+     * @return A message describing the command protocol format.
+     */
+    String getExpectedMessage();
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java Fri Feb  9 23:35:28 2007
@@ -90,42 +90,35 @@
         }
     }
 
-    protected ListResult[] doList( ImapSession session, String base, String pattern ) throws MailboxException {
-        return doList(  session,  base,  pattern, false);
-    }
-    
-    
-    protected ListResult[] doList( ImapSession session, String base, String pattern, boolean subscribed ) throws MailboxException
-    {
-        try {
-            return session.getMailboxManager().list(base,pattern,false);
-        } catch (MailboxManagerException e) {
-            throw new MailboxException(e);  
-        }
-    }
-    
+
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         String referenceName = parser.mailbox( request );
         String mailboxPattern = parser.listMailbox( request );
         parser.endLine( request );
-        final ListCommandMessage result = new ListCommandMessage(referenceName, mailboxPattern, tag);
+        final ListCommandMessage result = createMessage(referenceName, mailboxPattern, tag);
         return result;
     }
     
-    private class ListCommandMessage extends AbstractImapCommandMessage {
+    protected ListCommandMessage createMessage(final String referenceName, final String mailboxPattern, final String tag) 
+    {
+        final ListCommandMessage result = new ListCommandMessage(this, referenceName, mailboxPattern, tag);
+        return result;
+    }
+    
+    protected static class ListCommandMessage extends AbstractImapCommandMessage {
         private final String baseReferenceName;
         private final String mailboxPattern;
 
-        public ListCommandMessage(final String referenceName, final String mailboxPattern,
+        public ListCommandMessage(final ImapCommand command, final String referenceName, final String mailboxPattern,
                 final String tag) {
-            super(tag);
+            super(tag, command);
             this.baseReferenceName = referenceName;
             this.mailboxPattern = mailboxPattern;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
 
-            final ListResponseMessage result = new ListResponseMessage(ListCommand.this, tag);
+            final ListResponseMessage result = new ListResponseMessage(command, tag);
             String referenceName = this.baseReferenceName;
             // Should the #user.userName section be removed from names returned?
             boolean removeUserPrefix;
@@ -220,9 +213,22 @@
             }
             return result;
         }
+        
+        protected ListResult[] doList( ImapSession session, String base, String pattern ) throws MailboxException {
+            return doList(  session,  base,  pattern, false);
+        }
+        
+        protected ListResult[] doList( ImapSession session, String base, String pattern, boolean subscribed ) throws MailboxException
+        {
+            try {
+                return session.getMailboxManager().list(base,pattern,false);
+            } catch (MailboxManagerException e) {
+                throw new MailboxException(e);  
+            }
+        }
     }
     
-    private class ListResponseMessage extends AbstractCommandResponseMessage {
+    private static class ListResponseMessage extends AbstractCommandResponseMessage {
         private List messages = new ArrayList();
         
         public ListResponseMessage(final ImapCommand command, final String tag) {

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java Fri Feb  9 23:35:28 2007
@@ -53,28 +53,28 @@
         final String userid = parser.astring( request );
         final String password = parser.astring( request );
         parser.endLine( request );
-        return new LoginCommandMessage(userid, password, tag);
+        return new LoginCommandMessage(this, userid, password, tag);
     }
     
-    private class LoginCommandMessage extends AbstractImapCommandMessage {
+    private static class LoginCommandMessage extends AbstractImapCommandMessage {
         private final String userid;
         private final String password;
         
-        public LoginCommandMessage(final String userid, final String password, String tag) {
-            super(tag);
+        public LoginCommandMessage(final ImapCommand command, final String userid, final String password, String tag) {
+            super(tag, command);
             this.userid = userid;
             this.password = password;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             ImapResponseMessage result;
             if ( session.getUsers().test( userid, password ) ) {
                 User user = session.getUsers().getUserByName( userid );
                 session.setAuthenticated( user );
-                result = CommandCompleteResponseMessage.createWithNoUnsolictedResponses(LoginCommand.this, tag);
+                result = CommandCompleteResponseMessage.createWithNoUnsolictedResponses(command, tag);
             }
             else {
-                result = new CommandFailedResponseMessage( LoginCommand.this, "Invalid login/password", tag );
+                result = new CommandFailedResponseMessage( command, "Invalid login/password", tag );
             }
             return result;
         }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java Fri Feb  9 23:35:28 2007
@@ -51,18 +51,17 @@
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         parser.endLine( request );
-        return new LogoutCommandMessage(tag);
+        return new LogoutCommandMessage(this, tag);
     }
     
-    private class LogoutCommandMessage extends AbstractImapCommandMessage {
+    private static class LogoutCommandMessage extends AbstractImapCommandMessage {
 
-        
-        public LogoutCommandMessage(final String tag) {
-            super(tag);
+        public LogoutCommandMessage(final ImapCommand command, final String tag) {
+            super(tag, command);
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
-            final LogoutResponseMessage result = new LogoutResponseMessage(LogoutCommand.this, tag);
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+            final LogoutResponseMessage result = new LogoutResponseMessage(command, tag);
             return result;
         }
         

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java Fri Feb  9 23:35:28 2007
@@ -30,14 +30,29 @@
 {
     public static final String NAME = "LSUB";
 
-    protected ListResult[] doList( ImapSession session, String base, String pattern )  throws MailboxException
-    {
-        return doList(session,base,pattern,true);
-    }
+
 
     /** @see ImapCommand#getName */
     public String getName()
     {
         return NAME;
+    }
+    
+    
+    
+    protected ListCommandMessage createMessage(String referenceName, String mailboxPattern, String tag) {
+        return new LsubListCommandMessage(this, referenceName, mailboxPattern, tag);
+    }
+
+    private static class LsubListCommandMessage extends ListCommandMessage 
+    {
+        public LsubListCommandMessage(ImapCommand command, String referenceName, String mailboxPattern, String tag) {
+            super(command, referenceName, mailboxPattern, tag);
+        }
+
+        protected ListResult[] doList( ImapSession session, String base, String pattern )  throws MailboxException
+        {
+            return doList(session,base,pattern,true);
+        }
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java Fri Feb  9 23:35:28 2007
@@ -46,7 +46,7 @@
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         parser.endLine( request );
-        return new CompleteCommandMessage(false, tag);
+        return new CompleteCommandMessage(this, false, tag);
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java Fri Feb  9 23:35:28 2007
@@ -52,21 +52,21 @@
         final String existingName = parser.mailbox( request );
         final String newName = parser.mailbox( request );
         parser.endLine( request );
-        return new RenameCommandMessage(existingName, newName, tag);
+        return new RenameCommandMessage(this, existingName, newName, tag);
     }
 
-    private class RenameCommandMessage extends AbstractImapCommandMessage {
+    private static class RenameCommandMessage extends AbstractImapCommandMessage {
         private final String existingName;
         private final String newName;
         
-        public RenameCommandMessage(final String existingName, final String newName, 
+        public RenameCommandMessage(final ImapCommand command, final String existingName, final String newName, 
                 final String tag) {
-            super(tag);
+            super(tag, command);
             this.existingName = existingName;
             this.newName = newName;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             try {
                 final String fullExistingName=session.buildFullName(this.existingName);
                 final String fullNewName=session.buildFullName(this.newName);
@@ -75,7 +75,7 @@
                throw new MailboxException(e);
             }
 
-            return new CommandCompleteResponseMessage(false, RenameCommand.this, tag);
+            return new CommandCompleteResponseMessage(false, command, tag);
         }
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java Fri Feb  9 23:35:28 2007
@@ -97,22 +97,22 @@
         // Parse the search term from the request
         final SearchTerm searchTerm = parser.searchTerm( request );
         parser.endLine( request );
-        final SearchImapCommand result = new SearchImapCommand(searchTerm, useUids, tag);
+        final SearchImapCommand result = new SearchImapCommand(this, searchTerm, useUids, tag);
         return result;
     }
     
-    private class SearchImapCommand extends AbstractImapCommandMessage {
+    private static class SearchImapCommand extends AbstractImapCommandMessage {
         private final SearchTerm searchTerm;
         private final boolean useUids;
 
-        public SearchImapCommand(final SearchTerm searchTerm, final boolean useUids,
+        public SearchImapCommand(final ImapCommand command, final SearchTerm searchTerm, final boolean useUids,
                 final String tag) {
-            super(tag);
+            super(tag, command);
             this.searchTerm = searchTerm;
             this.useUids = useUids;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             ImapMailboxSession mailbox = session.getSelected().getMailbox();
             final int resultCode;
             if (useUids) {
@@ -140,7 +140,7 @@
                 }
             }
             final SearchResponseMessage result = 
-                new SearchResponseMessage(SearchCommand.this, idList.toString(), 
+                new SearchResponseMessage(command, idList.toString(), 
                         useUids, tag);
             return result;
         }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java Fri Feb  9 23:35:28 2007
@@ -67,22 +67,22 @@
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         final String mailboxName = parser.mailbox( request );
         parser.endLine( request );
-        final SelectCommandMessage result = new SelectCommandMessage(mailboxName, isExamine, tag);
+        final SelectCommandMessage result = new SelectCommandMessage(this, mailboxName, isExamine, tag);
         return result;
     }
     
-    private class SelectCommandMessage extends AbstractImapCommandMessage {
+    private static class SelectCommandMessage extends AbstractImapCommandMessage {
         private final String mailboxName;
         private final boolean isExamine;
         
-        public SelectCommandMessage(final String mailboxName, final boolean isExamine,
+        public SelectCommandMessage(final ImapCommand command, final String mailboxName, final boolean isExamine,
                 final String tag) {
-            super(tag);
+            super(tag, command);
             this.mailboxName = mailboxName;
             this.isExamine = isExamine;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             ImapResponseMessage result;
             session.deselect();
             try {
@@ -96,7 +96,7 @@
                 final long uidValidity = mailbox.getUidValidity();
                 final MessageResult firstUnseen = mailbox.getFirstUnseen(MessageResult.MSN);
                 final int messageCount = mailbox.getMessageCount();
-                result = new SelectResponseMessage(SelectCommand.this, permanentFlags, 
+                result = new SelectResponseMessage(command, permanentFlags, 
                         writeable, recentCount, uidValidity, firstUnseen, messageCount,
                         tag);
             } catch (MailboxManagerException e) {

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java Fri Feb  9 23:35:28 2007
@@ -120,21 +120,21 @@
         final StatusDataItems statusDataItems = parser.statusDataItems( request );
         parser.endLine( request );
         final StatusCommandMessage result = 
-            new StatusCommandMessage(mailboxName, statusDataItems, tag);
+            new StatusCommandMessage(this, mailboxName, statusDataItems, tag);
         return result;
     }
     
-    private class StatusCommandMessage extends AbstractImapCommandMessage {
+    private static class StatusCommandMessage extends AbstractImapCommandMessage {
         private final String mailboxName;
         private final StatusDataItems statusDataItems;
         
-        public StatusCommandMessage(final String mailboxName, final StatusDataItems statusDataItems, final String tag) {
-            super(tag);
+        public StatusCommandMessage(final ImapCommand command, final String mailboxName, final StatusDataItems statusDataItems, final String tag) {
+            super(tag, command);
             this.mailboxName = mailboxName;
             this.statusDataItems = statusDataItems;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             final Logger logger = getLogger(); 
 
             StringBuffer buffer = new StringBuffer( mailboxName );
@@ -196,7 +196,7 @@
             }
             buffer.append(')');
             final StatusResponseMessage result = 
-                new StatusResponseMessage(StatusCommand.this, buffer.toString(), tag);
+                new StatusResponseMessage(command, buffer.toString(), tag);
             return result;
         }
     }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java Fri Feb  9 23:35:28 2007
@@ -123,25 +123,25 @@
         final StoreDirective directive = parser.storeDirective( request );
         final Flags flags = parser.flagList( request );
         parser.endLine( request );
-        return new StoreCommandMessage(idSet, directive, flags, useUids, tag);
+        return new StoreCommandMessage(this, idSet, directive, flags, useUids, tag);
     }
     
-    private class StoreCommandMessage extends AbstractImapCommandMessage {
+    private static class StoreCommandMessage extends AbstractImapCommandMessage {
         private final IdRange[] idSet;
         private final StoreDirective directive;
         private final Flags flags;
         private final boolean useUids;
         
-        public StoreCommandMessage(final IdRange[] idSet, final StoreDirective directive, final Flags flags, 
+        public StoreCommandMessage(final ImapCommand command, final IdRange[] idSet, final StoreDirective directive, final Flags flags, 
                 final boolean useUids, final String tag) {
-            super(tag);
+            super(tag, command);
             this.idSet = idSet;
             this.directive = directive;
             this.flags = flags;
             this.useUids = useUids;
         }
         
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
 
             ImapMailboxSession mailbox = session.getSelected().getMailbox();
             MailboxListener silentListener = null;
@@ -177,7 +177,7 @@
             }
             
             final StoreResponseMessage result = 
-                new StoreResponseMessage(StoreCommand.this, useUids, tag);
+                new StoreResponseMessage(command, useUids, tag);
             return result;
         }
     }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java Fri Feb  9 23:35:28 2007
@@ -50,26 +50,26 @@
         parser.endLine( request );
         
         final SubscribeCommandMessage result = 
-            new SubscribeCommandMessage(mailboxName, tag);
+            new SubscribeCommandMessage(this, mailboxName, tag);
         return result;
     }
     
-    private class SubscribeCommandMessage extends AbstractImapCommandMessage {
+    private static class SubscribeCommandMessage extends AbstractImapCommandMessage {
         private final String mailboxName;
         
-        public SubscribeCommandMessage(final String mailboxName, final String tag) {
-            super(tag);
+        public SubscribeCommandMessage(final ImapCommand command, final String mailboxName, final String tag) {
+            super(tag, command);
             this.mailboxName = mailboxName;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             try {
                 final String fullMailboxName = session.buildFullName(this.mailboxName);
                 session.getMailboxManager().setSubscription(fullMailboxName,true);
             } catch (MailboxManagerException e) {
                throw new MailboxException(e);
             }
-            return new CommandCompleteResponseMessage(false, SubscribeCommand.this, tag);
+            return new CommandCompleteResponseMessage(false, command, tag);
         }
         
     }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java Fri Feb  9 23:35:28 2007
@@ -49,25 +49,25 @@
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         final String mailboxName = parser.mailbox( request );
         parser.endLine( request );
-        return new UnsubscribeCommandMessage(mailboxName, tag);
+        return new UnsubscribeCommandMessage(this, mailboxName, tag);
     }
     
-    private class UnsubscribeCommandMessage extends AbstractImapCommandMessage {
+    private static class UnsubscribeCommandMessage extends AbstractImapCommandMessage {
         private final String mailboxName;
 
-        public UnsubscribeCommandMessage(final String mailboxName, final String tag) {
-            super(tag);
+        public UnsubscribeCommandMessage(final ImapCommand command, final String mailboxName, final String tag) {
+            super(tag, command);
             this.mailboxName = mailboxName;
         }
 
-        protected ImapResponseMessage doProcess(ImapSession session, String tag) throws MailboxException, AuthorizationException, ProtocolException {
+        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
             try {
                 final String fullMailboxName=session.buildFullName(this.mailboxName);
                 session.getMailboxManager().setSubscription(fullMailboxName,false);
             } catch (MailboxManagerException e) {
                 throw new MailboxException(e);
             }
-            return new CommandCompleteResponseMessage(false, UnsubscribeCommand.this, tag);
+            return new CommandCompleteResponseMessage(false, command, tag);
         }
         
     }

Modified: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java?view=diff&rev=505647&r1=505646&r2=505647
==============================================================================
--- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java (original)
+++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java Fri Feb  9 23:35:28 2007
@@ -7,7 +7,7 @@
 
     public static final String NAME = "MOCK";
 
-    protected String getArgSyntax() {
+    public String getArgSyntax() {
         return null;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org