You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/12/04 08:48:54 UTC

[1/8] james-project git commit: JAMES-2589 Encrypted Payload Configuration should work

Repository: james-project
Updated Branches:
  refs/heads/master 0e3ffde31 -> d78ea34ec


JAMES-2589 Encrypted Payload Configuration should work


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

Branch: refs/heads/master
Commit: f454266fa6a3eaac0812c3426782cc39c34e4876
Parents: eccab45
Author: tran tien duc <dt...@linagora.com>
Authored: Thu Nov 29 18:49:04 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:08 2018 +0700

----------------------------------------------------------------------
 .../ObjectStorageBlobConfiguration.java         |  4 ++++
 .../ObjectStorageDependenciesModule.java        |  8 +------
 .../james/CassandraRabbitMQJamesServerTest.java | 25 +++++++++-----------
 3 files changed, 16 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f454266f/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
index a58a8d9..7be4a96 100644
--- a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
@@ -26,6 +26,7 @@ import java.util.Optional;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.blob.objectstorage.ContainerName;
+import org.apache.james.blob.objectstorage.PayloadCodec;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage;
@@ -257,6 +258,9 @@ public class ObjectStorageBlobConfiguration {
         return payloadCodec;
     }
 
+    public PayloadCodec getPayloadCodec() {
+        return payloadCodec.create(this);
+    }
 
     public Optional<String> getAesSalt() {
         return aesSalt;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f454266f/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
index 4577159..0aeb26d 100644
--- a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
@@ -32,7 +32,6 @@ import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAOBuilder;
-import org.apache.james.blob.objectstorage.PayloadCodec;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage;
@@ -54,12 +53,6 @@ public class ObjectStorageDependenciesModule extends AbstractModule {
 
     @Provides
     @Singleton
-    private PayloadCodec buildPayloadCodec(ObjectStorageBlobConfiguration configuration) {
-        return configuration.getPayloadCodecFactory().create(configuration);
-    }
-
-    @Provides
-    @Singleton
     private ObjectStorageBlobConfiguration getObjectStorageConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
         try {
             Configuration configuration = propertiesProvider.getConfiguration(ConfigurationComponent.NAME);
@@ -75,6 +68,7 @@ public class ObjectStorageDependenciesModule extends AbstractModule {
         ObjectStorageBlobsDAO dao = selectDaoBuilder(configuration)
             .container(configuration.getNamespace())
             .blobIdFactory(blobIdFactory)
+            .payloadCodec(configuration.getPayloadCodec())
             .build();
         dao.createContainer(configuration.getNamespace()).get(1, TimeUnit.MINUTES);
         return dao;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f454266f/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
index 61fe428..2ab287d 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
 import static org.junit.jupiter.api.TestInstance.Lifecycle;
 
+import org.apache.james.blob.objectstorage.AESPayloadCodec;
 import org.apache.james.blob.objectstorage.DefaultPayloadCodec;
 import org.apache.james.blob.objectstorage.PayloadCodec;
 import org.apache.james.core.Domain;
@@ -94,21 +95,18 @@ class CassandraRabbitMQJamesServerTest {
     @TestInstance(Lifecycle.PER_CLASS)
     class WithEncryptedSwift implements ContractSuite {
         @RegisterExtension
-        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
-            .extension(new CassandraExtension())
-            .extension(new RabbitMQExtension())
+        JamesServerExtension testExtension = baseExtensionBuilder()
             .extension(new SwiftBlobStoreExtension(PayloadCodecFactory.AES256))
             .server(CONFIGURATION_BUILDER)
             .build();
 
         @Test
-        void encryptedPayloadShouldBeConfiguredWhenProvidingEncryptedPayloadConfigurationButNot(GuiceJamesServer jamesServer) {
+        void encryptedPayloadShouldBeConfiguredWhenProvidingEncryptedPayloadConfiguration(GuiceJamesServer jamesServer) {
             PayloadCodec payloadCodec = jamesServer.getProbe(DockerSwiftTestRule.TestSwiftBlobStoreProbe.class)
                 .getSwiftPayloadCodec();
 
             assertThat(payloadCodec)
-                .isInstanceOf(DefaultPayloadCodec.class);
+                .isInstanceOf(AESPayloadCodec.class);
         }
     }
 
@@ -116,12 +114,8 @@ class CassandraRabbitMQJamesServerTest {
     @TestInstance(Lifecycle.PER_CLASS)
     class WithDefaultSwift implements ContractSuite {
         @RegisterExtension
-        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
-            .extension(new CassandraExtension())
-            .extension(new RabbitMQExtension())
+        JamesServerExtension testExtension = baseExtensionBuilder()
             .extension(new SwiftBlobStoreExtension())
-            .server(CONFIGURATION_BUILDER)
             .build();
 
         @Test
@@ -138,11 +132,14 @@ class CassandraRabbitMQJamesServerTest {
     @TestInstance(Lifecycle.PER_CLASS)
     class WithoutSwift implements ContractSuite {
         @RegisterExtension
-        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        JamesServerExtension testExtension = baseExtensionBuilder().build();
+    }
+
+    private static JamesServerExtensionBuilder baseExtensionBuilder() {
+        return new JamesServerExtensionBuilder()
             .extension(new EmbeddedElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new RabbitMQExtension())
-            .server(CONFIGURATION_BUILDER)
-            .build();
+            .server(CONFIGURATION_BUILDER);
     }
 }


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


[8/8] james-project git commit: JAMES-2544 Avoid negative bucketIds in RabbitMQMailQueue

Posted by bt...@apache.org.
JAMES-2544 Avoid negative bucketIds in RabbitMQMailQueue


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

Branch: refs/heads/master
Commit: d78ea34ecec0618e6581ebb8844805bc0a0d7aa6
Parents: acdb0da
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 10:52:02 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:48:14 2018 +0700

----------------------------------------------------------------------
 .../view/cassandra/CassandraMailQueueMailStore.java         | 2 +-
 .../apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java  | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d78ea34e/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
index 550ac16..41c28a9 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
@@ -79,7 +79,7 @@ public class CassandraMailQueueMailStore {
 
     private BucketId computedBucketId(Mail mail) {
         int mailKeyHashCode = mail.getName().hashCode();
-        int bucketIdValue = mailKeyHashCode % configuration.getBucketCount();
+        int bucketIdValue = Math.abs(mailKeyHashCode) % configuration.getBucketCount();
         return BucketId.of(bucketIdValue);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d78ea34e/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
index 0db32d6..a3b69d9 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
@@ -23,6 +23,7 @@ import static java.time.temporal.ChronoUnit.HOURS;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.apache.james.queue.api.Mails.defaultMail;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 
 import java.time.Duration;
 import java.time.Instant;
@@ -218,6 +219,14 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract, MailQ
         assertThat(initialized).isTrue();
     }
 
+    @Test
+    void enQueueShouldNotThrowOnMailNameWithNegativeHash() {
+        String negativehashedString = "this sting will have a negative hash"; //hash value: -1256871313
+        
+        assertThatCode(() -> getMailQueue().enQueue(defaultMail().name(negativehashedString).build()))
+            .doesNotThrowAnyException();
+    }
+
     @Disabled("JAMES-2614 RabbitMQMailQueueTest::concurrentEnqueueDequeueShouldNotFail is unstable." +
         "The related test is disabled, and need to be re-enabled after investigation and a fix.")
     @Test


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


[6/8] james-project git commit: MAILBOX-292 Make Maildir Mailbox Id persistent

Posted by bt...@apache.org.
MAILBOX-292 Make Maildir Mailbox Id persistent


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

Branch: refs/heads/master
Commit: 7e32da51a29bee1c732b2b13708bb4b986140119
Parents: d9bcebc
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 30 16:00:34 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:46 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/maildir/MaildirFolder.java    | 54 +++++++++++++++-
 .../apache/james/mailbox/maildir/MaildirId.java |  7 ++
 .../james/mailbox/maildir/MaildirStore.java     |  1 +
 .../mailbox/maildir/mail/MailboxCache.java      | 68 --------------------
 .../maildir/mail/MaildirMailboxMapper.java      | 63 ++++++++++--------
 .../DomainUserMaildirMailboxManagerTest.java    |  9 ---
 .../FullUserMaildirMailboxManagerTest.java      | 10 ---
 .../maildir/src/test/resources/logback-test.xml | 28 ++++++++
 8 files changed, 125 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
index 4982726..b31b522 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
@@ -58,6 +58,7 @@ public class MaildirFolder {
     public static final String VALIDITY_FILE = "james-uidvalidity";
     public static final String UIDLIST_FILE = "james-uidlist";
     public static final String ACL_FILE = "james-acl";
+    public static final String MAILBOX_ID_FILE = "james-mailboxId";
     public static final String CUR = "cur";
     public static final String NEW = "new";
     public static final String TMP = "tmp";
@@ -68,7 +69,8 @@ public class MaildirFolder {
     private final File tmpFolder;
     private final File uidFile;
     private final File aclFile;
-    
+    private final File mailboxIdFile;
+
     private Optional<MessageUid> lastUid;
     private int messageCount = 0;
     private long uidValidity = -1;
@@ -91,6 +93,7 @@ public class MaildirFolder {
         this.tmpFolder = new File(rootFolder, TMP);
         this.uidFile = new File(rootFolder, UIDLIST_FILE);
         this.aclFile = new File(rootFolder, ACL_FILE);
+        this.mailboxIdFile = new File(rootFolder, MAILBOX_ID_FILE);
         this.locker = locker;
         this.path = path;
         this.lastUid = Optional.empty();
@@ -163,6 +166,10 @@ public class MaildirFolder {
     public File getCurFolder() {
         return curFolder;
     }
+
+    public File getMailboxIdFile() {
+        return mailboxIdFile;
+    }
     
     /**
      * Returns the ./new folder of this Maildir folder.
@@ -294,6 +301,51 @@ public class MaildirFolder {
             fos.write(String.valueOf(uidValidity).getBytes());
         }
     }
+
+    /**
+     * Sets the mailboxId for this mailbox and writes it to the file system
+     * @param mailboxId
+     * @throws IOException
+     */
+    public void setMailboxId(MaildirId mailboxId) throws IOException {
+        saveMailboxId(mailboxId);
+    }
+
+    /**
+     * Read the mailboxId of the given mailbox from the file system.
+     * If the respective file is not yet there, it gets created and
+     * filled with a brand new uidValidity.
+     * @return The uidValidity
+     * @throws IOException if there are problems with the validity file
+     */
+    public MaildirId readMailboxId() throws IOException {
+        if (!mailboxIdFile.exists()) {
+            MaildirId maildirId = MaildirId.random();
+            saveMailboxId(maildirId);
+            return maildirId;
+        }
+        try (FileInputStream fis = new FileInputStream(mailboxIdFile);
+             InputStreamReader isr = new InputStreamReader(fis)) {
+            char[] mailboxId = new char[20];
+            int len = isr.read(mailboxId);
+            int idAsInt = Integer.parseInt(String.valueOf(mailboxId, 0, len).trim());
+            return MaildirId.of(idAsInt);
+        }
+    }
+
+    /**
+     * Save the given MaildirId to the file system
+     * @param id
+     * @throws IOException
+     */
+    private void saveMailboxId(MaildirId id) throws IOException {
+        if (!mailboxIdFile.createNewFile()) {
+            throw new IOException("Could not create file " + mailboxIdFile);
+        }
+        try (FileOutputStream fos = new FileOutputStream(mailboxIdFile)) {
+            fos.write(String.valueOf(id.getRawId()).getBytes());
+        }
+    }
     
     /**
      * Sets and returns a new uidValidity for this folder.

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
index 69de83f..18df444 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox.maildir;
 
 import java.io.Serializable;
+import java.security.SecureRandom;
 
 import org.apache.james.mailbox.model.MailboxId;
 
@@ -31,6 +32,12 @@ public class MaildirId implements MailboxId, Serializable {
         }
     }
 
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    public static MaildirId random() {
+        return MaildirId.of(Math.abs(RANDOM.nextInt()));
+    }
+
     public static MaildirId of(int id) {
         return new MaildirId(id);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
index f7a2d8d..b0a3192 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
@@ -132,6 +132,7 @@ public class MaildirStore implements UidProvider, ModSeqProvider {
         folder.setMessageNameStrictParse(isMessageNameStrictParse());
         try {
             Mailbox loadedMailbox = new SimpleMailbox(mailboxPath, folder.getUidValidity());
+            loadedMailbox.setMailboxId(folder.readMailboxId());
             loadedMailbox.setACL(folder.getACL(session));
             return loadedMailbox;
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MailboxCache.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MailboxCache.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MailboxCache.java
deleted file mode 100644
index cf04c1e..0000000
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MailboxCache.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.maildir.mail;
-
-import java.util.ArrayList;
-
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
-import org.apache.james.mailbox.maildir.MaildirId;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-
-public class MailboxCache {
-    /**
-     * A request-scoped list of mailboxes in order to refer to them via id
-     */
-    private final ArrayList<Mailbox> mailboxCache = new ArrayList<>();
-
-    /**
-     * Stores a copy of a mailbox in a cache valid for one request. This is to enable
-     * referring to renamed mailboxes via id.
-     * @param mailbox The mailbox to cache
-     * @return the cached mailbox
-     */
-    public synchronized Mailbox cacheMailbox(Mailbox mailbox) {
-        mailboxCache.add(new SimpleMailbox(mailbox));
-        int id = mailboxCache.size() - 1;
-        mailbox.setMailboxId(MaildirId.of(id));
-        return mailbox;
-    }
-
-    /**
-     * Retrieves a mailbox from the cache
-     * @param mailboxId The id of the mailbox to retrieve
-     * @return The mailbox
-     * @throws MailboxNotFoundException If the mailboxId is not in the cache
-     */
-    public synchronized Mailbox getCachedMailbox(MaildirId mailboxId) throws MailboxNotFoundException {
-        if (mailboxId == null) {
-            throw new MailboxNotFoundException("null");
-        }
-        try {
-            return mailboxCache.get(mailboxId.getRawId());
-        } catch (IndexOutOfBoundsException e) {
-            throw new MailboxNotFoundException(mailboxId);
-        }
-    }
-
-    public synchronized void clear() {
-        mailboxCache.clear();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
index b1b83f9..454d857 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
@@ -23,6 +23,8 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
+import java.util.Random;
 import java.util.regex.Pattern;
 
 import org.apache.commons.io.FileUtils;
@@ -55,18 +57,12 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
      * The {@link MaildirStore} the mailboxes reside in
      */
     private final MaildirStore maildirStore;
-    
-    /**
-     * A request-scoped list of mailboxes in order to refer to them via id
-     */
-    private final MailboxCache mailboxCache;
 
     private final MailboxSession session;
     
     public MaildirMailboxMapper(MaildirStore maildirStore, MailboxSession session) {
         this.maildirStore = maildirStore;
         this.session = session;
-        this.mailboxCache = new MailboxCache();
     }
 
     @Override
@@ -109,14 +105,18 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
     @Override
     public Mailbox findMailboxByPath(MailboxPath mailboxPath)
             throws MailboxException, MailboxNotFoundException {      
-        Mailbox mailbox = maildirStore.loadMailbox(session, mailboxPath);
-        return mailboxCache.cacheMailbox(mailbox);
+        return maildirStore.loadMailbox(session, mailboxPath);
     }
     
     @Override
     public Mailbox findMailboxById(MailboxId id) throws MailboxException, MailboxNotFoundException {
-        MaildirId mailboxId = (MaildirId)id;
-        return mailboxCache.getCachedMailbox(mailboxId);
+        if (id == null) {
+            throw new MailboxNotFoundException("null");
+        }
+        return list().stream()
+            .filter(mailbox -> mailbox.getMailboxId().equals(id))
+            .findAny()
+            .orElseThrow(() -> new MailboxNotFoundException(id));
     }
     
     @Override
@@ -131,13 +131,13 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
         for (File folder : folders) {
             if (folder.isDirectory()) {
                 Mailbox mailbox = maildirStore.loadMailbox(session, root, mailboxPath.getNamespace(), mailboxPath.getUser(), folder.getName());
-                mailboxList.add(mailboxCache.cacheMailbox(mailbox));
+                mailboxList.add(mailbox);
             }
         }
         // INBOX is in the root of the folder
         if (Pattern.matches(mailboxPath.getName().replace(MaildirStore.WILDCARD, ".*"), MailboxConstants.INBOX)) {
             Mailbox mailbox = maildirStore.loadMailbox(session, root, mailboxPath.getNamespace(), mailboxPath.getUser(), "");
-            mailboxList.add(0, mailboxCache.cacheMailbox(mailbox));
+            mailboxList.add(0, mailbox);
         }
         return mailboxList;
     }
@@ -152,8 +152,11 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
 
     @Override
     public MailboxId save(Mailbox mailbox) throws MailboxException {
+        MaildirId maildirId = Optional.ofNullable(mailbox.getMailboxId())
+            .map(mailboxId -> (MaildirId) mailboxId)
+            .orElseGet(MaildirId::random);
         try {
-            Mailbox originalMailbox = mailboxCache.getCachedMailbox((MaildirId) mailbox.getMailboxId());
+            Mailbox originalMailbox = findMailboxById(mailbox.getMailboxId());
             MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
             // equals with null check
             if (originalMailbox.getName() == null ? mailbox.getName() != null : !originalMailbox.getName().equals(mailbox.getName())) {
@@ -171,6 +174,9 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
                         if (!originalFolder.getCurFolder().renameTo(folder.getCurFolder())) {
                             throw new IOException("Could not rename folder " + originalFolder.getCurFolder() + " to " + folder.getCurFolder());
                         }
+                        if (!originalFolder.getMailboxIdFile().renameTo(folder.getMailboxIdFile())) {
+                            throw new IOException("Could not rename folder " + originalFolder.getCurFolder() + " to " + folder.getCurFolder());
+                        }
                         if (!originalFolder.getNewFolder().renameTo(folder.getNewFolder())) {
                             throw new IOException("Could not rename folder " + originalFolder.getNewFolder() + " to " + folder.getNewFolder());
                         }
@@ -192,6 +198,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
                         FileUtils.forceMkdir(originalFolder.getCurFolder());
                         FileUtils.forceMkdir(originalFolder.getNewFolder());
                         FileUtils.forceMkdir(originalFolder.getTmpFolder());
+                        originalFolder.setMailboxId(MaildirId.of(Math.abs(new Random().nextInt())));
                     } catch (IOException e) {
                         throw new MailboxException("Failed to save Mailbox " + mailbox, e);
                     }
@@ -224,14 +231,14 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
             }
             try {
                 folder.setUidValidity(mailbox.getUidValidity());
+                folder.setMailboxId(maildirId);
             } catch (IOException ioe) {
                 throw new MailboxException("Failed to save Mailbox " + mailbox, ioe);
 
             }
             folder.setACL(session, mailbox.getACL());
         }
-        mailboxCache.cacheMailbox(mailbox);
-        return mailbox.getMailboxId();
+        return maildirId;
     }
 
     @Override
@@ -240,26 +247,28 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
        File maildirRoot = maildirStore.getMaildirRoot();
        List<Mailbox> mailboxList = new ArrayList<>();
         
-       if (maildirStore.getMaildirLocation().endsWith("/" + MaildirStore.PATH_FULLUSER)) {
-           File[] users = maildirRoot.listFiles();
-           visitUsersForMailboxList(null, users, mailboxList);
+
+
+       if (maildirStore.getMaildirLocation().endsWith("/" + MaildirStore.PATH_DOMAIN + "/" + MaildirStore.PATH_USER)) {
+           File[] domains = maildirRoot.listFiles();
+           for (File domain : domains) {
+               File[] users = domain.listFiles();
+               visitUsersForMailboxList(domain, users, mailboxList);
+           }
            return mailboxList;
        }
-       
-       File[] domains = maildirRoot.listFiles();
-       for (File domain: domains) {
-           File[] users = domain.listFiles();
-           visitUsersForMailboxList(domain, users, mailboxList);
-       }
-       return mailboxList;
+
+        File[] users = maildirRoot.listFiles();
+        visitUsersForMailboxList(null, users, mailboxList);
+        return mailboxList;
         
     }
 
     @Override
     public void endRequest() {
-        mailboxCache.clear();
+
     }
-    
+
     private void visitUsersForMailboxList(File domain, File[] users, List<Mailbox> mailboxList) throws MailboxException {
         
         String userName = null;

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
index 508fc54..cc494f1 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
@@ -18,13 +18,9 @@
  ****************************************************************/
 package org.apache.james.mailbox.maildir;
 
-import java.io.UnsupportedEncodingException;
-
 import org.apache.james.junit.TemporaryFolderExtension;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManagerTest;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class DomainUserMaildirMailboxManagerTest extends MailboxManagerTest {
@@ -41,9 +37,4 @@ public class DomainUserMaildirMailboxManagerTest extends MailboxManagerTest {
         }
     }
 
-    @Disabled("https://issues.apache.org/jira/browse/MAILBOX-292")
-    @Override
-    public void createMailboxShouldReturnRightId() throws MailboxException, UnsupportedEncodingException {
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/FullUserMaildirMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/FullUserMaildirMailboxManagerTest.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/FullUserMaildirMailboxManagerTest.java
index b69f30f..e08097f 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/FullUserMaildirMailboxManagerTest.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/FullUserMaildirMailboxManagerTest.java
@@ -18,13 +18,9 @@
  ****************************************************************/
 package org.apache.james.mailbox.maildir;
 
-import java.io.UnsupportedEncodingException;
-
 import org.apache.james.junit.TemporaryFolderExtension;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManagerTest;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.junit.Ignore;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class FullUserMaildirMailboxManagerTest extends MailboxManagerTest {
@@ -39,10 +35,4 @@ public class FullUserMaildirMailboxManagerTest extends MailboxManagerTest {
             throw new RuntimeException(e);
         }
     }
-
-    @Ignore("https://issues.apache.org/jira/browse/MAILBOX-292")
-    @Override
-    public void createMailboxShouldReturnRightId() throws MailboxException, UnsupportedEncodingException {
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e32da51/mpt/impl/imap-mailbox/maildir/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/maildir/src/test/resources/logback-test.xml b/mpt/impl/imap-mailbox/maildir/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..b02f0d8
--- /dev/null
+++ b/mpt/impl/imap-mailbox/maildir/src/test/resources/logback-test.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+        <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
+                <resetJUL>true</resetJUL>
+        </contextListener>
+
+        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+                <encoder>
+                        <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
+                        <immediateFlush>false</immediateFlush>
+                </encoder>
+        </appender>
+
+        <root level="WARN">
+                <appender-ref ref="CONSOLE" />
+        </root>
+
+
+        <logger name="org.apache.james" level="WARN" >
+                <appender-ref ref="CONSOLE" />
+        </logger>
+
+        <logger name="org.apache.james.backends.cassandra.DockerCassandraRule" level="WARN" >
+                <appender-ref ref="CONSOLE" />
+        </logger>
+
+</configuration>


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


[7/8] james-project git commit: MAILBOX-292 MaildirId should be relying on UUID

Posted by bt...@apache.org.
MAILBOX-292 MaildirId should be relying on UUID

As these ids are randomly allocated, using 128 bits instead of 32 allow
to drastically reduce chances of collisions.


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

Branch: refs/heads/master
Commit: acdb0da00935a83ab4bbc08b891e615f5a688f12
Parents: 7e32da5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 3 10:14:33 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:47 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/maildir/MaildirFolder.java    | 13 ++---
 .../apache/james/mailbox/maildir/MaildirId.java | 59 ++++++++------------
 .../maildir/MaildirMailboxIdDeserializer.java   |  2 +-
 .../maildir/mail/MaildirMailboxMapper.java      |  3 +-
 .../MaildirMailboxIdDeserializerTest.java       |  6 +-
 5 files changed, 35 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/acdb0da0/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
index b31b522..bbb7694 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
@@ -27,6 +27,7 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -39,6 +40,7 @@ import java.util.SortedMap;
 import java.util.TreeMap;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MailboxPathLocker.LockAwareExecution;
@@ -324,12 +326,9 @@ public class MaildirFolder {
             saveMailboxId(maildirId);
             return maildirId;
         }
-        try (FileInputStream fis = new FileInputStream(mailboxIdFile);
-             InputStreamReader isr = new InputStreamReader(fis)) {
-            char[] mailboxId = new char[20];
-            int len = isr.read(mailboxId);
-            int idAsInt = Integer.parseInt(String.valueOf(mailboxId, 0, len).trim());
-            return MaildirId.of(idAsInt);
+        try (FileInputStream fileInputStream = new FileInputStream(mailboxIdFile)) {
+            String serializedMaildirId = IOUtils.toString(fileInputStream, StandardCharsets.UTF_8);
+            return MaildirId.fromString(serializedMaildirId);
         }
     }
 
@@ -343,7 +342,7 @@ public class MaildirFolder {
             throw new IOException("Could not create file " + mailboxIdFile);
         }
         try (FileOutputStream fos = new FileOutputStream(mailboxIdFile)) {
-            fos.write(String.valueOf(id.getRawId()).getBytes());
+            fos.write(id.serialize().getBytes(StandardCharsets.UTF_8));
         }
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/acdb0da0/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
index 18df444..f620a9d 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirId.java
@@ -19,7 +19,8 @@
 package org.apache.james.mailbox.maildir;
 
 import java.io.Serializable;
-import java.security.SecureRandom;
+import java.util.Objects;
+import java.util.UUID;
 
 import org.apache.james.mailbox.model.MailboxId;
 
@@ -28,64 +29,50 @@ public class MaildirId implements MailboxId, Serializable {
     public static class Factory implements MailboxId.Factory {
         @Override
         public MaildirId fromString(String serialized) {
-            return of(Integer.valueOf(serialized));
+            return MaildirId.fromString(serialized);
         }
     }
 
-    private static final SecureRandom RANDOM = new SecureRandom();
-
     public static MaildirId random() {
-        return MaildirId.of(Math.abs(RANDOM.nextInt()));
+        return MaildirId.of(UUID.randomUUID());
     }
 
-    public static MaildirId of(int id) {
+    public static MaildirId of(UUID id) {
         return new MaildirId(id);
     }
 
-    private final int id;
-
-    private MaildirId(int id) {
-        this.id = id;
+    public static MaildirId fromString(String serialized) {
+        return of(UUID.fromString(serialized));
     }
 
-    public int getRawId() {
-        return id;
+    private final UUID id;
+
+    private MaildirId(UUID id) {
+        this.id = id;
     }
 
     @Override
     public String serialize() {
-        return String.valueOf(id);
+        return id.toString();
     }
 
     @Override
     public String toString() {
-        return String.valueOf(id);
-    }
-    
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + id;
-        return result;
+        return id.toString();
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        MaildirId other = (MaildirId) obj;
-        if (id != other.id) {
-            return false;
+    public final boolean equals(Object o) {
+        if (o instanceof MaildirId) {
+            MaildirId maildirId = (MaildirId) o;
+
+            return Objects.equals(this.id, maildirId.id);
         }
-        return true;
+        return false;
     }
 
+    @Override
+    public final int hashCode() {
+        return Objects.hash(id);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/acdb0da0/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java
index 16f301c..088b5b8 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java
@@ -27,7 +27,7 @@ public class MaildirMailboxIdDeserializer implements MailboxIdDeserializer {
     @Override
     public MaildirId deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException {
         try {
-            return MaildirId.of(Integer.valueOf(serializedMailboxId));
+            return MaildirId.fromString(serializedMailboxId);
         } catch (Exception e) {
             throw new MailboxIdDeserialisationException("Can not deserialize " + serializedMailboxId, e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/acdb0da0/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
index 454d857..173aba6 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
@@ -24,7 +24,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
-import java.util.Random;
 import java.util.regex.Pattern;
 
 import org.apache.commons.io.FileUtils;
@@ -198,7 +197,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
                         FileUtils.forceMkdir(originalFolder.getCurFolder());
                         FileUtils.forceMkdir(originalFolder.getNewFolder());
                         FileUtils.forceMkdir(originalFolder.getTmpFolder());
-                        originalFolder.setMailboxId(MaildirId.of(Math.abs(new Random().nextInt())));
+                        originalFolder.setMailboxId(MaildirId.random());
                     } catch (IOException e) {
                         throw new MailboxException("Failed to save Mailbox " + mailbox, e);
                     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/acdb0da0/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java
index a56a0fc..b1e1667 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java
@@ -21,6 +21,8 @@ package org.apache.james.mailbox.maildir;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.UUID;
+
 import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
 import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
 import org.junit.Before;
@@ -28,9 +30,9 @@ import org.junit.Test;
 
 public class MaildirMailboxIdDeserializerTest {
 
-    private static final String SERIALIZED_ID = "123";
+    private static final String SERIALIZED_ID = "2f3a4fcc-ca64-36e3-9bcf-33e92dd93135";
     private static final String MALFORMED_SERIALIZED_ID = "az";
-    private static final MaildirId MAILDIR_ID = MaildirId.of(Integer.valueOf(SERIALIZED_ID));
+    private static final MaildirId MAILDIR_ID = MaildirId.of(UUID.fromString(SERIALIZED_ID));
 
     private MailboxIdDeserializer mailboxIdDeserializer;
 


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


[2/8] james-project git commit: JAMES-2589 Encrypted Payload Configuration does not work

Posted by bt...@apache.org.
JAMES-2589 Encrypted Payload Configuration does not work


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

Branch: refs/heads/master
Commit: eccab4541b5c5484ac8f683879ec5e6e1363928a
Parents: 0e3ffde
Author: tran tien duc <dt...@linagora.com>
Authored: Thu Nov 29 18:44:20 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:08 2018 +0700

----------------------------------------------------------------------
 .../objectstorage/ObjectStorageBlobsDAO.java    |  6 ++-
 .../guice/DockerSwiftTestRule.java              | 18 ++++++++
 .../james/CassandraRabbitMQJamesServerTest.java | 44 ++++++++++++++++++--
 .../james/modules/SwiftBlobStoreExtension.java  | 11 ++++-
 4 files changed, 72 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/eccab454/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
index b83d2c4..00b9b97 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
@@ -39,7 +39,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.hash.Hashing;
 import com.google.common.hash.HashingInputStream;
@@ -143,8 +142,11 @@ public class ObjectStorageBlobsDAO implements BlobStore {
 
     }
 
-    @VisibleForTesting
     public void deleteContainer() {
         blobStore.deleteContainer(containerName.value());
     }
+
+    public PayloadCodec getPayloadCodec() {
+        return payloadCodec;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/eccab454/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
index 1f3c34a..d813f85 100644
--- a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
+++ b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
@@ -27,12 +27,14 @@ import org.apache.james.CleanupTasksPerformer;
 import org.apache.james.GuiceModuleTestRule;
 import org.apache.james.blob.objectstorage.ContainerName;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
+import org.apache.james.blob.objectstorage.PayloadCodec;
 import org.apache.james.blob.objectstorage.swift.Credentials;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.TenantName;
 import org.apache.james.blob.objectstorage.swift.UserName;
 import org.apache.james.modules.objectstorage.ObjectStorageBlobConfiguration;
 import org.apache.james.modules.objectstorage.PayloadCodecFactory;
+import org.apache.james.utils.GuiceProbe;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
@@ -41,6 +43,20 @@ import com.google.inject.multibindings.Multibinder;
 
 public class DockerSwiftTestRule implements GuiceModuleTestRule {
 
+    public static class TestSwiftBlobStoreProbe implements GuiceProbe {
+
+        private final ObjectStorageBlobsDAO swiftBlobStore;
+
+        @Inject
+        TestSwiftBlobStoreProbe(ObjectStorageBlobsDAO swiftBlobStore) {
+            this.swiftBlobStore = swiftBlobStore;
+        }
+
+        public PayloadCodec getSwiftPayloadCodec() {
+            return swiftBlobStore.getPayloadCodec();
+        }
+    }
+
     private static class ContainerCleanUp implements CleanupTasksPerformer.CleanupTask {
 
         private final ObjectStorageBlobsDAO blobsDAO;
@@ -104,6 +120,8 @@ public class DockerSwiftTestRule implements GuiceModuleTestRule {
             Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class)
                 .addBinding()
                 .to(ContainerCleanUp.class);
+
+            Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(TestSwiftBlobStoreProbe.class);
         };
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/eccab454/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
index f4f9885..61fe428 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
@@ -19,13 +19,18 @@
 
 package org.apache.james;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
-import static org.junit.jupiter.api.TestInstance.*;
+import static org.junit.jupiter.api.TestInstance.Lifecycle;
 
+import org.apache.james.blob.objectstorage.DefaultPayloadCodec;
+import org.apache.james.blob.objectstorage.PayloadCodec;
 import org.apache.james.core.Domain;
 import org.apache.james.modules.RabbitMQExtension;
 import org.apache.james.modules.SwiftBlobStoreExtension;
 import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.modules.objectstorage.PayloadCodecFactory;
+import org.apache.james.modules.objectstorage.guice.DockerSwiftTestRule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
@@ -66,7 +71,7 @@ class CassandraRabbitMQJamesServerTest {
         }
     }
 
-    interface ContratSuite extends JmapJamesServerContract, MailsShouldBeWellReceived, JamesServerContract {}
+    interface ContractSuite extends JmapJamesServerContract, MailsShouldBeWellReceived, JamesServerContract {}
 
     private static final String DOMAIN = "domain";
     private static final String JAMES_USER = "james-user@" + DOMAIN;
@@ -87,7 +92,29 @@ class CassandraRabbitMQJamesServerTest {
 
     @Nested
     @TestInstance(Lifecycle.PER_CLASS)
-    class WithSwift implements ContratSuite {
+    class WithEncryptedSwift implements ContractSuite {
+        @RegisterExtension
+        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new CassandraExtension())
+            .extension(new RabbitMQExtension())
+            .extension(new SwiftBlobStoreExtension(PayloadCodecFactory.AES256))
+            .server(CONFIGURATION_BUILDER)
+            .build();
+
+        @Test
+        void encryptedPayloadShouldBeConfiguredWhenProvidingEncryptedPayloadConfigurationButNot(GuiceJamesServer jamesServer) {
+            PayloadCodec payloadCodec = jamesServer.getProbe(DockerSwiftTestRule.TestSwiftBlobStoreProbe.class)
+                .getSwiftPayloadCodec();
+
+            assertThat(payloadCodec)
+                .isInstanceOf(DefaultPayloadCodec.class);
+        }
+    }
+
+    @Nested
+    @TestInstance(Lifecycle.PER_CLASS)
+    class WithDefaultSwift implements ContractSuite {
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerExtensionBuilder()
             .extension(new EmbeddedElasticSearchExtension())
@@ -96,11 +123,20 @@ class CassandraRabbitMQJamesServerTest {
             .extension(new SwiftBlobStoreExtension())
             .server(CONFIGURATION_BUILDER)
             .build();
+
+        @Test
+        void defaultPayloadShouldBeByDefault(GuiceJamesServer jamesServer) {
+            PayloadCodec payloadCodec = jamesServer.getProbe(DockerSwiftTestRule.TestSwiftBlobStoreProbe.class)
+                .getSwiftPayloadCodec();
+
+            assertThat(payloadCodec)
+                .isInstanceOf(DefaultPayloadCodec.class);
+        }
     }
 
     @Nested
     @TestInstance(Lifecycle.PER_CLASS)
-    class WithoutSwift implements ContratSuite {
+    class WithoutSwift implements ContractSuite {
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerExtensionBuilder()
             .extension(new EmbeddedElasticSearchExtension())

http://git-wip-us.apache.org/repos/asf/james-project/blob/eccab454/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
index 71d4d92..d113f1d 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
@@ -21,6 +21,7 @@ package org.apache.james.modules;
 
 import org.apache.james.GuiceModuleTestExtension;
 import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration;
+import org.apache.james.modules.objectstorage.PayloadCodecFactory;
 import org.apache.james.modules.objectstorage.guice.DockerSwiftTestRule;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
@@ -29,7 +30,15 @@ import com.google.inject.util.Modules;
 
 public class SwiftBlobStoreExtension implements GuiceModuleTestExtension {
 
-    private final DockerSwiftTestRule swiftRule = new DockerSwiftTestRule();
+    private final DockerSwiftTestRule swiftRule;
+
+    public SwiftBlobStoreExtension() {
+        this.swiftRule = new DockerSwiftTestRule();
+    }
+
+    public SwiftBlobStoreExtension(PayloadCodecFactory payloadCodecFactory) {
+        this.swiftRule = new DockerSwiftTestRule(payloadCodecFactory);
+    }
 
     @Override
     public void beforeAll(ExtensionContext extensionContext) {


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


[5/8] james-project git commit: MAILBOX-354 MailboxListenerRegistry does not need to throw

Posted by bt...@apache.org.
MAILBOX-354 MailboxListenerRegistry does not need to 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/d22fe0eb
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d22fe0eb
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d22fe0eb

Branch: refs/heads/master
Commit: d22fe0ebfbc2d972559112c867679ff54ad6d65c
Parents: b853de8
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 30 10:42:59 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:32 2018 +0700

----------------------------------------------------------------------
 .../mailbox/store/event/MailboxListenerRegistry.java     | 11 +++++------
 .../modules/mailbox/MailboxListenersLoaderImpl.java      |  8 +-------
 2 files changed, 6 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d22fe0eb/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
index f68a7c8..d29caff 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
 
 import com.google.common.collect.HashMultimap;
@@ -38,22 +37,22 @@ public class MailboxListenerRegistry {
 
     public MailboxListenerRegistry() {
         this.globalListeners = new ConcurrentLinkedQueue<>();
-        this.listeners = Multimaps.synchronizedMultimap(HashMultimap.<MailboxPath, MailboxListener>create());
+        this.listeners = Multimaps.synchronizedMultimap(HashMultimap.create());
     }
 
-    public void addListener(MailboxPath path, MailboxListener listener) throws MailboxException {
+    public void addListener(MailboxPath path, MailboxListener listener) {
         listeners.put(path, listener);
     }
 
-    public void addGlobalListener(MailboxListener listener) throws MailboxException {
+    public void addGlobalListener(MailboxListener listener) {
         globalListeners.add(listener);
     }
 
-    public void removeListener(MailboxPath mailboxPath, MailboxListener listener) throws MailboxException {
+    public void removeListener(MailboxPath mailboxPath, MailboxListener listener) {
         listeners.remove(mailboxPath, listener);
     }
 
-    public void removeGlobalListener(MailboxListener listener) throws MailboxException {
+    public void removeGlobalListener(MailboxListener listener) {
         globalListeners.remove(listener);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d22fe0eb/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
index 866553c..44dc178 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
@@ -23,7 +23,6 @@ import java.util.Set;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
 import org.apache.james.utils.ExtendedClassLoader;
 import org.slf4j.Logger;
@@ -64,12 +63,7 @@ public class MailboxListenersLoaderImpl implements Configurable, MailboxListener
 
     @Override
     public void register(MailboxListener listener) {
-        try {
-            registry.addGlobalListener(listener);
-        } catch (MailboxException e) {
-            LOGGER.error("Error while registering global listener {}", listener, e);
-            throw new RuntimeException(e);
-        }
+        registry.addGlobalListener(listener);
     }
 
     @Override


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


[3/8] james-project git commit: MAILBOX-354 MailboxListeners should be registered by MailboxId

Posted by bt...@apache.org.
MAILBOX-354 MailboxListeners should be registered by MailboxId

It was previously done on MailboxPath, which is mutable.

Mutability leads to significantly harder code when it comes to mailbox renames.


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

Branch: refs/heads/master
Commit: d9bcebc7dd546bd5f11f3d9b496491e7c9042fe2
Parents: d22fe0e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 30 10:52:11 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:32 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/MailboxListenerSupport.java   |   9 +-
 .../james/mailbox/MailboxManagerStressTest.java |   7 +-
 .../mailbox/store/StoreMailboxManager.java      |   8 +-
 .../event/DefaultDelegatingMailboxListener.java |  21 ++--
 .../store/event/MailboxListenerRegistry.java    |  24 ++---
 .../DefaultDelegatingMailboxListenerTest.java   |  61 +++--------
 .../event/MailboxListenerRegistryTest.java      | 100 +++++++------------
 .../james/imap/processor/IdleProcessor.java     |   4 +-
 .../processor/base/SelectedMailboxImpl.java     |   7 +-
 .../processor/base/SelectedMailboxImplTest.java |   8 +-
 10 files changed, 93 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java
index 1f5e35d..f76b70f 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox;
 
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 
 /**
@@ -37,7 +38,7 @@ public interface MailboxListenerSupport {
      * everyone has removed itself.
      * </p>
      * 
-     * @param mailboxPath
+     * @param mailboxId
      *            not null
      * @param listener
      *            not null
@@ -45,17 +46,17 @@ public interface MailboxListenerSupport {
      *            not null
      * @throws MailboxException
      */
-    void addListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException;
+    void addListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException;
 
     /**
      * Remove the {@link MailboxListener}
      * 
-     * @param mailboxPath
+     * @param mailboxId
      * @param listner
      * @param session
      * @throws MailboxException
      */
-    void removeListener(MailboxPath mailboxPath, MailboxListener listner, MailboxSession session) throws MailboxException;
+    void removeListener(MailboxId mailboxId, MailboxListener listner, MailboxSession session) throws MailboxException;
     
     /**
      * Add a {@link MailboxListener} which get fired for ever

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
index 8f41eb7..9f13dec 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.CountDownLatch;
@@ -32,6 +33,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mime4j.dom.Message;
 import org.junit.Test;
@@ -61,9 +63,8 @@ public abstract class MailboxManagerStressTest {
         MailboxSession session = mailboxManager.createSystemSession(username);
         mailboxManager.startProcessingRequest(session);
         final MailboxPath path = MailboxPath.forUser(username, "INBOX");
-        mailboxManager.createMailbox(path, session);
-        mailboxManager.addListener(path, new MailboxListener() {
-
+        Optional<MailboxId> mailboxId = mailboxManager.createMailbox(path, session);
+        mailboxManager.addListener(mailboxId.get(), new MailboxListener() {
             @Override
             public ListenerType getType() {
                 return ListenerType.MAILBOX;

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 7eb53d8..63c30ef 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -768,8 +768,8 @@ public class StoreMailboxManager implements MailboxManager {
     }
 
     @Override
-    public void addListener(MailboxPath path, MailboxListener listener, MailboxSession session) throws MailboxException {
-        delegatingListener.addListener(path, listener, session);
+    public void addListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException {
+        delegatingListener.addListener(mailboxId, listener, session);
     }
 
     /**
@@ -803,8 +803,8 @@ public class StoreMailboxManager implements MailboxManager {
     }
 
     @Override
-    public void removeListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException {
-        delegatingListener.removeListener(mailboxPath, listener, session);
+    public void removeListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException {
+        delegatingListener.removeListener(mailboxId, listener, session);
 
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
index a380304..59b91cc 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
@@ -27,14 +27,14 @@ import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.metrics.api.NoopMetricFactory;
 
 import com.google.common.annotations.VisibleForTesting;
 
 /**
  * Receive a {@link org.apache.james.mailbox.MailboxListener.MailboxEvent} and delegate it to an other
- * {@link MailboxListener} depending on the registered name
+ * {@link MailboxListener} depending on the registered mailboxId
  *
  * This is a mono instance Thread safe implementation for DelegatingMailboxListener
  */
@@ -61,11 +61,11 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen
     }
 
     @Override
-    public void addListener(MailboxPath path, MailboxListener listener, MailboxSession session) throws MailboxException {
+    public void addListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException {
         if (listener.getType() != ListenerType.MAILBOX) {
             throw new MailboxException(listener.getClass().getCanonicalName() + " registred on specific MAILBOX operation while its listener type was " + listener.getType());
         }
-        registry.addListener(path, listener);
+        registry.addListener(mailboxId, listener);
     }
 
     @Override
@@ -77,12 +77,12 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen
     }
 
     @Override
-    public void removeListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException {
-        registry.removeListener(mailboxPath, listener);
+    public void removeListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) {
+        registry.removeListener(mailboxId, listener);
     }
 
     @Override
-    public void removeGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException {
+    public void removeGlobalListener(MailboxListener listener, MailboxSession session) {
         registry.removeGlobalListener(listener);
     }
 
@@ -95,12 +95,9 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen
     }
 
     private void mailboxEvent(MailboxEvent mailboxEvent) {
-        Collection<MailboxListener> listenerSnapshot = registry.getLocalMailboxListeners(mailboxEvent.getMailboxPath());
+        Collection<MailboxListener> listenerSnapshot = registry.getLocalMailboxListeners(mailboxEvent.getMailboxId());
         if (mailboxEvent instanceof MailboxDeletion && listenerSnapshot.size() > 0) {
-            registry.deleteRegistryFor(mailboxEvent.getMailboxPath());
-        } else if (mailboxEvent instanceof MailboxRenamed && listenerSnapshot.size() > 0) {
-            MailboxRenamed renamed = (MailboxRenamed) mailboxEvent;
-            registry.handleRename(renamed.getMailboxPath(), renamed.getNewPath());
+            registry.deleteRegistryFor(mailboxEvent.getMailboxId());
         }
         deliverEventToMailboxListeners(mailboxEvent, listenerSnapshot);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
index d29caff..83461e6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
@@ -23,7 +23,7 @@ import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableList;
@@ -32,7 +32,7 @@ import com.google.common.collect.Multimaps;
 
 public class MailboxListenerRegistry {
 
-    private final Multimap<MailboxPath, MailboxListener> listeners;
+    private final Multimap<MailboxId, MailboxListener> listeners;
     private final ConcurrentLinkedQueue<MailboxListener> globalListeners;
 
     public MailboxListenerRegistry() {
@@ -40,36 +40,32 @@ public class MailboxListenerRegistry {
         this.listeners = Multimaps.synchronizedMultimap(HashMultimap.create());
     }
 
-    public void addListener(MailboxPath path, MailboxListener listener) {
-        listeners.put(path, listener);
+    public void addListener(MailboxId mailboxId, MailboxListener listener) {
+        listeners.put(mailboxId, listener);
     }
 
     public void addGlobalListener(MailboxListener listener) {
         globalListeners.add(listener);
     }
 
-    public void removeListener(MailboxPath mailboxPath, MailboxListener listener) {
-        listeners.remove(mailboxPath, listener);
+    public void removeListener(MailboxId mailboxId, MailboxListener listener) {
+        listeners.remove(mailboxId, listener);
     }
 
     public void removeGlobalListener(MailboxListener listener) {
         globalListeners.remove(listener);
     }
 
-    public List<MailboxListener> getLocalMailboxListeners(MailboxPath path) {
-        return ImmutableList.copyOf(listeners.get(path));
+    public List<MailboxListener> getLocalMailboxListeners(MailboxId mailboxId) {
+        return ImmutableList.copyOf(listeners.get(mailboxId));
     }
 
     public List<MailboxListener> getGlobalListeners() {
         return ImmutableList.copyOf(globalListeners);
     }
 
-    public void deleteRegistryFor(MailboxPath path) {
-        listeners.removeAll(path);
-    }
-
-    public void handleRename(MailboxPath oldName, MailboxPath newName) {
-        listeners.putAll(newName, listeners.removeAll(oldName));
+    public void deleteRegistryFor(MailboxId mailboxId) {
+        listeners.removeAll(mailboxId);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
index 190e0b2..c9a411a 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
@@ -45,6 +45,7 @@ public class DefaultDelegatingMailboxListenerTest {
     private static final MailboxPath MAILBOX_PATH = new MailboxPath("namespace", "user", "name");
     private static final MailboxPath OTHER_MAILBOX_PATH = new MailboxPath("namespace", "other", "name");
     private static final MailboxId MAILBOX_ID = TestId.of(100);
+    private static final MailboxId OTHER_MAILBOX_ID = TestId.of(42);
 
     private DefaultDelegatingMailboxListener defaultDelegatingMailboxListener;
     private EventCollector mailboxEventCollector;
@@ -57,7 +58,7 @@ public class DefaultDelegatingMailboxListenerTest {
         eachNodeEventCollector = new EventCollector(MailboxListener.ListenerType.EACH_NODE);
         onceEventCollector = new EventCollector(MailboxListener.ListenerType.ONCE);
         defaultDelegatingMailboxListener = new DefaultDelegatingMailboxListener();
-        defaultDelegatingMailboxListener.addListener(MAILBOX_PATH, mailboxEventCollector, null);
+        defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxEventCollector, null);
         defaultDelegatingMailboxListener.addGlobalListener(onceEventCollector, null);
         defaultDelegatingMailboxListener.addGlobalListener(eachNodeEventCollector, null);
     }
@@ -65,13 +66,13 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test(expected = MailboxException.class)
     public void addListenerShouldThrowOnEACH_NODEListenerType() throws Exception {
         MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.EACH_NODE);
-        defaultDelegatingMailboxListener.addListener(MAILBOX_PATH, mailboxListener, null);
+        defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxListener, null);
     }
 
     @Test(expected = MailboxException.class)
     public void addListenerShouldThrowOnONCEListenerType() throws Exception {
         MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.ONCE);
-        defaultDelegatingMailboxListener.addListener(MAILBOX_PATH, mailboxListener, null);
+        defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxListener, null);
     }
 
     @Test(expected = MailboxException.class)
@@ -81,7 +82,7 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void eventShouldWork() throws Exception {
+    public void eventShouldWork() {
         MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
@@ -90,8 +91,8 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() throws Exception {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
+    public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() {
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -99,39 +100,7 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void mailboxRenamedEventShouldUnregisterMAILBOXFromTheirPreviousPath() throws Exception {
-        MailboxListener.MailboxRenamed event = new MailboxListener.MailboxRenamed(null, MAILBOX_PATH, MAILBOX_ID) {
-            @Override
-            public MailboxPath getNewPath() {
-                return OTHER_MAILBOX_PATH;
-            }
-        };
-        defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
-        defaultDelegatingMailboxListener.event(secondEvent);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event, secondEvent);
-    }
-
-    @Test
-    public void mailboxRenamedEventShouldRegisterMAILBOXToTheirNewPath() throws Exception {
-        MailboxListener.MailboxRenamed event = new MailboxListener.MailboxRenamed(null, MAILBOX_PATH, MAILBOX_ID) {
-            @Override
-            public MailboxPath getNewPath() {
-                return OTHER_MAILBOX_PATH;
-            }
-        };
-        defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
-        defaultDelegatingMailboxListener.event(secondEvent);
-        assertThat(mailboxEventCollector.getEvents()).containsOnly(event, secondEvent);
-        assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event, secondEvent);
-    }
-
-    @Test
-    public void mailboxDeletionShouldUnregisterMAILBOXListeners() throws Exception {
+    public void mailboxDeletionShouldUnregisterMAILBOXListeners() {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount deletedMessageCount = QuotaCount.count(123);
         QuotaSize totalDeletedSize = QuotaSize.size(456);
@@ -145,7 +114,7 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() throws Exception {
+    public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
@@ -159,8 +128,8 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void removeListenerShouldWork() throws Exception {
-        defaultDelegatingMailboxListener.removeListener(MAILBOX_PATH, mailboxEventCollector, null);
+    public void removeListenerShouldWork() {
+        defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null);
         MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
@@ -169,8 +138,8 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void removeListenerShouldNotRemoveAListenerFromADifferentPath() throws Exception {
-        defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_PATH, mailboxEventCollector, null);
+    public void removeListenerShouldNotRemoveAListenerFromADifferentPath() {
+        defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null);
         MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
@@ -179,7 +148,7 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void removeGlobalListenerShouldWorkForONCE() throws Exception {
+    public void removeGlobalListenerShouldWorkForONCE() {
         defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null);
         MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
@@ -189,7 +158,7 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void removeGlobalListenerShouldWorkForEACH_NODE() throws Exception {
+    public void removeGlobalListenerShouldWorkForEACH_NODE() {
         defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null);
         MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
index 58b0e11..04d2b1a 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
@@ -23,15 +23,15 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.TestId;
 import org.junit.Before;
 import org.junit.Test;
 
-
 public class MailboxListenerRegistryTest {
+    private static final MailboxId MAILBOX_ID = TestId.of(42);
+    private static final MailboxId OTHER_MAILBOX_ID = TestId.of(43);
 
-    private static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("user", "INBOX");
-    private static final MailboxPath OTHER_MAILBOX_PATH = MailboxPath.forUser("user", "other");
     private MailboxListenerRegistry testee;
     private MailboxListener mailboxListener;
     private MailboxListener otherMailboxListener;
@@ -50,36 +50,36 @@ public class MailboxListenerRegistryTest {
 
     @Test
     public void getLocalMailboxListenersShouldReturnEmptyList() {
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty();
     }
 
     @Test
-    public void addGlobalListenerShouldAddAGlobalListener() throws Exception {
+    public void addGlobalListenerShouldAddAGlobalListener() {
         testee.addGlobalListener(mailboxListener);
 
         assertThat(testee.getGlobalListeners()).containsOnly(mailboxListener);
     }
 
     @Test
-    public void addListenerShouldAddAListener() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
+    public void addListenerShouldAddAListener() {
+        testee.addListener(MAILBOX_ID, mailboxListener);
 
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsOnly(mailboxListener);
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsOnly(mailboxListener);
     }
 
     @Test
-    public void addListenerTwiceShouldAddAListenerOnlyOnce() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
-        testee.addListener(MAILBOX_PATH, mailboxListener);
+    public void addListenerTwiceShouldAddAListenerOnlyOnce() {
+        testee.addListener(MAILBOX_ID, mailboxListener);
+        testee.addListener(MAILBOX_ID, mailboxListener);
 
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsExactly(mailboxListener);
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsExactly(mailboxListener);
     }
 
     @Test
-    public void addListenerShouldAddAListenerOnCorrectPath() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
+    public void addListenerShouldAddAListenerOnCorrectPath() {
+        testee.addListener(MAILBOX_ID, mailboxListener);
 
-        assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).isEmpty();
+        assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_ID)).isEmpty();
     }
 
     @Test
@@ -92,16 +92,16 @@ public class MailboxListenerRegistryTest {
     }
 
     @Test
-    public void removeListenerShouldWork() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
+    public void removeListenerShouldWork() {
+        testee.addListener(MAILBOX_ID, mailboxListener);
 
-        testee.removeListener(MAILBOX_PATH, mailboxListener);
+        testee.removeListener(MAILBOX_ID, mailboxListener);
 
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty();
     }
 
     @Test
-    public void removeGlobalListenerShouldNotRemoveOtherListeners() throws Exception {
+    public void removeGlobalListenerShouldNotRemoveOtherListeners() {
         testee.addGlobalListener(mailboxListener);
         testee.addGlobalListener(otherMailboxListener);
 
@@ -111,64 +111,32 @@ public class MailboxListenerRegistryTest {
     }
 
     @Test
-    public void removeListenerShouldNotRemoveOtherListeners() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
-        testee.addListener(MAILBOX_PATH, otherMailboxListener);
-
-        testee.removeListener(MAILBOX_PATH, mailboxListener);
-
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsOnly(otherMailboxListener);
-    }
-
-    @Test
-    public void deleteRegistryForShouldRemoveAllListeners() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
-        testee.addListener(MAILBOX_PATH, otherMailboxListener);
-
-        testee.deleteRegistryFor(MAILBOX_PATH);
-
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
-    }
-
-    @Test
-    public void handleRenameShouldMoveListeners() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
-        testee.addListener(MAILBOX_PATH, otherMailboxListener);
-
-        testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH);
-
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
-        assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener, otherMailboxListener);
-    }
-
-    @Test
-    public void handleRenameShouldPreservePreviouslyRegisteredListeners() throws Exception {
-        testee.addListener(OTHER_MAILBOX_PATH, mailboxListener);
+    public void removeListenerShouldNotRemoveOtherListeners() {
+        testee.addListener(MAILBOX_ID, mailboxListener);
+        testee.addListener(MAILBOX_ID, otherMailboxListener);
 
-        testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH);
+        testee.removeListener(MAILBOX_ID, mailboxListener);
 
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
-        assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener);
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsOnly(otherMailboxListener);
     }
 
     @Test
-    public void handleRenameShouldMergeListenersIfNeeded() throws Exception {
-        testee.addListener(MAILBOX_PATH, mailboxListener);
-        testee.addListener(OTHER_MAILBOX_PATH, otherMailboxListener);
+    public void deleteRegistryForShouldRemoveAllListeners() {
+        testee.addListener(MAILBOX_ID, mailboxListener);
+        testee.addListener(MAILBOX_ID, otherMailboxListener);
 
-        testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH);
+        testee.deleteRegistryFor(MAILBOX_ID);
 
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
-        assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener, otherMailboxListener);
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty();
     }
 
     @Test
-    public void removeGlobalListenerShouldNotThrowOnAbsentListener() throws Exception {
+    public void removeGlobalListenerShouldNotThrowOnAbsentListener() {
         testee.removeGlobalListener(mailboxListener);
     }
 
     @Test
-    public void removeListenerShouldNotThrowOnAbsentListener() throws Exception {
-        testee.removeListener(MAILBOX_PATH, mailboxListener);
+    public void removeListenerShouldNotThrowOnAbsentListener() {
+        testee.removeListener(MAILBOX_ID, mailboxListener);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
index 01cab31..684c9e9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
@@ -93,7 +93,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme
             final IdleMailboxListener idleListener;
             if (sm != null) {
                 idleListener = new IdleMailboxListener(session, responder);
-                mailboxManager.addListener(sm.getPath(), idleListener, mailboxSession);
+                mailboxManager.addListener(sm.getMailboxId(), idleListener, mailboxSession);
             } else {
                 idleListener = null;
             }
@@ -112,7 +112,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme
 
                     if (idleListener != null) {
                         try {
-                            mailboxManager.removeListener(sm.getPath(), idleListener, mailboxSession);
+                            mailboxManager.removeListener(sm.getMailboxId(), idleListener, mailboxSession);
                         } catch (MailboxException e) {
                                 LOGGER.error("Unable to remove idle listener for mailbox {}", sm.getPath(), e);
                         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
index 9402ba1..f0eb68e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
@@ -93,10 +93,11 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
 
         uidMsnConverter = new UidMsnConverter();
 
-        mailboxManager.addListener(path, this, mailboxSession);
-
         MessageManager messageManager = mailboxManager.getMailbox(path, mailboxSession);
         mailboxId = messageManager.getId();
+
+        mailboxManager.addListener(mailboxId, this, mailboxSession);
+
         applicableFlags = messageManager.getApplicableFlags(mailboxSession);
         uidMsnConverter.addAll(ImmutableList.copyOf(
             messageManager.search(new SearchQuery(SearchQuery.all()), mailboxSession)));
@@ -122,7 +123,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
         MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
 
         try {
-            mailboxManager.removeListener(path, this, mailboxSession);
+            mailboxManager.removeListener(mailboxId, this, mailboxSession);
         } catch (MailboxException e) {
             LOGGER.error("Unable to remove listener {} from mailbox while closing it", this, e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index b640cba..12daae0 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -46,6 +46,7 @@ import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
@@ -74,6 +75,7 @@ public class SelectedMailboxImplTest {
     private MailboxPath mailboxPath;
     private ImapSession imapSession;
     private Mailbox mailbox;
+    private TestId mailboxId;
 
     @Before
     public void setUp() throws Exception {
@@ -83,6 +85,7 @@ public class SelectedMailboxImplTest {
         messageManager = mock(MessageManager.class);
         imapSession = mock(ImapSession.class);
         mailbox = mock(Mailbox.class);
+        mailboxId = TestId.of(42);
 
         when(mailboxManager.getMailbox(eq(mailboxPath), any(MailboxSession.class)))
             .thenReturn(messageManager);
@@ -90,6 +93,7 @@ public class SelectedMailboxImplTest {
             .thenReturn(new Flags());
         when(messageManager.search(any(SearchQuery.class), any(MailboxSession.class)))
             .then(delayedSearchAnswer());
+        when(messageManager.getId()).thenReturn(mailboxId);
 
         when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mock(MailboxSession.class));
 
@@ -107,7 +111,7 @@ public class SelectedMailboxImplTest {
         final AtomicInteger successCount = new AtomicInteger(0);
         doAnswer(generateEmitEventAnswer(successCount))
             .when(mailboxManager)
-            .addListener(eq(mailboxPath), any(MailboxListener.class), any(MailboxSession.class));
+            .addListener(eq(mailboxId), any(MailboxListener.class), any(MailboxSession.class));
 
         SelectedMailboxImpl selectedMailbox = new SelectedMailboxImpl(
             mailboxManager,
@@ -122,7 +126,7 @@ public class SelectedMailboxImplTest {
         final AtomicInteger successCount = new AtomicInteger(0);
         doAnswer(generateEmitEventAnswer(successCount))
             .when(mailboxManager)
-            .addListener(eq(mailboxPath), any(MailboxListener.class), any(MailboxSession.class));
+            .addListener(eq(mailboxId), any(MailboxListener.class), any(MailboxSession.class));
 
         new SelectedMailboxImpl(
             mailboxManager,


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


[4/8] james-project git commit: MAILBOX-354 Selected mailbox should expose the MailboxId

Posted by bt...@apache.org.
MAILBOX-354 Selected mailbox should expose the MailboxId


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

Branch: refs/heads/master
Commit: b853de8a5be321ed3ffe986dd75161557eaaada3
Parents: f454266
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Nov 30 10:32:48 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 4 15:47:32 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/imap/api/process/SelectedMailbox.java  | 9 +++++++++
 .../james/imap/processor/base/SelectedMailboxImpl.java      | 8 ++++++++
 2 files changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b853de8a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
index 710eba5..4157de8 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
@@ -21,9 +21,11 @@ package org.apache.james.imap.api.process;
 
 import java.util.Collection;
 import java.util.Optional;
+
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 
 /**
@@ -90,6 +92,13 @@ public interface SelectedMailbox {
     MailboxPath getPath();
 
     /**
+     * Return the mailboxId of the selected Mailbox.
+     *
+     * This is beneficial as the MailboxId is immutable.
+     */
+    MailboxId getMailboxId();
+
+    /**
      * Is the given uid recent ?
      * 
      * @return true if the given uid is recent

http://git-wip-us.apache.org/repos/asf/james-project/blob/b853de8a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
index 0579c61..9402ba1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -61,6 +62,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
 
     private final MailboxManager mailboxManager;
 
+    private final MailboxId mailboxId;
     private MailboxPath path;
 
     private final ImapSession session;
@@ -94,6 +96,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
         mailboxManager.addListener(path, this, mailboxSession);
 
         MessageManager messageManager = mailboxManager.getMailbox(path, mailboxSession);
+        mailboxId = messageManager.getId();
         applicableFlags = messageManager.getApplicableFlags(mailboxSession);
         uidMsnConverter.addAll(ImmutableList.copyOf(
             messageManager.search(new SearchQuery(SearchQuery.all()), mailboxSession)));
@@ -162,6 +165,11 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
         return path;
     }
 
+    @Override
+    public MailboxId getMailboxId() {
+        return mailboxId;
+    }
+
     private void checkExpungedRecents() {
         for (MessageUid uid : expungedUids()) {
             removeRecent(uid);


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