james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r596875 - in /james/server/trunk: core-library/src/main/java/org/apache/james/mailboxmanager/impl/ core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/ core-library/src/main/java/org/apache/james/mailboxmanager/tracking/ core...
Date Tue, 20 Nov 2007 23:21:22 GMT
Author: rdonkin
Date: Tue Nov 20 15:21:20 2007
New Revision: 596875

URL: http://svn.apache.org/viewvc?rev=596875&view=rev
Log:
Switched arrays to iterators in MailboxAPI. Unfortunately, more work is needed with the events before lazy loading could be introduced into Torque.

Modified:
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/tracking/UidChangeTracker.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/FlaggedSessionMailboxWrapper.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/ImapMailboxSessionWrapper.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/NumberStableSessionWrapper.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java
    james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java
    james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SearchProcessor.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapSessionImpl.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/SelectedMailboxSession.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/FetchCommand.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/SearchCommand.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/AbstractImapMailboxSelfTestCase.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/impl/UidChangeTrackerTestCase.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueImapMailboxSelfTestCase.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/repository/TorqueMailboxManagerMailRepositoryNativeTestCase.java
    james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java Tue Nov 20 15:21:20 2007
@@ -177,7 +177,7 @@
 
     public void setSize(int size) {
         this.size=size;
-        includedResults = SIZE;
+        includedResults |= SIZE;
     }
 
     public void setInternalDate(Date internalDate) {

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java Tue Nov 20 15:21:20 2007
@@ -34,10 +34,12 @@
 public abstract class AbstractGeneralMailbox extends AbstractLogFactoryAware implements GeneralMailbox {
     
     public Collection list() throws MailboxManagerException {
-        MessageResult[] messageResult=getMessages(GeneralMessageSetImpl.all(), MessageResult.KEY);
-        Collection result=new ArrayList(messageResult.length);
-        for (int i = 0; i < messageResult.length; i++) {
-            result.add(messageResult[i].getKey());
+        final Iterator it = getMessages(GeneralMessageSetImpl.all(), MessageResult.KEY);
+        final Collection result = new ArrayList(100);
+        while (it.hasNext()) {
+            final MessageResult next = (MessageResult) it.next();
+            final String key = (next).getKey();
+            result.add(key);
         }
         return result;
     }
@@ -46,14 +48,17 @@
         remove(GeneralMessageSetImpl.oneKey(key));
     }
 
-    public MimeMessage retrieve(String key) throws MailboxManagerException {
-        MessageResult[] result = getMessages(GeneralMessageSetImpl.oneKey(key),
+    public MimeMessage retrieve(final String key) throws MailboxManagerException {
+        final Iterator it = getMessages(GeneralMessageSetImpl.oneKey(key),
                 MessageResult.MIME_MESSAGE);
-        if (result != null && result.length == 1) {
-            return result[0].getMimeMessage();
+        final MimeMessage result;
+        if (it.hasNext()) {
+            final MessageResult message = (MessageResult) it.next();
+            result = message.getMimeMessage();
         } else {
-            return null;
+            result = null;
         }
+        return result;
     }
 
     public String store(MimeMessage message) throws MailboxManagerException {

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java Tue Nov 20 15:21:20 2007
@@ -19,15 +19,12 @@
 
 package org.apache.james.mailboxmanager.mailbox;
 
-import java.util.List;
+import java.util.Iterator;
 
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.MessageResult;
 
 public interface EventQueueingSessionMailbox {
     
-    MessageResult[] getFlagEvents(boolean reset) throws MailboxManagerException;
-    
-    MessageResult[] getExpungedEvents(boolean reset) throws MailboxManagerException;
+    Iterator getExpungedEvents(boolean reset) throws MailboxManagerException;
 
 }

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java Tue Nov 20 15:21:20 2007
@@ -52,7 +52,8 @@
      * 
      * @param result
      *            which fields to be returned in MessageResult
-     * @return MessageResult with the fields defined by <b>result</b><br />
+     * @return {@link MessageResult} <code>Iterator</code> with 
+     * the fields defined by <b>result</b><br />
      *         <ul>
      *         <li> IMAP, UIDPLUS: nothing required </li>
      *         <li> Javamail Folder: requires the expunged Message[]</li>
@@ -60,7 +61,7 @@
      * @throws MailboxManagerException
      *             if anything went wrong
      */
-    MessageResult[] expunge(GeneralMessageSet set, int result)
+    Iterator expunge(GeneralMessageSet set, int result)
             throws MailboxManagerException;
     
 

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java Tue Nov 20 15:21:20 2007
@@ -20,6 +20,7 @@
 package org.apache.james.mailboxmanager.mailbox;
 
 import java.util.Date;
+import java.util.Iterator;
 
 import javax.mail.internet.MimeMessage;
 
@@ -91,7 +92,7 @@
      * @throws MailboxManagerException 
      */
 
-    MessageResult[] getMessages(GeneralMessageSet set, int result) throws MailboxManagerException;
+    Iterator getMessages(GeneralMessageSet set, int result) throws MailboxManagerException;
     
     void remove(GeneralMessageSet set)
             throws MailboxManagerException;

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java Tue Nov 20 15:21:20 2007
@@ -19,9 +19,10 @@
 
 package org.apache.james.mailboxmanager.mailbox;
 
+import java.util.Iterator;
+
 import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.SearchParameters;
 
 public interface SearchableMailbox {
@@ -38,5 +39,5 @@
      * @throws UnsupportedCriteriaException when any of the search parameters are 
      * not supported by this mailbox
      */
-    MessageResult[] search(GeneralMessageSet set,SearchParameters searchTerm, int result) throws MailboxManagerException;
+    Iterator search(GeneralMessageSet set,SearchParameters searchTerm, int result) throws MailboxManagerException;
 }

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/tracking/UidChangeTracker.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/tracking/UidChangeTracker.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/tracking/UidChangeTracker.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/tracking/UidChangeTracker.java Tue Nov 20 15:21:20 2007
@@ -19,7 +19,10 @@
 
 package org.apache.james.mailboxmanager.tracking;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -50,11 +53,12 @@
         this.lastUid = lastUid;
     }
 
-    public synchronized void expunged(MessageResult[] expunged) {
-        for (int i = 0; i < expunged.length; i++) {
-            if (expunged[i] != null) {
-                cache.remove(new Long(expunged[i].getUid()));
-                eventDispatcher.expunged(expunged[i], 0);
+    public synchronized void expunged(final List expunged) {
+        for (Iterator it = expunged.iterator();it.hasNext();) {
+            final MessageResult result = (MessageResult) it.next();
+            if (result != null) {
+                cache.remove(new Long(result.getUid()));
+                eventDispatcher.expunged(result, 0);
             }
         }
     }
@@ -65,11 +69,11 @@
      * @param sessionId id of the session upating the flags
      * @see #flagsUpdated(MessageResult, long)
      */
-    public synchronized void flagsUpdated(MessageResult[] messageResults, long sessionId) {
+    public synchronized void flagsUpdated(Collection messageResults, long sessionId) {
         if (messageResults != null) {
-            final int length = messageResults.length;
-            for (int i=0;i<length;i++) {
-                flagsUpdated(messageResults[i], sessionId);
+            for (final Iterator it = messageResults.iterator();it.hasNext();) {
+                final MessageResult result = (MessageResult) it.next();
+                flagsUpdated(result, sessionId);
             }
         }
     }
@@ -88,11 +92,10 @@
         }
     }
     
-    public synchronized void found(UidRange range,
-            MessageResult[] messageResults) {
+    public synchronized void found(UidRange range, final Collection messageResults) {
         Set expectedSet = getSubSet(range);
-        for (int i = 0; i < messageResults.length; i++) {
-            final MessageResult messageResult = messageResults[i];
+        for (final Iterator it=messageResults.iterator();it.hasNext();) {
+            final MessageResult messageResult = (MessageResult) it.next();
             if (messageResult != null) {
                 long uid = messageResult.getUid();
                 if (uid>lastScannedUid) {
@@ -163,8 +166,9 @@
     public synchronized void found(MessageResult messageResult) {
         if (messageResult != null) {
             long uid = messageResult.getUid();
-            found(new UidRange(uid, uid),
-                    new MessageResult[] { messageResult });
+            Collection results = new ArrayList();
+            results.add(messageResult);
+            found(new UidRange(uid, uid), results);
         }
     }
 

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/FlaggedSessionMailboxWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/FlaggedSessionMailboxWrapper.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/FlaggedSessionMailboxWrapper.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/FlaggedSessionMailboxWrapper.java Tue Nov 20 15:21:20 2007
@@ -26,7 +26,6 @@
 import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;
-import org.apache.james.mailboxmanager.impl.MessageResultImpl;
 import org.apache.james.mailboxmanager.mailbox.FlaggedMailbox;
 
 public class FlaggedSessionMailboxWrapper extends SessionMailboxWrapper {
@@ -36,8 +35,11 @@
     }
     
     
-    public synchronized MessageResult[] expunge(GeneralMessageSet set, int result) throws MailboxManagerException {
-        return addMsnToResults(((FlaggedMailbox) mailbox).expunge(toUidSet(set), noMsnResult(result)),result);
+    public synchronized Iterator expunge(GeneralMessageSet set, int result) throws MailboxManagerException {
+        final GeneralMessageSet uidSet = toUidSet(set);
+        final int noMsnResult = noMsnResult(result);
+        final Iterator expunge = ((FlaggedMailbox) mailbox).expunge(uidSet, noMsnResult);
+        return addMsn(expunge);
     }
 
     public MessageResult getFirstUnseen(int result) throws MailboxManagerException {
@@ -58,32 +60,6 @@
 
     public Iterator setFlags(Flags flags, boolean value, boolean replace, GeneralMessageSet set, int result) throws MailboxManagerException {
         final Iterator results = ((FlaggedMailbox) mailbox).setFlags(flags, value, replace,toUidSet(set), result);
-        return new MsnIterator(results, getNumberCache());
-    }
-    
-    private static final class MsnIterator implements Iterator {
-        private final Iterator it;
-        private final UidToMsnBidiMap map;
-        
-        public MsnIterator(final Iterator it, final UidToMsnBidiMap map) {
-            this.it = it;
-            this.map = map;
-        }
-        
-        public boolean hasNext() {
-            return it.hasNext();
-        }
-
-        public Object next() {
-            final MessageResult next = (MessageResult) it.next();
-            final MessageResultImpl result = new MessageResultImpl(next);
-            result.setMsn(map.getMsn(result.getUid()));
-            return result;
-        }
-
-        public void remove() {
-            throw new UnsupportedOperationException();
-        }
-        
+        return addMsn(results);
     }
 }

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/ImapMailboxSessionWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/ImapMailboxSessionWrapper.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/ImapMailboxSessionWrapper.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/ImapMailboxSessionWrapper.java Tue Nov 20 15:21:20 2007
@@ -19,9 +19,10 @@
 
 package org.apache.james.mailboxmanager.wrapper;
 
+import java.util.Iterator;
+
 import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.Quota;
 import org.apache.james.mailboxmanager.SearchParameters;
 import org.apache.james.mailboxmanager.acl.MailboxRights;
@@ -64,8 +65,9 @@
         return ((ImapMailbox) mailbox).getUidNext();
     }
 
-    public MessageResult[] search(GeneralMessageSet set, SearchParameters searchTerm, int result) throws MailboxManagerException {
-        return addMsnToResults(((SearchableMailbox)mailbox).search(set, searchTerm, noMsnResult(result)),result);
+    public Iterator search(GeneralMessageSet set, SearchParameters searchTerm, int result) throws MailboxManagerException {
+        final Iterator results = ((SearchableMailbox)mailbox).search(set, searchTerm, noMsnResult(result));
+        return addMsn(results);
     }
 
     public long getSessionId() {

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/NumberStableSessionWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/NumberStableSessionWrapper.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/NumberStableSessionWrapper.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/NumberStableSessionWrapper.java Tue Nov 20 15:21:20 2007
@@ -19,6 +19,7 @@
 
 package org.apache.james.mailboxmanager.wrapper;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
@@ -42,6 +43,32 @@
 public abstract class NumberStableSessionWrapper extends AbstractGeneralMailbox implements EventQueueingSessionMailbox,
         MailboxListener {
 
+    private static final class MsnIterator implements Iterator {
+            private final Iterator it;
+            private final UidToMsnBidiMap map;
+            
+            public MsnIterator(final Iterator it, final UidToMsnBidiMap map) {
+                this.it = it;
+                this.map = map;
+            }
+            
+            public boolean hasNext() {
+                return it.hasNext();
+            }
+    
+            public Object next() {
+                final MessageResult next = (MessageResult) it.next();
+                final MessageResultImpl result = new MessageResultImpl(next);
+                result.setMsn(map.getMsn(result.getUid()));
+                return result;
+            }
+    
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+            
+        }
+
     protected GeneralMailbox mailbox;
 
     private UidToMsnBidiMap numberCache = null;
@@ -76,11 +103,13 @@
         if (numberCache == null && mailbox != null) {
             startingNumberCache = true;
             try {
-                MessageResult[] mr = mailbox.getMessages(GeneralMessageSetImpl
+                final Iterator it = mailbox.getMessages(GeneralMessageSetImpl
                         .all(), MessageResult.UID);
                 numberCache = new UidToMsnBidiMap();
-                for (int i = 0; i < mr.length; i++) {
-                    numberCache.add(mr[i].getUid());
+                while (it.hasNext()) {
+                    final MessageResult result = (MessageResult) it.next();
+                    final long uid = result.getUid();
+                    numberCache.add(uid);
                 }
             } finally {
                 startingNumberCache = false;
@@ -139,13 +168,13 @@
         return msnFlagEvents;
     }
 
-    public synchronized MessageResult[] getExpungedEvents(boolean reset)
+    public synchronized Iterator getExpungedEvents(boolean reset)
             throws MailboxManagerException {
         final MessageResult[] msnExpungedEvents  = buildMsnEvents(expungedEventList,reset);
         if (reset) {
             expungedEventList = new TreeSet();
         } 
-        return msnExpungedEvents;
+        return Arrays.asList(msnExpungedEvents).iterator();
     }
 
     protected MessageResult[]  buildMsnEvents(final Collection messageResults, 
@@ -244,6 +273,10 @@
         mailbox=null;
     }
     
+    protected final Iterator addMsn(Iterator iterator) throws MailboxManagerException {
+        return new MsnIterator(iterator, getNumberCache());
+    }
+
     /**
      * for testing
      * @return the listener this class uses to subscribe to Mailbox events

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java Tue Nov 20 15:21:20 2007
@@ -20,6 +20,7 @@
 package org.apache.james.mailboxmanager.wrapper;
 
 import java.util.Date;
+import java.util.Iterator;
 
 import javax.mail.internet.MimeMessage;
 
@@ -51,10 +52,10 @@
         return mailbox.getMessageResultTypes() | MessageResult.MSN;
     }
 
-    public MessageResult[] getMessages(GeneralMessageSet set, int result)
+    public Iterator getMessages(GeneralMessageSet set, int result)
             throws MailboxManagerException {
-        return addMsnToResults(mailbox.getMessages(toUidSet(set),
-                noMsnResult(result)), result);
+        return addMsn(mailbox.getMessages(toUidSet(set),
+                noMsnResult(result)));
     }
 
     public int getMessageSetTypes() {

Modified: james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java (original)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java Tue Nov 20 15:21:20 2007
@@ -27,12 +27,9 @@
 import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.impl.MessageResultImpl;
 import org.jmock.MockObjectTestCase;
 
-import junit.framework.TestCase;
-
 public class MessageResultImplIncludedResultsTest extends MockObjectTestCase {
 
     MessageResultImpl result;
@@ -139,5 +136,85 @@
         assertEquals(MessageResult.BODY_CONTENT, result.getIncludedResults());
         result = new MessageResultImpl(this.result);
         assertEquals(MessageResult.BODY_CONTENT, result.getIncludedResults());
+    }
+    
+    public void testShouldIncludedResultsWhenFlagsAndUidSet() {
+        Flags flags = new Flags();
+        result.setFlags(flags);
+        result.setUid(99);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        MessageResult result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+    }
+    
+    public void testShouldIncludedResultsWhenAllSet() {
+        Flags flags = new Flags();
+        result.setFlags(flags);
+        assertEquals(MessageResult.FLAGS, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        result.setUid(99);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        result.setMessageBody(content);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS | MessageResult.BODY_CONTENT, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        assertTrue(MessageResultUtils.isBodyContentIncluded(result));
+        result.setFullMessage(content);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS | 
+                MessageResult.BODY_CONTENT | MessageResult.FULL_CONTENT, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        assertTrue(MessageResultUtils.isBodyContentIncluded(result));
+        assertTrue(MessageResultUtils.isFullContentIncluded(result));
+        result.setHeaders(new ArrayList());
+        assertEquals(MessageResult.UID | MessageResult.FLAGS | 
+                MessageResult.BODY_CONTENT | MessageResult.FULL_CONTENT 
+                | MessageResult.HEADERS, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        assertTrue(MessageResultUtils.isBodyContentIncluded(result));
+        assertTrue(MessageResultUtils.isFullContentIncluded(result));
+        assertTrue(MessageResultUtils.isHeadersIncluded(result));
+        result.setInternalDate(new Date());
+        assertEquals(MessageResult.UID | MessageResult.FLAGS | 
+                MessageResult.BODY_CONTENT | MessageResult.FULL_CONTENT 
+                | MessageResult.HEADERS | MessageResult.INTERNAL_DATE, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        assertTrue(MessageResultUtils.isBodyContentIncluded(result));
+        assertTrue(MessageResultUtils.isFullContentIncluded(result));
+        assertTrue(MessageResultUtils.isHeadersIncluded(result));
+        assertTrue(MessageResultUtils.isInternalDateIncluded(result));
+        result.setSize(100);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS | 
+                MessageResult.BODY_CONTENT | MessageResult.FULL_CONTENT 
+                | MessageResult.HEADERS | MessageResult.INTERNAL_DATE
+                | MessageResult.SIZE, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        assertTrue(MessageResultUtils.isBodyContentIncluded(result));
+        assertTrue(MessageResultUtils.isFullContentIncluded(result));
+        assertTrue(MessageResultUtils.isHeadersIncluded(result));
+        assertTrue(MessageResultUtils.isInternalDateIncluded(result));
+        assertTrue(MessageResultUtils.isSizeIncluded(result));
+        result.setMsn(100);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS | 
+                MessageResult.BODY_CONTENT | MessageResult.FULL_CONTENT 
+                | MessageResult.HEADERS | MessageResult.INTERNAL_DATE
+                | MessageResult.SIZE | MessageResult.MSN, result.getIncludedResults());
+        assertTrue(MessageResultUtils.isFlagsIncluded(result));
+        assertTrue(MessageResultUtils.isUidIncluded(result));
+        assertTrue(MessageResultUtils.isBodyContentIncluded(result));
+        assertTrue(MessageResultUtils.isFullContentIncluded(result));
+        assertTrue(MessageResultUtils.isHeadersIncluded(result));
+        assertTrue(MessageResultUtils.isInternalDateIncluded(result));
+        assertTrue(MessageResultUtils.isSizeIncluded(result));
+        assertTrue(MessageResultUtils.isMsnIncluded(result));
     }
 }

Modified: james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java (original)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java Tue Nov 20 15:21:20 2007
@@ -106,6 +106,12 @@
         assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.MIME_MESSAGE), MessageResult.MIME_MESSAGE | MessageResult.FLAGS));
     }
     
+    public void testFlagsAndUidIncluded() throws Exception {
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.UID), MessageResult.FLAGS));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.UID), MessageResult.UID));
+    }
+    
+    
     private MessageResult mock(int included) {
         return mock(included, true);
     }

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java Tue Nov 20 15:21:20 2007
@@ -109,9 +109,9 @@
 
     private void addExpungedResponses(List responses, final ImapMailboxSession mailbox) {
         try {
-            MessageResult[] expunged = mailbox.getExpungedEvents(true);
-            for (int i = 0; i < expunged.length; i++) {
-                MessageResult mr = expunged[i];
+            final Iterator expunged = mailbox.getExpungedEvents(true);
+            while (expunged.hasNext()) {
+                MessageResult mr = (MessageResult) expunged.next();
                 final int msn = mr.getMsn();
                 // TODO: use factory
                 ExpungeResponse response = new ExpungeResponse(msn);
@@ -129,9 +129,9 @@
             for (final Iterator it = events.flagUpdateUids(); it.hasNext();) {
                 Long uid = (Long) it.next();
                 GeneralMessageSet messageSet = GeneralMessageSetImpl.oneUid(uid.longValue());
-                final MessageResult[] messages = mailbox.getMessages(messageSet, MessageResult.FLAGS | MessageResult.MSN);
-                for (int i = 0; i < messages.length; i++) {
-                    MessageResult mr = messages[i];
+                final Iterator messages = mailbox.getMessages(messageSet, MessageResult.FLAGS | MessageResult.MSN);
+                while (messages.hasNext()) {
+                    MessageResult mr = (MessageResult) it.next();
                     int msn = mr.getMsn();
                     final Flags flags = mr.getFlags();
                     final Long uidOut;

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java Tue Nov 20 15:21:20 2007
@@ -88,14 +88,15 @@
             for (int i = 0; i < idSet.length; i++) {
                 GeneralMessageSet messageSet = GeneralMessageSetImpl.range(idSet[i]
                         .getLowVal(), idSet[i].getHighVal(), useUids);
-                MessageResult[] fetchResults;
-                    fetchResults = mailbox.getMessages(messageSet, resultToFetch);
-                for (int j = 0; j < fetchResults.length; j++) {
-                    String msgData = outputMessage(fetch, fetchResults[j], mailbox,
+                final Iterator it = mailbox.getMessages(messageSet, resultToFetch);
+                while (it.hasNext()) {
+                    final MessageResult result = (MessageResult) it.next();
+                    String msgData = outputMessage(fetch, result, mailbox,
                             useUids);
+                    final int msn = result.getMsn();
                     // TODO: this is inefficient
                     // TODO: stream output upon response
-                    LegacyFetchResponse response = new LegacyFetchResponse(fetchResults[j].getMsn(), msgData);
+                    LegacyFetchResponse response = new LegacyFetchResponse(msn, msgData);
                     responder.respond(response);
                 }
             }

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SearchProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SearchProcessor.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SearchProcessor.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/SearchProcessor.java Tue Nov 20 15:21:20 2007
@@ -19,20 +19,19 @@
 
 package org.apache.james.imapserver.processor.imap4rev1;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.mail.search.SearchTerm;
 
 import org.apache.james.api.imap.ImapCommand;
-import org.apache.james.api.imap.ImapConstants;
 import org.apache.james.api.imap.ImapMessage;
 import org.apache.james.api.imap.ProtocolException;
 import org.apache.james.api.imap.message.request.ImapRequest;
-import org.apache.james.api.imap.message.response.ImapResponseMessage;
 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.ImapProcessor.Responder;
 import org.apache.james.imap.message.request.imap4rev1.SearchRequest;
 import org.apache.james.imap.message.response.imap4rev1.server.SearchResponse;
 import org.apache.james.imapserver.processor.base.AbstractImapRequestProcessor;
@@ -76,24 +75,33 @@
             resultCode = MessageResult.MSN;
         }
         
-        MessageResult[] messageResults;
+        final Iterator it;
         try {
             // TODO: implementation
-            messageResults = mailbox.search(GeneralMessageSetImpl.all(),
+            it = mailbox.search(GeneralMessageSetImpl.all(),
                     new SearchParameters(), resultCode);
         } catch (MailboxManagerException e) {
             throw new MailboxException(e);
         }
 
-        final int length = messageResults.length;
-        long[] ids = new long[length];
-        for (int i = 0; i < length; i++) {
+        final List results = new ArrayList();
+        while (it.hasNext()) {
+            final MessageResult result = (MessageResult) it.next();
+            final Long number;
             if (useUids) {
-                ids[i] = messageResults[i].getUid();
+                number = new Long(result.getUid());
             } else {
-                ids[i] = messageResults[i].getMsn();
+                number = new Long(result.getMsn());
             }
+            results.add(number);
         }
+        
+        final int length = results.size();
+        long[] ids = new long[length];
+        for (int i = 0; i < length; i++) {
+            ids[i] = ((Long) results.get(i)).longValue();
+        }
+        
         final SearchResponse response = new SearchResponse(ids);
         responder.respond(response);
         boolean omitExpunged = (!useUids);

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapSessionImpl.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapSessionImpl.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapSessionImpl.java Tue Nov 20 15:21:20 2007
@@ -101,10 +101,10 @@
 
                 // Expunged messages
                 if (!omitExpunged) {
-                    MessageResult[] expunged = selected.getMailbox().getExpungedEvents(
+                    final Iterator expunged = selected.getMailbox().getExpungedEvents(
                             true);
-                    for (int i = 0; i < expunged.length; i++) {
-                        MessageResult mr = expunged[i];
+                    while (expunged.hasNext()) {
+                        MessageResult mr = (MessageResult) expunged.next();
                         response.expungeResponse(mr.getMsn());
                     }
                 }

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/SelectedMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/SelectedMailboxSession.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/SelectedMailboxSession.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/SelectedMailboxSession.java Tue Nov 20 15:21:20 2007
@@ -20,11 +20,11 @@
 package org.apache.james.imapserver;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;
@@ -64,8 +64,8 @@
         for (final Iterator it = events.flagUpdateUids(); it.hasNext();) {
             Long uid = (Long) it.next();
             GeneralMessageSet messageSet = GeneralMessageSetImpl.oneUid(uid.longValue());
-            final MessageResult[] messages = mailbox.getMessages(messageSet, MessageResult.FLAGS | MessageResult.MSN);
-            results.addAll(Arrays.asList(messages));
+            final Iterator messages = mailbox.getMessages(messageSet, MessageResult.FLAGS | MessageResult.MSN);
+            results.addAll(IteratorUtils.toList(messages));
         }
         return results.iterator();
     }

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/FetchCommand.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/FetchCommand.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/FetchCommand.java Tue Nov 20 15:21:20 2007
@@ -80,19 +80,20 @@
             fetch.uid = true;
         }
 
-        int resultToFetch = fetch.getNeededMessageResult();
-        ImapMailboxSession mailbox = session.getSelected().getMailbox();
+        final int resultToFetch = fetch.getNeededMessageResult();
+        final ImapMailboxSession mailbox = session.getSelected().getMailbox();
         for (int i = 0; i < idSet.length; i++) {
-            GeneralMessageSet messageSet=GeneralMessageSetImpl.range(idSet[i].getLowVal(),idSet[i].getHighVal(),useUids);
-            MessageResult[] result;
+            final GeneralMessageSet messageSet=GeneralMessageSetImpl.range(idSet[i].getLowVal(),idSet[i].getHighVal(),useUids);
+            final Iterator it;
             try {
-                result = mailbox.getMessages(messageSet,resultToFetch);
+                it = mailbox.getMessages(messageSet,resultToFetch);
             } catch (MailboxManagerException e) {
                 throw new MailboxException(e);
             }
-            for (int j = 0; j < result.length; j++) {
-                String msgData = outputMessage( fetch, result[j], mailbox, useUids );
-                response.fetchResponse( result[j].getMsn(), msgData );
+            while (it.hasNext()) {
+                final MessageResult result = (MessageResult) it.next();
+                String msgData = outputMessage( fetch, result, mailbox, useUids );
+                response.fetchResponse( result.getMsn(), msgData );
 
             }
         }

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/SearchCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/SearchCommand.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/SearchCommand.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/commands/SearchCommand.java Tue Nov 20 15:21:20 2007
@@ -19,11 +19,7 @@
 
 package org.apache.james.imapserver.commands;
 
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.mail.search.SearchTerm;
+import java.util.Iterator;
 
 import org.apache.james.imapserver.ImapRequestLineReader;
 import org.apache.james.imapserver.ImapResponse;
@@ -33,7 +29,6 @@
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.SearchParameters;
-import org.apache.james.mailboxmanager.SearchParameters.NamedSearchCriteria;
 import org.apache.james.mailboxmanager.SearchParameters.NumericRange;
 import org.apache.james.mailboxmanager.SearchParameters.SearchCriteria;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
@@ -77,21 +72,27 @@
         } else {
             result= MessageResult.MSN;
         }
-        MessageResult[] messageResults;
+        final Iterator it;
         try {
-            messageResults = mailbox.search(GeneralMessageSetImpl.all(),searchTerm, result);
+            it = mailbox.search(GeneralMessageSetImpl.all(),searchTerm, result);
         } catch (MailboxManagerException e) {
           throw new MailboxException(e);
         }
         StringBuffer idList = new StringBuffer();
-        for (int i = 0; i < messageResults.length; i++) {
-            if ( i > 0 ) {
+        boolean first = true;
+        while (it.hasNext()) {
+            if ( first ) {
+                first = false;
+            } else {
                 idList.append( SP );
             }
+            final MessageResult message = (MessageResult) it.next();
             if ( useUids ) {
-                idList.append( messageResults[i].getUid());
+                final long uid = message.getUid();
+                idList.append( uid );
             } else {
-                idList.append( messageResults[i].getMsn());
+                final int msn = message.getMsn();
+                idList.append( msn );
             }
         }
         

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java Tue Nov 20 15:21:20 2007
@@ -39,6 +39,7 @@
 import javax.mail.internet.MimeMessage;
 
 import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.james.imapserver.ImapRequestHandler;
 import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ImapSessionImpl;
@@ -130,10 +131,11 @@
     
     public MimeMessage[] getMessages(String folder) throws MailboxManagerException {
         GeneralMailboxSession mailbox=getImapMailboxSession(folder);
-        MessageResult[] messageResults=mailbox.getMessages(GeneralMessageSetImpl.all(),MessageResult.MIME_MESSAGE);
-        MimeMessage[] mms=new MimeMessage[messageResults.length];
-        for (int i = 0; i < messageResults.length; i++) {
-            mms[i]=messageResults[i].getMimeMessage();
+        Iterator iterator =mailbox.getMessages(GeneralMessageSetImpl.all(),MessageResult.MIME_MESSAGE);
+        List messages = IteratorUtils.toList(iterator);
+        MimeMessage[] mms=new MimeMessage[messages.size()];
+        for (int i = 0; i < messages.size(); i++) {
+            mms[i]=((MessageResult) messages.get(i)).getMimeMessage();
         }
         mailbox.close();
         return mms;
@@ -141,11 +143,11 @@
     
     public long[] getUids(String folder) throws MailboxManagerException {
         GeneralMailboxSession mailbox=getImapMailboxSession(folder);
-        MessageResult[] messageResults=mailbox.getMessages(GeneralMessageSetImpl.all(),MessageResult.UID);
-
-        long[] uids=new long[messageResults.length];
-        for (int i = 0; i < messageResults.length; i++) {
-            uids[i]=messageResults[i].getUid();
+        Iterator iterator = mailbox.getMessages(GeneralMessageSetImpl.all(),MessageResult.UID);
+        List messages = IteratorUtils.toList(iterator);
+        long[] uids=new long[messages.size()];
+        for (int i = 0; i < messages.size(); i++) {
+            uids[i]=((MessageResult)messages.get(i)).getUid();
         }
         mailbox.close();
         return uids;

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/AbstractImapMailboxSelfTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/AbstractImapMailboxSelfTestCase.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/AbstractImapMailboxSelfTestCase.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/AbstractImapMailboxSelfTestCase.java Tue Nov 20 15:21:20 2007
@@ -20,6 +20,8 @@
 package org.apache.james.mailboxmanager;
 
 import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.mail.Flags;
 import javax.mail.MessagingException;
@@ -27,6 +29,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
 import org.apache.james.mailboxmanager.impl.MailboxListenerCollector;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
@@ -90,20 +93,20 @@
             assertEquals(i+1, mr.getMsn());
         }
         mailbox.setFlags(new Flags(Flags.Flag.DELETED), true, false, GeneralMessageSetImpl.uidRange(2, 4), MessageResult.NOTHING);
-        final MessageResult[] expungeResult1=mailbox.expunge(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator expungeResult1=mailbox.expunge(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {2,3,4},new int[] {2,3,4},expungeResult1);
         
-        final MessageResult[] getResult1 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator getResult1 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {1,5},new int[] {1,5},getResult1);
         
         
-        final MessageResult[] expungeEventResult1 = mailbox.getExpungedEvents(false);
+        final Iterator expungeEventResult1 = mailbox.getExpungedEvents(false);
         checkMessageResults(new long[] {2,3,4},new int[] {2,3,4},expungeEventResult1);
-        final MessageResult[] expungeEventResult2 = mailbox.getExpungedEvents(true);
+        final Iterator expungeEventResult2 = mailbox.getExpungedEvents(true);
         checkMessageResults(new long[] {2,3,4},new int[] {2,2,2},expungeEventResult2);
         
         
-        final MessageResult[] getResult2 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator getResult2 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {1,5},new int[] {1,2},getResult2);
         
         for (int i = 0; i < 5; i++) {
@@ -112,24 +115,24 @@
             assertEquals(3+i, mr.getMsn());
         }
 
-        final MessageResult[] getResult3 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator getResult3 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {1,5,6,7,8,9,10},new int[] {1,2,3,4,5,6,7},getResult3);
         
         mailbox.setFlags(new Flags(Flags.Flag.DELETED), true, false, GeneralMessageSetImpl.msnRange(2,4), MessageResult.NOTHING);
         mailbox.setFlags(new Flags(Flags.Flag.DELETED), true, false, GeneralMessageSetImpl.oneMsn(6), MessageResult.NOTHING);
         
-        final MessageResult[] expungeResult2=mailbox.expunge(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator expungeResult2=mailbox.expunge(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {5,6,7,9},new int[] {2,3,4,6},expungeResult2);
         
-        final MessageResult[] getResult4 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator getResult4 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {1,8,10},new int[] {1,5,7},getResult4);
         
-        final MessageResult[] expungeEventResult3 = mailbox.getExpungedEvents(false);
+        final Iterator expungeEventResult3 = mailbox.getExpungedEvents(false);
         checkMessageResults(new long[] {5,6,7,9},new int[] {2,3,4,6},expungeEventResult3);
-        final MessageResult[] expungeEventResult4 = mailbox.getExpungedEvents(true);
+        final Iterator expungeEventResult4 = mailbox.getExpungedEvents(true);
         checkMessageResults(new long[] {5,6,7,9},new int[] {2,2,2,3},expungeEventResult4);
         
-        final MessageResult[] getResult5 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
+        final Iterator getResult5 = mailbox.getMessages(GeneralMessageSetImpl.all(), MessageResult.UID | MessageResult.MSN);
         checkMessageResults(new long[] {1,8,10},new int[] {1,2,3},getResult5);
     }
     
@@ -140,13 +143,6 @@
         assertEquals(2, mailbox.getUidNext());
     }
     
-    public void testAddedEvents() throws MailboxManagerException, MessagingException {
-        assertEquals(0,mailbox.getFlagEvents(false).length);
-        MessageResult mr=mailbox.appendMessage(TestUtil.createMessage(), new Date(), MessageResult.UID | MessageResult.MSN);
-        assertEquals(0,mailbox.getFlagEvents(false).length);
-        assertEquals(0,mailbox.getFlagEvents(true).length);
-    }
-    
     protected void assertEventCount(MailboxListenerCollector collector,long[] added, long[] flags, long[] expunged) {
         assertEquals("added size", added.length, collector.getAddedList(true).size());
         assertEquals("flags size", added.length, collector.getFlaggedList(true).size());
@@ -154,12 +150,14 @@
         
     }
     
-    protected void checkMessageResults(long[] uids,int[] msns,MessageResult[] messageResults) {
+    protected void checkMessageResults(long[] uids,int[] msns, Iterator messages) {
+        List messageResults = IteratorUtils.toList(messages);
         assertEquals(uids.length, msns.length);
-        assertEquals(uids.length, messageResults.length);
-        for (int i = 0; i < messageResults.length; i++) {
-            assertEquals("Uid at pos "+i,uids[i], messageResults[i].getUid());
-            assertEquals("Msn at pos "+i,msns[i], messageResults[i].getMsn());
+        assertEquals(uids.length, messageResults.size());
+        int i=0;
+        for (Iterator it=messageResults.iterator(); it.hasNext();i++) {
+            assertEquals("Uid at pos "+i,uids[i], ((MessageResult)it.next()).getUid());
+            assertEquals("Msn at pos "+i,msns[i], ((MessageResult)it.next()).getMsn());
         }
     }
 

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/impl/UidChangeTrackerTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/impl/UidChangeTrackerTestCase.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/impl/UidChangeTrackerTestCase.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/impl/UidChangeTrackerTestCase.java Tue Nov 20 15:21:20 2007
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailboxmanager.impl;
 
+import java.util.Arrays;
+
 import javax.mail.Flags;
 
 import junit.framework.TestCase;
@@ -55,28 +57,28 @@
         results=new MessageResultImpl[1];
         
         results[0]=new MessageResultImpl(1000l);
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
         assertCollectorSizes(0,0,0);
         
         results[0]=new MessageResultImpl(1001l);
-        tracker.found(new UidRange(1001,1001),results);
+        tracker.found(new UidRange(1001,1001),Arrays.asList(results));
         assertCollectorSizes(1,0,0);
         assertEquals(1001,((MessageResult) collector.getAddedList(true).get(0)).getUid());
         assertCollectorSizes(0,0,0);
         
         results[0]=new MessageResultImpl(1001l,new Flags(Flags.Flag.FLAGGED));
-        tracker.found(new UidRange(1001,1001),results);
+        tracker.found(new UidRange(1001,1001),Arrays.asList(results));
         assertCollectorSizes(0,0,1);
         result=(MessageResult) collector.getFlaggedList(true).get(0);
         assertEquals(1001,result.getUid());
         assertEquals(new Flags(Flags.Flag.FLAGGED),result.getFlags());
         
         // nothing changed
-        tracker.found(new UidRange(1001,1001),results);
+        tracker.found(new UidRange(1001,1001),Arrays.asList(results));
         assertCollectorSizes(0,0,0);
         
         // 1000 got expunged
-        tracker.found(new UidRange(1000,1001),results);
+        tracker.found(new UidRange(1000,1001),Arrays.asList(results));
         assertCollectorSizes(0,1,0);
         assertEquals(1000,((MessageResult) collector.getExpungedList(true).get(0)).getUid());
         
@@ -88,29 +90,29 @@
         
         MessageResult result;
         results[0]=new MessageResultImpl(1000l,new Flags(Flags.Flag.FLAGGED));
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
         assertCollectorSizes(0,0,0);
         
         results[0]=new MessageResultImpl(1000l);
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
         assertCollectorSizes(0,0,0);
 
         results[0]=new MessageResultImpl(1000l,new Flags(Flags.Flag.FLAGGED));
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
 
         results[0]=new MessageResultImpl(1000l,new Flags(Flags.Flag.SEEN));
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
         assertCollectorSizes(0,0,1);
         result=(MessageResult) collector.getFlaggedList(true).get(0);
         assertEquals(1000,result.getUid());
         assertEquals(new Flags(Flags.Flag.SEEN),result.getFlags());
         
         results[0]=new MessageResultImpl(1000l);
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
         assertCollectorSizes(0,0,0);
         
         results[0]=new MessageResultImpl(1000l,new Flags(Flags.Flag.DRAFT));
-        tracker.found(new UidRange(1000,1000),results);
+        tracker.found(new UidRange(1000,1000),Arrays.asList(results));
         assertCollectorSizes(0,0,1);
         result=(MessageResult) collector.getFlaggedList(true).get(0);
         assertEquals(1000,result.getUid());

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueImapMailboxSelfTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueImapMailboxSelfTestCase.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueImapMailboxSelfTestCase.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueImapMailboxSelfTestCase.java Tue Nov 20 15:21:20 2007
@@ -19,10 +19,7 @@
 
 package org.apache.james.mailboxmanager.torque;
 
-import javax.mail.MessagingException;
-
 import org.apache.james.mailboxmanager.AbstractImapMailboxSelfTestCase;
-import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
 import org.apache.james.mailboxmanager.mock.MockUser;
 import org.apache.james.mailboxmanager.mock.TorqueMailboxManagerProviderSingleton;
@@ -41,10 +38,6 @@
         mailboxManager = mailboxManagerProvider .getMailboxManagerInstance(new MockUser());
         
         super.setUp();
-    }
-    
-    public void testAddedEvents() throws MailboxManagerException, MessagingException {
-        super.testAddedEvents();
     }
 
 }

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java Tue Nov 20 15:21:20 2007
@@ -25,6 +25,7 @@
 import javax.mail.Flags;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.TestUtil;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
@@ -78,18 +79,18 @@
         mr = MailboxRowPeer.retrieveByPK(mr.getMailboxId());
         assertEquals(1, mr.getLastUid());
         
-        MessageResult[] messageResult=torqueMailbox.getMessages(GeneralMessageSetImpl.oneUid(1l),MessageResult.MIME_MESSAGE);
+        List messageResult=IteratorUtils.toList(torqueMailbox.getMessages(GeneralMessageSetImpl.oneUid(1l),MessageResult.MIME_MESSAGE));
         assertNotNull(messageResult);
-        assertEquals(1,messageResult.length);
-        messageResult[0].getMimeMessage().writeTo(System.out);
-        assertTrue(TorqueTestUtil.contentEquals(mm,messageResult[0].getMimeMessage(),true));
+        assertEquals(1,messageResult.size());
+        //((MessageResult)messageResult.get(0)).getMimeMessage().writeTo(System.out);
+        assertTrue(TorqueTestUtil.contentEquals(mm,((MessageResult)messageResult.get(0)).getMimeMessage(),true));
         
         Flags f=new Flags();
         f.add(Flags.Flag.DELETED);
         torqueMailbox.setFlags(f,true,false, GeneralMessageSetImpl.oneUid(1l), MessageResult.NOTHING);
-        MessageResult[] messageResults=torqueMailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.UID);
-        assertEquals(1,messageResults.length);
-        assertEquals(1l,messageResults[0].getUid());
+        List messageResults=IteratorUtils.toList(torqueMailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.UID));
+        assertEquals(1,messageResults.size());
+        assertEquals(1l,((MessageResult)messageResults.get(0)).getUid());
     }
 
 }

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/repository/TorqueMailboxManagerMailRepositoryNativeTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/repository/TorqueMailboxManagerMailRepositoryNativeTestCase.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/repository/TorqueMailboxManagerMailRepositoryNativeTestCase.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/repository/TorqueMailboxManagerMailRepositoryNativeTestCase.java Tue Nov 20 15:21:20 2007
@@ -21,7 +21,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -33,6 +32,7 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
@@ -109,18 +109,15 @@
 
     
     protected Collection getNativeMessages() {
-        final MessageResult[] mr;
+        final Iterator it;
         try {
-            mr = getShadowMailbox().getMessages(GeneralMessageSetImpl.all(),
+            it = getShadowMailbox().getMessages(GeneralMessageSetImpl.all(),
                     MessageResult.MIME_MESSAGE);
 
         } catch (MailboxManagerException e) {
             throw new RuntimeException(e);
         }
-        Collection existing = new ArrayList();
-        for (int i = 0; i < mr.length; i++) {
-            existing.add(mr[i].getMimeMessage());
-        }
+        Collection existing = IteratorUtils.toList(it);
         return existing;
     }
 

Modified: james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java (original)
+++ james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java Tue Nov 20 15:21:20 2007
@@ -24,6 +24,7 @@
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
@@ -35,6 +36,7 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.commons.logging.Log;
 import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxListener;
@@ -235,7 +237,7 @@
                 GeneralMessageSet set=GeneralMessageSetImpl.uidRange(lastScannedUid+1, uid);
                 Criteria criteria=criteriaForMessageSet(set);
                 List messageRows=mailboxRow.getMessageRows(criteria);
-                MessageResult[] messageResults=fillMessageResult(messageRows, MessageResult.UID);
+                List messageResults=fillMessageResult(messageRows, MessageResult.UID);
                 getUidChangeTracker().found(uidRangeForMessageSet(set), messageResults);
             }
         }
@@ -273,7 +275,7 @@
         return criteria;
     }
 
-    public MessageResult[] getMessages(GeneralMessageSet set, int result)
+    public Iterator getMessages(GeneralMessageSet set, int result)
             throws MailboxManagerException {
         try {
             lock.readLock().acquire();
@@ -281,7 +283,7 @@
                 checkAccess();
                 set=toUidSet(set);
                 if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
-                    return new MessageResult[0];
+                    return IteratorUtils.EMPTY_ITERATOR;
                 }
                 UidRange range = uidRangeForMessageSet(set);
                 try {
@@ -301,13 +303,13 @@
         }
     }
 
-    private MessageResult[] getMessages(int result, UidRange range, Criteria c) throws TorqueException, MessagingException, MailboxManagerException {
+    private Iterator getMessages(int result, UidRange range, Criteria c) throws TorqueException, MessagingException, MailboxManagerException {
         List l = MessageRowPeer.doSelectJoinMessageFlags(c);
-        MessageResult[] messageResults = fillMessageResult(l, result
+        final Collection messageResults = fillMessageResult(l, result
                 | MessageResult.UID | MessageResult.FLAGS);
         checkForScanGap(range.getFromUid());
         getUidChangeTracker().found(range, messageResults);
-        return messageResults;
+        return messageResults.iterator();
     }
 
     private static UidRange uidRangeForMessageSet(GeneralMessageSet set)
@@ -322,14 +324,14 @@
         }
     }
 
-    private MessageResult[] fillMessageResult(List messageRows, int result)
+    private List fillMessageResult(List messageRows, int result)
             throws TorqueException, MessagingException, MailboxManagerException {
-        MessageResult[] messageResults = new MessageResult[messageRows.size()];
-        int i = 0;
+        
+        final List messageResults = new ArrayList(messageRows.size());
         for (Iterator iter = messageRows.iterator(); iter.hasNext();) {
             MessageRow messageRow=(MessageRow)iter.next();
-            messageResults[i] = fillMessageResult(messageRow, result);
-            i++;
+            MessageResult messageResult = fillMessageResult(messageRow, result);
+            messageResults.add(messageResult);
         }
         return messageResults;
     }
@@ -625,7 +627,7 @@
         }
     }
 
-    public MessageResult[] expunge(GeneralMessageSet set, int result)
+    public Iterator expunge(GeneralMessageSet set, int result)
             throws MailboxManagerException {
         try {
             lock.writeLock().acquire();
@@ -640,11 +642,11 @@
         }
     }
 
-    private MessageResult[] doExpunge(GeneralMessageSet set, int result) throws MailboxManagerException {
+    private Iterator doExpunge(GeneralMessageSet set, int result) throws MailboxManagerException {
         checkAccess();
         set=toUidSet(set);  
         if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
-            return new MessageResult[0];
+            return IteratorUtils.EMPTY_ITERATOR;
         }
         try {
             // TODO put this into a serializable transaction
@@ -655,7 +657,7 @@
             c.add(MessageFlagsPeer.DELETED, true);
 
             final List messageRows = getMailboxRow().getMessageRows(c);
-            final MessageResult[] messageResults = fillMessageResult(messageRows, result
+            final List messageResults = fillMessageResult(messageRows, result
                     | MessageResult.UID | MessageResult.FLAGS);
 
             for (Iterator iter = messageRows.iterator(); iter.hasNext();) {
@@ -666,7 +668,7 @@
                 MessageRowPeer.doDelete(todelc);
             }
             getUidChangeTracker().expunged(messageResults);
-            return messageResults;
+            return messageResults.iterator();
         } catch (Exception e) {
             throw new MailboxManagerException(e);
         }
@@ -699,7 +701,7 @@
             // TODO put this into a serializeable transaction
             final List messageRows = getMailboxRow()
                     .getMessageRows(criteriaForMessageSet(set));
-            final MessageResult[] beforeResults = fillMessageResult(messageRows,
+            final Collection beforeResults = fillMessageResult(messageRows,
                     MessageResult.UID | MessageResult.FLAGS);
             UidRange uidRange=uidRangeForMessageSet(set);
             checkForScanGap(uidRange.getFromUid());
@@ -722,11 +724,11 @@
                     messageFlags.save();
                 }
             }
-            final MessageResult[] afterResults = fillMessageResult(messageRows,
+            final Collection afterResults = fillMessageResult(messageRows,
                     results | MessageResult.UID | MessageResult.FLAGS);
             tracker.flagsUpdated(afterResults, sessionId);
             tracker.found(uidRange, afterResults);
-            return Arrays.asList(afterResults).iterator();
+            return afterResults.iterator();
         } catch (Exception e) {
             throw new MailboxManagerException(e);
         }
@@ -826,7 +828,7 @@
         this.mailboxRow = mailboxRow;
     }
 
-    public MessageResult[] search(GeneralMessageSet set, SearchParameters parameters,
+    public Iterator search(GeneralMessageSet set, SearchParameters parameters,
             int result) throws MailboxManagerException {
         try {
             lock.readLock().acquire();
@@ -834,7 +836,7 @@
                 checkAccess();
                 set=toUidSet(set);
                 if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
-                    return new MessageResult[0];
+                    return IteratorUtils.EMPTY_ITERATOR;
                 }
                 
                 TorqueCriteriaBuilder builder = new TorqueCriteriaBuilder();
@@ -930,7 +932,7 @@
                     }
                 }
                 
-                final MessageResult[] results = getMessages(result, new UidRange(1, -1), builder.getCriteria());
+                final Iterator results = getMessages(result, new UidRange(1, -1), builder.getCriteria());
                 return results;
             } catch (TorqueException e) {
                 throw new MailboxManagerException(e);

Modified: james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=596875&r1=596874&r2=596875&view=diff
==============================================================================
--- james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java (original)
+++ james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java Tue Nov 20 15:21:20 2007
@@ -24,6 +24,8 @@
 import java.util.List;
 import java.util.Random;
 
+import javax.mail.internet.MimeMessage;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.mailboxmanager.GeneralMessageSet;
@@ -210,9 +212,11 @@
     public void copyMessages(GeneralMailbox from, GeneralMessageSet set, String to) throws MailboxManagerException {
         GeneralMailboxSession toMailbox=(GeneralMailboxSession)getGeneralMailboxSession(to);
         
-        MessageResult[] mr=from.getMessages(set, MessageResult.MIME_MESSAGE | MessageResult.INTERNAL_DATE);
-        for (int i = 0; i < mr.length; i++) {
-            toMailbox.appendMessage(mr[i].getMimeMessage(), mr[i].getInternalDate(), MessageResult.NOTHING);
+        Iterator it = from.getMessages(set, MessageResult.MIME_MESSAGE | MessageResult.INTERNAL_DATE);
+        while (it.hasNext()) {
+            final MessageResult result = (MessageResult) it.next();
+            final MimeMessage mimeMessage = result.getMimeMessage();
+            toMailbox.appendMessage(mimeMessage, result.getInternalDate(), MessageResult.NOTHING);
         }
        
         toMailbox.close();



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