james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r537643 [4/4] - in /james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src: main/java/org/apache/james/experimental/imapserver/ main/java/org/apache/james/experimental/imapserver/decode/ main/java/org/apache/james/experi...
Date Sun, 13 May 2007 19:25:44 GMT
Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/FetchProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/FetchProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/FetchProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/FetchProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,356 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.core.MimeMessageWrapper;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapConstants;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.BodyFetchElement;
+import org.apache.james.experimental.imapserver.message.FetchData;
+import org.apache.james.experimental.imapserver.message.FetchResponseMessage;
+import org.apache.james.experimental.imapserver.message.IdRange;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.FetchRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.experimental.imapserver.store.MessageFlags;
+import org.apache.james.experimental.imapserver.store.SimpleMessageAttributes;
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+import org.apache.mailet.dates.RFC822DateFormat;
+
+import com.sun.mail.util.CRLFOutputStream;
+
+
+public class FetchProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof FetchRequest) {
+			final FetchRequest request = (FetchRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected FetchRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Fetch processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(FetchRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        final boolean useUids = request.isUseUids();
+        final IdRange[] idSet = request.getIdSet();
+        final FetchData fetch = request.getFetch();
+		final ImapResponseMessage result = doProcess(useUids, idSet, fetch, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final boolean useUids, final IdRange[] idSet, final FetchData fetch,
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        
+        FetchResponseMessage result = 
+            new FetchResponseMessage(command, useUids, tag);
+        // TODO only fetch needed results
+        int resultToFetch = MessageResult.FLAGS | MessageResult.MIME_MESSAGE
+                | MessageResult.INTERNAL_DATE | MessageResult.MSN
+                | MessageResult.SIZE;
+        ImapMailboxSession mailbox = session.getSelected().getMailbox();
+        for (int i = 0; i < idSet.length; i++) {
+            GeneralMessageSet messageSet=GeneralMessageSetImpl.range(idSet[i].getLowVal(),idSet[i].getHighVal(),useUids);
+            MessageResult[] fetchResults;
+            try {
+                fetchResults = mailbox.getMessages(messageSet,resultToFetch);
+            } catch (MailboxManagerException e) {
+                throw new MailboxException(e);
+            }
+            for (int j = 0; j < fetchResults.length; j++) {
+                String msgData = outputMessage( fetch, fetchResults[j], mailbox, useUids );
+                // TODO: this is inefficient
+                // TODO: stream output upon response
+                result.addMessageData(fetchResults[j].getMsn(), msgData );
+            }
+        }
+        return result;
+    }
+    
+
+    private String outputMessage(FetchData fetch, MessageResult result,
+            ImapMailboxSession mailbox, boolean useUids)
+            throws MailboxException, ProtocolException {
+        // Check if this fetch will cause the "SEEN" flag to be set on this
+        // message
+        // If so, update the flags, and ensure that a flags response is included
+        // in the response.
+        try {
+            boolean ensureFlagsResponse = false;
+            if (fetch.isSetSeen()
+                    && !result.getFlags().contains(Flags.Flag.SEEN)) {
+                mailbox.setFlags(new Flags(Flags.Flag.SEEN), true, false,
+                        GeneralMessageSetImpl.oneUid(result.getUid()), null);
+                result.getFlags().add(Flags.Flag.SEEN);
+                ensureFlagsResponse = true;
+            }
+
+            StringBuffer response = new StringBuffer();
+
+            // FLAGS response
+            if (fetch.isFlags() || ensureFlagsResponse) {
+                response.append(" FLAGS ");
+                response.append(MessageFlags.format(result.getFlags()));
+            }
+
+            // INTERNALDATE response
+            if (fetch.isInternalDate()) {
+                response.append(" INTERNALDATE \"");
+                // TODO format properly
+                response.append(RFC822DateFormat.toString(result
+                        .getInternalDate())); // not right format
+                response.append("\"");
+
+            }
+
+            // RFC822.SIZE response
+            if (fetch.isSize()) {
+                response.append(" RFC822.SIZE ");
+                response.append(result.getSize());
+            }
+
+            SimpleMessageAttributes attrs = new SimpleMessageAttributes(result
+                    .getMimeMessage(), getLogger());
+
+            // ENVELOPE response
+            if (fetch.isEnvelope()) {
+                response.append(" ENVELOPE ");
+                response.append(attrs.getEnvelope());
+            }
+
+            // BODY response
+            if (fetch.isBody()) {
+                response.append(" BODY ");
+                response.append(attrs.getBodyStructure(false));
+            }
+
+            // BODYSTRUCTURE response
+            if (fetch.isBodyStructure()) {
+                response.append(" BODYSTRUCTURE ");
+                response.append(attrs.getBodyStructure(true));
+            }
+
+            // UID response
+            if (fetch.isUid()) {
+                response.append(" UID ");
+                response.append(result.getUid());
+            }
+
+            // BODY part responses.
+            Collection elements = fetch.getBodyElements();
+            for (Iterator iterator = elements.iterator(); iterator.hasNext();) {
+                BodyFetchElement fetchElement = (BodyFetchElement) iterator
+                        .next();
+                response.append(ImapConstants.SP);
+                response.append(fetchElement.getResponseName());
+                response.append(ImapConstants.SP);
+
+                // Various mechanisms for returning message body.
+                String sectionSpecifier = fetchElement.getParameters();
+
+                MimeMessage mimeMessage = result.getMimeMessage();
+                try {
+                    handleBodyFetch(mimeMessage, sectionSpecifier, response);
+                } catch (MessagingException e) {
+                    throw new MailboxException(e.getMessage(), e);
+                }
+            }
+
+            if (response.length() > 0) {
+                // Remove the leading " ".
+                return response.substring(1);
+            } else {
+                return "";
+            }
+        } catch (MailboxManagerException mme) {
+            throw new MailboxException(mme);
+        } catch (MessagingException me) {
+            throw new MailboxException(me);       
+        }
+    }
+    
+    private void handleBodyFetch( MimeMessage mimeMessage,
+                                  String sectionSpecifier,
+                                  StringBuffer response )
+            throws ProtocolException, MessagingException
+    {
+        if ( sectionSpecifier.length() == 0 ) {
+            // TODO - need to use an InputStream from the response here.
+            ByteArrayOutputStream bout = new ByteArrayOutputStream();
+            try {
+                mimeMessage.writeTo(new CRLFOutputStream(bout));
+            }
+            catch ( IOException e ) {
+                throw new ProtocolException( "Error reading message source", e);
+            }
+            byte[] bytes = bout.toByteArray();
+            addLiteral( bytes, response );
+            // TODO JD maybe we've to add CRLF here
+            
+        }
+        else if ( sectionSpecifier.equalsIgnoreCase( "HEADER" ) ) {
+            Enumeration e = mimeMessage.getAllHeaderLines();
+            addHeaders( e, response );
+        }
+        else if ( sectionSpecifier.startsWith( "HEADER.FIELDS.NOT " ) ) {
+            String[] excludeNames = extractHeaderList( sectionSpecifier, "HEADER.FIELDS.NOT ".length() );
+            Enumeration e = mimeMessage.getNonMatchingHeaderLines( excludeNames );
+            addHeaders( e, response );
+        }
+        else if ( sectionSpecifier.startsWith( "HEADER.FIELDS " ) ) {
+            String[] includeNames = extractHeaderList( sectionSpecifier, "HEADER.FIELDS ".length() );
+            Enumeration e = mimeMessage.getMatchingHeaderLines( includeNames );
+            addHeaders( e, response );
+        }
+        else if ( sectionSpecifier.equalsIgnoreCase( "MIME" ) ) {
+            // TODO implement
+            throw new ProtocolException( "MIME not yet implemented." );
+        }
+        else if ( sectionSpecifier.equalsIgnoreCase( "TEXT" ) ) {
+            // TODO - need to use an InputStream from the response here.
+            // TODO - this is a hack. To get just the body content, I'm using a null
+            // input stream to take the headers. Need to have a way of ignoring headers.
+            ByteArrayOutputStream headerOut = new ByteArrayOutputStream();
+            ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
+            try {
+                // TODO James Trunk : Is this okay?
+                MimeMessageWrapper mmw=new MimeMessageWrapper(mimeMessage);
+                
+                mmw.writeTo(headerOut, bodyOut );
+                byte[] bytes = bodyOut.toByteArray();
+
+                addLiteral( bytes, response );
+
+            }
+            catch ( IOException e ) {
+                throw new ProtocolException( "Error reading message source", e);
+            }
+        }
+        else {
+            // Should be a part specifier followed by a section specifier.
+            // See if there's a leading part specifier.
+            // If so, get the number, get the part, and call this recursively.
+            int dotPos = sectionSpecifier.indexOf( '.' );
+            if ( dotPos == -1 ) {
+                throw new ProtocolException( "Malformed fetch attribute: " + sectionSpecifier );
+            }
+            int partNumber = Integer.parseInt( sectionSpecifier.substring( 0, dotPos ) );
+            String partSectionSpecifier = sectionSpecifier.substring( dotPos + 1 );
+
+            // TODO - get the MimePart of the mimeMessage, and call this method
+            // with the new partSectionSpecifier.
+//        MimeMessage part;
+//        handleBodyFetch( part, partSectionSpecifier, response );
+            throw new ProtocolException( "Mime parts not yet implemented for fetch." );
+        }
+
+    }
+
+    private void addLiteral( byte[] bytes, StringBuffer response )
+    {
+        response.append('{' );
+        response.append( bytes.length ); // TODO JD addLiteral: why was it  bytes.length +1 here?
+        response.append( '}' );
+        response.append( "\r\n" );
+
+        for ( int i = 0; i < bytes.length; i++ ) {
+            byte b = bytes[i];
+            response.append((char)b);
+        }
+    }
+
+    // TODO should do this at parse time.
+    private String[] extractHeaderList( String headerList, int prefixLen )
+    {
+        // Remove the trailing and leading ')('
+        String tmp = headerList.substring( prefixLen + 1, headerList.length() - 1 );
+        String[] headerNames = split( tmp, " " );
+        return headerNames;
+    }
+    
+    private String[] split(String value, String delimiter) {
+        ArrayList strings = new ArrayList();
+        int startPos = 0;
+        int delimPos;
+        while ( (delimPos = value.indexOf(delimiter, startPos) ) != -1) {
+            String sub = value.substring(startPos, delimPos);
+            strings.add(sub);
+            startPos = delimPos + 1;
+        }
+        String sub = value.substring(startPos);
+        strings.add(sub);
+        
+        return (String[]) strings.toArray(new String[0]);
+    }
+
+    private void addHeaders( Enumeration e, StringBuffer response )
+    {
+        List lines = new ArrayList();
+        int count = 0;
+        while (e.hasMoreElements()) {
+            String line = (String)e.nextElement();
+            count += line.length() + 2;
+            lines.add(line);
+        }
+        response.append( '{' );
+        response.append( count + 2 );
+        response.append( '}' );
+        response.append("\r\n");
+
+        Iterator lit = lines.iterator();
+        while (lit.hasNext()) {
+            String line = (String)lit.next();
+            response.append( line );
+            response.append( "\r\n" );
+        }
+        response.append("\r\n");
+    }
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/ListProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/ListProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/ListProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/ListProcessor.java Sun May 13 12:25:39 2007
@@ -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.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapConstants;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.ListResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.ListRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.ListResult;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.impl.ListResultImpl;
+
+
+public class ListProcessor extends AbstractListingProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof ListRequest) {
+			final ListRequest request = (ListRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected ListRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by List processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(ListRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final String baseReferenceName = request.getBaseReferenceName();
+		final String mailboxPatternString = request.getMailboxPattern();
+		final ImapResponseMessage result = doProcess(baseReferenceName, mailboxPatternString, session, tag, command);
+		return result;
+	}
+    
+    protected ListResult[] doList( ImapSession session, String base, String pattern ) throws MailboxException {
+        return doList(  session,  base,  pattern, false);
+    }
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.CommandCompleteResponseMessage;
+import org.apache.james.experimental.imapserver.message.CommandFailedResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.LoginRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.services.User;
+
+
+public class LoginProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof LoginRequest) {
+			final LoginRequest request = (LoginRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected LoginRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Login processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(LoginRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final String userid = request.getUserid();
+		final String passwd = request.getPassword();
+		final ImapResponseMessage result = doProcess(userid, passwd, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final String userid, final String password, 
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        ImapResponseMessage result;
+        if ( session.getUsers().test( userid, password ) ) {
+            User user = session.getUsers().getUserByName( userid );
+            session.setAuthenticated( user );
+            result = CommandCompleteResponseMessage.createWithNoUnsolictedResponses(command, tag);
+        }
+        else {
+            result = new CommandFailedResponseMessage( command, "Invalid login/password", tag );
+        }
+        return result;
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LogoutProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LogoutProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LogoutProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LogoutProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,64 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.LogoutResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.LogoutRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+
+
+public class LogoutProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof LogoutRequest) {
+			final LogoutRequest request = (LogoutRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected LogoutRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Logout processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(LogoutRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result = doProcess(session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        final LogoutResponseMessage result = new LogoutResponseMessage(command, tag);
+        return result;
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LsubProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LsubProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LsubProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LsubProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,64 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.LsubRequest;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.ListResult;
+
+
+public class LsubProcessor extends AbstractListingProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof LsubRequest) {
+			final LsubRequest request = (LsubRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected LsubRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Lsub processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(LsubRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final String baseReferenceName = request.getBaseReferenceName();
+		final String mailboxPatternString = request.getMailboxPattern();
+		final ImapResponseMessage result = doProcess(baseReferenceName, mailboxPatternString, session, tag, command);
+		return result;
+	}
+    
+    protected ListResult[] doList( ImapSession session, String base, String pattern ) throws MailboxException {
+        return doList(  session,  base,  pattern, true);
+    }
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/NoopProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/NoopProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/NoopProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/NoopProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,64 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.CommandCompleteResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.NoopRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+
+
+public class NoopProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof NoopRequest) {
+			final NoopRequest request = (NoopRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected NoopRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Noop processor.");
+		}
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(NoopRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result = doProcess(session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        // TODO: untagged responses?
+        final CommandCompleteResponseMessage result = new CommandCompleteResponseMessage(false, command, tag);
+        return result;
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/RenameProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/RenameProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/RenameProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/RenameProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,75 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.CommandCompleteResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.RenameRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+
+public class RenameProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof RenameRequest) {
+			final RenameRequest request = (RenameRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected RenameRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Rename processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(RenameRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final String existingName = request.getExistingName();
+		final String newName = request.getNewName();
+		final ImapResponseMessage result = doProcess(existingName, newName, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final String existingName, final String newName, 
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        try {
+            final String fullExistingName=session.buildFullName(existingName);
+            final String fullNewName=session.buildFullName(newName);
+            session.getMailboxManager().renameMailbox( fullExistingName, fullNewName );
+        } catch (MailboxManagerException e) {
+           throw new MailboxException(e);
+        }
+
+        return new CommandCompleteResponseMessage(false, command, tag);
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SearchProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SearchProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SearchProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SearchProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,102 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import javax.mail.search.SearchTerm;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapConstants;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.SearchResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.SearchRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+
+
+public class SearchProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof SearchRequest) {
+			final SearchRequest request = (SearchRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected SearchRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Search processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(SearchRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final SearchTerm searchTerm = request.getSearchTerm();
+		final boolean useUids = request.isUseUids();
+		final ImapResponseMessage result = doProcess(searchTerm, useUids, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final SearchTerm searchTerm, final boolean useUids, 
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        ImapMailboxSession mailbox = session.getSelected().getMailbox();
+        final int resultCode;
+        if (useUids) {
+            resultCode= MessageResult.UID;
+        } else {
+            resultCode= MessageResult.MSN;
+        }
+        MessageResult[] messageResults;
+        try {
+            messageResults = mailbox.search(GeneralMessageSetImpl.all(),searchTerm, resultCode);
+        } catch (MailboxManagerException e) {
+          throw new MailboxException(e);
+        }
+        // TODO: probably more efficient to stream data
+        // TODO: directly to response
+        StringBuffer idList = new StringBuffer();
+        for (int i = 0; i < messageResults.length; i++) {
+            if ( i > 0 ) {
+                idList.append( ImapConstants.SP );
+            }
+            if ( useUids ) {
+                idList.append( messageResults[i].getUid());
+            } else {
+                idList.append( messageResults[i].getMsn());
+            }
+        }
+        final SearchResponseMessage result = 
+            new SearchResponseMessage(command, idList.toString(), 
+                    useUids, tag);
+        return result;
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StatusProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StatusProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StatusProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StatusProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,134 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapConstants;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.StatusDataItems;
+import org.apache.james.experimental.imapserver.message.StatusResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.StatusRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+
+
+public class StatusProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof StatusRequest) {
+			final StatusRequest request = (StatusRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected StatusRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Status processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(StatusRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+	    final String mailboxName = request.getMailboxName();
+	    final StatusDataItems statusDataItems = request.getStatusDataItems();
+		final ImapResponseMessage result = doProcess(mailboxName, statusDataItems, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final String mailboxName, final StatusDataItems statusDataItems,
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        final Logger logger = getLogger(); 
+
+        // TODO: response should not be prepared in process
+        // TODO: return a transfer object
+        StringBuffer buffer = new StringBuffer( mailboxName );
+        buffer.append( ImapConstants.SP );
+        buffer.append( "(" );
+        try {
+            String fullMailboxName= session.buildFullName(mailboxName);
+            
+            if (logger != null && logger.isDebugEnabled()) { 
+                logger.debug("Status called on mailbox named " + mailboxName + " (" + fullMailboxName + ")"); 
+            }
+            
+            ImapMailboxSession mailbox = session.getMailboxManager().getImapMailboxSession(fullMailboxName);
+            
+            if (statusDataItems.isMessages()) {
+                buffer.append(ImapConstants.STATUS_MESSAGES);
+                buffer.append(ImapConstants.SP);
+
+                buffer.append(mailbox.getMessageCount());
+
+                buffer.append(ImapConstants.SP);
+            }
+
+            if (statusDataItems.isRecent()) {
+                buffer.append(ImapConstants.STATUS_RECENT);
+                buffer.append(ImapConstants.SP);
+                buffer.append(mailbox.getRecentCount(false));
+                buffer.append(ImapConstants.SP);
+            }
+
+            if (statusDataItems.isUidNext()) {
+                buffer.append(ImapConstants.STATUS_UIDNEXT);
+                buffer.append(ImapConstants.SP);
+                buffer.append(mailbox.getUidNext());
+                buffer.append(ImapConstants.SP);
+            }
+
+            if (statusDataItems.isUidValidity()) {
+                buffer.append(ImapConstants.STATUS_UIDVALIDITY);
+                buffer.append(ImapConstants.SP);
+                buffer.append(mailbox.getUidValidity());
+                buffer.append(ImapConstants.SP);
+            }
+
+            if (statusDataItems.isUnseen()) {
+                buffer.append(ImapConstants.STATUS_UNSEEN);
+                buffer.append(ImapConstants.SP);
+                buffer.append(mailbox.getUnseenCount());
+                buffer.append(ImapConstants.SP);
+            }
+        } catch (MailboxManagerException e) {
+            if (logger != null && logger.isDebugEnabled()) { 
+                logger.debug("STATUS command failed: ", e); 
+            }
+            throw new MailboxException(e);
+        }
+        if ( buffer.charAt( buffer.length() - 1 ) == ' ' ) {
+            buffer.setLength( buffer.length() - 1 );
+        }
+        buffer.append(')');
+        final StatusResponseMessage result = 
+            new StatusResponseMessage(command, buffer.toString(), tag);
+        return result;
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StoreProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StoreProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StoreProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/StoreProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,114 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import javax.mail.Flags;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.IdRange;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.StoreDirective;
+import org.apache.james.experimental.imapserver.message.StoreResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.StoreRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+
+
+public class StoreProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof StoreRequest) {
+			final StoreRequest request = (StoreRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected StoreRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Store processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(StoreRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final IdRange[] idSet = request.getIdSet();
+	    final StoreDirective directive = request.getDirective();
+	    final Flags flags = request.getFlags();
+	    final boolean useUids = request.isUseUids();
+		final ImapResponseMessage result = doProcess(idSet, directive, flags, useUids, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final IdRange[] idSet, final StoreDirective directive,
+			final Flags flags, final boolean useUids, 
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+
+        ImapMailboxSession mailbox = session.getSelected().getMailbox();
+        MailboxListener silentListener = null;
+
+        final boolean replace;
+        final boolean value;
+        if (directive.getSign() < 0) {
+            value=false;
+            replace=false;
+        }
+        else if (directive.getSign() > 0) {
+            value=true;
+            replace=false;
+        }
+        else {
+            replace=true;
+            value=true;
+        }
+        try {
+            if (directive.isSilent()) {
+                silentListener = session.getSelected().getMailbox();
+            }
+            for (int i = 0; i < idSet.length; i++) {
+                final GeneralMessageSet messageSet = GeneralMessageSetImpl
+                        .range(idSet[i].getLowVal(), idSet[i].getHighVal(),
+                                useUids);
+
+                mailbox.setFlags(flags, value, replace, messageSet,
+                        silentListener);
+            }
+        } catch (MailboxManagerException e) {
+            throw new MailboxException(e);
+        }
+        
+        final StoreResponseMessage result = 
+            new StoreResponseMessage(command, useUids, tag);
+        return result;
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SubscribeProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SubscribeProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SubscribeProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/SubscribeProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,72 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.CommandCompleteResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.SubscribeRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+
+public class SubscribeProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof SubscribeRequest) {
+			final SubscribeRequest request = (SubscribeRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected SubscribeRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Subscribe processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(SubscribeRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final String mailboxName = request.getMailboxName();
+		final ImapResponseMessage result = doProcess(mailboxName, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final String mailboxName, 
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        try {
+            final String fullMailboxName = session.buildFullName(mailboxName);
+            session.getMailboxManager().setSubscription(fullMailboxName,true);
+        } catch (MailboxManagerException e) {
+           throw new MailboxException(e);
+        }
+        return new CommandCompleteResponseMessage(false, command, tag);
+	}
+}

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/UnsubscribeProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/UnsubscribeProcessor.java?view=auto&rev=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/UnsubscribeProcessor.java (added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/UnsubscribeProcessor.java Sun May 13 12:25:39 2007
@@ -0,0 +1,72 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.experimental.imapserver.processor.imap4rev1;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.experimental.imapserver.AuthorizationException;
+import org.apache.james.experimental.imapserver.ImapSession;
+import org.apache.james.experimental.imapserver.ProtocolException;
+import org.apache.james.experimental.imapserver.commands.ImapCommand;
+import org.apache.james.experimental.imapserver.message.BadResponseMessage;
+import org.apache.james.experimental.imapserver.message.CommandCompleteResponseMessage;
+import org.apache.james.experimental.imapserver.message.ImapResponseMessage;
+import org.apache.james.experimental.imapserver.message.request.AbstractImapRequest;
+import org.apache.james.experimental.imapserver.message.request.imap4rev1.UnsubscribeRequest;
+import org.apache.james.experimental.imapserver.processor.AbstractImapRequestProcessor;
+import org.apache.james.experimental.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+
+public class UnsubscribeProcessor extends AbstractImapRequestProcessor {
+	
+	protected ImapResponseMessage doProcess(AbstractImapRequest message, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final ImapResponseMessage result;
+		if (message instanceof UnsubscribeRequest) {
+			final UnsubscribeRequest request = (UnsubscribeRequest) message;
+			result = doProcess(request, session, tag, command);
+		} else {
+			final Logger logger = getLogger();
+			if (logger != null)
+			{
+				logger.debug("Expected UnsubscribeRequest, was " + message);
+			}
+			result = new BadResponseMessage("Command unknown by Unsubscribe processor.");
+		}
+		
+		return result;
+	}
+
+	private ImapResponseMessage doProcess(UnsubscribeRequest request, ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+		final String authType = request.getMailboxName();
+		final ImapResponseMessage result = doProcess(authType, session, tag, command);
+		return result;
+	}
+	
+	private ImapResponseMessage doProcess(final String mailboxName, 
+			ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        try {
+            final String fullMailboxName=session.buildFullName(mailboxName);
+            session.getMailboxManager().setSubscription(fullMailboxName,false);
+        } catch (MailboxManagerException e) {
+            throw new MailboxException(e);
+        }
+        return new CommandCompleteResponseMessage(false, command, tag);
+	}
+}

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/commands/MockCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/commands/MockCommand.java?view=diff&rev=537643&r1=537642&r2=537643
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/commands/MockCommand.java (original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/commands/MockCommand.java Sun May 13 12:25:39 2007
@@ -3,7 +3,7 @@
 import org.apache.james.experimental.imapserver.ImapRequestLineReader;
 import org.apache.james.experimental.imapserver.ProtocolException;
 import org.apache.james.experimental.imapserver.commands.CommandTemplate;
-import org.apache.james.experimental.imapserver.message.ImapCommandMessage;
+import org.apache.james.experimental.imapserver.message.ImapRequestMessage;
 
 public class MockCommand extends CommandTemplate {
 
@@ -17,7 +17,7 @@
         return NAME;
     }
 
-    protected ImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
+    protected ImapRequestMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
         // TODO implementation
         return null;
     }



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


Mime
View raw message