james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r760659 - in /james/imap/trunk: api/src/main/java/org/apache/james/imap/api/ decode/src/main/java/org/apache/james/imap/decode/parser/ message/src/main/java/org/apache/james/imap/encode/ message/src/main/java/org/apache/james/imap/message/r...
Date Tue, 31 Mar 2009 21:32:08 GMT
Author: rdonkin
Date: Tue Mar 31 21:32:07 2009
New Revision: 760659

URL: http://svn.apache.org/viewvc?rev=760659&view=rev
Log:
Codec and processor for IMAP Namespaces IMAP-76  https://issues.apache.org/jira/browse/IMAP-76

Added:
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NamespaceCommandParser.java
  (with props)
    james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/NamespaceResponseEncoder.java
  (with props)
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/NamespaceRequest.java
  (with props)
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/NamespaceResponse.java
  (with props)
    james/imap/trunk/message/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
  (with props)
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
  (with props)
    james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
  (with props)
Modified:
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/Imap4Rev1MessageFactory.java
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NoopCommandParser.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/Imap4Rev1MessageFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/Imap4Rev1MessageFactory.java?rev=760659&r1=760658&r2=760659&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/Imap4Rev1MessageFactory.java
(original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/Imap4Rev1MessageFactory.java
Tue Mar 31 21:32:07 2009
@@ -125,4 +125,6 @@
 
     public ImapMessage createUnsubscribeMessage(final ImapCommand command,
             final String mailboxName, final String tag);
+    
+    public ImapMessage createNamespaceMessage(final ImapCommand command, final String tag);
 }

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java?rev=760659&r1=760658&r2=760659&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java (original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java Tue Mar
31 21:32:07 2009
@@ -143,6 +143,8 @@
 
     public String RFC822_MESSAGE_ID = "Message-ID";
 
+    public static final String NAMESPACE_COMMAND_NAME = "NAMESPACE";
+
     public static final char BACK_SLASH = '\\';
 
     public static final String STATUS_UNSEEN = "UNSEEN";

Added: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NamespaceCommandParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NamespaceCommandParser.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NamespaceCommandParser.java
(added)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NamespaceCommandParser.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.decode.parser;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.ProtocolException;
+import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+
+public class NamespaceCommandParser extends AbstractImapCommandParser {
+
+    public NamespaceCommandParser() {
+        super(
+                ImapCommand
+                        .authenticatedStateCommand(ImapConstants.NAMESPACE_COMMAND_NAME));
+    }
+
+    @Override
+    protected ImapMessage decode(ImapCommand command,
+            ImapRequestLineReader request, String tag, Log logger)
+            throws ProtocolException {
+        return getMessageFactory().createNamespaceMessage(command, tag);
+    }
+}

Propchange: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NamespaceCommandParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NoopCommandParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NoopCommandParser.java?rev=760659&r1=760658&r2=760659&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NoopCommandParser.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/NoopCommandParser.java
Tue Mar 31 21:32:07 2009
@@ -35,8 +35,7 @@
     protected ImapMessage decode(ImapCommand command,
             ImapRequestLineReader request, String tag, Log logger) throws ProtocolException
{
         endLine(request);
-        final ImapMessage result = getMessageFactory().createNoopMessage(
-                command, tag);
+        final ImapMessage result = getMessageFactory().createNoopMessage(command, tag);
         return result;
     }
 

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/NamespaceResponseEncoder.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/NamespaceResponseEncoder.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/NamespaceResponseEncoder.java
(added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/NamespaceResponseEncoder.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.encode;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.base.AbstractChainedImapEncoder;
+import org.apache.james.imap.message.response.NamespaceResponse;
+import org.apache.james.imap.message.response.NamespaceResponse.Namespace;
+
+/**
+ * Encodes namespace responses.
+ */
+public class NamespaceResponseEncoder extends AbstractChainedImapEncoder {
+
+    public NamespaceResponseEncoder(ImapEncoder next) {
+        super(next);
+    }
+
+    @Override
+    protected void doEncode(ImapMessage acceptableMessage,
+            ImapResponseComposer composer, ImapSession session)
+            throws IOException {
+        final NamespaceResponse response = (NamespaceResponse) acceptableMessage;
+        composer.untagged();
+
+        final List<NamespaceResponse.Namespace> personal = response
+                .getPersonal();
+        encode(personal, composer);
+        final List<NamespaceResponse.Namespace> users = response.getUsers();
+        encode(users, composer);
+        final List<NamespaceResponse.Namespace> shared = response.getShared();
+        encode(shared, composer);
+    }
+
+    private void encode(List<Namespace> namespaces,
+            ImapResponseComposer composer) throws IOException {
+        if (namespaces == null || namespaces.isEmpty()) {
+            composer.nil();
+        } else {
+            composer.openParen();
+            for (NamespaceResponse.Namespace namespace : namespaces) {
+                encode(namespace, composer);
+            }
+            composer.closeParen();
+        }
+    }
+
+    private void encode(Namespace namespace, ImapResponseComposer composer)
+            throws IOException {
+        composer.openParen();
+        composer.quote(namespace.getPrefix());
+        composer.quote(Character.toString(namespace.getDeliminator()));
+        composer.closeParen();
+    }
+
+    @Override
+    protected boolean isAcceptable(ImapMessage message) {
+        return message instanceof NamespaceResponse;
+    }
+
+}

Propchange: james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/NamespaceResponseEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java?rev=760659&r1=760658&r2=760659&view=diff
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
(original)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
Tue Mar 31 21:32:07 2009
@@ -167,4 +167,8 @@
     public StatusResponse bye(HumanReadableTextKey displayTextKey) {
         return statusResponseFactory.bye(displayTextKey);
     }
+
+	public ImapMessage createNamespaceMessage(ImapCommand command, String tag) {
+		return new NamespaceRequest(command, tag);
+	}
 }

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/NamespaceRequest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/NamespaceRequest.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/NamespaceRequest.java
(added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/NamespaceRequest.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.request;
+
+import org.apache.james.imap.api.ImapCommand;
+
+/**
+ * Describes a NAMESPACE command.
+ */
+public class NamespaceRequest extends AbstractImapRequest {
+
+    public NamespaceRequest(ImapCommand command, String tag) {
+        super(tag, command);
+    }
+}

Propchange: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/NamespaceRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/NamespaceResponse.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/NamespaceResponse.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/NamespaceResponse.java
(added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/NamespaceResponse.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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;
+
+import java.util.List;
+
+import org.apache.james.imap.api.message.response.ImapResponseMessage;
+
+/**
+ * Describes a NAMESPACE response.
+ */
+public class NamespaceResponse implements ImapResponseMessage {
+
+    private final List<Namespace> personal;
+
+    private final List<Namespace> users;
+
+    private final List<Namespace> shared;
+
+    public NamespaceResponse(final List<Namespace> personal,
+            final List<Namespace> users, final List<Namespace> shared) {
+        super();
+        this.personal = personal;
+        this.users = users;
+        this.shared = shared;
+    }
+
+    /**
+     * Gets the personal namespace.
+     * 
+     * @return possibly null
+     */
+    public List<Namespace> getPersonal() {
+        return personal;
+    }
+
+    /**
+     * Gets shared namespaces.
+     * 
+     * @return possibly null
+     */
+    public List<Namespace> getShared() {
+        return shared;
+    }
+
+    /**
+     * Gets the namespaces for other users.
+     * 
+     * @return possibly null
+     */
+    public List<Namespace> getUsers() {
+        return users;
+    }
+
+    /**
+     * Describes a namespace.
+     */
+    public static final class Namespace {
+        private final String prefix;
+
+        private final char deliminator;
+
+        public Namespace(final String prefix, final char deliminator) {
+            super();
+            this.prefix = prefix;
+            this.deliminator = deliminator;
+        }
+
+        /**
+         * Gets the deliminator used to separate mailboxes.
+         * 
+         * @return not null
+         */
+        public char getDeliminator() {
+            return deliminator;
+        }
+
+        /**
+         * Gets the leading prefix used by this namespace. 
+         * @return not null
+         */
+        public String getPrefix() {
+            return prefix;
+        }
+    }
+}

Propchange: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/NamespaceResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/imap/trunk/message/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/message/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
(added)
+++ james/imap/trunk/message/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,223 @@
+/****************************************************************
+ * 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.encode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.response.NamespaceResponse;
+import org.jmock.Expectations;
+import org.jmock.Sequence;
+import org.jmock.integration.junit3.MockObjectTestCase;
+
+public class NamespaceResponseEncoderTest extends MockObjectTestCase {
+
+    ImapSession dummySession;
+
+    ImapResponseComposer mockComposer;
+
+    NamespaceResponseEncoder subject;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        dummySession = mock(ImapSession.class);
+        final ImapEncoder stubNextEncoderInChain = mock(ImapEncoder.class);
+        subject = new NamespaceResponseEncoder(stubNextEncoderInChain);
+        mockComposer = mock(ImapResponseComposer.class);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testOneSharedNamespaceShouldWriteNilThenPrefixThenDeliminatorThenNil()
+            throws Exception {
+        final String aPrefix = "A Prefix";
+        final String aDeliminator = "@";
+        checking(new Expectations() {
+            {
+                final Sequence sequence = sequence("Composition order");
+                oneOf(mockComposer).untagged();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aPrefix);
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aDeliminator);
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+            }
+        });
+        List<NamespaceResponse.Namespace> namespaces = new ArrayList<NamespaceResponse.Namespace>();
+        namespaces.add(new NamespaceResponse.Namespace(aPrefix, aDeliminator
+                .charAt(0)));
+        subject.doEncode(new NamespaceResponse(null, null, namespaces),
+                mockComposer, dummySession);
+    }
+
+    public void testOneUsersNamespaceShouldWriteNilThenPrefixThenDeliminatorThenNil()
+            throws Exception {
+        final String aPrefix = "A Prefix";
+        final String aDeliminator = "@";
+        checking(new Expectations() {
+            {
+                final Sequence sequence = sequence("Composition order");
+                oneOf(mockComposer).untagged();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aPrefix);
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aDeliminator);
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+            }
+        });
+        List<NamespaceResponse.Namespace> namespaces = new ArrayList<NamespaceResponse.Namespace>();
+        namespaces.add(new NamespaceResponse.Namespace(aPrefix, aDeliminator
+                .charAt(0)));
+        subject.doEncode(new NamespaceResponse(null, namespaces, null),
+                mockComposer, dummySession);
+    }
+
+    public void testOnePersonalNamespaceShouldWritePrefixThenDeliminatorThenNilNil()
+            throws Exception {
+        final String aPrefix = "A Prefix";
+        final String aDeliminator = "@";
+        checking(new Expectations() {
+            {
+                final Sequence sequence = sequence("Composition order");
+                oneOf(mockComposer).untagged();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aPrefix);
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aDeliminator);
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+            }
+        });
+        List<NamespaceResponse.Namespace> namespaces = new ArrayList<NamespaceResponse.Namespace>();
+        namespaces.add(new NamespaceResponse.Namespace(aPrefix, aDeliminator
+                .charAt(0)));
+        subject.doEncode(new NamespaceResponse(namespaces, null, null),
+                mockComposer, dummySession);
+    }
+
+    public void testTwoPersonalNamespaceShouldWritePrefixThenDeliminatorThenNilNil()
+            throws Exception {
+        final String aPrefix = "A Prefix";
+        final String aDeliminator = "@";
+        final String anotherPrefix = "Another Prefix";
+        final String anotherDeliminator = "^";
+        checking(new Expectations() {
+            {
+                final Sequence sequence = sequence("Composition order");
+                oneOf(mockComposer).untagged();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aPrefix);
+                inSequence(sequence);
+                oneOf(mockComposer).quote(aDeliminator);
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).openParen();
+                inSequence(sequence);
+                oneOf(mockComposer).quote(anotherPrefix);
+                inSequence(sequence);
+                oneOf(mockComposer).quote(anotherDeliminator);
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).closeParen();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+            }
+        });
+        List<NamespaceResponse.Namespace> namespaces = new ArrayList<NamespaceResponse.Namespace>();
+        namespaces.add(new NamespaceResponse.Namespace(aPrefix, aDeliminator
+                .charAt(0)));
+        namespaces.add(new NamespaceResponse.Namespace(anotherPrefix,
+                anotherDeliminator.charAt(0)));
+        subject.doEncode(new NamespaceResponse(namespaces, null, null),
+                mockComposer, dummySession);
+    }
+
+    public void testAllNullShouldWriteAllNIL() throws Exception {
+        checking(new Expectations() {
+            {
+                final Sequence sequence = sequence("Composition order");
+                oneOf(mockComposer).untagged();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+                oneOf(mockComposer).nil();
+                inSequence(sequence);
+            }
+        });
+        subject.doEncode(new NamespaceResponse(null, null, null), mockComposer,
+                dummySession);
+    }
+
+    public void testNamespaceResponseIsAcceptable() throws Exception {
+        assertFalse(subject.isAcceptable(mock(ImapMessage.class)));
+        assertTrue(subject
+                .isAcceptable(new NamespaceResponse(null, null, null)));
+    }
+
+}

Propchange: james/imap/trunk/message/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
(added)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.processor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.request.ImapRequest;
+import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.NamespaceRequest;
+import org.apache.james.imap.message.response.NamespaceResponse;
+import org.apache.james.imap.mailbox.MailboxManager;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
+
+/**
+ * Processes a NAMESPACE command into a suitable set of responses.
+ */
+public class NamespaceProcessor extends AbstractMailboxProcessor {
+
+    private final NamespaceResponse response;
+    
+    public NamespaceProcessor(ImapProcessor next,
+            MailboxManagerProvider mailboxManagerProvider,
+            StatusResponseFactory factory) {
+        super(next, mailboxManagerProvider, factory);
+        final List<NamespaceResponse.Namespace> personalSpaces = new ArrayList<NamespaceResponse.Namespace>();
+        personalSpaces.add(new NamespaceResponse.Namespace("", MailboxManager.HIERARCHY_DELIMITER));
+        response = new NamespaceResponse(personalSpaces, null, null);
+    }
+
+    @Override
+    protected void doProcess(ImapRequest message, ImapSession session,
+            String tag, ImapCommand command, Responder responder) {
+        responder.respond(response);
+        unsolicitedResponses(session, responder, false);
+        okComplete(command, tag, responder);
+    }
+
+    @Override
+    protected boolean isAcceptable(ImapMessage message) {
+        return message instanceof NamespaceRequest;
+    }
+
+}

Propchange: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java?rev=760659&view=auto
==============================================================================
--- james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
(added)
+++ james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
Tue Mar 31 21:32:07 2009
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
+import org.apache.james.imap.message.request.NamespaceRequest;
+import org.jmock.integration.junit3.MockObjectTestCase;
+
+public class NamespaceProcessorTest extends MockObjectTestCase {
+
+    NamespaceProcessor subject;
+    StatusResponseFactory mockStatusResponse;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        mockStatusResponse = mock(StatusResponseFactory.class);
+        subject = new NamespaceProcessor(mock(ImapProcessor.class), mock(MailboxManagerProvider.class),
mockStatusResponse);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+    
+    public void testShouldAcceptNamespaceRequests() throws Exception {
+        assertFalse(subject.isAcceptable(mock(ImapMessage.class)));
+        assertTrue(subject.isAcceptable(new NamespaceRequest(ImapCommand.anyStateCommand("Name"),
"TAG")));
+    }
+}

Propchange: james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
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