james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r730977 - in /james/protocols/imap/trunk: api/src/main/java/org/apache/james/api/imap/process/ mailbox/src/main/java/org/apache/james/imap/mailbox/util/ mailbox/src/test/java/org/apache/james/mailboxmanager/util/ processor/src/main/java/org...
Date Sat, 03 Jan 2009 12:34:40 GMT
Author: rdonkin
Date: Sat Jan  3 04:34:39 2009
New Revision: 730977

URL: http://svn.apache.org/viewvc?rev=730977&view=rev
Log:
Move response composition out from selected mailbox

Removed:
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/AbstractImapRequestProcessor.java
Modified:
    james/protocols/imap/trunk/api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
    james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/mailboxmanager/util/MailboxEventAnalyserTest.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/AbstractMailboxAwareProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AppendProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AuthenticateProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CapabilityProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CheckProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CloseProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/ExpungeProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/Imap4Rev1ProcessorFactory.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/LogoutProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/NoopProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/RenameProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/SearchProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/StoreProcessor.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/fetch/FetchProcessor.java
    james/protocols/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/imap4rev1/SearchProcessorTest.java

Modified: james/protocols/imap/trunk/api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java (original)
+++ james/protocols/imap/trunk/api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java Sat Jan  3 04:34:39 2009
@@ -19,15 +19,13 @@
 
 package org.apache.james.api.imap.process;
 
-import java.util.List;
+import java.util.Collection;
+
 
 public interface SelectedImapMailbox {
 
     public abstract void deselect();
 
-    public abstract List unsolicitedResponses(boolean omitExpunged,
-            boolean useUid);
-
     public int msn(long uid);
 
     public abstract long uid(int i);
@@ -51,4 +49,18 @@
      *         otherwise
      */
     public boolean isDeletedByOtherSession();
+
+    public boolean isSizeChanged();
+
+    public boolean isRecentUidRemoved();
+
+    public void resetRecentUidRemoved();
+
+    public void resetEvents();
+
+    public Collection<Long> expungedUids();
+
+    public void expunged(Collection<Long> expungedUids);
+
+    public Collection<Long> flagUpdateUids();
 }
\ No newline at end of file

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java (original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java Sat Jan  3 04:34:39 2009
@@ -19,6 +19,8 @@
 
 package org.apache.james.imap.mailbox.util;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.TreeSet;
@@ -37,17 +39,17 @@
 
     private final long sessionId;
 
-    private final Set flagUpdateUids;
+    private final Set<Long> flagUpdateUids;
 
     private final Flags.Flag uninterestingFlag;
 
-    private final Set expungedUids;
+    private final Set<Long> expungedUids;
 
     public MailboxEventAnalyser(final long sessionId) {
         super();
         this.sessionId = sessionId;
-        flagUpdateUids = new TreeSet();
-        expungedUids = new TreeSet();
+        flagUpdateUids = new TreeSet<Long>();
+        expungedUids = new TreeSet<Long>();
         uninterestingFlag = Flags.Flag.RECENT;
     }
 
@@ -139,12 +141,12 @@
         return isDeletedByOtherSession;
     }
 
-    public Iterator flagUpdateUids() {
-        return flagUpdateUids.iterator();
+    public Collection<Long> flagUpdateUids() {
+        return Collections.unmodifiableSet(flagUpdateUids);
     }
 
-    public Iterator expungedUids() {
-        return expungedUids.iterator();
+    public Collection<Long> expungedUids() {
+        return Collections.unmodifiableSet(expungedUids);
     }
 
     public boolean hasExpungedUids() {

Modified: james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/mailboxmanager/util/MailboxEventAnalyserTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/mailboxmanager/util/MailboxEventAnalyserTest.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/mailboxmanager/util/MailboxEventAnalyserTest.java (original)
+++ james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/mailboxmanager/util/MailboxEventAnalyserTest.java Sat Jan  3 04:34:39 2009
@@ -69,7 +69,7 @@
                 90, new Flags(), 11);
         analyser.event(update);
         assertNotNull(analyser.flagUpdateUids());
-        assertFalse(analyser.flagUpdateUids().hasNext());
+        assertFalse(analyser.flagUpdateUids().iterator().hasNext());
     }
 
     public void testShouldSetUidWhenSystemFlagChange() throws Exception {
@@ -78,7 +78,7 @@
                 uid, new Flags(), 11);
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.event(update);
-        final Iterator iterator = analyser.flagUpdateUids();
+        final Iterator iterator = analyser.flagUpdateUids().iterator();
         assertNotNull(iterator);
         assertTrue(iterator.hasNext());
         assertEquals(new Long(uid), iterator.next());
@@ -93,7 +93,7 @@
         analyser.event(update);
         analyser.reset();
         assertNotNull(analyser.flagUpdateUids());
-        assertFalse(analyser.flagUpdateUids().hasNext());
+        assertFalse(analyser.flagUpdateUids().iterator().hasNext());
     }
 
     public void testShouldNotSetUidWhenSystemFlagChangeDifferentSessionInSilentMode()
@@ -104,7 +104,7 @@
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.setSilentFlagChanges(true);
         analyser.event(update);
-        final Iterator iterator = analyser.flagUpdateUids();
+        final Iterator iterator = analyser.flagUpdateUids().iterator();
         assertNotNull(iterator);
         assertTrue(iterator.hasNext());
         assertEquals(new Long(uid), iterator.next());
@@ -118,7 +118,7 @@
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.setSilentFlagChanges(true);
         analyser.event(update);
-        final Iterator iterator = analyser.flagUpdateUids();
+        final Iterator iterator = analyser.flagUpdateUids().iterator();
         assertNotNull(iterator);
         assertFalse(iterator.hasNext());
     }
@@ -128,7 +128,7 @@
                 886, new Flags(), BASE_SESSION_ID);
         update.flags.add(Flags.Flag.RECENT);
         analyser.event(update);
-        final Iterator iterator = analyser.flagUpdateUids();
+        final Iterator iterator = analyser.flagUpdateUids().iterator();
         assertNotNull(iterator);
         assertFalse(iterator.hasNext());
     }

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/AbstractMailboxAwareProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/AbstractMailboxAwareProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/AbstractMailboxAwareProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/AbstractMailboxAwareProcessor.java Sat Jan  3 04:34:39 2009
@@ -18,26 +18,307 @@
  ****************************************************************/
 package org.apache.james.imap.processor.base;
 
+import static org.apache.james.api.imap.ImapConstants.NAMESPACE_PREFIX;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.MessagingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.display.HumanReadableTextKey;
+import org.apache.james.api.imap.message.request.ImapRequest;
+import org.apache.james.api.imap.message.response.ImapResponseMessage;
+import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.api.imap.process.SelectedImapMailbox;
+import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxExistsException;
 import org.apache.james.imap.mailbox.MailboxManager;
 import org.apache.james.imap.mailbox.MailboxManagerProvider;
+import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.MessageRange;
+import org.apache.james.imap.mailbox.MessageResult;
+import org.apache.james.imap.mailbox.util.FetchGroupImpl;
+import org.apache.james.imap.mailbox.util.MessageRangeImpl;
+import org.apache.james.imap.message.response.imap4rev1.ExistsResponse;
+import org.apache.james.imap.message.response.imap4rev1.ExpungeResponse;
+import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
+import org.apache.james.imap.message.response.imap4rev1.RecentResponse;
+import org.apache.james.imap.message.response.imap4rev1.status.UntaggedNoResponse;
 
-abstract public class AbstractMailboxAwareProcessor extends
-        AbstractImapRequestProcessor {
+abstract public class AbstractMailboxAwareProcessor extends AbstractChainedImapProcessor {
 
     private final MailboxManagerProvider mailboxManagerProvider;
 
+    private final StatusResponseFactory factory;
+
     public AbstractMailboxAwareProcessor(final ImapProcessor next,
             final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next);
         this.mailboxManagerProvider = mailboxManagerProvider;
+        
+        this.factory = factory;
+    }
+
+    protected final void doProcess(final ImapMessage acceptableMessage,
+            final Responder responder, final ImapSession session) {
+        final ImapRequest request = (ImapRequest) acceptableMessage;
+        process(request, responder, session);
+    }
+
+    protected final void process(final ImapRequest message,
+            final Responder responder, final ImapSession session) {
+        final ImapCommand command = message.getCommand();
+        final String tag = message.getTag();
+        doProcess(message, command, tag, responder, session);
+    }
+
+    protected void no(final ImapCommand command, final String tag,
+            final Responder responder, final MessagingException e) {
+        final Log logger = getLog();
+        final ImapResponseMessage response;
+        if (e instanceof MailboxExistsException) {
+            response = factory.taggedNo(tag, command,
+                    HumanReadableTextKey.FAILURE_MAILBOX_EXISTS);
+        } else if (e instanceof MailboxNotFoundException) {
+            response = factory.taggedNo(tag, command,
+                    HumanReadableTextKey.FAILURE_NO_SUCH_MAILBOX);
+        } else {
+            if (logger != null) {
+                logger.info(e.getMessage());
+                logger.debug("Processing failed:", e);
+            }
+            response = factory.taggedNo(tag, command,
+                    HumanReadableTextKey.GENERIC_FAILURE_DURING_PROCESSING);
+        }
+        responder.respond(response);
+    }
+
+    final void doProcess(final ImapRequest message, final ImapCommand command,
+            final String tag, Responder responder, ImapSession session) {
+        if (!command.validForState(session.getState())) {
+            ImapResponseMessage response = factory.taggedNo(tag, command,
+                    HumanReadableTextKey.INVALID_COMMAND);
+            responder.respond(response);
+
+        } else {
+            doProcess(message, session, tag, command, responder);
+        }
+    }
+
+    protected void unsolicitedResponses(final ImapSession session,
+            final ImapProcessor.Responder responder, boolean omitExpunged,
+            boolean useUids) {
+        final List responses = unsolicitedResponses(session, omitExpunged, useUids);
+        respond(responder, responses);
+    }
+
+    protected void unsolicitedResponses(final ImapSession session,
+            final ImapProcessor.Responder responder, boolean useUids) {
+        final List responses = unsolicitedResponses(session, useUids);
+        respond(responder, responses);
+    }
+
+    protected List unsolicitedResponses(final ImapSession session, boolean useUid) {
+        return unsolicitedResponses(session, false, useUid);
+    }
+
+    /**
+     * Sends any unsolicited responses to the client, such as EXISTS and FLAGS
+     * responses when the selected mailbox is modified by another user.
+     * 
+     * @return <code>List</code> of {@link ImapResponseMessage}'s
+     */
+    protected List unsolicitedResponses(final ImapSession session, boolean omitExpunged, boolean useUid) {
+        final List results;
+        final SelectedImapMailbox selected = session.getSelected();
+        if (selected == null) {
+            results = Collections.EMPTY_LIST;
+        } else {
+            results = unsolicitedResponses(session, selected, omitExpunged, useUid);
+        }
+        return results;
+    }
+
+    /**
+     * @see org.apache.james.api.imap.process.SelectedImapMailbox#unsolicitedResponses(boolean,
+     *      boolean)
+     */
+    public List unsolicitedResponses(final ImapSession session, final SelectedImapMailbox selected, boolean omitExpunged, boolean useUid) {
+        final List results = new ArrayList();
+        final boolean sizeChanged = selected.isSizeChanged();
+        // New message response
+            if (sizeChanged) {
+                addExistsResponses(session, selected, results);
+            }
+            // Expunged messages
+            if (!omitExpunged) {
+                addExpungedResponses(selected, results);
+            }
+            if (sizeChanged || (selected.isRecentUidRemoved() && !omitExpunged)) {
+                addRecentResponses(selected, results);
+                selected.resetRecentUidRemoved();
+            }
+    
+            // Message updates
+            addFlagsResponses(session, selected, results, useUid);
+    
+            selected.resetEvents();
+
+        return results;
+    }
+
+    private void addExpungedResponses(final SelectedImapMailbox selected, List responses) {
+        final Collection<Long> expungedUids = selected.expungedUids();
+        for (final Long uid: expungedUids) {
+            final long uidValue = uid.longValue();
+            final int msn = selected.msn(uidValue);
+            // TODO: use factory
+            ExpungeResponse response = new ExpungeResponse(msn);
+            responses.add(response);
+        }
+        selected.expunged(expungedUids);
     }
 
+    private void addFlagsResponses(final ImapSession session, final SelectedImapMailbox selected, final List responses, boolean useUid) {
+        try {
+            final Collection<Long> flagUpdateUids = selected.flagUpdateUids();
+            if (!flagUpdateUids.isEmpty()) {
+                final Mailbox mailbox = getMailbox(session, selected);
+                final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+                for (final Long uid: flagUpdateUids) {
+                    MessageRange messageSet = MessageRangeImpl.oneUid(uid.longValue());
+                    addFlagsResponses(session, selected, responses, useUid, messageSet, mailbox, mailboxSession);
+                }
+            }
+        } catch (MessagingException e) {
+            final String message = "Failed to retrieve flags data";
+            handleResponseException(responses, e, message);
+        }
+    }
+
+    private void addFlagsResponses(final ImapSession session, final SelectedImapMailbox selected, 
+            final List responses, boolean useUid, MessageRange messageSet, Mailbox mailbox, MailboxSession mailboxSession)
+    throws MailboxException {
+        final Iterator it = mailbox.getMessages(messageSet, FetchGroupImpl.FLAGS, mailboxSession);
+        while (it.hasNext()) {
+            MessageResult mr = (MessageResult) it.next();
+            final long uid = mr.getUid();
+            int msn = selected.msn(uid);
+            final Flags flags = mr.getFlags();
+            final Long uidOut;
+            if (useUid) {
+                uidOut = new Long(uid);
+            } else {
+                uidOut = null;
+            }
+            if (selected.isRecent(uid)) {
+                flags.add(Flags.Flag.RECENT);
+            } else {
+                flags.remove(Flags.Flag.RECENT);
+            }
+            FetchResponse response = new FetchResponse(msn, flags, uidOut,
+                    null, null, null, null, null, null);
+            responses.add(response);
+        }
+    }
+
+    private Mailbox getMailbox(final ImapSession session, final SelectedImapMailbox selected) throws MailboxException {
+        final String fullMailboxName = buildFullName(session, selected.getName());
+        final MailboxManager mailboxManager = getMailboxManager(session);
+        final Mailbox mailbox = mailboxManager.getMailbox(fullMailboxName, false);
+        return mailbox;
+    }
+
+    private void addRecentResponses(final SelectedImapMailbox selected, final List responses) {
+        final int recentCount = selected.recentCount();
+//      TODO: use factory
+        RecentResponse response = new RecentResponse(recentCount);
+        responses.add(response);
+    }
+
+    private void addExistsResponses(final ImapSession session, final SelectedImapMailbox selected, final List responses) {
+        try {
+            final Mailbox mailbox = getMailbox(session, selected);
+            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final int messageCount = mailbox.getMessageCount(mailboxSession);
+            // TODO: use factory
+            ExistsResponse response = new ExistsResponse(messageCount);
+            responses.add(response);
+        } catch (MailboxException e) {
+            final String message = "Failed to retrieve exists count data";
+            handleResponseException(responses, e, message);
+        }
+    }
+
+    private void handleResponseException(final List responses,
+            MessagingException e, final String message) {
+        getLog().info(message);
+        getLog().debug(message, e);
+        // TODO: consider whether error message should be passed to the user
+        UntaggedNoResponse response = new UntaggedNoResponse(message, null);
+        responses.add(response);
+    }
+    
+    private void respond(final ImapProcessor.Responder responder,
+            final List responses) {
+        for (final Iterator it = responses.iterator(); it.hasNext();) {
+            ImapResponseMessage message = (ImapResponseMessage) it.next();
+            responder.respond(message);
+        }
+    }
+
+    protected void okComplete(final ImapCommand command, final String tag,
+            final ImapProcessor.Responder responder) {
+        final StatusResponse response = factory.taggedOk(tag, command,
+                HumanReadableTextKey.COMPLETED);
+        responder.respond(response);
+    }
+
+    protected void no(final ImapCommand command, final String tag,
+            final ImapProcessor.Responder responder,
+            final HumanReadableTextKey displayTextKey) {
+        final StatusResponse response = factory.taggedNo(tag, command,
+                displayTextKey);
+        responder.respond(response);
+    }
+
+    protected void no(final ImapCommand command, final String tag,
+            final ImapProcessor.Responder responder,
+            final HumanReadableTextKey displayTextKey,
+            final StatusResponse.ResponseCode responseCode) {
+        final StatusResponse response = factory.taggedNo(tag, command,
+                displayTextKey, responseCode);
+        responder.respond(response);
+    }
+
+    protected void bye(final ImapProcessor.Responder responder) {
+        final StatusResponse response = factory.bye(HumanReadableTextKey.BYE);
+        responder.respond(response);
+    }
+
+    protected void bye(final ImapProcessor.Responder responder,
+            final HumanReadableTextKey key) {
+        final StatusResponse response = factory.bye(key);
+        responder.respond(response);
+    }
+
+    protected abstract void doProcess(final ImapRequest message,
+            ImapSession session, String tag, ImapCommand command,
+            Responder responder);
+
     public String buildFullName(final ImapSession session, String mailboxName)
             throws MailboxException {
         final String user = ImapSessionUtils.getUserName(session);

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java Sat Jan  3 04:34:39 2009
@@ -19,31 +19,18 @@
 
 package org.apache.james.imap.processor.base;
 
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 
-import javax.mail.Flags;
-import javax.mail.MessagingException;
-
 import org.apache.james.api.imap.AbstractLogEnabled;
 import org.apache.james.api.imap.process.SelectedImapMailbox;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
-import org.apache.james.imap.mailbox.MessageRange;
-import org.apache.james.imap.mailbox.MessageResult;
-import org.apache.james.imap.mailbox.util.FetchGroupImpl;
 import org.apache.james.imap.mailbox.util.MailboxEventAnalyser;
-import org.apache.james.imap.mailbox.util.MessageRangeImpl;
 import org.apache.james.imap.mailbox.util.UidToMsnConverter;
-import org.apache.james.imap.message.response.imap4rev1.ExistsResponse;
-import org.apache.james.imap.message.response.imap4rev1.ExpungeResponse;
-import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
-import org.apache.james.imap.message.response.imap4rev1.RecentResponse;
-import org.apache.james.imap.message.response.imap4rev1.status.UntaggedNoResponse;
 
 // TODO: deal with deleted or renamed mailboxes
 public class SelectedMailboxSessionImpl extends AbstractLogEnabled implements
@@ -55,9 +42,7 @@
 
     private final UidToMsnConverter converter;
 
-    private final MailboxSession mailboxSession;
-
-    private final Set recentUids;
+    private final Set<Long> recentUids;
 
     private boolean recentUidRemoved;
 
@@ -66,8 +51,7 @@
     public SelectedMailboxSessionImpl(Mailbox mailbox, List uids,
             MailboxSession mailboxSession, final String name) throws MailboxException {
         this.mailbox = mailbox;
-        this.mailboxSession = mailboxSession;
-        recentUids = new TreeSet();
+        recentUids = new TreeSet<Long>();
         recentUidRemoved = false;
         final long sessionId = mailboxSession.getSessionId();
         events = new MailboxEventAnalyser(sessionId);
@@ -90,33 +74,6 @@
         return events.isSizeChanged();
     }
 
-    /**
-     * @see org.apache.james.api.imap.process.SelectedImapMailbox#unsolicitedResponses(boolean,
-     *      boolean)
-     */
-    public List unsolicitedResponses(boolean omitExpunged, boolean useUid) {
-        final List results = new ArrayList();
-        final boolean sizeChanged = isSizeChanged();
-        // New message response
-        if (sizeChanged) {
-            addExistsResponses(results);
-        }
-        // Expunged messages
-        if (!omitExpunged) {
-            addExpungedResponses(results);
-        }
-        if (sizeChanged || (recentUidRemoved && !omitExpunged)) {
-            addRecentResponses(results);
-            recentUidRemoved = false;
-        }
-
-        // Message updates
-        addFlagsResponses(results, useUid);
-
-        events.reset();
-        return results;
-    }
-
     public int msn(long uid) {
         return converter.getMsn(uid);
     }
@@ -131,90 +88,6 @@
         return events.isDeletedByOtherSession();
     }
 
-    private void addExpungedResponses(List responses) {
-        for (Iterator it = events.expungedUids(); it.hasNext();) {
-            final Long uid = (Long) it.next();
-            final long uidValue = uid.longValue();
-            final int msn = msn(uidValue);
-            // TODO: use factory
-            ExpungeResponse response = new ExpungeResponse(msn);
-            responses.add(response);
-        }
-
-        for (Iterator it = events.expungedUids(); it.hasNext();) {
-            final Long uid = (Long) it.next();
-            final long uidValue = uid.longValue();
-            converter.expunge(uidValue);
-        }
-    }
-
-    private void addFlagsResponses(final List responses, boolean useUid) {
-        try {
-            for (final Iterator it = events.flagUpdateUids(); it.hasNext();) {
-                Long uid = (Long) it.next();
-                MessageRange messageSet = MessageRangeImpl.oneUid(uid
-                        .longValue());
-                addFlagsResponses(responses, useUid, messageSet);
-            }
-        } catch (MessagingException e) {
-            final String message = "Failed to retrieve flags data";
-            handleResponseException(responses, e, message);
-        }
-    }
-
-    private void addFlagsResponses(final List responses, boolean useUid, MessageRange messageSet)
-            throws MailboxException {
-        final Iterator it = mailbox.getMessages(messageSet, FetchGroupImpl.FLAGS, mailboxSession);
-        while (it.hasNext()) {
-            MessageResult mr = (MessageResult) it.next();
-            final long uid = mr.getUid();
-            int msn = msn(uid);
-            final Flags flags = mr.getFlags();
-            final Long uidOut;
-            if (useUid) {
-                uidOut = new Long(uid);
-            } else {
-                uidOut = null;
-            }
-            if (isRecent(uid)) {
-                flags.add(Flags.Flag.RECENT);
-            } else {
-                flags.remove(Flags.Flag.RECENT);
-            }
-            FetchResponse response = new FetchResponse(msn, flags, uidOut,
-                    null, null, null, null, null, null);
-            responses.add(response);
-        }
-    }
-
-    private void addRecentResponses(final List responses) {
-        final int recentCount = recentCount();
-        // TODO: use factory
-        RecentResponse response = new RecentResponse(recentCount);
-        responses.add(response);
-    }
-
-    private void handleResponseException(final List responses,
-            MessagingException e, final String message) {
-        getLog().info(message);
-        getLog().debug(message, e);
-        // TODO: consider whether error message should be passed to the user
-        UntaggedNoResponse response = new UntaggedNoResponse(message, null);
-        responses.add(response);
-    }
-
-    private void addExistsResponses(final List responses) {
-        try {
-            final int messageCount = mailbox.getMessageCount(mailboxSession);
-            // TODO: use factory
-            ExistsResponse response = new ExistsResponse(messageCount);
-            responses.add(response);
-        } catch (MailboxException e) {
-            final String message = "Failed to retrieve exists count data";
-            handleResponseException(responses, e, message);
-        }
-    }
-
     public long uid(int msn) {
         return converter.getUid(msn);
     }
@@ -236,8 +109,7 @@
         checkExpungedRecents();
         final long[] results = new long[recentUids.size()];
         int count = 0;
-        for (Iterator it = recentUids.iterator(); it.hasNext();) {
-            Long uid = (Long) it.next();
+        for (final Long uid: recentUids) {
             results[count++] = uid.longValue();
         }
         return results;
@@ -253,16 +125,14 @@
     }
 
     private void checkExpungedRecents() {
-        for (final Iterator it = events.expungedUids(); it.hasNext();) {
-            final Long uid = (Long) it.next();
+        for (final Long uid: events.expungedUids()) {
             removeRecent(uid.longValue());
         }
     }
 
     public boolean isRecent(long uid) {
         boolean result = false;
-        for (Iterator ir = recentUids.iterator(); ir.hasNext();) {
-            Long recentUid = (Long) ir.next();
+        for (final Long recentUid: recentUids) {
             if (recentUid.longValue() == uid) {
                 result = true;
                 break;
@@ -270,4 +140,31 @@
         }
         return result;
     }
+
+    public boolean isRecentUidRemoved() {
+        return recentUidRemoved;
+    }
+
+    public void resetRecentUidRemoved() {
+        recentUidRemoved = false;
+    }
+
+    public void resetEvents() {
+        events.reset();
+    }
+
+    public Collection<Long> expungedUids() {
+        return events.expungedUids();
+    }
+
+    public void expunged(Collection<Long> expungedUids) {
+        for (final Long uid: expungedUids) {
+            final long uidValue = uid.longValue();
+            converter.expunge(uidValue);
+        }
+    }
+
+    public Collection<Long> flagUpdateUids() {
+        return events.flagUpdateUids();
+    }
 }

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AppendProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AppendProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AppendProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AppendProcessor.java Sat Jan  3 04:34:39 2009
@@ -73,8 +73,7 @@
 
             final String fullMailboxName = buildFullName(session, mailboxName);
             final MailboxManager mailboxManager = getMailboxManager(session);
-            final Mailbox mailbox = mailboxManager.getMailbox(fullMailboxName,
-                    false);
+            final Mailbox mailbox = mailboxManager.getMailbox(fullMailboxName, false);
             appendToMailbox(mimeMessage, datetime, session, tag, command,
                     mailbox, responder, fullMailboxName);
 

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AuthenticateProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AuthenticateProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AuthenticateProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AuthenticateProcessor.java Sat Jan  3 04:34:39 2009
@@ -26,14 +26,15 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.message.request.imap4rev1.AuthenticateRequest;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 
-public class AuthenticateProcessor extends AbstractImapRequestProcessor {
+public class AuthenticateProcessor extends AbstractMailboxAwareProcessor {
 
-    public AuthenticateProcessor(final ImapProcessor next,
+    public AuthenticateProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CapabilityProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CapabilityProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CapabilityProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CapabilityProcessor.java Sat Jan  3 04:34:39 2009
@@ -28,17 +28,18 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.message.request.imap4rev1.CapabilityRequest;
 import org.apache.james.imap.message.response.imap4rev1.server.CapabilityResponse;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 
-public class CapabilityProcessor extends AbstractImapRequestProcessor {
+public class CapabilityProcessor extends AbstractMailboxAwareProcessor {
 
     private final List<String> capabilities;
 
-    public CapabilityProcessor(final ImapProcessor next,
+    public CapabilityProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory, final List<String> capabilities) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
         this.capabilities = capabilities;
     }
 

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CheckProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CheckProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CheckProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CheckProcessor.java Sat Jan  3 04:34:39 2009
@@ -25,14 +25,15 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.message.request.imap4rev1.CheckRequest;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 
-public class CheckProcessor extends AbstractImapRequestProcessor {
+public class CheckProcessor extends AbstractMailboxAwareProcessor {
 
-    public CheckProcessor(final ImapProcessor next,
+    public CheckProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CloseProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CloseProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CloseProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/CloseProcessor.java Sat Jan  3 04:34:39 2009
@@ -27,18 +27,19 @@
 import org.apache.james.api.imap.process.ImapSession;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.util.FetchGroupImpl;
 import org.apache.james.imap.mailbox.util.MessageRangeImpl;
 import org.apache.james.imap.message.request.imap4rev1.CloseRequest;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class CloseProcessor extends AbstractImapRequestProcessor {
+public class CloseProcessor extends AbstractMailboxAwareProcessor {
 
-    public CloseProcessor(final ImapProcessor next,
+    public CloseProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/ExpungeProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/ExpungeProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/ExpungeProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/ExpungeProcessor.java Sat Jan  3 04:34:39 2009
@@ -36,15 +36,15 @@
 import org.apache.james.imap.mailbox.util.FetchGroupImpl;
 import org.apache.james.imap.mailbox.util.MessageRangeImpl;
 import org.apache.james.imap.message.request.imap4rev1.ExpungeRequest;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class ExpungeProcessor extends AbstractImapRequestProcessor {
+public class ExpungeProcessor extends AbstractMailboxAwareProcessor {
 
     public ExpungeProcessor(final ImapProcessor next,
             final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/Imap4Rev1ProcessorFactory.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/Imap4Rev1ProcessorFactory.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/Imap4Rev1ProcessorFactory.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/Imap4Rev1ProcessorFactory.java Sat Jan  3 04:34:39 2009
@@ -19,10 +19,12 @@
 
 package org.apache.james.imap.processor.imap4rev1;
 
+import static org.apache.james.api.imap.ImapConstants.SUPPORTS_LITERAL_PLUS;
+import static org.apache.james.api.imap.ImapConstants.VERSION;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import static org.apache.james.api.imap.ImapConstants.*;
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.imap.mailbox.MailboxManagerProvider;
@@ -39,14 +41,14 @@
             final StatusResponseFactory statusResponseFactory) {
         
         final LogoutProcessor logoutProcessor = new LogoutProcessor(
-                chainEndProcessor, statusResponseFactory);
+                chainEndProcessor, mailboxManagerProvider, statusResponseFactory);
         final List<String> capabilities = new ArrayList<String>();
         capabilities.add(VERSION);
         capabilities.add(SUPPORTS_LITERAL_PLUS);
         final CapabilityProcessor capabilityProcessor = new CapabilityProcessor(
-                logoutProcessor, statusResponseFactory, capabilities);
+                logoutProcessor, mailboxManagerProvider, statusResponseFactory, capabilities);
         final CheckProcessor checkProcessor = new CheckProcessor(
-                capabilityProcessor, statusResponseFactory);
+                capabilityProcessor, mailboxManagerProvider, statusResponseFactory);
         final LoginProcessor loginProcessor = new LoginProcessor(
                 checkProcessor, mailboxManagerProvider, statusResponseFactory);
         final RenameProcessor renameProcessor = new RenameProcessor(
@@ -56,7 +58,7 @@
         final CreateProcessor createProcessor = new CreateProcessor(
                 deleteProcessor, mailboxManagerProvider, statusResponseFactory);
         final CloseProcessor closeProcessor = new CloseProcessor(
-                createProcessor, statusResponseFactory);
+                createProcessor, mailboxManagerProvider, statusResponseFactory);
         final UnsubscribeProcessor unsubscribeProcessor = new UnsubscribeProcessor(
                 closeProcessor, mailboxManagerProvider, statusResponseFactory);
         final SubscribeProcessor subscribeProcessor = new SubscribeProcessor(
@@ -66,7 +68,7 @@
                 subscribeProcessor, mailboxManagerProvider,
                 statusResponseFactory);
         final AuthenticateProcessor authenticateProcessor = new AuthenticateProcessor(
-                copyProcessor, statusResponseFactory);
+                copyProcessor, mailboxManagerProvider, statusResponseFactory);
         final ExpungeProcessor expungeProcessor = new ExpungeProcessor(
                 authenticateProcessor, mailboxManagerProvider,
                 statusResponseFactory);
@@ -75,9 +77,9 @@
         final AppendProcessor appendProcessor = new AppendProcessor(
                 examineProcessor, mailboxManagerProvider, statusResponseFactory);
         final StoreProcessor storeProcessor = new StoreProcessor(
-                appendProcessor, statusResponseFactory);
+                appendProcessor, mailboxManagerProvider, statusResponseFactory);
         final NoopProcessor noopProcessor = new NoopProcessor(storeProcessor,
-                statusResponseFactory);
+                mailboxManagerProvider, statusResponseFactory);
         final StatusProcessor statusProcessor = new StatusProcessor(
                 noopProcessor, mailboxManagerProvider, statusResponseFactory);
         final LSubProcessor lsubProcessor = new LSubProcessor(statusProcessor,
@@ -85,11 +87,11 @@
         final ListProcessor listProcessor = new ListProcessor(lsubProcessor,
                 mailboxManagerProvider, statusResponseFactory);
         final SearchProcessor searchProcessor = new SearchProcessor(
-                listProcessor, statusResponseFactory);
+                listProcessor, mailboxManagerProvider, statusResponseFactory);
         final SelectProcessor selectProcessor = new SelectProcessor(
                 searchProcessor, mailboxManagerProvider, statusResponseFactory);
         final ImapProcessor result = new FetchProcessor(selectProcessor,
-                statusResponseFactory);
+                mailboxManagerProvider, statusResponseFactory);
         return result;
     }
 }

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/LogoutProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/LogoutProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/LogoutProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/LogoutProcessor.java Sat Jan  3 04:34:39 2009
@@ -25,14 +25,15 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.message.request.imap4rev1.LogoutRequest;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 
-public class LogoutProcessor extends AbstractImapRequestProcessor {
+public class LogoutProcessor extends AbstractMailboxAwareProcessor {
 
-    public LogoutProcessor(final ImapProcessor next,
+    public LogoutProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/NoopProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/NoopProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/NoopProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/NoopProcessor.java Sat Jan  3 04:34:39 2009
@@ -25,14 +25,15 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.message.request.imap4rev1.NoopRequest;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 
-public class NoopProcessor extends AbstractImapRequestProcessor {
+public class NoopProcessor extends AbstractMailboxAwareProcessor {
 
-    public NoopProcessor(final ImapProcessor next,
+    public NoopProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/RenameProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/RenameProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/RenameProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/RenameProcessor.java Sat Jan  3 04:34:39 2009
@@ -26,8 +26,8 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
-import org.apache.james.imap.mailbox.MailboxExistsException;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxExistsException;
 import org.apache.james.imap.mailbox.MailboxManager;
 import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/SearchProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/SearchProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/SearchProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/SearchProcessor.java Sat Jan  3 04:34:39 2009
@@ -40,6 +40,7 @@
 import org.apache.james.api.imap.process.SelectedImapMailbox;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.mailbox.MessageResult;
 import org.apache.james.imap.mailbox.SearchQuery;
 import org.apache.james.imap.mailbox.MessageResult.FetchGroup;
@@ -47,14 +48,14 @@
 import org.apache.james.imap.mailbox.util.FetchGroupImpl;
 import org.apache.james.imap.message.request.imap4rev1.SearchRequest;
 import org.apache.james.imap.message.response.imap4rev1.server.SearchResponse;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class SearchProcessor extends AbstractImapRequestProcessor {
+public class SearchProcessor extends AbstractMailboxAwareProcessor {
 
-    public SearchProcessor(final ImapProcessor next,
+    public SearchProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/StoreProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/StoreProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/StoreProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/StoreProcessor.java Sat Jan  3 04:34:39 2009
@@ -33,6 +33,7 @@
 import org.apache.james.api.imap.process.SelectedImapMailbox;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.MessageResult;
@@ -41,16 +42,16 @@
 import org.apache.james.imap.mailbox.util.MessageRangeImpl;
 import org.apache.james.imap.message.request.imap4rev1.StoreRequest;
 import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class StoreProcessor extends AbstractImapRequestProcessor {
+public class StoreProcessor extends AbstractMailboxAwareProcessor {
 
     private static final FetchGroup STORE_FETCH_GROUP = FetchGroupImpl.FLAGS;
 
-    public StoreProcessor(final ImapProcessor next,
+    public StoreProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/fetch/FetchProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/fetch/FetchProcessor.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/fetch/FetchProcessor.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/fetch/FetchProcessor.java Sat Jan  3 04:34:39 2009
@@ -35,6 +35,7 @@
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
 import org.apache.james.imap.mailbox.Mailbox;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.MessageResult;
@@ -45,15 +46,15 @@
 import org.apache.james.imap.mailbox.util.MessageRangeImpl;
 import org.apache.james.imap.message.request.imap4rev1.FetchRequest;
 import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
-import org.apache.james.imap.processor.base.AbstractImapRequestProcessor;
+import org.apache.james.imap.processor.base.AbstractMailboxAwareProcessor;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 import org.apache.james.mime4j.field.address.parser.ParseException;
 
-public class FetchProcessor extends AbstractImapRequestProcessor {
+public class FetchProcessor extends AbstractMailboxAwareProcessor {
 
-    public FetchProcessor(final ImapProcessor next,
+    public FetchProcessor(final ImapProcessor next, final MailboxManagerProvider mailboxManagerProvider,
             final StatusResponseFactory factory) {
-        super(next, factory);
+        super(next, mailboxManagerProvider, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {

Modified: james/protocols/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/imap4rev1/SearchProcessorTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/imap4rev1/SearchProcessorTest.java?rev=730977&r1=730976&r2=730977&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/imap4rev1/SearchProcessorTest.java (original)
+++ james/protocols/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/imap4rev1/SearchProcessorTest.java Sat Jan  3 04:34:39 2009
@@ -20,6 +20,7 @@
 package org.apache.james.imap.processor.imap4rev1;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.mail.Flags.Flag;
@@ -37,6 +38,8 @@
 import org.apache.james.api.imap.process.SelectedImapMailbox;
 import org.apache.james.api.imap.process.ImapProcessor.Responder;
 import org.apache.james.imap.mailbox.Mailbox;
+import org.apache.james.imap.mailbox.MailboxManager;
+import org.apache.james.imap.mailbox.MailboxManagerProvider;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.SearchQuery;
 import org.apache.james.imap.mailbox.util.FetchGroupImpl;
@@ -94,6 +97,12 @@
 
     Mock mailbox;
 
+    Mock mailboxManagerProvider;
+    
+    Mock mailboxManager;
+    
+    Mock mailboxSession;
+    
     ImapCommand imapCommand;
 
     ImapProcessor.Responder responderImpl;
@@ -109,7 +118,12 @@
         statusResponse = mock(StatusResponse.class);
         responderImpl = (ImapProcessor.Responder) responder.proxy();
         mailbox = mock(Mailbox.class);
-        processor = new SearchProcessor((ImapProcessor) next.proxy(),
+        mailboxManagerProvider = mock(MailboxManagerProvider.class);
+        mailboxManager = mock(MailboxManager.class);
+        mailboxSession = mock(MailboxSession.class);
+        
+        processor = new SearchProcessor((ImapProcessor) next.proxy(), 
+                (MailboxManagerProvider) mailboxManagerProvider.proxy(),
                 (StatusResponseFactory) serverResponseFactory.proxy());
         expectOk();
     }
@@ -125,8 +139,9 @@
         Mock selectedMailbox = mock(SelectedImapMailbox.class);
         selectedMailbox.expects(once()).method("uid").with(eq(1729)).will(
                 returnValue(1729L));
-        selectedMailbox.expects(once()).method("unsolicitedResponses").with(eq(true),
-                eq(false)).will(returnValue(new ArrayList()));
+        
+        allowUnsolicitedResponses(selectedMailbox);
+        
         session.expects(atLeastOnce()).method("getSelected").will(
                 returnValue(selectedMailbox.proxy()));
         selectedMailbox.expects(once()).method("getRecent").will(
@@ -134,6 +149,23 @@
         check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
     }
 
+    private void allowUnsolicitedResponses(Mock selectedMailbox) {
+        selectedMailbox.expects(atLeastOnce()).method("isSizeChanged").will(returnValue(false));
+        selectedMailbox.expects(atMostOnce()).method("getName").will(returnValue("name"));
+        selectedMailbox.expects(atMostOnce()).method("isRecentUidRemoved").will(returnValue(false));
+        selectedMailbox.expects(atMostOnce()).method("flagUpdateUids").will(returnValue(Collections.EMPTY_LIST));
+        selectedMailbox.expects(atMostOnce()).method("resetEvents");
+        
+        session.expects(atMostOnce()).method("getAttribute").with(eq(ImapSessionUtils.SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY)).will(returnValue(mailbox));
+        session.expects(atMostOnce()).method("getAttribute").with(eq(ImapSessionUtils.MAILBOX_USER_ATTRIBUTE_SESSION_KEY)).will(returnValue("user"));
+        session.expects(atMostOnce()).method("getAttribute").with(eq(ImapSessionUtils.MAILBOX_MANAGER_ATTRIBUTE_SESSION_KEY)).will(returnValue(mailboxManager.proxy()));
+        session.expects(atMostOnce()).method("getAttribute").with(eq(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).will(returnValue(mailboxSession.proxy()));
+        
+        mailboxManagerProvider.expects(atMostOnce()).method("getMailboxManager").will(returnValue(mailboxManager.proxy()));
+        mailboxManager.expects(atMostOnce()).method("resolve").with(eq("user"), eq("name")).will(returnValue("user"));
+        mailboxManager.expects(atMostOnce()).method("getMailbox").with(eq("user"), eq(false)).will(returnValue(mailbox.proxy()));
+    }
+
     public void testSequenceSetUpperUnlimited() throws Exception {
         final IdRange[] ids = { new IdRange(1, Long.MAX_VALUE) };
         final SearchQuery.NumericRange[] ranges = { new SearchQuery.NumericRange(
@@ -141,8 +173,7 @@
         Mock selectedMailbox = mock(SelectedImapMailbox.class);
         selectedMailbox.expects(once()).method("uid").with(eq(1)).will(
                 returnValue(42L));
-        selectedMailbox.expects(once()).method("unsolicitedResponses").with(eq(true),
-                eq(false)).will(returnValue(new ArrayList()));
+        allowUnsolicitedResponses(selectedMailbox);
         session.expects(atLeastOnce()).method("getSelected").will(
                 returnValue(selectedMailbox.proxy()));
         selectedMailbox.expects(once()).method("getRecent").will(
@@ -161,8 +192,7 @@
                 returnValue(1729L));
         selectedMailbox.expects(once()).method("getRecent").will(
                 returnValue(EMPTY));
-        selectedMailbox.expects(once()).method("unsolicitedResponses").with(eq(true),
-                eq(false)).will(returnValue(new ArrayList()));
+        allowUnsolicitedResponses(selectedMailbox);
         session.expects(atLeastOnce()).method("getSelected").will(
                 returnValue(selectedMailbox.proxy()));
         check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
@@ -177,8 +207,7 @@
                 returnValue(42L));
         selectedMailbox.expects(once()).method("getRecent").will(
                 returnValue(EMPTY));
-        selectedMailbox.expects(once()).method("unsolicitedResponses").with(eq(true),
-                eq(false)).will(returnValue(new ArrayList()));
+        allowUnsolicitedResponses(selectedMailbox);
         session.expects(atLeastOnce()).method("getSelected").will(
                 returnValue(selectedMailbox.proxy()));
         check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));



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