Author: rdonkin
Date: Sun Jan  4 03:51:30 2009
New Revision: 731222

URL: http://svn.apache.org/viewvc?rev=731222&view=rev
Log:
Do not store mailbox instance

Modified:
    
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
    
james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyserTest.java
    
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/ImapSessionUtils.java
    
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
    
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractMailboxProcessor.java
    
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractSelectionProcessor.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/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
    
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/RenameSelected.test
    
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
 Sun Jan  4 03:51:30 2009
@@ -481,4 +481,8 @@
     public void deleted(MailboxSession session) {
         tracker.mailboxDeleted(session.getSessionId());
     }
+
+    public void reportRenamed(String to) {
+        tracker.reportRenamed(to);
+    }
 }

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
 Sun Jan  4 03:51:30 2009
@@ -196,7 +196,11 @@
                 mailbox.setName(to);
                 mapper.save(mailbox);
 
-                mailboxes.remove(from);
+                final JPAMailbox jpaMailbox = mailboxes.remove(from);
+                if (jpaMailbox != null) {
+                    jpaMailbox.reportRenamed(to);
+                    mailboxes.put(to, jpaMailbox);
+                }
 
                 // rename submailbox
                 final List<Mailbox> subMailboxes = 
mapper.findMailboxWithNameLike(from + HIERARCHY_DELIMITER + "%");

Modified: 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
 (original)
+++ 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
 Sun Jan  4 03:51:30 2009
@@ -48,6 +48,18 @@
      */
     public interface MailboxDeletionEvent extends Event {
     }
+    
+    
+    /**
+     * Indicates that a mailbox has been renamed.
+     */
+    public interface MailboxRenamed extends Event {
+        /**
+         * Gets the new name for this mailbox.
+         * @return name, not null
+         */
+        public String getNewName();
+    }
 
     /**
      * A mailbox event related to a message.
@@ -82,4 +94,5 @@
 
     public abstract class Added implements MessageEvent {
     }
+
 }

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -31,26 +31,31 @@
 
 public class MailboxEventAnalyser implements MailboxListener {
 
-    private boolean isDeletedByOtherSession = false;
-
-    private boolean sizeChanged = false;
-
-    private boolean silentFlagChanges = false;
-
     private final long sessionId;
-
     private final Set<Long> flagUpdateUids;
-
     private final Flags.Flag uninterestingFlag;
-
     private final Set<Long> expungedUids;
+    
+    private boolean isDeletedByOtherSession = false;
+    private boolean sizeChanged = false;
+    private boolean silentFlagChanges = false;
+    private String mailboxName;
 
-    public MailboxEventAnalyser(final long sessionId) {
+    public MailboxEventAnalyser(final long sessionId, final String 
mailboxName) {
         super();
         this.sessionId = sessionId;
         flagUpdateUids = new TreeSet<Long>();
         expungedUids = new TreeSet<Long>();
         uninterestingFlag = Flags.Flag.RECENT;
+        this.mailboxName = mailboxName;
+    }
+    
+    public String getMailboxName() {
+        return mailboxName;
+    }
+
+    public void setMailboxName(String mailboxName) {
+        this.mailboxName = mailboxName;
     }
 
     public void event(Event event) {
@@ -75,6 +80,9 @@
             if (eventSessionId != sessionId) {
                 isDeletedByOtherSession = true;
             }
+        } else if (event instanceof MailboxRenamed) {
+            final MailboxRenamed mailboxRenamed = (MailboxRenamed) event;
+            setMailboxName(mailboxRenamed.getNewName());
         }
     }
 

Modified: 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
 (original)
+++ 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
 Sun Jan  4 03:51:30 2009
@@ -22,17 +22,16 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
 
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
 import org.apache.james.imap.mailbox.MailboxListener;
 
-import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet;
-
 public class MailboxEventDispatcher implements MailboxListener {
 
-    private final Set listeners = new CopyOnWriteArraySet();
+    private final Set<MailboxListener> listeners = new 
CopyOnWriteArraySet<MailboxListener>();
 
     public void addMailboxListener(MailboxListener mailboxListener) {
         listeners.add(mailboxListener);
@@ -78,6 +77,10 @@
     public int size() {
         return listeners.size();
     }
+    
+    public void mailboxRenamed(String to, long sessionId) {
+        event(new MailboxRenamedEventImpl(to, sessionId));
+    }
 
     private final static class AddedImpl extends MailboxListener.Added {
 
@@ -246,6 +249,24 @@
         public long getSessionId() {
             return sessionId;
         }
+    }
+
+    private static final class MailboxRenamedEventImpl implements 
MailboxListener.MailboxRenamed {
+        private final String newName;
+        private final long sessionId;
+
+        public MailboxRenamedEventImpl(final String newName, final long 
sessionId) {
+            super();
+            this.newName = newName;
+            this.sessionId = sessionId;
+        }
+
+        public String getNewName() {
+            return newName;
+        }
 
+        public long getSessionId() {
+            return sessionId;
+        }
     }
 }

Modified: 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
 (original)
+++ 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
 Sun Jan  4 03:51:30 2009
@@ -41,7 +41,7 @@
 
     private final MailboxEventDispatcher eventDispatcher;
 
-    private final TreeMap cache;
+    private final TreeMap<Long, Flags> cache;
 
     private long lastUidAtStart;
 
@@ -53,7 +53,7 @@
         this.lastUidAtStart = lastUid;
         this.lastUid = lastUid;
         eventDispatcher = new MailboxEventDispatcher();
-        cache = new TreeMap();
+        cache = new TreeMap<Long, Flags>();
     }
 
     public synchronized void expunged(final long[] uidsExpunged) {
@@ -134,7 +134,7 @@
 
     public synchronized void found(UidRange range,
             final MessageFlags[] messageFlags) {
-        Set expectedSet = getSubSet(range);
+        Set<Long> expectedSet = getSubSet(range);
         final int length = messageFlags.length;
         for (int i = 0; i < length; i++) {
             final MessageFlags message = messageFlags[i];
@@ -189,17 +189,17 @@
         }
     }
 
-    private SortedSet getSubSet(UidRange range) {
+    private SortedSet<Long> getSubSet(UidRange range) {
         final Long rangeStartLong = new Long(range.getFromUid());
         if (range.getToUid() > 0) {
             final long nextUidAfterRange = range.getToUid() + 1;
             final Long nextUidAfterRangeLong = new Long(nextUidAfterRange);
-            final SortedMap subMap = cache.subMap(rangeStartLong,
+            final SortedMap<Long, Flags> subMap = cache.subMap(rangeStartLong,
                     nextUidAfterRangeLong);
-            final Set keySet = subMap.keySet();
-            return new TreeSet(keySet);
+            final Set<Long> keySet = subMap.keySet();
+            return new TreeSet<Long>(keySet);
         } else {
-            return new TreeSet(cache.tailMap(rangeStartLong).keySet());
+            return new TreeSet<Long>(cache.tailMap(rangeStartLong).keySet());
         }
 
     }
@@ -208,7 +208,7 @@
             throws MessagingException {
         if (messageResult != null) {
             long uid = messageResult.getUid();
-            Collection results = new ArrayList();
+            Collection<MessageResult> results = new ArrayList<MessageResult>();
             results.add(messageResult);
             found(new UidRange(uid, uid), results);
         }
@@ -240,4 +240,8 @@
         eventDispatcher.mailboxDeleted(sessionId);
     }
 
+    public void reportRenamed(String to) {
+        eventDispatcher.mailboxRenamed(to, Mailbox.ANONYMOUS_SESSION);
+    }
+
 }

Modified: 
james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyserTest.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyserTest.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyserTest.java
 (original)
+++ 
james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyserTest.java
 Sun Jan  4 03:51:30 2009
@@ -38,7 +38,7 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        analyser = new MailboxEventAnalyser(BASE_SESSION_ID);
+        analyser = new MailboxEventAnalyser(BASE_SESSION_ID, "Mailbox Name");
     }
 
     protected void tearDown() throws Exception {

Modified: 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/ImapSessionUtils.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/ImapSessionUtils.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/ImapSessionUtils.java
 (original)
+++ 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/ImapSessionUtils.java
 Sun Jan  4 03:51:30 2009
@@ -26,8 +26,6 @@
 
     public static final String MAILBOX_USER_ATTRIBUTE_SESSION_KEY = 
"org.apache.james.api.imap.MAILBOX_USER_ATTRIBUTE_SESSION_KEY";
 
-    public static final String SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY = 
"org.apache.james.api.imap.SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY";
-
     public static final String MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY = 
"org.apache.james.api.imap.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY";
 
     public static MailboxSession getMailboxSession(final ImapSession session) {

Modified: 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
 (original)
+++ 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
 Sun Jan  4 03:51:30 2009
@@ -33,7 +33,6 @@
 import org.apache.james.imap.mailbox.util.MailboxEventAnalyser;
 import org.apache.james.imap.mailbox.util.UidToMsnConverter;
 
-// TODO: deal with deleted or renamed mailboxes
 public class SelectedMailboxImpl extends AbstractLogEnabled implements
         SelectedMailbox {
 
@@ -47,21 +46,18 @@
 
     private boolean recentUidRemoved;
 
-    private final String name;
-
     public SelectedMailboxImpl(final Mailbox mailbox, final List<Long> uids,
             final MailboxSession mailboxSession, final String name) throws 
MailboxException {
         this.mailbox = mailbox;
         recentUids = new TreeSet<Long>();
         recentUidRemoved = false;
         final long sessionId = mailboxSession.getSessionId();
-        events = new MailboxEventAnalyser(sessionId);
+        events = new MailboxEventAnalyser(sessionId, name);
         // Ignore events from our session
         events.setSilentFlagChanges(true);
         mailbox.addListener(events);
         converter = new UidToMsnConverter(uids);
         mailbox.addListener(converter);
-        this.name = name;
     }
 
     /**
@@ -117,7 +113,7 @@
     }
 
     public String getName() {
-        return name;
+        return events.getMailboxName();
     }
 
     private void checkExpungedRecents() {

Modified: 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractMailboxProcessor.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractMailboxProcessor.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractMailboxProcessor.java
 (original)
+++ 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractMailboxProcessor.java
 Sun Jan  4 03:51:30 2009
@@ -310,9 +310,16 @@
         return result;
     }
 
-    public Mailbox getSelectedMailbox(final ImapSession session) {
-        Mailbox result = (Mailbox) session
-                
.getAttribute(ImapSessionUtils.SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY);
+    public Mailbox getSelectedMailbox(final ImapSession session) throws 
MailboxException {
+        Mailbox result;
+        final SelectedMailbox selectedMailbox = session.getSelected();
+        if (selectedMailbox == null) {
+            result = null;
+        } else {
+            final String mailboxName = selectedMailbox.getName();
+            final MailboxManager mailboxManager = getMailboxManager();
+            result = mailboxManager.getMailbox(mailboxName);
+        }
         return result;
     }
 

Modified: 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractSelectionProcessor.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractSelectionProcessor.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractSelectionProcessor.java
 (original)
+++ 
james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/imap4rev1/AbstractSelectionProcessor.java
 Sun Jan  4 03:51:30 2009
@@ -205,9 +205,6 @@
         sessionMailbox = new SelectedMailboxImpl(mailbox, uids,
                 mailboxSession, name);
         session.selected(sessionMailbox);
-        session.setAttribute(
-                ImapSessionUtils.SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY,
-                mailbox);
         return sessionMailbox;
     }
 

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -47,24 +47,25 @@
 
     protected void doProcess(ImapRequest message, ImapSession session,
             String tag, ImapCommand command, Responder responder) {
-        Mailbox mailbox = getSelectedMailbox(session);
-        if (mailbox.isWriteable()) {
-            try {
-                final MailboxSession mailboxSession = ImapSessionUtils
-                        .getMailboxSession(session);
-                mailbox.expunge(MessageRangeImpl.all(), FetchGroupImpl.MINIMAL,
-                        mailboxSession);
-                session.deselect();
-                // TODO: the following comment was present in the code before
-                // refactoring
-                // TODO: doesn't seem to match the implementation
-                // TODO: check that implementation is correct
-                // Don't send unsolicited responses on close.
-                unsolicitedResponses(session, responder, false);
-                okComplete(command, tag, responder);
-            } catch (MailboxException e) {
-                no(command, tag, responder, e);
+        try {
+            Mailbox mailbox = getSelectedMailbox(session);
+            if (mailbox.isWriteable()) {
+                
+                    final MailboxSession mailboxSession = ImapSessionUtils
+                            .getMailboxSession(session);
+                    mailbox.expunge(MessageRangeImpl.all(), 
FetchGroupImpl.MINIMAL,
+                            mailboxSession);
+                    session.deselect();
+                    // TODO: the following comment was present in the code 
before
+                    // refactoring
+                    // TODO: doesn't seem to match the implementation
+                    // TODO: check that implementation is correct
+                    // Don't send unsolicited responses on close.
+                    unsolicitedResponses(session, responder, false);
+                    okComplete(command, tag, responder);
             }
+        } catch (MailboxException e) {
+            no(command, tag, responder, e);
         }
     }
 }

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -52,17 +52,17 @@
 
     protected void doProcess(ImapRequest message, ImapSession session,
             String tag, ImapCommand command, Responder responder) {
-        Mailbox mailbox = getSelectedMailbox(session);
-        if (!mailbox.isWriteable()) {
-            no(command, tag, responder,
-                    HumanReadableTextKey.MAILBOX_IS_READ_ONLY);
-        } else {
-            try {
+        try {
+            final Mailbox mailbox = getSelectedMailbox(session);
+            if (!mailbox.isWriteable()) {
+                no(command, tag, responder,
+                        HumanReadableTextKey.MAILBOX_IS_READ_ONLY);
+            } else {
                 final Iterator it = mailbox.expunge(MessageRangeImpl.all(),
                         FetchGroupImpl.MINIMAL, ImapSessionUtils
-                                .getMailboxSession(session));
+                        .getMailboxSession(session));
                 final SelectedMailbox mailboxSession = session
-                        .getSelected();
+                .getSelected();
                 if (mailboxSession != null) {
                     while (it.hasNext()) {
                         final MessageResult result = (MessageResult) it.next();
@@ -72,9 +72,9 @@
                 }
                 unsolicitedResponses(session, responder, false);
                 okComplete(command, tag, responder);
-            } catch (MailboxException e) {
-                no(command, tag, responder, e);
             }
+        } catch (MailboxException e) {
+            no(command, tag, responder, e);
         }
     }
 }

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -67,7 +67,7 @@
             final SearchRequest request = (SearchRequest) message;
             final SearchKey searchKey = request.getSearchKey();
             final boolean useUids = request.isUseUids();
-            Mailbox mailbox = getSelectedMailbox(session);
+            final Mailbox mailbox = getSelectedMailbox(session);
             final FetchGroup fetchGroup = FetchGroupImpl.MINIMAL;
 
             final SearchQuery query = toQuery(searchKey, session);

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -67,8 +67,6 @@
         final boolean isSignedPlus = request.isSignedPlus();
         final boolean isSignedMinus = request.isSignedMinus();
 
-        Mailbox mailbox = getSelectedMailbox(session);
-
         final boolean replace;
         final boolean value;
         if (isSignedMinus) {
@@ -82,6 +80,7 @@
             value = true;
         }
         try {
+            final Mailbox mailbox = getSelectedMailbox(session);
             for (int i = 0; i < idSet.length; i++) {
                 final long lowVal;
                 final long highVal;

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -69,7 +69,7 @@
         final FetchData fetch = request.getFetch();
         try {
             FetchGroup resultToFetch = getFetchGroup(fetch);
-            Mailbox mailbox = getSelectedMailbox(session);
+            final Mailbox mailbox = getSelectedMailbox(session);
             for (int i = 0; i < idSet.length; i++) {
                 final FetchResponseBuilder builder = new FetchResponseBuilder(
                         new EnvelopeBuilder(getLog()));

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=731222&r1=731221&r2=731222&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
 Sun Jan  4 03:51:30 2009
@@ -108,6 +108,8 @@
 
     ImapProcessor.Responder responderImpl;
 
+    Mock selectedMailbox;
+
     protected void setUp() throws Exception {
         super.setUp();
         serverResponseFactory = mock(StatusResponseFactory.class);
@@ -122,6 +124,7 @@
         mailboxManagerProvider = mock(MailboxManagerProvider.class);
         mailboxManager = mock(MailboxManager.class);
         mailboxSession = mock(MailboxSession.class);
+        selectedMailbox = mock(SelectedMailbox.class);
         
         processor = new SearchProcessor((ImapProcessor) next.proxy(), 
                 (MailboxManagerProvider) mailboxManagerProvider.proxy(),
@@ -134,181 +137,169 @@
     }
 
     public void testSequenceSetLowerUnlimited() throws Exception {
+        expectsGetSelectedMailbox();
         final IdRange[] ids = { new IdRange(Long.MAX_VALUE, 1729) };
         final SearchQuery.NumericRange[] ranges = { new 
SearchQuery.NumericRange(
                 Long.MAX_VALUE, 1729L) };
-        Mock selectedMailbox = mock(SelectedMailbox.class);
         selectedMailbox.expects(once()).method("uid").with(eq(1729)).will(
                 returnValue(1729L));
         
-        allowUnsolicitedResponses(selectedMailbox);
+        allowUnsolicitedResponses();
         
-        session.expects(atLeastOnce()).method("getSelected").will(
-                returnValue(selectedMailbox.proxy()));
-        selectedMailbox.expects(once()).method("getRecent").will(
-                returnValue(new ArrayList<Long>()));
         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));
+    private void allowUnsolicitedResponses() {
         
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_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()));
+        
session.expects(atMostOnce()).method("getAttribute").with(eq(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).will(returnValue(mailboxSession.proxy()));
        
     }
 
     public void testSequenceSetUpperUnlimited() throws Exception {
+        expectsGetSelectedMailbox();
         final IdRange[] ids = { new IdRange(1, Long.MAX_VALUE) };
         final SearchQuery.NumericRange[] ranges = { new 
SearchQuery.NumericRange(
                 42, Long.MAX_VALUE) };
-        Mock selectedMailbox = mock(SelectedMailbox.class);
         selectedMailbox.expects(once()).method("uid").with(eq(1)).will(
                 returnValue(42L));
-        allowUnsolicitedResponses(selectedMailbox);
-        session.expects(atLeastOnce()).method("getSelected").will(
-                returnValue(selectedMailbox.proxy()));
-        selectedMailbox.expects(once()).method("getRecent").will(
-                returnValue(new ArrayList<Long>()));
+        allowUnsolicitedResponses();
         check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
     }
 
     public void testSequenceSetMsnRange() throws Exception {
+        expectsGetSelectedMailbox();
         final IdRange[] ids = { new IdRange(1, 5) };
         final SearchQuery.NumericRange[] ranges = { new 
SearchQuery.NumericRange(
                 42, 1729) };
-        Mock selectedMailbox = mock(SelectedMailbox.class);
         selectedMailbox.expects(once()).method("uid").with(eq(1)).will(
                 returnValue(42L));
         selectedMailbox.expects(once()).method("uid").with(eq(5)).will(
                 returnValue(1729L));
-        selectedMailbox.expects(once()).method("getRecent").will(
-                returnValue(new ArrayList<Long>()));
-        allowUnsolicitedResponses(selectedMailbox);
-        session.expects(atLeastOnce()).method("getSelected").will(
-                returnValue(selectedMailbox.proxy()));
+        allowUnsolicitedResponses();
         check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
     }
 
     public void testSequenceSetSingleMsn() throws Exception {
+        expectsGetSelectedMailbox();
         final IdRange[] ids = { new IdRange(1) };
         final SearchQuery.NumericRange[] ranges = { new 
SearchQuery.NumericRange(
                 42) };
-        Mock selectedMailbox = mock(SelectedMailbox.class);
+        
         selectedMailbox.expects(exactly(2)).method("uid").with(eq(1)).will(
                 returnValue(42L));
-        selectedMailbox.expects(once()).method("getRecent").will(
-                returnValue(new ArrayList<Long>()));
-        allowUnsolicitedResponses(selectedMailbox);
-        session.expects(atLeastOnce()).method("getSelected").will(
-                returnValue(selectedMailbox.proxy()));
+        allowUnsolicitedResponses();
         check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
     }
 
     public void testALL() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildAll(), SearchQuery.all());
     }
 
+    private void expectsGetSelectedMailbox() {
+        
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()));
+        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(selectedMailbox.proxy()));
+        
selectedMailbox.expects(atMostOnce()).method("isRecentUidRemoved").will(returnValue(false));
+        
selectedMailbox.expects(atLeastOnce()).method("isSizeChanged").will(returnValue(false));
+        
selectedMailbox.expects(atLeastOnce()).method("getName").will(returnValue("MailboxName"));
+        
selectedMailbox.expects(atMostOnce()).method("flagUpdateUids").will(returnValue(Collections.EMPTY_LIST));
+        selectedMailbox.expects(atMostOnce()).method("resetEvents");
+        
mailboxManager.expects(atLeastOnce()).method("getMailbox").will(returnValue(mailbox.proxy()));
+        
selectedMailbox.expects(once()).method("getRecent").will(returnValue(new 
ArrayList<Long>()));
+    }
+
     public void testANSWERED() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildAnswered(), SearchQuery.flagIsSet(Flag.ANSWERED));
     }
 
     public void testBCC() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildBcc(ADDRESS), SearchQuery.headerContains(
                 ImapConstants.RFC822_BCC, ADDRESS));
     }
 
     public void testBEFORE() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildBefore(DAY_MONTH_YEAR), SearchQuery
                 .internalDateBefore(DAY, MONTH, YEAR));
     }
 
     public void testBODY() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildBody(SUBJECT), SearchQuery.bodyContains(SUBJECT));
     }
 
     public void testCC() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildCc(ADDRESS), SearchQuery.headerContains(
                 ImapConstants.RFC822_CC, ADDRESS));
     }
 
     public void testDELETED() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildDeleted(), SearchQuery.flagIsSet(Flag.DELETED));
     }
 
     public void testDRAFT() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildDraft(), SearchQuery.flagIsSet(Flag.DRAFT));
     }
 
     public void testFLAGGED() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildFlagged(), SearchQuery.flagIsSet(Flag.FLAGGED));
     }
 
     public void testFROM() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildFrom(ADDRESS), SearchQuery.headerContains(
                 ImapConstants.RFC822_FROM, ADDRESS));
     }
 
     public void testHEADER() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildHeader(ImapConstants.RFC822_IN_REPLY_TO, ADDRESS),
                 SearchQuery.headerContains(ImapConstants.RFC822_IN_REPLY_TO,
                         ADDRESS));
     }
 
     public void testKEYWORD() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildKeyword(KEYWORD), SearchQuery.flagIsSet(KEYWORD));
     }
 
     public void testLARGER() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildLarger(SIZE), SearchQuery.sizeGreaterThan(SIZE));
     }
 
     public void testNEW() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildNew(), SearchQuery.and(SearchQuery
                 .flagIsSet(Flag.RECENT), SearchQuery.flagIsUnSet(Flag.SEEN)));
     }
 
     public void testNOT() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildNot(SearchKey.buildOn(DAY_MONTH_YEAR)),
                 SearchQuery.not(SearchQuery.internalDateOn(DAY, MONTH, YEAR)));
     }
 
     public void testOLD() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildOld(), SearchQuery.flagIsUnSet(Flag.RECENT));
     }
 
     public void testON() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildOn(DAY_MONTH_YEAR), SearchQuery.internalDateOn(
                 DAY, MONTH, YEAR));
     }
 
     public void testAND() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         List<SearchKey> keys = new ArrayList<SearchKey>();
         keys.add(SearchKey.buildOn(DAY_MONTH_YEAR));
         keys.add(SearchKey.buildOld());
@@ -321,102 +312,102 @@
     }
 
     public void testOR() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildOr(SearchKey.buildOn(DAY_MONTH_YEAR), SearchKey
                 .buildOld()), SearchQuery.or(SearchQuery.internalDateOn(DAY,
                 MONTH, YEAR), SearchQuery.flagIsUnSet(Flag.RECENT)));
     }
 
     public void testRECENT() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildRecent(), SearchQuery.flagIsSet(Flag.RECENT));
     }
 
     public void testSEEN() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSeen(), SearchQuery.flagIsSet(Flag.SEEN));
     }
 
     public void testSENTBEFORE() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSentBefore(DAY_MONTH_YEAR), SearchQuery
                 .headerDateBefore(ImapConstants.RFC822_DATE, DAY, MONTH, 
YEAR));
     }
 
     public void testSENTON() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSentOn(DAY_MONTH_YEAR), SearchQuery.headerDateOn(
                 ImapConstants.RFC822_DATE, DAY, MONTH, YEAR));
     }
 
     public void testSENTSINCE() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSentSince(DAY_MONTH_YEAR), SearchQuery
                 .headerDateAfter(ImapConstants.RFC822_DATE, DAY, MONTH, YEAR));
     }
 
     public void testSINCE() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSince(DAY_MONTH_YEAR), SearchQuery
                 .internalDateAfter(DAY, MONTH, YEAR));
     }
 
     public void testSMALLER() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSmaller(SIZE), SearchQuery.sizeLessThan(SIZE));
     }
 
     public void testSUBJECT() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildSubject(SUBJECT), SearchQuery.headerContains(
                 ImapConstants.RFC822_SUBJECT, SUBJECT));
     }
 
     public void testTEXT() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildText(SUBJECT), SearchQuery.mailContains(SUBJECT));
     }
 
     public void testTO() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildTo(ADDRESS), SearchQuery.headerContains(
                 ImapConstants.RFC822_TO, ADDRESS));
     }
 
     public void testUID() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUidSet(IDS), SearchQuery.uid(RANGES));
     }
 
     public void testUNANSWERED() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUnanswered(), SearchQuery
                 .flagIsUnSet(Flag.ANSWERED));
     }
 
     public void testUNDELETED() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUndeleted(), 
SearchQuery.flagIsUnSet(Flag.DELETED));
     }
 
     public void testUNDRAFT() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUndraft(), SearchQuery.flagIsUnSet(Flag.DRAFT));
     }
 
     public void testUNFLAGGED() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUnflagged(), 
SearchQuery.flagIsUnSet(Flag.FLAGGED));
     }
 
     public void testUNKEYWORD() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUnkeyword(KEYWORD), SearchQuery
                 .flagIsUnSet(KEYWORD));
     }
 
     public void testUNSEEN() throws Exception {
-        
session.expects(atLeastOnce()).method("getSelected").will(returnValue(null));
+        expectsGetSelectedMailbox();
         check(SearchKey.buildUnseen(), SearchQuery.flagIsUnSet(Flag.SEEN));
     }
 
@@ -433,9 +424,6 @@
         session.expects(once()).method("getAttribute").with(
                 eq(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
                 .will(returnValue((MailboxSession) mailboxSession));
-        session.expects(once()).method("getAttribute").with(
-                eq(ImapSessionUtils.SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY))
-                .will(returnValue((Mailbox) mailbox.proxy()));
         mailbox.expects(once()).method("search").with(eq(query),
                 eq(FetchGroupImpl.MINIMAL), eq(mailboxSession)).will(
                 returnValue(new ArrayList().iterator()));

Modified: 
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/RenameSelected.test
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/RenameSelected.test?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/RenameSelected.test
 (original)
+++ 
james/protocols/imap/trunk/seda/src/test/resources/org/apache/james/imap/scripts/RenameSelected.test
 Sun Jan  4 03:51:30 2009
@@ -216,37 +216,37 @@
 C: A19 SELECT anothermailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 5 EXISTS
-S: \* 0 RECENT
+S: \* 5 RECENT
 S: \* OK \[UIDVALIDITY \d+\]
 S: \* OK \[UNSEEN 1\](.)*
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\]
 S: A19 OK \[READ-WRITE\] SELECT completed\.
 C: A20 FETCH 1:* (FLAGS UID BODY.PEEK[HEADER.FIELDS (DATE FROM TO ORIGINATOR 
X-LIST)])
-S: \* 1 FETCH \(FLAGS \(\\Answered \\Flagged\) UID 1 BODY\[HEADER\.FIELDS 
\(DATE FROM TO ORIGINATOR X-LIST\)\] \{130\}
+S: \* 1 FETCH \(FLAGS \(\\Answered \\Flagged \\Recent\) UID 1 
BODY\[HEADER\.FIELDS \(DATE FROM TO ORIGINATOR X-LIST\)\] \{130\}
 S: From: Timothy Tayler <timo...@example\.org>
 S: To: Samual Smith <sam...@example\.org>
 S: Date: Thu, 14 Feb 2008 12:00:00 \+0000 \(GMT\)
 S: 
 S: \)
-S: \* 2 FETCH \(FLAGS \(\\Answered \\Flagged\) UID 2 BODY\[HEADER\.FIELDS 
\(DATE FROM TO ORIGINATOR X-LIST\)\] \{116\}
+S: \* 2 FETCH \(FLAGS \(\\Answered \\Flagged \\Recent\) UID 2 
BODY\[HEADER\.FIELDS \(DATE FROM TO ORIGINATOR X-LIST\)\] \{116\}
 S: From: John Smith <j...@example\.org>
 S: To: Timothy Taylor <t...@example\.org>
 S: Date: Sat, 23 Feb 2008 07:48:03 -0600
 S: 
 S: \)
-S: \* 3 FETCH \(FLAGS \(\\Answered\) UID 3 BODY\[HEADER\.FIELDS \(DATE FROM TO 
ORIGINATOR X-LIST\)\] \{116\}
+S: \* 3 FETCH \(FLAGS \(\\Answered \\Recent\) UID 3 BODY\[HEADER\.FIELDS 
\(DATE FROM TO ORIGINATOR X-LIST\)\] \{116\}
 S: From: John Smith <j...@example\.org>
 S: To: Timothy Taylor <t...@example\.org>
 S: Date: Sat, 23 Feb 2008 07:48:03 -0600
 S: 
 S: \)
-S: \* 4 FETCH \(FLAGS \(\) UID 4 BODY\[HEADER\.FIELDS \(DATE FROM TO 
ORIGINATOR X-LIST\)\] \{130\}
+S: \* 4 FETCH \(FLAGS \(\\Recent\) UID 4 BODY\[HEADER\.FIELDS \(DATE FROM TO 
ORIGINATOR X-LIST\)\] \{130\}
 S: From: Timothy Tayler <timo...@example\.org>
 S: To: Samual Smith <sam...@example\.org>
 S: Date: Thu, 14 Feb 2008 12:00:00 \+0000 \(GMT\)
 S: 
 S: \)
-S: \* 5 FETCH \(FLAGS \(\) UID 5 BODY\[HEADER\.FIELDS \(DATE FROM TO 
ORIGINATOR X-LIST\)\] \{167\}
+S: \* 5 FETCH \(FLAGS \(\\Recent\) UID 5 BODY\[HEADER\.FIELDS \(DATE FROM TO 
ORIGINATOR X-LIST\)\] \{167\}
 S: From: "Brian G\. Hutton" <br...@example\.org>
 S: To: Timothy Taylor <t...@example\.org>, fa...@example\.org, Huh\? 
<s...@example\.org>
 S: Date: Sat, 23 Feb 2008 07:48:03 -0600

Modified: 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
 (original)
+++ 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
 Sun Jan  4 03:51:30 2009
@@ -829,4 +829,9 @@
     public void deleted(MailboxSession session) {
         tracker.mailboxDeleted(session.getSessionId());
     }
+
+    public void reportRenamed(MailboxRow mailboxRow) {
+        tracker.reportRenamed(mailboxRow.getName());
+        this.mailboxRow = mailboxRow;
+    }
 }

Modified: 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=731222&r1=731221&r2=731222&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
 (original)
+++ 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
 Sun Jan  4 03:51:30 2009
@@ -196,7 +196,11 @@
                 mr.setName(to);
                 mr.save();
 
-                mailboxes.remove(from);
+                TorqueMailbox torqueMailbox = (TorqueMailbox) 
mailboxes.remove(from);
+                if (torqueMailbox != null) {
+                    torqueMailbox.reportRenamed(mr);
+                    mailboxes.put(to, torqueMailbox);
+                }
 
                 // rename submailbox
                 Criteria c = new Criteria();



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to