You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2007/05/27 19:24:31 UTC
svn commit: r542006 [2/2] - in
/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james:
experimental/imapserver/ experimental/imapserver/decode/
experimental/imapserver/decode/base/ experimental/imapserver...
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/Imap4Rev1CommandParserFactory.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/Imap4Rev1CommandParserFactory.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/Imap4Rev1CommandParserFactory.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/Imap4Rev1CommandParserFactory.java Sun May 27 10:24:28 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.decode.imap4rev1;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.api.imap.ImapConstants;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1MessageFactory;
+import org.apache.james.imapserver.codec.decode.DelegatingImapCommandParser;
+import org.apache.james.imapserver.codec.decode.ImapCommandParser;
+import org.apache.james.imapserver.codec.decode.ImapCommandParserFactory;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.MessagingImapCommandParser;
+
+/**
+ * A factory for ImapCommand instances, provided based on the command name.
+ * Command instances are created on demand, when first accessed.
+ *
+ * @version $Revision: 109034 $
+ */
+public class Imap4Rev1CommandParserFactory extends AbstractLogEnabled implements ImapCommandParserFactory
+{
+ private Map _imapCommands;
+ private final Imap4Rev1MessageFactory messageFactory;
+ private final Imap4Rev1CommandFactory commandFactory;
+
+ public Imap4Rev1CommandParserFactory(final Imap4Rev1MessageFactory messageFactory, final Imap4Rev1CommandFactory commandFactory)
+ {
+ this.messageFactory = messageFactory;
+ this.commandFactory = commandFactory;
+ _imapCommands = new HashMap();
+
+ // Commands valid in any state
+ // CAPABILITY, NOOP, and LOGOUT
+ _imapCommands.put( ImapConstants.CAPABILITY_COMMAND_NAME, CapabilityCommandParser.class );
+ _imapCommands.put( ImapConstants.NOOP_COMMAND_NAME, NoopCommandParser.class );
+ _imapCommands.put( ImapConstants.LOGOUT_COMMAND_NAME, LogoutCommandParser.class );
+
+ // Commands valid in NON_AUTHENTICATED state.
+ // AUTHENTICATE and LOGIN
+ _imapCommands.put( ImapConstants.AUTHENTICATE_COMMAND_NAME, AuthenticateCommandParser.class );
+ _imapCommands.put( ImapConstants.LOGIN_COMMAND_NAME, LoginCommandParser.class );
+
+ // Commands valid in AUTHENTICATED or SELECTED state.
+ // RFC2060: SELECT, EXAMINE, CREATE, DELETE, RENAME, SUBSCRIBE, UNSUBSCRIBE, LIST, LSUB, STATUS, and APPEND
+ _imapCommands.put( ImapConstants.SELECT_COMMAND_NAME, SelectCommandParser.class );
+ _imapCommands.put( ImapConstants.EXAMINE_COMMAND_NAME, ExamineCommandParser.class );
+ _imapCommands.put( ImapConstants.CREATE_COMMAND_NAME, CreateCommandParser.class );
+ _imapCommands.put( ImapConstants.DELETE_COMMAND_NAME, DeleteCommandParser.class );
+ _imapCommands.put( ImapConstants.RENAME_COMMAND_NAME, RenameCommandParser.class );
+ _imapCommands.put( ImapConstants.SUBSCRIBE_COMMAND_NAME, SubscribeCommandParser.class );
+ _imapCommands.put( ImapConstants.UNSUBSCRIBE_COMMAND_NAME, UnsubscribeCommandParser.class );
+ _imapCommands.put( ImapConstants.LIST_COMMAND_NAME, ListCommandParser.class );
+ _imapCommands.put( ImapConstants.LSUB_COMMAND_NAME, LsubCommandParser.class );
+ _imapCommands.put( ImapConstants.STATUS_COMMAND_NAME, StatusCommandParser.class );
+ _imapCommands.put( ImapConstants.APPEND_COMMAND_NAME, AppendCommandParser.class );
+
+// // RFC2342 NAMESPACE
+// _imapCommands.put( "NAMESPACE", NamespaceCommand.class );
+
+ // RFC2086 GETACL, SETACL, DELETEACL, LISTRIGHTS, MYRIGHTS
+// _imapCommands.put( "GETACL", GetAclCommand.class );
+// _imapCommands.put( "SETACL", SetAclCommand.class );
+// _imapCommands.put( "DELETEACL", DeleteAclCommand.class );
+// _imapCommands.put( "LISTRIGHTS", ListRightsCommand.class );
+// _imapCommands.put( "MYRIGHTS", MyRightsCommand.class );
+
+
+ // Commands only valid in SELECTED state.
+ // CHECK, CLOSE, EXPUNGE, SEARCH, FETCH, STORE, COPY, and UID
+ _imapCommands.put( ImapConstants.CHECK_COMMAND_NAME, CheckCommandParser.class );
+ _imapCommands.put( ImapConstants.CLOSE_COMMAND_NAME, CloseCommandParser.class );
+ _imapCommands.put( ImapConstants.EXPUNGE_COMMAND_NAME, ExpungeCommandParser.class );
+ _imapCommands.put( ImapConstants.COPY_COMMAND_NAME, CopyCommandParser.class );
+ _imapCommands.put( ImapConstants.SEARCH_COMMAND_NAME, SearchCommandParser.class );
+ _imapCommands.put( ImapConstants.FETCH_COMMAND_NAME, FetchCommandParser.class );
+ _imapCommands.put( ImapConstants.STORE_COMMAND_NAME, StoreCommandParser.class );
+ _imapCommands.put( ImapConstants.UID_COMMAND_NAME, UidCommandParser.class );
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.james.experimental.imapserver.decode.imap4rev1.ImapCommandParserFactory#getParser(java.lang.String)
+ */
+ public ImapCommandParser getParser( String commandName )
+ {
+ Class cmdClass = ( Class ) _imapCommands.get( commandName.toUpperCase() );
+
+ if ( cmdClass == null ) {
+ return null;
+ }
+ else {
+ return createCommand( cmdClass );
+ }
+ }
+
+ private ImapCommandParser createCommand( Class commandClass )
+ {
+ final Logger logger = getLogger();
+ try {
+ ImapCommandParser cmd = ( ImapCommandParser ) commandClass.newInstance();
+ initialiseParser(commandClass, logger, cmd);
+ return cmd;
+ }
+ catch ( Exception e ) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Create command instance failed: ", e);
+ }
+ // TODO: would probably be better to manage this in protocol
+ // TODO: this runtime will produce a nasty disconnect for the client
+ throw new CascadingRuntimeException( "Could not create command instance: " + commandClass.getName(), e );
+ }
+ }
+
+ protected void initialiseParser(Class commandClass, final Logger logger, ImapCommandParser cmd) {
+ setupLogger(cmd);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Created command " + commandClass);
+ }
+
+ if ( cmd instanceof DelegatingImapCommandParser ) {
+ ( ( DelegatingImapCommandParser) cmd ).setParserFactory( this );
+ }
+
+ if (cmd instanceof MessagingImapCommandParser) {
+ ((MessagingImapCommandParser) cmd).setMessageFactory(messageFactory);
+ }
+
+ if (cmd instanceof InitialisableCommandFactory) {
+ ((InitialisableCommandFactory) cmd).init(commandFactory);
+ }
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/ListCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/ListCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/ListCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/ListCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1MessageFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+
+class ListCommandParser extends AbstractUidCommandParser implements InitialisableCommandFactory
+{
+ public ListCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getList();
+ setCommand(command);
+ }
+
+ /**
+ * Reads an argument of type "list_mailbox" from the request, which is
+ * the second argument for a LIST or LSUB command. Valid values are a "string"
+ * argument, an "atom" with wildcard characters.
+ * @return An argument of type "list_mailbox"
+ */
+ public String listMailbox( ImapRequestLineReader request ) throws ProtocolException
+ {
+ char next = request.nextWordChar();
+ switch ( next ) {
+ case '"':
+ return consumeQuoted( request );
+ case '{':
+ return consumeLiteral( request );
+ default:
+ return consumeWord( request, new ListCharValidator() );
+ }
+ }
+
+ private class ListCharValidator extends ATOM_CHARValidator
+ {
+ public boolean isValid( char chr )
+ {
+ if ( isListWildcard( chr ) ) {
+ return true;
+ }
+ return super.isValid( chr );
+ }
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+ String referenceName = mailbox( request );
+ String mailboxPattern = listMailbox( request );
+ endLine( request );
+ final ImapMessage result = createMessage(command, referenceName, mailboxPattern, tag);
+ return result;
+ }
+
+ protected ImapMessage createMessage(ImapCommand command, final String referenceName, final String mailboxPattern, final String tag)
+ {
+ final Imap4Rev1MessageFactory factory = getMessageFactory();
+ final ImapMessage result = factory.createListMessage(command, referenceName, mailboxPattern, tag);
+ return result;
+ }
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LoginCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LoginCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LoginCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LoginCommandParser.java Sun May 27 10:24:28 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class LoginCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public LoginCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getLogin();
+ setCommand(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ final String userid = astring( request );
+ final String password = astring( request );
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createLoginMessage(command, userid, password, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LogoutCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LogoutCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LogoutCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LogoutCommandParser.java Sun May 27 10:24:28 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class LogoutCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public LogoutCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getLogout();
+ setCommand(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createLogoutMessage(command, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LsubCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LsubCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LsubCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/LsubCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+
+class LsubCommandParser extends ListCommandParser implements InitialisableCommandFactory {
+
+ public LsubCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getLsub();
+ setCommand(command);
+ }
+
+ protected ImapMessage createMessage(ImapCommand command, String referenceName, String mailboxPattern, String tag) {
+ final ImapMessage result = getMessageFactory().createLsubMessage(command, referenceName, mailboxPattern, tag);
+ return result;
+ }
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/NoopCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/NoopCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/NoopCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/NoopCommandParser.java Sun May 27 10:24:28 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class NoopCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public NoopCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getNoop();
+ setCommand(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createNoopMessage(command, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/RenameCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/RenameCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/RenameCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/RenameCommandParser.java Sun May 27 10:24:28 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.imapserver.codec.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class RenameCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public RenameCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getRename();
+ setCommand(command);
+ }
+
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ final String existingName = mailbox( request );
+ final String newName = mailbox( request );
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createRenameMessage(command, existingName, newName, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParser.java Sun May 27 10:24:28 2007
@@ -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.imapserver.codec.decode.imap4rev1;
+
+import javax.mail.Message;
+import javax.mail.search.SearchTerm;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+
+class SearchCommandParser extends AbstractUidCommandParser implements InitialisableCommandFactory
+{
+ public SearchCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getSearch();
+ setCommand(command);
+ }
+
+ /**
+ * Parses the request argument into a valid search term.
+ * Not yet implemented - all searches will return everything for now.
+ * TODO implement search
+ */
+ public SearchTerm searchTerm( ImapRequestLineReader request )
+ throws ProtocolException
+ {
+ // Dummy implementation
+ // Consume to the end of the line.
+ char next = request.nextChar();
+ while ( next != '\n' ) {
+ request.consume();
+ next = request.nextChar();
+ }
+
+ // Return a search term that matches everything.
+ return new SearchTerm()
+ {
+ private static final long serialVersionUID = 5290284637903768771L;
+
+ public boolean match( Message message )
+ {
+ return true;
+ }
+ };
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+ // Parse the search term from the request
+ final SearchTerm searchTerm = searchTerm( request );
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createSearchImapMessage(command, searchTerm, useUids, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SelectCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SelectCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SelectCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SelectCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,50 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class SelectCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public SelectCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getSelect();
+ setCommand(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ final String mailboxName = mailbox( request );
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createSelectMessage(command, mailboxName, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StatusCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StatusCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StatusCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StatusCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+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.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1MessageFactory;
+import org.apache.james.api.imap.message.StatusDataItems;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class StatusCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory
+{
+ public StatusCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getStatus();
+ setCommand(command);
+ }
+
+ StatusDataItems statusDataItems( ImapRequestLineReader request )
+ throws ProtocolException
+ {
+ StatusDataItems items = new StatusDataItems();
+
+ request.nextWordChar();
+ consumeChar( request, '(' );
+ CharacterValidator validator = new NoopCharValidator();
+ String nextWord = consumeWord( request, validator );
+ while ( ! nextWord.endsWith(")" ) ) {
+ addItem( nextWord, items );
+ nextWord = consumeWord( request, validator );
+ }
+ // Got the closing ")", may be attached to a word.
+ if ( nextWord.length() > 1 ) {
+ addItem( nextWord.substring(0, nextWord.length() - 1 ), items );
+ }
+
+ return items;
+ }
+
+ private void addItem( String nextWord, StatusDataItems items )
+ throws ProtocolException
+ {
+ if ( nextWord.equals( ImapConstants.STATUS_MESSAGES ) ) {
+ items.setMessages(true);
+ }
+ else if ( nextWord.equals( ImapConstants.STATUS_RECENT ) ) {
+ items.setRecent(true);
+ }
+ else if ( nextWord.equals( ImapConstants.STATUS_UIDNEXT ) ) {
+ items.setUidNext(true);
+ }
+ else if ( nextWord.equals( ImapConstants.STATUS_UIDVALIDITY ) ) {
+ items.setUidValidity(true);
+ }
+ else if ( nextWord.equals( ImapConstants.STATUS_UNSEEN ) ) {
+ items.setUnseen(true);
+ }
+ else {
+ throw new ProtocolException( "Unknown status item: '" + nextWord + "'" );
+ }
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ final String mailboxName = mailbox( request );
+ final StatusDataItems statusDataItems = statusDataItems( request );
+ endLine( request );
+ final Imap4Rev1MessageFactory factory = getMessageFactory();
+ final ImapMessage result = factory.createStatusMessage(command, mailboxName, statusDataItems, tag);
+ return result;
+ }
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+import javax.mail.Flags;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.api.imap.message.IdRange;
+import org.apache.james.api.imap.message.StoreDirective;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+
+class StoreCommandParser extends AbstractUidCommandParser implements InitialisableCommandFactory
+{
+ public StoreCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getStore();
+ setCommand(command);
+ }
+
+ StoreDirective storeDirective( ImapRequestLineReader request ) throws ProtocolException
+ {
+ int sign = 0;
+ boolean silent = false;
+
+ char next = request.nextWordChar();
+ if ( next == '+' ) {
+ sign = 1;
+ request.consume();
+ }
+ else if ( next == '-' ) {
+ sign = -1;
+ request.consume();
+ }
+ else {
+ sign = 0;
+ }
+
+ String directive = consumeWord( request, new NoopCharValidator() );
+ if ( "FLAGS".equalsIgnoreCase( directive ) ) {
+ silent = false;
+ }
+ else if ( "FLAGS.SILENT".equalsIgnoreCase( directive ) ) {
+ silent = true;
+ }
+ else {
+ throw new ProtocolException( "Invalid Store Directive: '" + directive + "'" );
+ }
+ return new StoreDirective( sign, silent );
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+ final IdRange[] idSet = parseIdRange( request );
+ final StoreDirective directive = storeDirective( request );
+ final Flags flags = flagList( request );
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createStoreMessage(command, idSet, directive, flags, useUids, tag);
+ return result;
+ }
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SubscribeCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SubscribeCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SubscribeCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/SubscribeCommandParser.java Sun May 27 10:24:28 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class SubscribeCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public SubscribeCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getSubscribe();
+ setCommand(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ final String mailboxName = mailbox( request );
+ endLine( request );
+
+ final ImapMessage result = getMessageFactory().createSubscribeMessage(command, mailboxName, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UidCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UidCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UidCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UidCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.DelegatingImapCommandParser;
+import org.apache.james.imapserver.codec.decode.ImapCommandParser;
+import org.apache.james.imapserver.codec.decode.ImapCommandParserFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class UidCommandParser extends AbstractImapCommandParser implements DelegatingImapCommandParser,InitialisableCommandFactory {
+ private ImapCommandParserFactory parserFactory;
+
+ public UidCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getUid();
+ setCommand(command);
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.DelegatingImapCommandParser#getParserFactory()
+ */
+ public ImapCommandParserFactory getParserFactory() {
+ return parserFactory;
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.DelegatingImapCommandParser#setParserFactory(org.apache.james.experimental.imapserver.decode.imap4rev1.Imap4Rev1CommandParserFactory)
+ */
+ public void setParserFactory( ImapCommandParserFactory imapCommandFactory )
+ {
+ this.parserFactory = imapCommandFactory;
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ // TODO: check the logic against the specification:
+ // TODO: suspect that it is now bust
+ // TODO: the command written may be wrong
+ // TODO: this will be easier to fix a little later
+ // TODO: also not sure whether the old implementation shares this flaw
+ String commandName = atom( request );
+ ImapCommandParser helperCommand = parserFactory.getParser( commandName );
+ // TODO: replace abstract class with interface
+ if ( helperCommand == null ||
+ ! (helperCommand instanceof AbstractUidCommandParser ) ) {
+ throw new ProtocolException("Invalid UID command: '" + commandName + "'" );
+ }
+ final AbstractUidCommandParser uidEnabled = (AbstractUidCommandParser) helperCommand;
+ final ImapMessage result = uidEnabled.decode( request, tag, true );
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UnsubscribeCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UnsubscribeCommandParser.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UnsubscribeCommandParser.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/imap4rev1/UnsubscribeCommandParser.java Sun May 27 10:24:28 2007
@@ -0,0 +1,50 @@
+/****************************************************************
+ * 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.decode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.InitialisableCommandFactory;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+class UnsubscribeCommandParser extends AbstractImapCommandParser implements InitialisableCommandFactory {
+
+ public UnsubscribeCommandParser() {
+ }
+
+ /**
+ * @see org.apache.james.imapserver.codec.decode.InitialisableCommandFactory#init(org.apache.james.api.imap.imap4rev1.Imap4Rev1CommandFactory)
+ */
+ public void init(Imap4Rev1CommandFactory factory)
+ {
+ final ImapCommand command = factory.getUnsubscribe();
+ setCommand(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+ final String mailboxName = mailbox( request );
+ endLine( request );
+ final ImapMessage result = getMessageFactory().createUnsubscribeMessage(command, mailboxName, tag);
+ return result;
+ }
+
+}
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/main/DefaultImapDecoder.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/main/DefaultImapDecoder.java?view=auto&rev=542006
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/main/DefaultImapDecoder.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/imapserver/codec/decode/main/DefaultImapDecoder.java Sun May 27 10:24:28 2007
@@ -0,0 +1,100 @@
+/****************************************************************
+ * 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.decode.main;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.ProtocolException;
+import org.apache.james.api.imap.imap4rev1.Imap4Rev1MessageFactory;
+import org.apache.james.imapserver.codec.decode.ImapCommandParser;
+import org.apache.james.imapserver.codec.decode.ImapCommandParserFactory;
+import org.apache.james.imapserver.codec.decode.ImapDecoder;
+import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
+import org.apache.james.imapserver.codec.decode.base.AbstractImapCommandParser;
+
+public class DefaultImapDecoder extends AbstractLogEnabled implements ImapDecoder {
+
+ private static final String INVALID_COMMAND = "Invalid command.";
+ private static final String REQUEST_SYNTAX = "Protocol Error: Was expecting <tag SPACE command [arguments]>";
+
+ private final Imap4Rev1MessageFactory messageFactory;
+ private final ImapCommandParserFactory imapCommands;
+
+
+ public DefaultImapDecoder (final Imap4Rev1MessageFactory messageFactory, final ImapCommandParserFactory imapCommands) {
+ this.messageFactory = messageFactory;
+ this.imapCommands = imapCommands;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.logger.AbstractLogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+ */
+ public void enableLogging(Logger logger) {
+ super.enableLogging(logger);
+ setupLogger(imapCommands);
+ }
+
+ public ImapMessage decode(ImapRequestLineReader request) {
+ ImapMessage message;
+ final Logger logger = getLogger();
+
+ try {
+ final String tag = AbstractImapCommandParser.tag( request );
+ message = decodeCommandTagged(request, logger, tag);
+ }
+ catch ( ProtocolException e ) {
+ logger.debug("error parsing request", e);
+ message = messageFactory.createBadRequestMessage( REQUEST_SYNTAX );
+ }
+ return message;
+ }
+
+ private ImapMessage decodeCommandTagged(final ImapRequestLineReader request, final Logger logger, final String tag) {
+ ImapMessage message;
+ if (logger.isDebugEnabled()) {
+ logger.debug( "Got <tag>: " + tag );
+ }
+ try {
+ final String commandName = AbstractImapCommandParser.atom( request );
+ message = decodeCommandNamed(request, tag, commandName, logger);
+ }
+ catch ( ProtocolException e ) {
+ logger.debug("Error during initial request parsing", e);
+ message = messageFactory.createErrorMessage(REQUEST_SYNTAX , tag);
+ }
+ return message;
+ }
+
+ private ImapMessage decodeCommandNamed(final ImapRequestLineReader request,
+ final String tag, String commandName, final Logger logger) {
+ ImapMessage message;
+ if (logger.isDebugEnabled()) {
+ logger.debug( "Got <command>: " + commandName);
+ }
+ final ImapCommandParser command = imapCommands.getParser( commandName );
+ if ( command == null ) {
+ logger.info("Missing command implementation.");
+ message = messageFactory.createErrorMessage(INVALID_COMMAND, tag);
+ } else {
+ message = command.parse( request, tag );
+ }
+ return message;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org