Author: norman
Date: Thu Jan 13 17:22:34 2011
New Revision: 1058675
URL: http://svn.apache.org/viewvc?rev=1058675&view=rev
Log:
Add UNSELECT support. See IMAP-244
Added:
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/UnselectCommandParser.java
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/UnselectRequest.java
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
Modified:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.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=1058675&r1=1058674&r2=1058675&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
Thu Jan 13 17:22:34 2011
@@ -177,6 +177,8 @@ public interface ImapConstants {
public static final String SELECT_COMMAND_NAME = "SELECT";
+ public static final String UNSELECT_COMMAND_NAME = "UNSELECT";
+
public static final String SEARCH_COMMAND_NAME = "SEARCH";
public static final String RENAME_COMMAND_NAME = "RENAME";
Modified:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java?rev=1058675&r1=1058674&r2=1058675&view=diff
==============================================================================
---
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
(original)
+++
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
Thu Jan 13 17:22:34 2011
@@ -199,6 +199,8 @@ public class HumanReadableText {
public static final HumanReadableText IDLING = new HumanReadableText(
"org.apache.james.imap.IDLING", "Idling");
+ public static final HumanReadableText UNSELECT = new HumanReadableText(
+ "org.apache.james.imap.UNSELECT", "No Mailbox selected.");
private final String defaultValue;
private final String key;
Modified:
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java?rev=1058675&r1=1058674&r2=1058675&view=diff
==============================================================================
---
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java
(original)
+++
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/ImapParserFactory.java
Thu Jan 13 17:22:34 2011
@@ -118,6 +118,9 @@ public class ImapParserFactory implement
_imapCommands.put(ImapConstants.IDLE_COMMAND_NAME,
IdleCommandParser.class);
_imapCommands.put(ImapConstants.STARTTLS, StartTLSCommandParser.class);
+
+ // RFC3691
+ _imapCommands.put(ImapConstants.UNSELECT_COMMAND_NAME,
UnselectCommandParser.class);
}
/**
Added:
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/UnselectCommandParser.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/UnselectCommandParser.java?rev=1058675&view=auto
==============================================================================
---
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/UnselectCommandParser.java
(added)
+++
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/UnselectCommandParser.java
Thu Jan 13 17:22:34 2011
@@ -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.imap.decode.parser;
+
+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.ImapRequestLineReader;
+import org.apache.james.imap.decode.DecodingException;
+import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+import org.apache.james.imap.message.request.UnselectRequest;
+
+/**
+ *
+ * Parse UNSELECT commands
+ *
+ *
+ * See RFC3691
+ *
+ */
+public class UnselectCommandParser extends AbstractImapCommandParser {
+
+ public UnselectCommandParser() {
+ // from the RFC it seems like the command should be valid in any
state. At least kind of, as
+ // we will return a "BAD" response if no mailbox is currently selected
in the UnselectProcessor
+
super(ImapCommand.anyStateCommand(ImapConstants.UNSELECT_COMMAND_NAME));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.imap.decode.base.AbstractImapCommandParser#decode(org.apache.james.imap.api.ImapCommand,
org.apache.james.imap.decode.ImapRequestLineReader, java.lang.String,
org.apache.james.imap.api.process.ImapSession)
+ */
+ protected ImapMessage decode(ImapCommand command,
+ ImapRequestLineReader request, String tag, ImapSession session)
throws DecodingException {
+ endLine(request);
+ final ImapMessage result = new UnselectRequest(tag, command);
+ return result;
+ }
+
+}
Added:
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/UnselectRequest.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/UnselectRequest.java?rev=1058675&view=auto
==============================================================================
---
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/UnselectRequest.java
(added)
+++
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/UnselectRequest.java
Thu Jan 13 17:22:34 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.request;
+
+import org.apache.james.imap.api.ImapCommand;
+
+public class UnselectRequest extends AbstractImapRequest{
+
+ public UnselectRequest(String tag, ImapCommand command) {
+ super(tag, command);
+ }
+
+}
Modified:
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java?rev=1058675&r1=1058674&r2=1058675&view=diff
==============================================================================
---
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
(original)
+++
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
Thu Jan 13 17:22:34 2011
@@ -99,16 +99,23 @@ public class DefaultProcessorChain {
final NamespaceProcessor namespaceProcessor = new NamespaceProcessor(
selectProcessor, mailboxManager, statusResponseFactory);
- capabilityProcessor.addProcessor(idleProcessor);
- capabilityProcessor.addProcessor(namespaceProcessor);
- // added to announce UIDPLUS support
- capabilityProcessor.addProcessor(expungeProcessor);
final ImapProcessor fetchProcessor = new
FetchProcessor(namespaceProcessor,
mailboxManager, statusResponseFactory, batchSize);
final StartTLSProcessor startTLSProcessor = new
StartTLSProcessor(fetchProcessor, statusResponseFactory);
+
+ final UnselectProcessor unselectProcessor = new
UnselectProcessor(startTLSProcessor, mailboxManager, statusResponseFactory);
+
capabilityProcessor.addProcessor(startTLSProcessor);
- return startTLSProcessor;
+ capabilityProcessor.addProcessor(idleProcessor);
+ capabilityProcessor.addProcessor(namespaceProcessor);
+ // added to announce UIDPLUS support
+ capabilityProcessor.addProcessor(expungeProcessor);
+
+ // announce the UNSELECT extension. See RFC3691
+ capabilityProcessor.addProcessor(unselectProcessor);
+
+ return unselectProcessor;
}
Added:
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java?rev=1058675&view=auto
==============================================================================
---
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
(added)
+++
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
Thu Jan 13 17:22:34 2011
@@ -0,0 +1,78 @@
+/****************************************************************
+ * 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.Arrays;
+import java.util.List;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.display.HumanReadableText;
+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.UnselectRequest;
+import org.apache.james.mailbox.MailboxManager;
+
+/**
+ * Processor which implements the UNSELECT extension.
+ *
+ * See RFC3691
+ *
+ */
+public class UnselectProcessor extends AbstractMailboxProcessor implements
CapabilityImplementingProcessor{
+
+ private final static List<String> UNSELECT = Arrays.asList("UNSELECT");
+
+ public UnselectProcessor(ImapProcessor next, MailboxManager
mailboxManager, StatusResponseFactory factory) {
+ super(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(ImapRequest message, ImapSession session, String
tag, ImapCommand command, Responder responder) {
+ if (session.getSelected() != null) {
+ session.deselect();
+ okComplete(command, tag, responder);
+ } else {
+ taggedBad(command, tag, responder, HumanReadableText.UNSELECT);
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.imap.processor.base.AbstractChainedProcessor#isAcceptable(org.apache.james.imap.api.ImapMessage)
+ */
+ protected boolean isAcceptable(ImapMessage message) {
+ return message instanceof UnselectRequest;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.imap.processor.CapabilityImplementingProcessor#getImplementedCapabilities(org.apache.james.imap.api.process.ImapSession)
+ */
+ public List<String> getImplementedCapabilities(ImapSession session) {
+ return UNSELECT;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]