james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r592415 [1/3] - in /james/server/trunk: core-library/src/main/java/org/apache/james/mailboxmanager/ experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ experimental-seda-imap-function/src/main/java/org/ap...
Date Tue, 06 Nov 2007 13:17:46 GMT
Author: rdonkin
Date: Tue Nov  6 05:17:42 2007
New Revision: 592415

URL: http://svn.apache.org/viewvc?rev=592415&view=rev
Log:
LIST and LSUB now use direct encoder.

Added:
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/AbstractTestOutputStreamImapResponseWriter.java
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterQuoteTest.java
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterTest.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/AbstractListingResponse.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/LSubResponse.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/ListResponse.java
      - copied, changed from r592330, james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/legacy/ListResponse.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java
      - copied, changed from r591949, james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposerImpl.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/LSubResponseEncoder.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListResponseEncoder.java
      - copied, changed from r592330, james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/ListResponseEncoder.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListingEncodingUtils.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/AbstractTestImapResponseComposer.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImplTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/InternetPrintWriter.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/LSubResponseEncoderTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListResponseEncoderTest.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/LSubProcessor.java
      - copied, changed from r592330, james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/LsubProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/AbstractTestListProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/LSubProcessorTest.java
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/ListProcessorTest.java
Removed:
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/legacy/ListResponse.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposerImpl.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/ListResponseEncoder.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/LsubProcessor.java
Modified:
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/ListResult.java
    james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapHandler.java
    james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapRequestHandler.java
    james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriter.java
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/ListPlus.test
    james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/ImapConstants.java
    james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/display/HumanReadableTextKey.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseWriter.java
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseCommandTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/BadResponseEncodeTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/CommandFailedResponseEncoderTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/ErrorResponseMessageTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/MockImapResponseWriter.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/AbstractImapRequestProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/AbstractMailboxAwareProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/ImapSessionUtils.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractListingProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AppendProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AuthenticateProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/CapabilityProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/CheckProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/CloseProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/CopyProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/CreateProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/DeleteProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/ExpungeProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/Imap4Rev1ProcessorFactory.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/ListProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/LoginProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/LogoutProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/NoopProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/RenameProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SearchProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/StatusProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/StoreProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SubscribeProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/UnsubscribeProcessor.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/ExperimentalListingTest.java

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/ListResult.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/ListResult.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/ListResult.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/ListResult.java Tue Nov  6 05:17:42 2007
@@ -26,7 +26,8 @@
 public interface ListResult {
     
     /**
-     * \Noinferiors, \Noselect, \Marked, \Unmarked TODO this should be done in a different way..
+     * \Noinferiors, \Noselect, \Marked, \Unmarked 
+     * TODO this should be done in a different way..
      */
     String[] getAttributes();
     
@@ -35,7 +36,5 @@
     /**
      * @return full namespace-name
      */
-    
     String getName();
-
 }

Modified: james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapHandler.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapHandler.java (original)
+++ james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapHandler.java Tue Nov  6 05:17:42 2007
@@ -35,7 +35,7 @@
 import org.apache.james.imapserver.codec.decode.ImapDecoder;
 import org.apache.james.imapserver.codec.encode.ImapEncoder;
 import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
-import org.apache.james.imapserver.codec.encode.ImapResponseComposerImpl;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 
 /**
  * The handler class for IMAP connections.

Modified: james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapRequestHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapRequestHandler.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapRequestHandler.java (original)
+++ james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapRequestHandler.java Tue Nov  6 05:17:42 2007
@@ -36,7 +36,7 @@
 import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
 import org.apache.james.imapserver.codec.encode.ImapEncoder;
 import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
-import org.apache.james.imapserver.codec.encode.ImapResponseComposerImpl;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 
 /**
  * @version $Revision: 109034 $

Modified: james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriter.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriter.java (original)
+++ james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriter.java Tue Nov  6 05:17:42 2007
@@ -34,10 +34,12 @@
 public class OutputStreamImapResponseWriter extends AbstractLogEnabled implements ImapConstants, ImapResponseWriter {
     
     private PrintWriter writer;
+    private boolean skipNextSpace;
 
     public OutputStreamImapResponseWriter( OutputStream output )
     {
         this.writer = new InternetPrintWriter( output, true );
+        skipNextSpace = false;
     }
 
     /**
@@ -70,14 +72,14 @@
     public void message( String message )
     {
         if ( message != null ) {
-            writer.print( SP );
+            space();
             writer.print( message );
         }
     }
 
     public void message( int number )
     {
-        writer.print( SP );
+        space();
         writer.print( number );
     }
 
@@ -86,7 +88,7 @@
         if ( responseCode != null ) {
             writer.print( " [" );
             writer.print( responseCode );
-            writer.print( "]" );
+            writer.print( ']' );
         }
     }
 
@@ -97,7 +99,52 @@
     }
 
     public void commandName(String commandName) {
-        writer.print( SP );
+        space();
         writer.print( commandName );
+    }
+
+    public void quote(String message) {
+        space();
+        writer.print( DQUOTE );
+        final int length = message.length();
+        for (int i=0;i<length;i++) {
+            char character = message.charAt(i);
+            if (character == ImapConstants.FORWARD_SLASH || character == DQUOTE) {
+                writer.print(ImapConstants.FORWARD_SLASH);
+            }
+            writer.print(character);
+        }
+        writer.print(DQUOTE);
+    }
+    
+    public void flush() {
+        writer.flush();
+    }
+
+    public void closeParen() {
+        writer.print(CLOSING_PARENTHESIS);
+        clearSkipNextSpace();
+    }
+
+    public void openParen() {
+        space();
+        writer.print(OPENING_PARENTHESIS);
+        skipNextSpace();
+    }
+    
+    private void clearSkipNextSpace() {
+        skipNextSpace = false;
+    }
+    
+    private void skipNextSpace() {
+        skipNextSpace = true;
+    }
+    
+    private void space() {
+        if (skipNextSpace) {
+            skipNextSpace = false;
+        } else {
+            writer.print(SP_CHAR);
+        }
     }
 }

Added: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/AbstractTestOutputStreamImapResponseWriter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/AbstractTestOutputStreamImapResponseWriter.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/AbstractTestOutputStreamImapResponseWriter.java (added)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/AbstractTestOutputStreamImapResponseWriter.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.encode.writer;
+
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractTestOutputStreamImapResponseWriter extends
+        TestCase {
+
+    OutputStreamImapResponseWriter writer;
+    ByteArrayOutputStream out;
+
+    public AbstractTestOutputStreamImapResponseWriter() {
+        super();
+    }
+
+    protected void setUp() throws Exception {
+        out = new ByteArrayOutputStream();
+        writer = new OutputStreamImapResponseWriter(out);
+    }
+
+    protected void checkExpected(String expected) throws Exception {
+        StringBuffer buffer = new StringBuffer();
+        writer.flush();
+        out.flush();
+        byte[] output = out.toByteArray();
+        for (int i=0;i<output.length;i++) {
+            buffer.append((char) output[i]);
+        }
+        assertEquals(expected, buffer.toString());
+    }
+
+}
\ No newline at end of file

Added: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterQuoteTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterQuoteTest.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterQuoteTest.java (added)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterQuoteTest.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,58 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.encode.writer;
+
+
+public class OutputStreamImapResponseWriterQuoteTest extends AbstractTestOutputStreamImapResponseWriter {
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testEmpty() throws Exception {
+        writer.quote("");
+        checkExpected(" \"\"");
+    }
+    
+    public void testStartSlash() throws Exception {
+        writer.quote("\\");
+        checkExpected(" \"\\\\\"");
+    }
+    
+    public void testSimpleQuote() throws Exception {
+        writer.quote("Simple");
+        checkExpected(" \"Simple\"");
+    }
+    
+    public void testComplexQuote() throws Exception {
+        writer.quote("Complex Quote With Spaces");
+        checkExpected(" \"Complex Quote With Spaces\"");
+    }
+    
+    public void testDQuoteQuote() throws Exception {
+        writer.quote("Complex\"Quote With Spaces");
+        checkExpected(" \"Complex\\\"Quote With Spaces\"");
+    }
+    
+    public void testFSlashQuote() throws Exception {
+        writer.quote("Complex Quote \\With Spaces");
+        checkExpected(" \"Complex Quote \\\\With Spaces\"");
+    }
+}

Added: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterTest.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterTest.java (added)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/encode/writer/OutputStreamImapResponseWriterTest.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,74 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.encode.writer;
+
+
+public class OutputStreamImapResponseWriterTest extends AbstractTestOutputStreamImapResponseWriter {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testCloseParen() throws Exception {
+        writer.closeParen();
+        checkExpected(")");
+    }
+
+    public void testOpenParen() throws Exception {
+        writer.openParen();
+        checkExpected(" (");
+    }
+
+    public void testOpenParenMessageCloseParen() throws Exception {
+        writer.openParen();
+        writer.message("Hello");
+        writer.closeParen();
+        checkExpected(" (Hello)");
+    }
+    
+
+    public void testOpenParenQuoteCloseParen() throws Exception {
+        writer.openParen();
+        writer.quote("Hello");
+        writer.closeParen();
+        checkExpected(" (\"Hello\")");
+    }
+    
+    public void testOpenParenOpenParenMessageCloseParenCloseParen() throws Exception {
+        writer.openParen();
+        writer.openParen();
+        writer.quote("Hello");
+        writer.closeParen();
+        writer.closeParen();
+        checkExpected(" ((\"Hello\"))");
+    }
+    
+    public void testOpenParenCloseParenMessage() throws Exception {
+        writer.openParen();
+        writer.closeParen();
+        writer.message("Hello");
+        checkExpected(" () Hello");
+    }
+    
+}

Modified: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/ListPlus.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/ListPlus.test?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/ListPlus.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/scripts/ListPlus.test Tue Nov  6 05:17:42 2007
@@ -36,34 +36,34 @@
 
 # Empty 1st arg searches default context (#mail)
 C: 10 LIST "" listtest
-S: \* LIST \(\) \"\.\" listtest
+S: \* LIST \(\) \"\.\" "listtest"
 S: 10 OK LIST completed.
 
 # % returns all mailboxes matching
 C: a1 LIST "" %
 SUB {
-S: \* LIST \(\) \"\.\" listtest
-S: \* LIST \(\) \"\.\" listtest1
-S: \* LIST \(\) \"\.\" INBOX
-S: \* LIST \(\) \"\.\" funny
+S: \* LIST \(\) \"\.\" \"listtest\"
+S: \* LIST \(\) \"\.\" \"listtest1\"
+S: \* LIST \(\) \"\.\" \"INBOX\"
+S: \* LIST \(\) \"\.\" \"funny\"
 }
 S: a1 OK List completed.
 
 C: a2 list "" funny.%
 SUB {
-S: \* LIST \(\) \"\.\" "\funny.name with gaps\"
+S: \* LIST \(\) \"\.\" \"funny.name with gaps\"
 S: \* LIST \(\) \"\.\" \"funny.name\"
 }
 S: a2 OK List completed.
 
 C: a3 LIST "" *
 SUB {
-S: \* LIST \(\) \"\.\" listtest
-S: \* LIST \(\) \"\.\" listtest1
-S: \* LIST \(\) \"\.\" INBOX
-S: \* LIST \(\) \"\.\" funny
-S: \* LIST \(\) \"\.\" "\funny.name with gaps\"
-S: \* LIST \(\) \"\.\" "\funny.name with gaps\.more\"
+S: \* LIST \(\) \"\.\" \"listtest\"
+S: \* LIST \(\) \"\.\" \"listtest1\"
+S: \* LIST \(\) \"\.\" \"INBOX\"
+S: \* LIST \(\) \"\.\" \"funny\"
+S: \* LIST \(\) \"\.\" \"funny.name with gaps\"
+S: \* LIST \(\) \"\.\" \"funny.name with gaps\.more\"
 S: \* LIST \(\) \"\.\" \"funny.name\"
 }
 S: a3 OK List completed.

Modified: james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/ImapConstants.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/ImapConstants.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/ImapConstants.java (original)
+++ james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/ImapConstants.java Tue Nov  6 05:17:42 2007
@@ -29,6 +29,13 @@
     String UNTAGGED = "*";
 
     String SP = " ";
+    
+    public static final String NIL = "NIL";
+    public static final char OPENING_PARENTHESIS = '(';
+    public static final char CLOSING_PARENTHESIS = ')';
+    public static final char SP_CHAR = ' ';
+    public static final char DQUOTE ='\"';
+    
     String VERSION = "IMAP4rev1";
     String CAPABILITIES = "LITERAL+";
 
@@ -40,6 +47,7 @@
     final String NAMESPACE_PREFIX = String.valueOf( NAMESPACE_PREFIX_CHAR );
 
     String INBOX_NAME = "INBOX";
+    public static final char FORWARD_SLASH = '\\';
     public static final String STATUS_UNSEEN = "UNSEEN";
     public static final String STATUS_UIDVALIDITY = "UIDVALIDITY";
     public static final String STATUS_UIDNEXT = "UIDNEXT";
@@ -71,4 +79,11 @@
     public static final String APPEND_COMMAND_NAME = "APPEND";
     public static final String CAPABILITY_RESPONSE = CAPABILITY_COMMAND_NAME + SP + VERSION + SP + CAPABILITIES;
     
+    public static final String LIST_RESPONSE_NAME = "LIST";
+    public static final String LSUB_RESPONSE_NAME = "LSUB";
+    
+    public static final String NAME_ATTRIBUTE_NOINFERIORS = "\\Noinferiors";
+    public static final String NAME_ATTRIBUTE_NOSELECT = "\\Noselect";
+    public static final String NAME_ATTRIBUTE_MARKED = "\\Marked";
+    public static final String NAME_ATTRIBUTE_UNMARKED = "\\Unmarked";
 }

Modified: james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/display/HumanReadableTextKey.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/display/HumanReadableTextKey.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/display/HumanReadableTextKey.java (original)
+++ james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/display/HumanReadableTextKey.java Tue Nov  6 05:17:42 2007
@@ -27,6 +27,10 @@
     public static final HumanReadableTextKey FAILURE_NO_SUCH_MAILBOX 
         = new HumanReadableTextKey("org.apache.james.imap.FAILURE_NO_SUCH_MAILBOX", 
                 "failed. No such mailbox.");
+
+    public static final HumanReadableTextKey COMPLETED 
+        = new HumanReadableTextKey("org.apache.james.imap.COMPLETED", 
+                "completed.");
     
     private final String defaultValue;
     private final String key;

Added: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/AbstractListingResponse.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/AbstractListingResponse.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/AbstractListingResponse.java (added)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/AbstractListingResponse.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,178 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imap.message.response.imap4rev1.server;
+
+/**
+ * <code>LIST</code> and <code>LSUB</code> return identical data.
+ */
+public abstract class AbstractListingResponse {
+
+    private final boolean noInferiors;
+    private final boolean noSelect;
+    private final boolean marked;
+    private final boolean unmarked;
+    private final String hierarchyDelimiter;
+    private final String name;
+
+    public AbstractListingResponse(final boolean noInferiors, final boolean noSelect, 
+            final boolean marked, final boolean unmarked, 
+            final String hierarchyDelimiter, final String name) {
+        super();
+        this.noInferiors = noInferiors;
+        this.noSelect = noSelect;
+        this.marked = marked;
+        this.unmarked = unmarked;
+        this.hierarchyDelimiter = hierarchyDelimiter;
+        this.name = name;
+    }
+
+    /**
+     * Gets hierarchy delimiter.
+     * @return hierarchy delimiter, 
+     * or null if no hierarchy exists
+     */
+    public final String getHierarchyDelimiter() {
+        return hierarchyDelimiter;
+    }
+
+    /**
+     * Is <code>Marked</code> name attribute set?
+     * @return true if <code>Marked</code>, false otherwise
+     */
+    public final boolean isMarked() {
+        return marked;
+    }
+
+    /**
+     * Gets the listed name.
+     * @return name of the listed mailbox, not null
+     */
+    public final String getName() {
+        return name;
+    }
+
+    /**
+     * Is <code>Noinferiors</code> name attribute set?
+     * @return true if <code>Noinferiors</code>,
+     * false otherwise
+     */
+    public final boolean isNoInferiors() {
+        return noInferiors;
+    }
+
+    /**
+     * Is <code>Noselect</code> name attribute set?
+     * @return true if <code>Noselect</code>,
+     * false otherwise
+     */
+    public final boolean isNoSelect() {
+        return noSelect;
+    }
+
+    /**
+     * Is <code>Unmarked</code> name attribute set?
+     * @return true if <code>Unmarked</code>,
+     * false otherwise
+     */
+    public final boolean isUnmarked() {
+        return unmarked;
+    }
+
+    /**
+     * Are any name attributes set?
+     * @return true if {@link #isNoInferiors()}, 
+     * {@link #isNoSelect()}, {@link #isMarked()} or 
+     * {@link #isUnmarked(){
+     */
+    public final boolean isNameAttributed() {
+        return noInferiors || noSelect || marked || unmarked;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((hierarchyDelimiter == null) ? 0 : hierarchyDelimiter.hashCode());
+        result = PRIME * result + (marked ? 1231 : 1237);
+        result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+        result = PRIME * result + (noInferiors ? 1231 : 1237);
+        result = PRIME * result + (noSelect ? 1231 : 1237);
+        result = PRIME * result + (unmarked ? 1231 : 1237);
+        return result;
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final AbstractListingResponse other = (AbstractListingResponse) obj;
+        if (hierarchyDelimiter == null) {
+            if (other.hierarchyDelimiter != null)
+                return false;
+        } else if (!hierarchyDelimiter.equals(other.hierarchyDelimiter))
+            return false;
+        if (marked != other.marked)
+            return false;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        if (noInferiors != other.noInferiors)
+            return false;
+        if (noSelect != other.noSelect)
+            return false;
+        if (unmarked != other.unmarked)
+            return false;
+        return true;
+    }
+
+    /**
+     * Renders object as a string suitable for logging.
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        final String TAB = " ";
+        
+        String retValue = getClass() + " ( "
+            + super.toString() + TAB
+            + "noInferiors = " + this.noInferiors + TAB
+            + "noSelect = " + this.noSelect + TAB
+            + "marked = " + this.marked + TAB
+            + "unmarked = " + this.unmarked + TAB
+            + "hierarchyDelimiter = " + this.hierarchyDelimiter + TAB
+            + "name = " + this.name + TAB
+            + " )";
+    
+        return retValue;
+    }
+    
+    
+}
\ No newline at end of file

Added: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/LSubResponse.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/LSubResponse.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/LSubResponse.java (added)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/LSubResponse.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.message.response.imap4rev1.server;
+
+import org.apache.james.api.imap.message.response.ImapResponseMessage;
+
+/**
+ * Values an IMAP4rev1 <code>LIST</code> response.
+ */
+public final class LSubResponse extends AbstractListingResponse implements ImapResponseMessage {
+    public LSubResponse(final boolean noInferiors, final boolean noSelect, 
+                        final boolean marked, final boolean unmarked, 
+                        final String hierarchyDelimiter, final String name) {
+        super(noInferiors, noSelect, marked, unmarked, hierarchyDelimiter, name);
+    }
+}

Copied: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/ListResponse.java (from r592330, james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/legacy/ListResponse.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/ListResponse.java?p2=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/ListResponse.java&p1=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/legacy/ListResponse.java&r1=592330&r2=592415&rev=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/legacy/ListResponse.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/server/ListResponse.java Tue Nov  6 05:17:42 2007
@@ -16,33 +16,17 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.imap.message.response.imap4rev1.legacy;
+package org.apache.james.imap.message.response.imap4rev1.server;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.james.api.imap.ImapCommand;
-import org.apache.james.imap.message.response.base.AbstractImapResponse;
+import org.apache.james.api.imap.message.response.ImapResponseMessage;
 
 /**
- * @deprecated responses should correspond directly to the specification
+ * Values an IMAP4rev1 <code>LIST</code> response.
  */
-public class ListResponse extends AbstractImapResponse {
-    private List messages = new ArrayList();
-
-    public ListResponse(final ImapCommand command, final String tag) {
-        super(command, tag);
-    }
-
-    public void addMessageData(String message) {
-        // TODO: this isn't efficient
-        // TODO: better to stream results
-        // TODO: pass data objects back and then encode
-        messages.add(message);
-    }
-
-    public List getMessages() {
-        return Collections.unmodifiableList(messages);
-    }
+public final class ListResponse extends AbstractListingResponse implements ImapResponseMessage {
+    public ListResponse(final boolean noInferiors, final boolean noSelect, 
+                        final boolean marked, final boolean unmarked, 
+                        final String hierarchyDelimiter, final String name) {
+        super(noInferiors, noSelect, marked, unmarked, hierarchyDelimiter, name);
+    }    
 }

Modified: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java Tue Nov  6 05:17:42 2007
@@ -19,6 +19,8 @@
 
 package org.apache.james.imapserver.codec.encode;
 
+import java.util.List;
+
 import javax.mail.Flags;
 
 import org.apache.james.api.imap.ImapCommand;
@@ -149,6 +151,17 @@
 
     public abstract void commandResponse(ImapCommand command, String message);
 
+    /**
+     * Writes a list response
+     * @param typeName <code>LIST</code> or <code>LSUB</code>.
+     * @param attributes name attributes, 
+     * or null if there are no attributes
+     * @param hierarchyDelimiter hierarchy delimiter, 
+     * or null if delimiter is <code>NIL</code>
+     * @param name mailbox name
+     */
+    public abstract void listResponse(String typeName, List attributes, String hierarchyDelimiter, String name);
+    
     /**
      * Writes the message provided to the client, prepended with the request
      * tag.

Modified: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseWriter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseWriter.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseWriter.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseWriter.java Tue Nov  6 05:17:42 2007
@@ -51,12 +51,28 @@
     void message( String message );
 
     void message( int number );
-
+ 
     /**
      * Writes a response code.
      * @param responseCode the response code, not null
      */
     void responseCode( String responseCode );
+
+    /**
+     * Writes a quoted message.
+     * @param message message, not null
+     */
+    void quote(String message);
+    
+    /**
+     * Opens a parenthesis - writes a <code>(</code>.
+     */
+    void openParen();
+    
+    /**
+     * Closes a parenthesis - writes a <code>)</code>.
+     */
+    void closeParen();
 
     /**
      * Ends a response.

Copied: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java (from r591949, james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposerImpl.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java?p2=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java&p1=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposerImpl.java&r1=591949&r2=592415&rev=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposerImpl.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java Tue Nov  6 05:17:42 2007
@@ -17,7 +17,10 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.imapserver.codec.encode;
+package org.apache.james.imapserver.codec.encode.base;
+
+import java.util.Iterator;
+import java.util.List;
 
 import javax.mail.Flags;
 
@@ -26,6 +29,8 @@
 import org.apache.james.api.imap.ImapCommand;
 import org.apache.james.api.imap.ImapConstants;
 import org.apache.james.api.imap.message.MessageFlags;
+import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
+import org.apache.james.imapserver.codec.encode.ImapResponseWriter;
 
 /**
  * Class providing methods to send response messages from the server to the
@@ -339,5 +344,41 @@
             message(text);
         }
         end();
+    }
+
+    public void listResponse(String typeName, List attributes, String hierarchyDelimiter, String name) {
+        untagged();
+        message(typeName);
+        openParen();
+        if (attributes != null) {
+            for (Iterator it=attributes.iterator();it.hasNext();) {
+                final String attribute = (String) it.next();
+                message(attribute);
+            }
+        }
+        closeParen();
+        
+        if (hierarchyDelimiter == null) {
+            message(NIL);
+        } else {
+            quote(hierarchyDelimiter);
+        }
+        
+        quote(name);
+        
+        end();
+    }
+
+    public void quote(String message) {
+        writer.quote(message);
+    }
+
+    public void closeParen() {
+        writer.closeParen();
+        
+    }
+
+    public void openParen() {
+        writer.openParen();
     }
 }

Added: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/LSubResponseEncoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/LSubResponseEncoder.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/LSubResponseEncoder.java (added)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/LSubResponseEncoder.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imapserver.codec.encode.imap4rev1.server;
+
+import org.apache.james.api.imap.ImapConstants;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.imap.message.response.imap4rev1.server.AbstractListingResponse;
+import org.apache.james.imap.message.response.imap4rev1.server.LSubResponse;
+import org.apache.james.imapserver.codec.encode.ImapEncoder;
+import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
+import org.apache.james.imapserver.codec.encode.base.AbstractChainedImapEncoder;
+
+/**
+ * Encoders IMAP4rev1 <code>List</code> responses.
+ */
+public class LSubResponseEncoder extends AbstractChainedImapEncoder {
+
+    
+    public LSubResponseEncoder(ImapEncoder next) {
+        super(next);
+    }
+    protected void doEncode(final ImapMessage acceptableMessage, 
+                                final ImapResponseComposer composer) {
+        final AbstractListingResponse response = (AbstractListingResponse) acceptableMessage;
+        ListingEncodingUtils.encodeListingResponse(ImapConstants.LSUB_RESPONSE_NAME
+                ,composer, response);
+    }
+
+    protected boolean isAcceptable(ImapMessage message) {
+        return (message instanceof LSubResponse);
+    }
+    
+}

Copied: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListResponseEncoder.java (from r592330, james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/ListResponseEncoder.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListResponseEncoder.java?p2=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListResponseEncoder.java&p1=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/ListResponseEncoder.java&r1=592330&r2=592415&rev=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/ListResponseEncoder.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListResponseEncoder.java Tue Nov  6 05:17:42 2007
@@ -16,20 +16,18 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.imapserver.codec.encode.imap4rev1.legacy;
+package org.apache.james.imapserver.codec.encode.imap4rev1.server;
 
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapConstants;
 import org.apache.james.api.imap.ImapMessage;
-import org.apache.james.imap.message.response.imap4rev1.legacy.ListResponse;
+import org.apache.james.imap.message.response.imap4rev1.server.AbstractListingResponse;
+import org.apache.james.imap.message.response.imap4rev1.server.ListResponse;
 import org.apache.james.imapserver.codec.encode.ImapEncoder;
 import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
 import org.apache.james.imapserver.codec.encode.base.AbstractChainedImapEncoder;
 
 /**
- * @deprecated responses should correspond directly to the specification
+ * Encoders IMAP4rev1 <code>List</code> responses.
  */
 public class ListResponseEncoder extends AbstractChainedImapEncoder {
 
@@ -37,19 +35,11 @@
     public ListResponseEncoder(ImapEncoder next) {
         super(next);
     }
-    protected void doEncode(ImapMessage acceptableMessage, ImapResponseComposer composer) {
-        ListResponse response = (ListResponse) acceptableMessage;
-        final List messages = response.getMessages();
-        final ImapCommand command = response.getCommand();
-        for (final Iterator it=messages.iterator();it.hasNext();) {
-            String message = (String) it.next();
-            
-            composer.commandResponse(command, message);
-        }
-        List unsolicitedResponses = response.getUnsolicatedResponses();
-        chainEncodeAll(unsolicitedResponses, composer);
-        final String tag = response.getTag();
-        composer.commandComplete( command, tag );        
+    protected void doEncode(final ImapMessage acceptableMessage, 
+                                final ImapResponseComposer composer) {
+        final AbstractListingResponse response = (AbstractListingResponse) acceptableMessage;
+        ListingEncodingUtils.encodeListingResponse(ImapConstants.LIST_RESPONSE_NAME, 
+                composer, response);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Added: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListingEncodingUtils.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListingEncodingUtils.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListingEncodingUtils.java (added)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/server/ListingEncodingUtils.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,62 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.codec.encode.imap4rev1.server;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.api.imap.ImapConstants;
+import org.apache.james.imap.message.response.imap4rev1.server.AbstractListingResponse;
+import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
+
+public class ListingEncodingUtils {
+    
+    public static void encodeListingResponse(final String responseTypeName, final ImapResponseComposer composer, final AbstractListingResponse response) {
+        final List attributes = getNameAttributes(response);
+        
+        final String name = response.getName();
+        final String hierarchyDelimiter = response.getHierarchyDelimiter();
+        
+        composer.listResponse(responseTypeName, attributes, hierarchyDelimiter, name);
+    }
+    
+    private static List getNameAttributes(final AbstractListingResponse response) {
+        final List attributes;
+        if (response.isNameAttributed()) {
+            attributes = new ArrayList();
+            if (response.isNoInferiors()) {
+                attributes.add(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
+            }
+            if (response.isNoSelect()) {
+                attributes.add(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
+            }
+            if (response.isMarked()) {
+                attributes.add(ImapConstants.NAME_ATTRIBUTE_MARKED);
+            }
+            if (response.isUnmarked()) {
+                attributes.add(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
+            }
+        } else {
+            attributes = null;
+        }
+        return attributes;
+    }
+
+}

Modified: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java Tue Nov  6 05:17:42 2007
@@ -35,11 +35,12 @@
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.ErrorResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.ExamineAndSelectResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.LegacyFetchResponseEncoder;
-import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.ListResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.LogoutResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.SearchResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.StatusCommandResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.StoreResponseEncoder;
+import org.apache.james.imapserver.codec.encode.imap4rev1.server.LSubResponseEncoder;
+import org.apache.james.imapserver.codec.encode.imap4rev1.server.ListResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.status.UntaggedNoResponseEncoder;
 
 /**
@@ -59,7 +60,8 @@
         final StatusCommandResponseEncoder statusCommandResponseEncoder = new StatusCommandResponseEncoder(storeResponseEncoder);
         final SearchResponseEncoder searchResponseEncoder = new SearchResponseEncoder(statusCommandResponseEncoder);
         final LogoutResponseEncoder logoutResponseEncoder = new LogoutResponseEncoder(searchResponseEncoder);
-        final ListResponseEncoder listResponseEncoder = new ListResponseEncoder(logoutResponseEncoder);
+        final LSubResponseEncoder lsubResponseEncoder = new LSubResponseEncoder(logoutResponseEncoder);
+        final ListResponseEncoder listResponseEncoder = new ListResponseEncoder(lsubResponseEncoder);
         final LegacyFetchResponseEncoder legacyFetchResponseEncoder = new LegacyFetchResponseEncoder(listResponseEncoder);
         final ExamineAndSelectResponseEncoder examineAndSelectResponseEncoder = new ExamineAndSelectResponseEncoder(legacyFetchResponseEncoder);
         final ErrorResponseEncoder errorResponseEncoder = new ErrorResponseEncoder(examineAndSelectResponseEncoder);

Added: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/AbstractTestImapResponseComposer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/AbstractTestImapResponseComposer.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/AbstractTestImapResponseComposer.java (added)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/AbstractTestImapResponseComposer.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,90 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.codec.encode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractTestImapResponseComposer extends TestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testQuotedDelimiter() throws Exception {
+        checkListResponseEncode("* LSUB () \"\\\"\" \"#news\"\r\n", "LSUB", null, "\"", "#news");
+        checkListResponseEncode("* LIST () \"\\\"\" \"#INBOX\"\r\n", "LIST", null, "\"", "#INBOX");
+        checkListResponseEncode("* LSUB () \"\\\\\" \"#news\"\r\n", "LSUB", null, "\\", "#news");
+        checkListResponseEncode("* LIST () \"\\\\\" \"#INBOX\"\r\n", "LIST", null, "\\", "#INBOX");
+    }
+    
+    public void testNilDelimiter() throws Exception {
+        checkListResponseEncode("* LSUB () NIL \"#news\"\r\n", "LSUB", null, null, "#news");
+        checkListResponseEncode("* LIST () NIL \"#INBOX\"\r\n", "LIST", null, null, "#INBOX");
+    }
+    
+    public void testSimple() throws Exception {
+        checkListResponseEncode("* LSUB () \".\" \"#news\"\r\n", "LSUB", null, ".", "#news");
+        checkListResponseEncode("* LIST () \".\" \"#INBOX\"\r\n", "LIST", null, ".", "#INBOX");
+        checkListResponseEncode("* LSUB () \".\" \"#news.sub\"\r\n", "LSUB", null, ".", "#news.sub");
+        checkListResponseEncode("* LIST () \".\" \"#INBOX.sub\"\r\n", "LIST", null, ".", "#INBOX.sub");
+    }
+
+    public void testSpecialNames() throws Exception {
+        checkListResponseEncode("* LSUB () \"\\\\\" \"#news\\\\sub\\\\directory\"\r\n", "LSUB", null, "\\", "#news\\sub\\directory");
+        checkListResponseEncode("* LIST () \"\\\\\" \"#INBOX\\\\sub\\\\directory\"\r\n", "LIST", null, "\\", "#INBOX\\sub\\directory");
+        checkListResponseEncode("* LSUB () \".\" \"#news.sub directory.what\"\r\n", "LSUB", null, ".", "#news.sub directory.what");
+        checkListResponseEncode("* LIST () \".\" \"#INBOX.sub directory.what\"\r\n", "LIST", null, ".", "#INBOX.sub directory.what");
+        checkListResponseEncode("* LSUB () \".\" \"#news.\\\"sub directory\\\".what\"\r\n", "LSUB", null, ".", "#news.\"sub directory\".what");
+        checkListResponseEncode("* LIST () \".\" \"#INBOX.\\\"sub directory\\\".what\"\r\n", "LIST", null, ".", "#INBOX.\"sub directory\".what");
+    }
+    
+    public void testAttributes() throws Exception {
+        List attributes = new ArrayList();
+        attributes.add("\\one");
+        attributes.add("\\two");
+        attributes.add("\\three");
+        attributes.add("\\four");
+        checkListResponseEncode("* LSUB (\\one \\two \\three \\four) \".\" \"#news\"\r\n", "LSUB", attributes, ".", "#news");
+        checkListResponseEncode("* LIST (\\one \\two \\three \\four) \".\" \"#INBOX\"\r\n", "LIST", attributes, ".", "#INBOX");
+    }
+    
+    private void checkListResponseEncode(String expected, String typeName, List attributes, 
+            String hierarchyDelimiter, String name) throws Exception {
+        StringBuffer buffer = new StringBuffer();
+        byte[] output = encodeListResponse(typeName, attributes, hierarchyDelimiter, name);
+        for (int i=0;i<output.length;i++) {
+            buffer.append((char) output[i]);
+        }
+        assertEquals(expected, buffer.toString());
+        clear();
+    }
+    
+    protected abstract byte[] encodeListResponse(String typeName, List attributes, 
+            String hierarchyDelimiter, String name) throws Exception;
+    
+    protected abstract void clear() throws Exception;
+}

Modified: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseCommandTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseCommandTest.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseCommandTest.java (original)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseCommandTest.java Tue Nov  6 05:17:42 2007
@@ -21,6 +21,7 @@
 
 import org.apache.james.api.imap.ImapCommand;
 import org.apache.james.api.imap.ImapConstants;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.MockImapResponseWriter;
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;

Modified: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseTest.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseTest.java (original)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/ImapResponseTest.java Tue Nov  6 05:17:42 2007
@@ -23,6 +23,7 @@
 
 import org.apache.james.api.imap.ImapConstants;
 import org.apache.james.api.imap.message.MessageFlags;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.MockImapResponseWriter;
 import org.jmock.MockObjectTestCase;
 

Added: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java (added)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,155 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.codec.encode.base;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.api.imap.ImapConstants;
+import org.apache.james.imapserver.codec.encode.ImapResponseWriter;
+
+/**
+ * Class providing methods to send response messages from the server
+ * to the client.
+ */
+public class ByteImapResponseWriter extends AbstractLogEnabled implements ImapConstants, ImapResponseWriter {
+    
+    private PrintWriter writer;
+    private ByteArrayOutputStream out;
+    private boolean skipNextSpace;
+    
+    public ByteImapResponseWriter(  )
+    {
+        clear();
+    }
+    
+    public byte[] getBytes() {
+        return out.toByteArray();
+    }
+
+    /**
+     * Writes the message provided to the client, prepended with the
+     * untagged marker "*".
+     *
+     * @param message The message to write to the client.
+     */
+    public void untaggedResponse( String message )
+    {
+        untagged();
+        message( message );
+        end();
+    }
+    
+    public void byeResponse( String message ) {
+        untaggedResponse(BYE + SP + message);
+    }
+
+    public void untagged()
+    {
+        writer.print( UNTAGGED );
+    }
+
+    public void tag(String tag)
+    {
+        writer.print( tag );
+    }
+
+    public void message( String message )
+    {
+        if ( message != null ) {
+            space();
+            writer.print( message );
+        }
+    }
+
+    public void message( int number )
+    {
+        space();
+        writer.print( number );
+    }
+
+    public void responseCode( String responseCode )
+    {
+        if ( responseCode != null ) {
+            writer.print( " [" );
+            writer.print( responseCode );
+            writer.print( "]" );
+        }
+    }
+
+    public void end()
+    {
+        writer.println();
+        writer.flush();
+    }
+
+    public void commandName(String commandName) {
+        space();
+        writer.print( commandName );
+    }
+
+    public void quote(String message) {
+        space();
+        writer.print(DQUOTE);
+        final int length = message.length();
+        for (int i=0;i<length;i++) {
+            char character = message.charAt(i);
+            if (character == ImapConstants.FORWARD_SLASH || character == DQUOTE) {
+                writer.print(ImapConstants.FORWARD_SLASH);
+            }
+            writer.print(character);
+        }
+        writer.print(DQUOTE);
+    }
+    
+    public void closeParen() {
+        writer.print(CLOSING_PARENTHESIS);
+        clearSkipNextSpace();
+    }
+
+    public void openParen() {
+        space();
+        writer.print(OPENING_PARENTHESIS);
+        skipNextSpace();
+    }
+    
+    public void clear() {
+        this.out = new ByteArrayOutputStream();
+        this.writer = new InternetPrintWriter( out, true );
+        this.skipNextSpace = false;
+    }
+    
+    private void clearSkipNextSpace() {
+        skipNextSpace = false;
+    }
+    
+    private void skipNextSpace() {
+        skipNextSpace = true;
+    }
+    
+    private void space() {
+        if (skipNextSpace) {
+            skipNextSpace = false;
+        } else {
+            writer.print(SP_CHAR);
+        }
+    }
+}

Added: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImplTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImplTest.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImplTest.java (added)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImplTest.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.codec.encode.base;
+
+import java.util.List;
+
+import org.apache.james.imapserver.codec.encode.AbstractTestImapResponseComposer;
+
+public class ImapResponseComposerImplTest extends
+        AbstractTestImapResponseComposer {
+
+    ImapResponseComposerImpl composer;
+    ByteImapResponseWriter writer;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        writer = new ByteImapResponseWriter();
+        composer = new ImapResponseComposerImpl(writer);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    protected byte[] encodeListResponse(String typeName, List attributes, String hierarchyDelimiter, String name) throws Exception {
+        composer.listResponse(typeName, attributes, hierarchyDelimiter, name);
+        return writer.getBytes();
+    }
+
+    protected void clear() throws Exception {
+        writer.clear();
+    }
+
+}

Added: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/InternetPrintWriter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/InternetPrintWriter.java?rev=592415&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/InternetPrintWriter.java (added)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/InternetPrintWriter.java Tue Nov  6 05:17:42 2007
@@ -0,0 +1,206 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+package org.apache.james.imapserver.codec.encode.base;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+/**
+ * Writes to a wrapped Writer class, ensuring that all line separators are '\r\n', regardless
+ * of platform.
+ */
+public class InternetPrintWriter
+    extends PrintWriter {
+
+    /**
+     * The line separator to use.
+     */
+    private static String lineSeparator = "\r\n";
+
+    /**
+     * Whether the Writer autoflushes on line feeds
+     */
+    private final boolean autoFlush;
+
+    /**
+     * Constructor that takes a writer to wrap.
+     *
+     * @param out the wrapped Writer
+     */
+    public InternetPrintWriter (Writer out) {
+        super (out);
+        autoFlush = false;
+    }
+
+    /**
+     * Constructor that takes a writer to wrap.
+     *
+     * @param out the wrapped Writer
+     * @param autoFlush whether to flush after each print call
+     */
+    public InternetPrintWriter (Writer out, boolean autoFlush) {
+        super (out, autoFlush);
+        this.autoFlush = autoFlush;
+    }
+
+    /**
+     * Constructor that takes a stream to wrap.
+     *
+     * @param out the wrapped OutputStream
+     */
+    public InternetPrintWriter (OutputStream out) {
+        super (out);
+        autoFlush = false;
+    }
+
+    /**
+     * Constructor that takes a stream to wrap.
+     *
+     * @param out the wrapped OutputStream
+     * @param autoFlush whether to flush after each print call
+     */
+    public InternetPrintWriter (OutputStream out, boolean autoFlush) {
+        super (out, autoFlush);
+        this.autoFlush = autoFlush;
+    }
+
+    /**
+     * Print a line separator.
+     */
+    public void println () {
+        synchronized (lock) {
+            write(lineSeparator);
+            if (autoFlush) {
+                flush();
+            }
+        }
+    }
+
+    /**
+     * Print a boolean followed by a line separator.
+     *
+     * @param x the boolean to print
+     */
+    public void println(boolean x) {
+        synchronized (lock) {
+            print(x);
+            println();
+        }
+    }
+
+    /**
+     * Print a char followed by a line separator.
+     *
+     * @param x the char to print
+     */
+    public void println(char x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print a int followed by a line separator.
+     *
+     * @param x the int to print
+     */
+    public void println (int x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print a long followed by a line separator.
+     *
+     * @param x the long to print
+     */
+    public void println (long x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print a float followed by a line separator.
+     *
+     * @param x the float to print
+     */
+    public void println (float x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print a double followed by a line separator.
+     *
+     * @param x the double to print
+     */
+    public void println (double x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print a character array followed by a line separator.
+     *
+     * @param x the character array to print
+     */
+    public void println (char[] x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print a String followed by a line separator.
+     *
+     * @param x the String to print
+     */
+    public void println (String x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+
+    /**
+     * Print an Object followed by a line separator.
+     *
+     * @param x the Object to print
+     */
+    public void println (Object x) {
+        synchronized (lock) {
+            print (x);
+            println ();
+        }
+    }
+}

Modified: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java (original)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java Tue Nov  6 05:17:42 2007
@@ -26,7 +26,7 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
 import org.apache.james.imapserver.codec.encode.ImapEncoder;
 import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
-import org.apache.james.imapserver.codec.encode.ImapResponseComposerImpl;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imapserver.codec.encode.imap4rev1.legacy.MockImapResponseWriter;
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;

Modified: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/BadResponseEncodeTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/BadResponseEncodeTest.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/BadResponseEncodeTest.java (original)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/BadResponseEncodeTest.java Tue Nov  6 05:17:42 2007
@@ -24,7 +24,7 @@
 import org.apache.james.imap.message.response.imap4rev1.legacy.BadResponse;
 import org.apache.james.imapserver.codec.encode.ImapEncoder;
 import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
-import org.apache.james.imapserver.codec.encode.ImapResponseComposerImpl;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 import org.jmock.Mock;
 
 public class BadResponseEncodeTest extends TestCase {

Modified: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/CommandFailedResponseEncoderTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/CommandFailedResponseEncoderTest.java?rev=592415&r1=592414&r2=592415&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/CommandFailedResponseEncoderTest.java (original)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/CommandFailedResponseEncoderTest.java Tue Nov  6 05:17:42 2007
@@ -24,7 +24,7 @@
 import org.apache.james.imap.message.response.imap4rev1.legacy.CommandFailedResponse;
 import org.apache.james.imapserver.codec.encode.ImapEncoder;
 import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
-import org.apache.james.imapserver.codec.encode.ImapResponseComposerImpl;
+import org.apache.james.imapserver.codec.encode.base.ImapResponseComposerImpl;
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;
 



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


Mime
View raw message