james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject james-project git commit: JAMES-2340 Moving messages out of an empty mailbox should not throw
Date Mon, 09 Apr 2018 02:19:22 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 99b5cb6c7 -> e5f7dc703


JAMES-2340 Moving messages out of an empty mailbox should not throw


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e5f7dc70
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e5f7dc70
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e5f7dc70

Branch: refs/heads/master
Commit: e5f7dc703602152ebd27155fc7d6d5163806a351
Parents: 99b5cb6
Author: benwa <btellier@linagora.com>
Authored: Fri Apr 6 16:16:36 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Mon Apr 9 09:17:52 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/MailboxManagerTest.java       | 13 +++++++++++
 .../mailbox/store/StoreMessageManager.java      | 24 ++++++++++++--------
 2 files changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e5f7dc70/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 2edda06..0b9614d 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
@@ -40,6 +41,7 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
@@ -938,4 +940,15 @@ public abstract class MailboxManagerTest {
                     .computedLimit(QuotaSize.unlimited())
                     .build()));
     }
+
+    @Test
+    public void moveMessagesShouldNotThrowWhenMovingAllMessagesOfAnEmptyMailbox() throws
Exception {
+        session = mailboxManager.createSystemSession(USER_1);
+
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+
+        assertThatCode(() -> mailboxManager.moveMessages(MessageRange.all(), inbox, inbox,
session))
+            .doesNotThrowAnyException();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e5f7dc70/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 202d3d3..3109f32 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -89,6 +89,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSortedMap;
 
 /**
  * Base class for {@link org.apache.james.mailbox.MessageManager}
@@ -750,22 +751,25 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
     private SortedMap<MessageUid, MessageMetaData> move(MessageRange set, StoreMessageManager
to, MailboxSession session) throws MailboxException {
         IteratorWrapper<MailboxMessage> originalRows = new IteratorWrapper<>(retrieveOriginalRows(set,
session));
 
-        MoveResult moveResult = to.move(originalRows, session);
-        SortedMap<MessageUid, MessageMetaData> moveUids = collectMetadata(moveResult.getMovedMessages());
+        if (originalRows.hasNext()) {
+            MoveResult moveResult = to.move(originalRows, session);
+            SortedMap<MessageUid, MessageMetaData> moveUids = collectMetadata(moveResult.getMovedMessages());
 
-        ImmutableMap.Builder<MessageUid, MailboxMessage> messagesMap = ImmutableMap.builder();
-        for (MailboxMessage message: originalRows.getEntriesSeen()) {
-            messagesMap.put(message.getUid(), immutableMailboxMessageFactory.from(to.getMailboxEntity().getMailboxId(),
message));
-        }
-        dispatcher.added(session, moveUids, to.getMailboxEntity(), messagesMap.build());
-        dispatcher.expunged(session, collectMetadata(moveResult.getOriginalMessages()), getMailboxEntity());
-        dispatcher.moved(session,
+            ImmutableMap.Builder<MessageUid, MailboxMessage> messagesMap = ImmutableMap.builder();
+            for (MailboxMessage message : originalRows.getEntriesSeen()) {
+                messagesMap.put(message.getUid(), immutableMailboxMessageFactory.from(to.getMailboxEntity().getMailboxId(),
message));
+            }
+            dispatcher.added(session, moveUids, to.getMailboxEntity(), messagesMap.build());
+            dispatcher.expunged(session, collectMetadata(moveResult.getOriginalMessages()),
getMailboxEntity());
+            dispatcher.moved(session,
                 MessageMoves.builder()
                     .previousMailboxIds(getMailboxEntity().getMailboxId())
                     .targetMailboxIds(to.getMailboxEntity().getMailboxId())
                     .build(),
                 messagesMap.build());
-        return moveUids;
+            return moveUids;
+        }
+        return ImmutableSortedMap.of();
     }
 
     private Iterator<MailboxMessage> retrieveOriginalRows(MessageRange set, MailboxSession
session) throws MailboxException {


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