james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [13/15] james-project git commit: MAILBOX-317 Add a MailboxAnnotationManager
Date Fri, 03 Nov 2017 02:33:30 GMT
MAILBOX-317 Add a MailboxAnnotationManager


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

Branch: refs/heads/master
Commit: 9e7abcbef868a1efed3efbb555271d5647d69b5a
Parents: fb0c391
Author: benwa <btellier@linagora.com>
Authored: Thu Nov 2 11:05:33 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Nov 3 09:32:32 2017 +0700

----------------------------------------------------------------------
 .../james/mailbox/MailboxAnnotationManager.java | 100 +++++++++++++
 .../apache/james/mailbox/MailboxManager.java    |  45 +-----
 .../cassandra/CassandraMailboxManager.java      |  26 +---
 .../CassandraMailboxManagerProvider.java        |   6 +-
 .../cassandra/CassandraTestSystemFixture.java   |   4 +-
 .../CassandraMailboxManagerAttachmentTest.java  |   6 +-
 mailbox/elasticsearch/pom.xml                   |   6 +
 .../ElasticSearchIntegrationTest.java           |  52 ++-----
 .../mailbox/hbase/HBaseMailboxManager.java      |   4 +-
 .../hbase/HBaseMailboxManagerStressTest.java    |   3 +
 .../mailbox/hbase/HBaseMailboxManagerTest.java  |   3 +
 .../james/mailbox/jcr/JCRMailboxManager.java    |   4 +-
 .../mailbox/jcr/JCRMailboxManagerProvider.java  |   4 +-
 .../james/mailbox/jpa/JPAMailboxManager.java    |  19 +--
 .../jpa/openjpa/OpenJPAMailboxManager.java      |  29 +---
 .../mailbox/jpa/JpaMailboxManagerProvider.java  |  12 +-
 mailbox/lucene/pom.xml                          |   6 +
 .../search/LuceneMessageSearchIndexTest.java    |  53 ++-----
 .../maildir/MaildirMailboxManagerProvider.java  |   5 +-
 .../inmemory/InMemoryMailboxManager.java        |  19 +--
 .../inmemory/MemoryMailboxManagerProvider.java  |   9 +-
 .../InMemoryMailboxManagerAttachmentTest.java   |   6 +-
 .../manager/InMemoryIntegrationResources.java   |  28 ++++
 mailbox/scanning-search/pom.xml                 |  12 ++
 .../search/SimpleMessageSearchIndexTest.java    |  52 ++-----
 .../store/StoreMailboxAnnotationManager.java    | 146 +++++++++++++++++++
 .../mailbox/store/StoreMailboxManager.java      |  77 ++--------
 .../StoreMailboxManagerAnnotationTest.java      |  48 ++----
 .../mailbox/store/StoreMailboxManagerTest.java  |   4 +-
 mailbox/tool/pom.xml                            |  12 ++
 .../james/mailbox/copier/MailboxCopierTest.java |  37 +----
 .../cassandra/host/CassandraHostSystem.java     |   5 +-
 mpt/impl/imap-mailbox/elasticsearch/pom.xml     |  10 ++
 .../host/ElasticSearchHostSystem.java           |  37 +----
 .../imapmailbox/hbase/host/HBaseHostSystem.java |   5 +-
 mpt/impl/imap-mailbox/inmemory/pom.xml          |  12 ++
 .../inmemory/host/InMemoryHostSystem.java       |  33 +----
 .../mpt/imapmailbox/jcr/host/JCRHostSystem.java |   5 +-
 .../mpt/imapmailbox/jpa/host/JPAHostSystem.java |  15 +-
 .../host/LuceneSearchHostSystem.java            |  17 ++-
 .../maildir/host/MaildirHostSystem.java         |   6 +-
 server/container/mailbox-adapter/pom.xml        |  12 ++
 .../adapter/mailbox/MailboxManagementTest.java  | 120 ++++++---------
 .../transport/matchers/IsOverQuotaTest.java     |  31 +---
 server/protocols/protocols-pop3/pom.xml         |  12 ++
 .../apache/james/pop3server/POP3ServerTest.java |  48 ++----
 46 files changed, 631 insertions(+), 574 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxAnnotationManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxAnnotationManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxAnnotationManager.java
new file mode 100644
index 0000000..740f7ef
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxAnnotationManager.java
@@ -0,0 +1,100 @@
+/****************************************************************
+ * 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;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.james.mailbox.exception.AnnotationException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.model.MailboxPath;
+
+/**
+ * <p>
+ * This class intends to manage mailbox annotations.
+ *
+ * Work will be delegated to it by {@link MailboxManager}
+ * </p>
+ */
+
+public interface MailboxAnnotationManager {
+
+    /**
+     * Return all mailbox's annotation as the {@link List} of {@link MailboxAnnotation} without order and
+     * do not contain any two annotations with the same key
+     * 
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @return              List<MailboxAnnotation>
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    List<MailboxAnnotation> getAllAnnotations(MailboxPath mailboxPath, MailboxSession session) throws MailboxException;
+
+    /**
+     * Return all mailbox's annotation filter by the list of the keys without order and
+     * do not contain any two annotations with the same key
+     * 
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @param keys          list of the keys should be filter
+     * @return              List<MailboxAnnotation>
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
+
+    /**
+     * Return all mailbox's annotation by the list of the keys and its children entries without order and
+     * do not contain any two annotations with the same key
+     *
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @param keys          list of the keys should be filter
+     * @return              List<MailboxAnnotation>
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
+
+    /**
+     * Return all mailbox's annotation by the list of the keys and its below entries without order and
+     * do not contain any two annotations with the same key
+     *
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @param keys          list of the keys should be filter
+     * @return              List<MailboxAnnotation>
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
+
+    /**
+     * Update the mailbox's annotations. This method can:
+     * - Insert new annotation if it does not exist
+     * - Update the new value for existed annotation
+     * - Delete the existed annotation if its value is nil
+     * 
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @param mailboxAnnotations    the list of annotation should be insert/udpate/delete
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    void updateAnnotations(MailboxPath mailboxPath, MailboxSession session, List<MailboxAnnotation> mailboxAnnotations) throws MailboxException, AnnotationException;
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index 287c790..7a55280 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -418,62 +418,27 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport {
     List<MailboxPath> list(MailboxSession session) throws MailboxException;
 
     /**
-     * Return all mailbox's annotation as the {@link List} of {@link MailboxAnnotation} without order and
-     * do not contain any two annotations with the same key
-     * 
-     * @param mailboxPath   the current mailbox
-     * @param session       the current session
-     * @return              List<MailboxAnnotation>
-     * @throws MailboxException in case of selected mailbox does not exist
+     * See {@link MailboxAnnotationManager#getAllAnnotations(MailboxPath, MailboxSession)}
      */
     List<MailboxAnnotation> getAllAnnotations(MailboxPath mailboxPath, MailboxSession session) throws MailboxException;
 
     /**
-     * Return all mailbox's annotation filter by the list of the keys without order and
-     * do not contain any two annotations with the same key
-     * 
-     * @param mailboxPath   the current mailbox
-     * @param session       the current session
-     * @param keys          list of the keys should be filter
-     * @return              List<MailboxAnnotation>
-     * @throws MailboxException in case of selected mailbox does not exist
+     * See {@link MailboxAnnotationManager#getAnnotationsByKeys(MailboxPath, MailboxSession, Set)}
      */
     List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
 
     /**
-     * Return all mailbox's annotation by the list of the keys and its children entries without order and
-     * do not contain any two annotations with the same key
-     *
-     * @param mailboxPath   the current mailbox
-     * @param session       the current session
-     * @param keys          list of the keys should be filter
-     * @return              List<MailboxAnnotation>
-     * @throws MailboxException in case of selected mailbox does not exist
+     * See {@link MailboxAnnotationManager#getAnnotationsByKeysWithOneDepth(MailboxPath, MailboxSession, Set)}
      */
     List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
 
     /**
-     * Return all mailbox's annotation by the list of the keys and its below entries without order and
-     * do not contain any two annotations with the same key
-     *
-     * @param mailboxPath   the current mailbox
-     * @param session       the current session
-     * @param keys          list of the keys should be filter
-     * @return              List<MailboxAnnotation>
-     * @throws MailboxException in case of selected mailbox does not exist
+     * See {@link MailboxAnnotationManager#getAnnotationsByKeysWithAllDepth(MailboxPath, MailboxSession, Set)}
      */
     List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
 
     /**
-     * Update the mailbox's annotations. This method can:
-     * - Insert new annotation if it does not exist
-     * - Update the new value for existed annotation
-     * - Delete the existed annotation if its value is nil
-     * 
-     * @param mailboxPath   the current mailbox
-     * @param session       the current session
-     * @param mailboxAnnotations    the list of annotation should be insert/udpate/delete
-     * @throws MailboxException in case of selected mailbox does not exist
+     * See {@link MailboxAnnotationManager#updateAnnotations(MailboxPath, MailboxSession, List)}
      */
     void updateAnnotations(MailboxPath mailboxPath, MailboxSession session, List<MailboxAnnotation> mailboxAnnotations) throws MailboxException, AnnotationException;
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
index 2f68d6c..a6d6603 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
@@ -28,11 +28,11 @@ import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
@@ -52,35 +52,17 @@ public class CassandraMailboxManager extends StoreMailboxManager {
 
     @Inject
     public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, Authorizator authorizator,
-                                   MailboxPathLocker locker, MessageParser messageParser, MessageId.Factory messageIdFactory,
-                                   MailboxEventDispatcher mailboxEventDispatcher, DelegatingMailboxListener delegatingMailboxListener,
-                                   StoreRightManager storeRightManager) {
-        this(mapperFactory,
-            authenticator,
-            authorizator,
-            locker,
-            messageParser,
-            messageIdFactory,
-            MailboxConstants.DEFAULT_LIMIT_ANNOTATIONS_ON_MAILBOX,
-            MailboxConstants.DEFAULT_LIMIT_ANNOTATION_SIZE,
-            mailboxEventDispatcher,
-            delegatingMailboxListener,
-            storeRightManager);
-    }
-
-    public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory, Authenticator authenticator,  Authorizator authorizator,
                                    MailboxPathLocker locker, MessageParser messageParser,
-                                   MessageId.Factory messageIdFactory, int limitOfAnnotations, int limitAnnotationSize,
+                                   MessageId.Factory messageIdFactory,
                                    MailboxEventDispatcher mailboxEventDispatcher, DelegatingMailboxListener delegatingMailboxListener,
-                                   StoreRightManager storeRightManager) {
+                                   StoreMailboxAnnotationManager annotationManager, StoreRightManager storeRightManager) {
         super(mapperFactory,
             authenticator,
             authorizator,
             locker,
             messageParser,
             messageIdFactory,
-            limitOfAnnotations,
-            limitAnnotationSize,
+            annotationManager,
             mailboxEventDispatcher,
             delegatingMailboxListener,
             storeRightManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
index 85d809f..3fca347 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -58,9 +59,12 @@ public class CassandraMailboxManagerProvider {
         Authorizator noAuthorizator = null;
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager,
+            LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
 
         CassandraMailboxManager manager = new CassandraMailboxManager(mapperFactory, noAuthenticator, noAuthorizator, new NoMailboxPathLocker(),
-            messageParser, messageIdFactory, LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE, mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
+            messageParser, messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener,
+            annotationManager, storeRightManager);
         try {
             manager.init();
         } catch (MailboxException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
index 1dfe2bc..8a4d46e 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
@@ -58,10 +59,11 @@ public class CassandraTestSystemFixture {
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
         StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver());
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager);
 
         CassandraMailboxManager cassandraMailboxManager = new CassandraMailboxManager(mapperFactory, mock(Authenticator.class), mock(Authorizator.class),
             new NoMailboxPathLocker(), new MessageParser(), new CassandraMessageId.Factory(),
-            mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
+            mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
         cassandraMailboxManager.init();
 
         return cassandraMailboxManager;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
index 6a3f5b0..e5d416a 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
@@ -49,6 +49,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -107,17 +108,18 @@ public class CassandraMailboxManagerAttachmentTest extends AbstractMailboxManage
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
         StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver());
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
 
         mailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory,
             noAuthenticator, noAuthorizator, new NoMailboxPathLocker(), new MessageParser(),
-            messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
+            messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
         mailboxManager.init();
         MessageParser failingMessageParser = mock(MessageParser.class);
         when(failingMessageParser.retrieveAttachments(any()))
             .thenThrow(new RuntimeException("Message parser set to fail"));
         parseFailingMailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory, noAuthenticator, noAuthorizator,
             new NoMailboxPathLocker(), failingMessageParser, messageIdFactory,
-            mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
+            mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
         parseFailingMailboxManager.init();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/pom.xml b/mailbox/elasticsearch/pom.xml
index 5ac7989..84156cb 100644
--- a/mailbox/elasticsearch/pom.xml
+++ b/mailbox/elasticsearch/pom.xml
@@ -59,6 +59,12 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-memory</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>apache-james-mailbox-store</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index d91e755..405f76f 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -36,31 +36,18 @@ import org.apache.james.backends.es.NodeMappingFactory;
 import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
 import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson;
 import org.apache.james.mailbox.elasticsearch.query.CriterionConverter;
 import org.apache.james.mailbox.elasticsearch.query.QueryConverter;
 import org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher;
 import org.apache.james.mailbox.inmemory.InMemoryId;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
-import org.apache.james.mailbox.inmemory.InMemoryMessageId;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.SearchQuery;
-import org.apache.james.mailbox.store.FakeAuthenticator;
-import org.apache.james.mailbox.store.FakeAuthorizator;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
-import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
-import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.apache.james.mailbox.store.search.AbstractMessageSearchIndexTest;
 import org.apache.james.mailbox.tika.TikaConfiguration;
 import org.apache.james.mailbox.tika.TikaContainer;
@@ -119,10 +106,12 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
             MailboxElasticSearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
 
-        MailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
-        InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver());
-        messageSearchIndex = new ElasticSearchListeningMessageSearchIndex(mapperFactory,
+        storeMailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver());
+
+
+        ElasticSearchListeningMessageSearchIndex elasticSearchListeningMessageSearchIndex = new ElasticSearchListeningMessageSearchIndex(
+            storeMailboxManager.getMapperFactory(),
             new ElasticSearchIndexer(client,
                 new DeleteByQueryPerformer(client,
                     Executors.newSingleThreadExecutor(),
@@ -132,32 +121,21 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
                 MailboxElasticSearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
-                new InMemoryId.Factory(), messageIdFactory,
+                new InMemoryId.Factory(), storeMailboxManager.getMessageIdFactory(),
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
                 MailboxElasticSearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
-        DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        storeMailboxManager = new InMemoryMailboxManager(
-            mapperFactory,
-            new FakeAuthenticator(),
-            FakeAuthorizator.defaultReject(),
-            new JVMMailboxPathLocker(),
-            new MessageParser(),
-            messageIdFactory,
-            mailboxEventDispatcher,
-            delegatingListener,
-            storeRightManager);
 
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,
             storeMailboxManager.getMapperFactory(),
-            mailboxEventDispatcher,
-            messageIdFactory,
-            new NoQuotaManager(),
-            new DefaultQuotaRootResolver(mapperFactory));
-        storeMailboxManager.setMessageSearchIndex(messageSearchIndex);
-        storeMailboxManager.init();
+            storeMailboxManager.getEventDispatcher(),
+            storeMailboxManager.getMessageIdFactory(),
+            storeMailboxManager.getQuotaManager(),
+            storeMailboxManager.getQuotaRootResolver());
+        storeMailboxManager.setMessageSearchIndex(elasticSearchListeningMessageSearchIndex);
+        storeMailboxManager.addGlobalListener(elasticSearchListeningMessageSearchIndex, new MockMailboxSession("admin"));
+        this.messageSearchIndex = elasticSearchListeningMessageSearchIndex;
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
index 25e74b2..5fe1378 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
@@ -52,9 +53,10 @@ public class HBaseMailboxManager extends StoreMailboxManager {
                                MessageId.Factory messageIdFactory,
                                MailboxEventDispatcher dispatcher,
                                DelegatingMailboxListener delegatingMailboxListener,
+                               StoreMailboxAnnotationManager annotationManager,
                                StoreRightManager storeRightManager) {
         super(mapperFactory, authenticator, authorizator, locker, messageParser, messageIdFactory,
-            dispatcher, delegatingMailboxListener, storeRightManager);
+            annotationManager, dispatcher, delegatingMailboxListener, storeRightManager);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerStressTest.java b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerStressTest.java
index 7a44866..688894d 100644
--- a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerStressTest.java
+++ b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerStressTest.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -71,6 +72,7 @@ public class HBaseMailboxManagerStressTest extends MailboxManagerStressTest {
         Authorizator noAuthorizator = null;
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager);
         HBaseMailboxManager manager = new HBaseMailboxManager(mapperFactory,
             noAuthenticator,
             noAuthorizator,
@@ -79,6 +81,7 @@ public class HBaseMailboxManagerStressTest extends MailboxManagerStressTest {
             messageIdFactory,
             mailboxEventDispatcher,
             delegatingListener,
+            annotationManager,
             storeRightManager);
 
         try {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
index 5d0cba7..5794093 100644
--- a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
+++ b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -71,6 +72,7 @@ public class HBaseMailboxManagerTest extends MailboxManagerTest {
         Authorizator noAuthorizator = null;
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager);
         HBaseMailboxManager manager = new HBaseMailboxManager(mapperFactory,
             noAuthenticator,
             noAuthorizator,
@@ -79,6 +81,7 @@ public class HBaseMailboxManagerTest extends MailboxManagerTest {
             messageIdFactory,
             mailboxEventDispatcher,
             delegatingListener,
+            annotationManager,
             storeRightManager);
 
         try {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
index eca67e9..9a1b935 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
@@ -28,6 +28,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
@@ -50,9 +51,10 @@ public class JCRMailboxManager extends StoreMailboxManager implements JCRImapCon
                              MessageId.Factory messageIdFactory,
                              MailboxEventDispatcher mailboxEventDispatcher,
                              DelegatingMailboxListener delegatingMailboxListener,
+                             StoreMailboxAnnotationManager annotationManager,
                              StoreRightManager storeRightManager) {
         super(mapperFactory, authenticator, authorizator, locker, messageParser, messageIdFactory,
-            mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
+            annotationManager, mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerProvider.java b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerProvider.java
index ee76ed6..40bc489 100644
--- a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerProvider.java
+++ b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerProvider.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -68,11 +69,12 @@ public class JCRMailboxManagerProvider {
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
         StoreRightManager storeRightManager = new StoreRightManager(mf, aclResolver, groupMembershipResolver);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mf, storeRightManager);
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
         JCRMailboxManager manager = new JCRMailboxManager(mf, noAuthenticator, noAuthorizator, locker,
             messageParser, new DefaultMessageId.Factory(), mailboxEventDispatcher, delegatingListener,
-            storeRightManager);
+            annotationManager, storeRightManager);
 
         try {
             manager.init();

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
index 77dcc68..2943e01 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
@@ -41,19 +42,6 @@ import org.apache.james.mailbox.store.transaction.Mapper;
  * JPA implementation of {@link StoreMailboxManager}
  */
 public abstract class JPAMailboxManager extends StoreMailboxManager {
-    
-    public JPAMailboxManager(JPAMailboxSessionMapperFactory mailboxSessionMapperFactory,
-                             Authenticator authenticator,
-                             Authorizator authorizator,
-                             MailboxPathLocker locker,
-                             MessageParser messageParser,
-                             MessageId.Factory messageIdFactory,
-                             DelegatingMailboxListener delegatingMailboxListener,
-                             MailboxEventDispatcher mailboxEventDispatcher,
-                             StoreRightManager storeRightManager) {
-        super(mailboxSessionMapperFactory, authenticator, authorizator, locker,
-            messageParser, messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
-    }
 
     public JPAMailboxManager(JPAMailboxSessionMapperFactory mailboxSessionMapperFactory,
                              Authenticator authenticator,
@@ -63,11 +51,10 @@ public abstract class JPAMailboxManager extends StoreMailboxManager {
                              MessageId.Factory messageIdFactory,
                              DelegatingMailboxListener delegatingMailboxListener,
                              MailboxEventDispatcher mailboxEventDispatcher,
-                             int limitAnnotation,
-                             int limitAnnotationSize,
+                             StoreMailboxAnnotationManager annotationManager,
                              StoreRightManager storeRightManager) {
         super(mailboxSessionMapperFactory, authenticator, authorizator, locker,
-            messageParser, messageIdFactory, limitAnnotation, limitAnnotationSize,
+            messageParser, messageIdFactory, annotationManager,
             mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
index 48339d1..5c25eeb 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
@@ -29,11 +29,11 @@ import org.apache.james.mailbox.jpa.JPAMailboxManager;
 import org.apache.james.mailbox.jpa.JPAMailboxSessionMapperFactory;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.EncryptDecryptHelper;
 import org.apache.james.mailbox.jpa.openjpa.OpenJPAMessageManager.AdvancedFeature;
-import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
@@ -56,13 +56,12 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
                                  boolean useStreaming,
                                  MessageParser messageParser,
                                  MessageId.Factory messageIdFactory,
-                                 int annotationLimit,
-                                 int annotationLimitSize,
+                                 StoreMailboxAnnotationManager annotationManager,
                                  DelegatingMailboxListener delegatingMailboxListener,
                                  MailboxEventDispatcher mailboxEventDispatcher,
                                  StoreRightManager storeRightManager) {
         super(mapperFactory, authenticator, authorizator, locker, messageParser,
-            messageIdFactory, delegatingMailboxListener, mailboxEventDispatcher, annotationLimit,  annotationLimitSize, storeRightManager);
+            messageIdFactory, delegatingMailboxListener, mailboxEventDispatcher, annotationManager, storeRightManager);
         if (useStreaming) {
             feature = AdvancedFeature.Streaming;
         } else {
@@ -77,11 +76,12 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
                                  String encryptPass,
                                  MessageParser messageParser,
                                  MessageId.Factory messageIdFactory,
+                                 StoreMailboxAnnotationManager annotationManager,
                                  DelegatingMailboxListener delegatingMailboxListener,
                                  MailboxEventDispatcher mailboxEventDispatcher,
                                  StoreRightManager storeRightManager) {
         super(mapperFactory, authenticator, authorizator, locker, messageParser,
-            messageIdFactory, delegatingMailboxListener, mailboxEventDispatcher, storeRightManager);
+            messageIdFactory, delegatingMailboxListener, mailboxEventDispatcher, annotationManager, storeRightManager);
         if (encryptPass != null) {
             EncryptDecryptHelper.init(encryptPass);
             feature = AdvancedFeature.Encryption;
@@ -98,24 +98,11 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
                                  MessageId.Factory messageIdFactory,
                                  DelegatingMailboxListener delegatingMailboxListener,
                                  MailboxEventDispatcher mailboxEventDispatcher,
+                                 StoreMailboxAnnotationManager annotationManager,
                                  StoreRightManager storeRightManager) {
         this(mapperFactory, authenticator, authorizator, new JVMMailboxPathLocker(), false,
-            messageParser, messageIdFactory, MailboxConstants.DEFAULT_LIMIT_ANNOTATIONS_ON_MAILBOX,
-            MailboxConstants.DEFAULT_LIMIT_ANNOTATION_SIZE, delegatingMailboxListener, mailboxEventDispatcher, storeRightManager);
-    }
-
-    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory,
-                                 Authenticator authenticator,
-                                 Authorizator authorizator,
-                                 MessageParser messageParser,
-                                 MessageId.Factory messageIdFactory,
-                                 int annotationLimit,
-                                 int annotationLimitSize,
-                                 DelegatingMailboxListener delegatingMailboxListener,
-                                 MailboxEventDispatcher mailboxEventDispatcher,
-                                 StoreRightManager storeRightManager) {
-        this(mapperFactory, authenticator, authorizator, new JVMMailboxPathLocker(), false,
-            messageParser, messageIdFactory, annotationLimit, annotationLimitSize, delegatingMailboxListener, mailboxEventDispatcher, storeRightManager);
+            messageParser, messageIdFactory,  annotationManager, delegatingMailboxListener, mailboxEventDispatcher,
+           storeRightManager);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
index a9a0180..8d1439c 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
@@ -33,7 +33,10 @@ import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
+import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
+import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 
@@ -56,9 +59,14 @@ public class JpaMailboxManagerProvider {
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
         StoreRightManager storeRightManager = new StoreRightManager(mf, aclResolver, groupMembershipResolver);
+        DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
+        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mf, storeRightManager,
+            LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
         OpenJPAMailboxManager openJPAMailboxManager = new OpenJPAMailboxManager(mf, noAuthenticator, noAuthorizator,
-            messageParser, new DefaultMessageId.Factory(), LIMIT_ANNOTATIONS,
-            LIMIT_ANNOTATION_SIZE, storeRightManager);
+            messageParser, new DefaultMessageId.Factory(),
+            delegatingListener, mailboxEventDispatcher, annotationManager,
+            storeRightManager);
 
         try {
             openJPAMailboxManager.init();

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/lucene/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/lucene/pom.xml b/mailbox/lucene/pom.xml
index 0da2934..947d584 100644
--- a/mailbox/lucene/pom.xml
+++ b/mailbox/lucene/pom.xml
@@ -49,6 +49,12 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-memory</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>apache-james-mailbox-store</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
index 2c6daaa..8d5683e 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
@@ -20,23 +20,11 @@
 package org.apache.james.mailbox.lucene.search;
 
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.InMemoryId;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
-import org.apache.james.mailbox.model.TestMessageId;
-import org.apache.james.mailbox.store.FakeAuthenticator;
-import org.apache.james.mailbox.store.FakeAuthorizator;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
-import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
-import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.apache.james.mailbox.store.search.AbstractMessageSearchIndexTest;
 import org.apache.lucene.store.RAMDirectory;
 import org.junit.Ignore;
@@ -49,35 +37,22 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
 
     @Override
     protected void initializeMailboxManager() throws Exception {
-        TestMessageId.Factory messageIdFactory = new TestMessageId.Factory();
-        MailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
-        UnionMailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        SimpleGroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, aclResolver, groupMembershipResolver);
-
-        DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        storeMailboxManager = new InMemoryMailboxManager(
-            mapperFactory,
-            new FakeAuthenticator(),
-            FakeAuthorizator.defaultReject(),
-            new JVMMailboxPathLocker(),
-            new MessageParser(),
-            messageIdFactory,
-            mailboxEventDispatcher,
-            delegatingListener,
-            storeRightManager);
+        storeMailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver());
 
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,
             storeMailboxManager.getMapperFactory(),
-            mailboxEventDispatcher,
-            messageIdFactory,
-            new NoQuotaManager(),
-            new DefaultQuotaRootResolver(mapperFactory));
-        messageSearchIndex = new LuceneMessageSearchIndex(mapperFactory, new InMemoryId.Factory(), new RAMDirectory(), messageIdFactory);
-        storeMailboxManager.setMessageSearchIndex(messageSearchIndex);
-        storeMailboxManager.init();
+            storeMailboxManager.getEventDispatcher(),
+            storeMailboxManager.getMessageIdFactory(),
+            storeMailboxManager.getQuotaManager(),
+            storeMailboxManager.getQuotaRootResolver());
+        LuceneMessageSearchIndex luceneMessageSearchIndex = new LuceneMessageSearchIndex(
+            storeMailboxManager.getMapperFactory(), new InMemoryId.Factory(), new RAMDirectory(),
+            storeMailboxManager.getMessageIdFactory());
+        storeMailboxManager.setMessageSearchIndex(luceneMessageSearchIndex);
+        storeMailboxManager.addGlobalListener(luceneMessageSearchIndex, new MockMailboxSession("admin"));
+        this.messageSearchIndex = luceneMessageSearchIndex;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
index 88bcf7c..4d10a6f 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
@@ -52,8 +53,10 @@ public class MaildirMailboxManagerProvider {
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mf, storeRightManager);
         StoreMailboxManager manager = new StoreMailboxManager(mf, noAuthenticator, noAuthorizator, new JVMMailboxPathLocker(),
-            messageParser, new DefaultMessageId.Factory(), mailboxEventDispatcher, delegatingListener, storeRightManager);
+            messageParser, new DefaultMessageId.Factory(), annotationManager,
+            mailboxEventDispatcher, delegatingListener, storeRightManager);
         manager.init();
 
         return manager;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
index 884bc9b..f333035 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
@@ -26,12 +26,11 @@ import javax.inject.Inject;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
@@ -46,20 +45,12 @@ public class InMemoryMailboxManager extends StoreMailboxManager {
     @Inject
     public InMemoryMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, Authorizator authorizator,
                                   MailboxPathLocker locker, MessageParser messageParser, MessageId.Factory messageIdFactory, MailboxEventDispatcher dispatcher,
-                                  DelegatingMailboxListener delegatingMailboxListener, StoreRightManager storeRightManager) {
-        super(mailboxSessionMapperFactory, authenticator, authorizator, locker, messageParser, messageIdFactory,
-            MailboxConstants.DEFAULT_LIMIT_ANNOTATIONS_ON_MAILBOX, MailboxConstants.DEFAULT_LIMIT_ANNOTATION_SIZE, dispatcher,
-            delegatingMailboxListener, storeRightManager);
-    }
-
-    public InMemoryMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator,  Authorizator authorizator,
-                                  MessageParser messageParser, MessageId.Factory messageIdFactory,
-                                  int limitOfAnnotations, int limitAnnotationSize,
-                                  MailboxEventDispatcher dispatcher,
                                   DelegatingMailboxListener delegatingMailboxListener,
+                                  StoreMailboxAnnotationManager annotationManager,
                                   StoreRightManager storeRightManager) {
-        super(mailboxSessionMapperFactory, authenticator, authorizator, new JVMMailboxPathLocker(), messageParser, messageIdFactory,
-            limitOfAnnotations, limitAnnotationSize, dispatcher, delegatingMailboxListener, storeRightManager);
+        super(mailboxSessionMapperFactory, authenticator, authorizator, locker, messageParser, messageIdFactory,
+            annotationManager, dispatcher,
+            delegatingMailboxListener, storeRightManager);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
index be1c2b9..5d290f6 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
@@ -28,6 +28,9 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.FakeAuthenticator;
 import org.apache.james.mailbox.store.FakeAuthorizator;
+import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreAttachmentManager;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -49,9 +52,11 @@ public class MemoryMailboxManagerProvider {
         MessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager,
+            LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
         InMemoryMailboxManager mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, new FakeAuthenticator(), FakeAuthorizator.defaultReject(),
-            messageParser, messageIdFactory, LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE,
-            mailboxEventDispatcher, delegatingListener, storeRightManager);
+            new JVMMailboxPathLocker(), messageParser, messageIdFactory, mailboxEventDispatcher, delegatingListener,
+            annotationManager, storeRightManager);
 
         try {
             mailboxManager.init();

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
index 56ea10a..0ba5857 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
@@ -37,6 +37,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
@@ -63,14 +64,15 @@ public class InMemoryMailboxManagerAttachmentTest extends AbstractMailboxManager
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
         mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, noAuthenticator, noAuthorizator, new NoMailboxPathLocker(),
-                new MessageParser(), messageIdFactory, mailboxEventDispatcher, delegatingListener, storeRightManager);
+                new MessageParser(), messageIdFactory, mailboxEventDispatcher, delegatingListener, annotationManager, storeRightManager);
         mailboxManager.init();
         MessageParser failingMessageParser = mock(MessageParser.class);
         when(failingMessageParser.retrieveAttachments(any(InputStream.class)))
             .thenThrow(new RuntimeException("Message parser set to fail"));
         parseFailingMailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, noAuthenticator, noAuthorizator, new NoMailboxPathLocker(),
-            failingMessageParser, messageIdFactory, mailboxEventDispatcher, delegatingListener, storeRightManager);
+            failingMessageParser, messageIdFactory, mailboxEventDispatcher, delegatingListener, annotationManager, storeRightManager);
         parseFailingMailboxManager.init();
         super.setUp();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index 536751e..3e84c32 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -34,9 +34,12 @@ import org.apache.james.mailbox.manager.ManagerTestResources;
 import org.apache.james.mailbox.quota.MaxQuotaManager;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.Authenticator;
+import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.FakeAuthenticator;
 import org.apache.james.mailbox.store.FakeAuthorizator;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
@@ -60,6 +63,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
         fakeAuthenticator.addUser(ManagerTestResources.OTHER_USER, ManagerTestResources.OTHER_USER_PASS);
         InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
         StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), groupMembershipResolver);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
@@ -72,6 +76,30 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
             new InMemoryMessageId.Factory(),
             mailboxEventDispatcher,
             delegatingListener,
+            annotationManager,
+            storeRightManager);
+        manager.init();
+        return manager;
+    }
+
+    public StoreMailboxManager createMailboxManager(GroupMembershipResolver groupMembershipResolver,
+                                                    Authenticator authenticator, Authorizator authorizator) throws MailboxException {
+        InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
+        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), groupMembershipResolver);
+        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
+
+        DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
+        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
+        StoreMailboxManager manager = new InMemoryMailboxManager(
+            mailboxSessionMapperFactory,
+            authenticator,
+            authorizator,
+            new NoMailboxPathLocker(),
+            new MessageParser(),
+            new InMemoryMessageId.Factory(),
+            mailboxEventDispatcher,
+            delegatingListener,
+            annotationManager,
             storeRightManager);
         manager.init();
         return manager;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/scanning-search/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/scanning-search/pom.xml b/mailbox/scanning-search/pom.xml
index e8d3acc..e188f87 100644
--- a/mailbox/scanning-search/pom.xml
+++ b/mailbox/scanning-search/pom.xml
@@ -38,11 +38,23 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-api</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>apache-james-mailbox-memory</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-memory</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>apache-james-mailbox-store</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
index e28f558..437e292 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
@@ -19,24 +19,10 @@
 
 package org.apache.james.mailbox.store.search;
 
-
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
-import org.apache.james.mailbox.inmemory.InMemoryMessageId;
-import org.apache.james.mailbox.store.FakeAuthenticator;
-import org.apache.james.mailbox.store.FakeAuthorizator;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
-import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
-import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.junit.Ignore;
 
 public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest {
@@ -47,35 +33,23 @@ public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest
 
     @Override
     protected void initializeMailboxManager() throws Exception {
-        MailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
-        messageSearchIndex = new SimpleMessageSearchIndex(mapperFactory, mapperFactory, new PDFTextExtractor());
-        InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
-        UnionMailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        SimpleGroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, aclResolver, groupMembershipResolver);
-
-        DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        storeMailboxManager = new InMemoryMailboxManager(
-            mapperFactory,
-            new FakeAuthenticator(),
-            FakeAuthorizator.defaultReject(),
-            new JVMMailboxPathLocker(),
-            new MessageParser(),
-            messageIdFactory,
-            mailboxEventDispatcher,
-            delegatingListener,
-            storeRightManager);
+        storeMailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver());
+
+        messageSearchIndex = new SimpleMessageSearchIndex(
+            storeMailboxManager.getMapperFactory(),
+            storeMailboxManager.getMapperFactory(),
+            new PDFTextExtractor());
 
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,
             storeMailboxManager.getMapperFactory(),
-            mailboxEventDispatcher,
-            messageIdFactory,
-            new NoQuotaManager(),
-            new DefaultQuotaRootResolver(mapperFactory));
+            storeMailboxManager.getEventDispatcher(),
+            storeMailboxManager.getMessageIdFactory(),
+            storeMailboxManager.getQuotaManager(),
+            storeMailboxManager.getQuotaRootResolver());
+
         storeMailboxManager.setMessageSearchIndex(messageSearchIndex);
-        storeMailboxManager.init();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e7abcbe/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java
new file mode 100644
index 0000000..69edea3
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java
@@ -0,0 +1,146 @@
+/****************************************************************
+ * 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.store;
+
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxAnnotationManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.AnnotationException;
+import org.apache.james.mailbox.exception.InsufficientRightsException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxACL.Right;
+import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.AnnotationMapper;
+import org.apache.james.mailbox.store.mail.MailboxMapper;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.transaction.Mapper;
+
+public class StoreMailboxAnnotationManager implements MailboxAnnotationManager {
+
+    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+
+    private final StoreRightManager rightManager;
+    private final int limitOfAnnotations;
+    private final int limitAnnotationSize;
+
+    @Inject
+    public StoreMailboxAnnotationManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
+                                         StoreRightManager rightManager) {
+        this(mailboxSessionMapperFactory,
+            rightManager,
+            MailboxConstants.DEFAULT_LIMIT_ANNOTATIONS_ON_MAILBOX,
+            MailboxConstants.DEFAULT_LIMIT_ANNOTATION_SIZE);
+    }
+
+    public StoreMailboxAnnotationManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
+                                         StoreRightManager rightManager,
+                                         int limitOfAnnotations,
+                                         int limitAnnotationSize) {
+        this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+        this.rightManager = rightManager;
+        this.limitOfAnnotations = limitOfAnnotations;
+        this.limitAnnotationSize = limitAnnotationSize;
+    }
+
+    public MailboxId checkThenGetMailboxId(MailboxPath path, MailboxSession session) throws MailboxException {
+        MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
+        Mailbox mailbox = mailboxMapper.findMailboxByPath(path);
+        if (!rightManager.hasRight(mailbox, Right.Read, session)) {
+            throw new InsufficientRightsException("Not enough rights on " + path);
+        }
+        return mailbox.getMailboxId();
+    }
+
+    @Override
+    public List<MailboxAnnotation> getAllAnnotations(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+        AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(session);
+
+        MailboxId mailboxId = checkThenGetMailboxId(mailboxPath, session);
+
+        return annotationMapper.execute(
+            () -> annotationMapper.getAllAnnotations(mailboxId));
+    }
+
+    @Override
+    public List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession session, final Set<MailboxAnnotationKey> keys)
+            throws MailboxException {
+        AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(session);
+        MailboxId mailboxId = checkThenGetMailboxId(mailboxPath, session);
+
+        return annotationMapper.execute(
+            () -> annotationMapper.getAnnotationsByKeys(mailboxId, keys));
+    }
+
+    @Override
+    public void updateAnnotations(MailboxPath mailboxPath, MailboxSession session, List<MailboxAnnotation> mailboxAnnotations)
+            throws MailboxException {
+        AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(session);
+        MailboxId mailboxId = checkThenGetMailboxId(mailboxPath, session);
+
+        annotationMapper.execute(Mapper.toTransaction(() -> {
+            for (MailboxAnnotation annotation : mailboxAnnotations) {
+                if (annotation.isNil()) {
+                    annotationMapper.deleteAnnotation(mailboxId, annotation.getKey());
+                } else if (canInsertOrUpdate(mailboxId, annotation, annotationMapper)) {
+                    annotationMapper.insertAnnotation(mailboxId, annotation);
+                }
+            }
+        }));
+    }
+
+    private boolean canInsertOrUpdate(MailboxId mailboxId, MailboxAnnotation annotation, AnnotationMapper annotationMapper) throws AnnotationException {
+        if (annotation.size() > limitAnnotationSize) {
+            throw new AnnotationException("annotation too big.");
+        }
+        if (!annotationMapper.exist(mailboxId, annotation)
+            && annotationMapper.countAnnotations(mailboxId) >= limitOfAnnotations) {
+            throw new AnnotationException("too many annotations.");
+        }
+        return true;
+    }
+
+    @Override
+    public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath mailboxPath, MailboxSession session,
+            Set<MailboxAnnotationKey> keys) throws MailboxException {
+        AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(session);
+        final MailboxId mailboxId = checkThenGetMailboxId(mailboxPath, session);
+
+        return annotationMapper.execute(
+            () -> annotationMapper.getAnnotationsByKeysWithOneDepth(mailboxId, keys));
+    }
+
+    @Override
+    public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath mailboxPath, MailboxSession session,
+            Set<MailboxAnnotationKey> keys) throws MailboxException {
+        AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(session);
+        MailboxId mailboxId = checkThenGetMailboxId(mailboxPath, session);
+
+        return annotationMapper.execute(
+            () -> annotationMapper.getAnnotationsByKeysWithAllDepth(mailboxId, keys));
+    }
+}


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


Mime
View raw message