You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2011/06/08 21:17:02 UTC

svn commit: r1133515 - in /james/imap/trunk: api/src/main/java/org/apache/james/imap/api/ message/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...

Author: norman
Date: Wed Jun  8 19:17:01 2011
New Revision: 1133515

URL: http://svn.apache.org/viewvc?rev=1133515&view=rev
Log:
Add support for ENABLE extension. See IMAP-315

Added:
    james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/EnableParser.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/EnableResponse.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/EnableProcessor.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java
Modified:
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java

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=1133515&r1=1133514&r2=1133515&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 Wed Jun  8 19:17:01 2011
@@ -97,6 +97,8 @@ public interface ImapConstants {
 
     public static final String SUPPORTS_XLIST = "XLIST";
 
+    public static final String SUPPORTS_ENABLE = "ENABLE";
+    
     public static final String INBOX_NAME = "INBOX";
 
     public static final String MIME_TYPE_TEXT = "TEXT";
@@ -202,6 +204,8 @@ public interface ImapConstants {
     public static final String AUTHENTICATE_COMMAND_NAME = "AUTHENTICATE";
 
     public static final String APPEND_COMMAND_NAME = "APPEND";
+    
+    public static final String ENABLE_COMMAND_NAME = "ENABLE";
 
     public static final String LIST_RESPONSE_NAME = "LIST";
 

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/EnableParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/EnableParser.java?rev=1133515&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/EnableParser.java (added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/EnableParser.java Wed Jun  8 19:17:01 2011
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+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.api.process.ImapSession;
+import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+import org.apache.james.imap.message.request.EnableRequest;
+
+public class EnableParser extends AbstractImapCommandParser {
+    
+    public EnableParser() {
+        super(ImapCommand.authenticatedStateCommand(ImapConstants.ENABLE_COMMAND_NAME));
+    }
+
+    @Override
+    protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException {
+        List<String> caps = new ArrayList<String>();
+        String cap = request.astring();
+        caps.add(cap);
+        while (request.nextChar() == ' ') {
+            request.consume();
+            cap = request.astring();
+            caps.add(cap);
+        }
+        request.eol();
+        return new EnableRequest(tag, command, caps);
+    }
+
+}

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java?rev=1133515&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java (added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java Wed Jun  8 19:17:01 2011
@@ -0,0 +1,69 @@
+/****************************************************************
+ * 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.ImapConstants;
+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.EnableResponse;
+
+/**
+ * Encodes <code>Enable</code> response.
+ */
+public class EnableResponseEncoder extends AbstractChainedImapEncoder {
+
+    public EnableResponseEncoder(ImapEncoder next) {
+        super(next);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.james.imap.encode.base.AbstractChainedImapEncoder#doEncode
+     * (org.apache.james.imap.api.ImapMessage,
+     * org.apache.james.imap.encode.ImapResponseComposer,
+     * org.apache.james.imap.api.process.ImapSession)
+     */
+    protected void doEncode(ImapMessage acceptableMessage, ImapResponseComposer composer, ImapSession session) throws IOException {
+        final EnableResponse response = (EnableResponse) acceptableMessage;
+        List<String> capabilities = response.getCapabilities();
+        composer.untagged();
+        composer.message(ImapConstants.ENABLE_COMMAND_NAME);
+        for (String capability : capabilities) {
+            composer.message(capability);
+        }
+        composer.end();
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.james.imap.encode.base.AbstractChainedImapEncoder#isAcceptable
+     * (org.apache.james.imap.api.ImapMessage)
+     */
+    protected boolean isAcceptable(ImapMessage message) {
+        return (message instanceof EnableResponse);
+    }
+}

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/EnableRequest.java?rev=1133515&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/EnableRequest.java (added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/EnableRequest.java Wed Jun  8 19:17:01 2011
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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 java.util.List;
+
+import org.apache.james.imap.api.ImapCommand;
+
+public class EnableRequest extends AbstractImapRequest{
+
+    private final List<String> capabilities;
+
+    public EnableRequest(final String tag, final ImapCommand command, List<String> capabilities) {
+        super(tag, command);
+        this.capabilities = capabilities;
+    }
+    
+    public List<String> getCapabilities() {
+        return capabilities;
+    }
+}

Added: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/EnableResponse.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/EnableResponse.java?rev=1133515&view=auto
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/EnableResponse.java (added)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/EnableResponse.java Wed Jun  8 19:17:01 2011
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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;
+
+public class EnableResponse extends CapabilityResponse{
+
+    public EnableResponse(List<String> capabilities) {
+        super(capabilities);
+    }
+
+}

Added: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/EnableProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/EnableProcessor.java?rev=1133515&view=auto
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/EnableProcessor.java (added)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/EnableProcessor.java Wed Jun  8 19:17:01 2011
@@ -0,0 +1,110 @@
+/****************************************************************
+ * 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 static org.apache.james.imap.api.ImapConstants.SUPPORTS_ENABLE;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.james.imap.api.ImapCommand;
+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.EnableRequest;
+import org.apache.james.imap.message.response.EnableResponse;
+import org.apache.james.mailbox.MailboxManager;
+
+public class EnableProcessor extends AbstractMailboxProcessor<EnableRequest> implements CapabilityImplementingProcessor {
+
+    private final List<PermitEnableCapabilityProcessor> capabilities = new ArrayList<PermitEnableCapabilityProcessor>();
+    private final static String ENABLED_CAPABILITIES = "ENABLED_CAPABILITIES";
+    
+    public EnableProcessor(final ImapProcessor next, final MailboxManager mailboxManager, final StatusResponseFactory factory, final List<PermitEnableCapabilityProcessor> capabilities) {
+        this(next, mailboxManager, factory);
+        this.capabilities.addAll(capabilities);
+
+    }
+
+    public EnableProcessor(final ImapProcessor next, final MailboxManager mailboxManager, final StatusResponseFactory factory) {
+        super(EnableRequest.class, next, mailboxManager, factory);
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.processor.AbstractMailboxProcessor#doProcess(org.apache.james.imap.api.message.request.ImapRequest, org.apache.james.imap.api.process.ImapSession, java.lang.String, org.apache.james.imap.api.ImapCommand, org.apache.james.imap.api.process.ImapProcessor.Responder)
+     */
+    protected void doProcess(EnableRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) {
+        List<String> caps = request.getCapabilities();
+        Set<String> enabledCaps = new HashSet<String>();
+        for (int i = 0; i < caps.size(); i++) {
+            String cap = caps.get(i);
+            for (int a = 0; a < capabilities.size(); a++) {
+                if (capabilities.get(a).getPermitEnableCapabilities(session).contains(cap)) {
+                    enabledCaps.add(cap);
+                }
+            }
+        }
+        getEnabledCapabilities(session).addAll(enabledCaps);
+        
+        responder.respond(new EnableResponse(new ArrayList<String>(enabledCaps)));
+        
+        unsolicitedResponses(session, responder, false);
+        okComplete(command, tag, responder);
+    }
+
+   
+    /**
+     * Add a {@link PermitEnableCapabilityProcessor} which can be enabled
+     * 
+     * @param implementor
+     */
+    public void addProcessor(PermitEnableCapabilityProcessor implementor) {
+        capabilities.add(implementor);
+    }
+
+    @SuppressWarnings("unchecked")
+    public static Set<String> getEnabledCapabilities(ImapSession session) {
+        Set<String> caps = (Set<String>) session.getAttribute(ENABLED_CAPABILITIES);
+        
+        if (caps == null) {
+            caps = new HashSet<String>();
+            session.setAttribute(ENABLED_CAPABILITIES, caps);
+        } 
+        return caps;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.processor.CapabilityImplementingProcessor#
+     * getImplementedCapabilities(org.apache.james.imap.api.process.ImapSession)
+     */
+    public List<String> getImplementedCapabilities(ImapSession session) {
+        final List<String> capabilities = new ArrayList<String>();
+        capabilities.add(SUPPORTS_ENABLE);
+    
+        return capabilities;
+    }
+
+}

Added: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java?rev=1133515&view=auto
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java (added)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java Wed Jun  8 19:17:01 2011
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.List;
+
+import org.apache.james.imap.api.process.ImapSession;
+
+public interface PermitEnableCapabilityProcessor extends CapabilityImplementingProcessor{
+
+    public List<String> getPermitEnableCapabilities(ImapSession session);
+
+}



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