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/07 01:10:24 UTC

[01/19] james-project git commit: JAMES-2616 add default method getUser() to Event

Repository: james-project
Updated Branches:
  refs/heads/master f121dd8d4 -> 8c99d0d9e


JAMES-2616 add default method getUser() to Event


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

Branch: refs/heads/master
Commit: f23ffa3a0a0dcd1bdce3352822a0cef96fc0ad3b
Parents: f121dd8
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:36:48 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:44:57 2018 +0700

----------------------------------------------------------------------
 mailbox/api/src/main/java/org/apache/james/mailbox/Event.java | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f23ffa3a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
index a2190cf..5d72aa2 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
@@ -18,7 +18,13 @@
  ****************************************************************/
 package org.apache.james.mailbox;
 
+import org.apache.james.core.User;
+
 public interface Event {
 
     MailboxSession getSession();
+
+    default User getUser() {
+        return getSession().getUser().getCoreUser();
+    }
 }


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


[07/19] james-project git commit: JAMES-2616 Remove un needed getters in MessageSearchIndex

Posted by bt...@apache.org.
JAMES-2616 Remove un needed getters in MessageSearchIndex


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

Branch: refs/heads/master
Commit: d242d9b3886a93341bcc97b7c42cfe2f2297d932
Parents: 372930c
Author: tran tien duc <dt...@linagora.com>
Authored: Tue Dec 4 17:20:36 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../META-INF/spring/mailbox-index-lucene.xml      |  2 ++
 .../META-INF/spring/mailbox-index-lucene.xml      |  2 ++
 .../store/search/LazyMessageSearchIndex.java      |  9 ++++++---
 .../store/search/ListeningMessageSearchIndex.java | 18 ------------------
 4 files changed, 10 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d242d9b3/mailbox/lucene/src/main/resources/META-INF/spring/mailbox-index-lucene.xml
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/resources/META-INF/spring/mailbox-index-lucene.xml b/mailbox/lucene/src/main/resources/META-INF/spring/mailbox-index-lucene.xml
index 1ed21f4..e44882b 100644
--- a/mailbox/lucene/src/main/resources/META-INF/spring/mailbox-index-lucene.xml
+++ b/mailbox/lucene/src/main/resources/META-INF/spring/mailbox-index-lucene.xml
@@ -29,6 +29,8 @@
 
     <bean id="lazyIndex" class="org.apache.james.mailbox.store.search.LazyMessageSearchIndex">
         <constructor-arg index="0" ref="luceneIndex"/>
+        <constructor-arg index="1" ref="messageMapperFactory"/>
+        <constructor-arg index="2" ref="mailboxmanager"/>
     </bean>
     <bean id="luceneIndex" class="org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex">
         <constructor-arg index="0" ref="messageMapperFactory"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d242d9b3/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml b/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
index 31c5790..5cf7f8e 100644
--- a/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
+++ b/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
@@ -29,6 +29,8 @@
 
     <bean id="lazyIndex" class="org.apache.james.mailbox.store.search.LazyMessageSearchIndex">
         <constructor-arg index="0" ref="luceneIndex"/>
+        <constructor-arg index="1" ref="messageMapperFactory"/>
+        <constructor-arg index="2" ref="mailboxmanager"/>
     </bean>
     <bean id="luceneIndex" class="org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex">
         <constructor-arg index="0" ref="messageMapperFactory"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d242d9b3/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index 766ffd6..5ede660 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
+import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.slf4j.Logger;
@@ -58,11 +59,13 @@ public class LazyMessageSearchIndex extends ListeningMessageSearchIndex {
 
     private final ListeningMessageSearchIndex index;
     private final ConcurrentHashMap<MailboxId, Object> indexed = new ConcurrentHashMap<>();
+    private final MessageMapperFactory factory;
     
     
-    public LazyMessageSearchIndex(ListeningMessageSearchIndex index) {
-        super(index.getFactory(), index.getMailboxManager());
+    public LazyMessageSearchIndex(ListeningMessageSearchIndex index, MessageMapperFactory factory, MailboxManager mailboxManager) {
+        super(factory, mailboxManager);
         this.index = index;
+        this.factory = factory;
     }
 
     @Override
@@ -109,7 +112,7 @@ public class LazyMessageSearchIndex extends ListeningMessageSearchIndex {
                 done = oldDone;
             }
             synchronized (done) {
-                Iterator<MailboxMessage> messages = getFactory().getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), FetchType.Full, -1);
+                Iterator<MailboxMessage> messages = factory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), FetchType.Full, -1);
                 while (messages.hasNext()) {
                     final MailboxMessage message = messages.next();
                     try {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d242d9b3/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index ff5ac8e..aff8454 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -56,24 +56,6 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
     }
 
     /**
-     * Return the {@link MessageMapperFactory}
-     * 
-     * @return factory
-     */
-    protected MessageMapperFactory getFactory() {
-        return factory;
-    }
-
-    /**
-     * Return the {@link MailboxManager}
-     *
-     * @return mailboxManager
-     */
-    protected MailboxManager getMailboxManager() {
-        return mailboxManager;
-    }
-
-    /**
      * Process the {@link org.apache.james.mailbox.Event} and update the index if
      * something relevant is received
      */


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


[04/19] james-project git commit: JAMES-2616 replace getSession() in MailboxAnnotationListener

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in MailboxAnnotationListener


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

Branch: refs/heads/master
Commit: 2cc43bc1fbdc79f83e8e851427f26afda6eb2e2d
Parents: 9ac7d7a
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:48:55 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:50 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/StoreMailboxManager.java      |  2 +-
 .../store/event/MailboxAnnotationListener.java        | 11 ++++++++---
 .../store/event/MailboxAnnotationListenerTest.java    | 14 +++++++++-----
 3 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2cc43bc1/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 a8fda79..7f3d040 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
@@ -248,7 +248,7 @@ public class StoreMailboxManager implements MailboxManager {
             moveBatcher = new MessageBatcher(MessageBatcher.NO_BATCH_SIZE);
         }
         if (hasCapability(MailboxCapabilities.Annotation)) {
-            this.addGlobalListener(new MailboxAnnotationListener(mailboxSessionMapperFactory), session);
+            this.addGlobalListener(new MailboxAnnotationListener(mailboxSessionMapperFactory, this), session);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/2cc43bc1/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
index a1ba834..e016361 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
@@ -24,6 +24,8 @@ import javax.inject.Inject;
 
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxId;
@@ -34,11 +36,13 @@ import org.slf4j.LoggerFactory;
 
 public class MailboxAnnotationListener implements MailboxListener {
     private static final Logger logger = LoggerFactory.getLogger(MailboxAnnotationListener.class);
-    private MailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private final MailboxManager mailboxManager;
 
     @Inject
-    public MailboxAnnotationListener(MailboxSessionMapperFactory mailboxSessionMapperFactory) {
+    public MailboxAnnotationListener(MailboxSessionMapperFactory mailboxSessionMapperFactory, MailboxManager mailboxManager) {
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+        this.mailboxManager = mailboxManager;
     }
     
     @Override
@@ -50,7 +54,8 @@ public class MailboxAnnotationListener implements MailboxListener {
     public void event(Event event) {
         if (event instanceof EventFactory.MailboxDeletionImpl) {
             try {
-                AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(event.getSession());
+                MailboxSession mailboxSession = mailboxManager.createSystemSession(event.getUser().asString());
+                AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(mailboxSession);
                 MailboxId mailboxId = ((EventFactory.MailboxDeletionImpl) event).getMailbox().getMailboxId();
 
                 deleteRelatedAnnotations(mailboxId, annotationMapper);

http://git-wip-us.apache.org/repos/asf/james-project/blob/2cc43bc1/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 69a1257..2f77a8b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -31,6 +31,7 @@ import java.util.Optional;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxAnnotation;
@@ -63,6 +64,7 @@ public class MailboxAnnotationListenerTest {
     public static final int UID_VALIDITY = 145;
     public static final TestId MAILBOX_ID = TestId.of(45);
 
+    @Mock private MailboxManager mailboxManager;
     @Mock private MailboxSessionMapperFactory mailboxSessionMapperFactory;
     @Mock private AnnotationMapper annotationMapper;
     @Mock private MailboxId mailboxId;
@@ -77,7 +79,7 @@ public class MailboxAnnotationListenerTest {
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         mailboxSession = new MockMailboxSession("test");
-        listener = new MailboxAnnotationListener(mailboxSessionMapperFactory);
+        listener = new MailboxAnnotationListener(mailboxSessionMapperFactory, mailboxManager);
         eventFactory = new EventFactory();
         mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY, mailboxId);
 
@@ -86,7 +88,9 @@ public class MailboxAnnotationListenerTest {
         QuotaSize quotaSize = QuotaSize.size(456);
         deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, quotaSize);
 
-        when(mailboxSessionMapperFactory.getAnnotationMapper(eq(deleteEvent.getSession()))).thenReturn(annotationMapper);
+        when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))
+            .thenReturn(mailboxSession);
+        when(mailboxSessionMapperFactory.getAnnotationMapper(eq(mailboxSession))).thenReturn(annotationMapper);
     }
 
     @Test
@@ -104,7 +108,7 @@ public class MailboxAnnotationListenerTest {
 
         listener.event(deleteEvent);
 
-        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(deleteEvent.getSession()));
+        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
         verify(annotationMapper).getAllAnnotations(eq(mailboxId));
 
         verifyNoMoreInteractions(mailboxSessionMapperFactory);
@@ -118,7 +122,7 @@ public class MailboxAnnotationListenerTest {
 
         listener.event(deleteEvent);
 
-        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(deleteEvent.getSession()));
+        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
         verify(annotationMapper).getAllAnnotations(eq(mailboxId));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(SHARED_KEY));
@@ -135,7 +139,7 @@ public class MailboxAnnotationListenerTest {
 
         listener.event(deleteEvent);
 
-        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(deleteEvent.getSession()));
+        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
         verify(annotationMapper).getAllAnnotations(eq(mailboxId));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(SHARED_KEY));


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


[02/19] james-project git commit: JAMES-2616 replace getSession() in ElasticSearchQuotaMailboxListener

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in ElasticSearchQuotaMailboxListener


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

Branch: refs/heads/master
Commit: 543284e21ad90147e6668741a228a3388195b18a
Parents: f23ffa3
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:40:09 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:44:58 2018 +0700

----------------------------------------------------------------------
 .../events/ElasticSearchQuotaMailboxListener.java      | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/543284e2/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
index 1bdd295..f901cfd 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
@@ -22,9 +22,9 @@ import javax.inject.Inject;
 import javax.inject.Named;
 
 import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.core.User;
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
 import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
 import org.slf4j.Logger;
@@ -56,7 +56,7 @@ public class ElasticSearchQuotaMailboxListener implements MailboxListener {
     public void event(Event event) {
         try {
             if (event instanceof QuotaUsageUpdatedEvent) {
-                handleEvent(getUser(event), (QuotaUsageUpdatedEvent) event);
+                handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
             }
         } catch (Exception e) {
             LOGGER.error("Can not index quota ratio", e);
@@ -64,12 +64,7 @@ public class ElasticSearchQuotaMailboxListener implements MailboxListener {
     }
 
     private void handleEvent(User user, QuotaUsageUpdatedEvent event) throws JsonProcessingException {
-        indexer.index(user.getUserName(), 
-                quotaRatioToElasticSearchJson.convertToJson(user.getUserName(), event));
-    }
-
-    private User getUser(Event event) {
-        return event.getSession()
-                .getUser();
+        indexer.index(user.asString(),
+                quotaRatioToElasticSearchJson.convertToJson(user.asString(), event));
     }
 }


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


[17/19] james-project git commit: JAMES-2616 replace getSession() in MessageSearchIndex

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in MessageSearchIndex


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

Branch: refs/heads/master
Commit: 9ce766797307ffd2754f370b97371fca8632e388
Parents: fd2005d
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 15:37:05 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 ...lasticSearchListeningMessageSearchIndex.java |  8 +++++---
 .../ElasticSearchIntegrationTest.java           |  3 ++-
 ...icSearchListeningMessageSearchIndexTest.java |  5 ++++-
 .../lucene/search/LuceneMessageSearchIndex.java | 10 ++++++----
 .../LuceneMailboxMessageSearchIndexTest.java    |  2 +-
 .../search/LuceneMessageSearchIndexTest.java    |  3 ++-
 .../META-INF/spring/mailbox-index-lucene.xml    |  1 +
 .../store/search/LazyMessageSearchIndex.java    |  2 +-
 .../search/ListeningMessageSearchIndex.java     | 20 +++++++++++++++-----
 .../host/ElasticSearchHostSystem.java           | 11 ++++++-----
 .../host/LuceneSearchHostSystem.java            |  2 +-
 11 files changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index ed008ef..2b76986 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -32,6 +32,7 @@ import javax.inject.Named;
 
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.UpdatedRepresentation;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManager.MessageCapabilities;
 import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
 import org.apache.james.mailbox.MailboxSession;
@@ -68,9 +69,10 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
 
     @Inject
     public ElasticSearchListeningMessageSearchIndex(MessageMapperFactory factory,
-            @Named(MailboxElasticSearchConstants.InjectionNames.MAILBOX) ElasticSearchIndexer indexer,
-            ElasticSearchSearcher searcher, MessageToElasticSearchJson messageToElasticSearchJson) {
-        super(factory);
+                                                    @Named(MailboxElasticSearchConstants.InjectionNames.MAILBOX) ElasticSearchIndexer indexer,
+                                                    ElasticSearchSearcher searcher, MessageToElasticSearchJson messageToElasticSearchJson,
+                                                    MailboxManager mailboxManager) {
+        super(factory, mailboxManager);
         this.elasticSearchIndexer = indexer;
         this.messageToElasticSearchJson = messageToElasticSearchJson;
         this.searcher = searcher;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/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 4dc236e..db68d9d 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
@@ -113,7 +113,8 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new InMemoryId.Factory(), storeMailboxManager.getMessageIdFactory(),
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
                 MailboxElasticSearchConstants.MESSAGE_TYPE),
-            new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
+            new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES),
+            storeMailboxManager);
 
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index df7872c..9cba34b 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -34,6 +34,7 @@ import javax.mail.Flags;
 
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.UpdatedRepresentation;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.MessageUid;
@@ -80,10 +81,12 @@ public class ElasticSearchListeningMessageSearchIndexTest {
         MessageMapperFactory mapperFactory = mock(MessageMapperFactory.class);
         messageToElasticSearchJson = mock(MessageToElasticSearchJson.class);
         ElasticSearchSearcher elasticSearchSearcher = mock(ElasticSearchSearcher.class);
+        MailboxManager mockMailboxManager = mock(MailboxManager.class);
 
         elasticSearchIndexer = mock(ElasticSearchIndexer.class);
         
-        testee = new ElasticSearchListeningMessageSearchIndex(mapperFactory, elasticSearchIndexer, elasticSearchSearcher, messageToElasticSearchJson);
+        testee = new ElasticSearchListeningMessageSearchIndex(mapperFactory, elasticSearchIndexer, elasticSearchSearcher,
+            messageToElasticSearchJson, mockMailboxManager);
         session = new MockMailboxSession(USERNAME);
         users = ImmutableList.of(session.getUser());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 964cdc8..9d091b9 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -366,9 +366,10 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
         MessageMapperFactory factory,
         MailboxId.Factory mailboxIdFactory,
         Directory directory,
-        MessageId.Factory messageIdFactory
+        MessageId.Factory messageIdFactory,
+        MailboxManager mailboxManager
     ) throws IOException {
-        this(factory, mailboxIdFactory, directory, false, true, messageIdFactory);
+        this(factory, mailboxIdFactory, directory, false, true, messageIdFactory, mailboxManager);
     }
 
     public LuceneMessageSearchIndex(
@@ -377,9 +378,10 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
             Directory directory,
             boolean dropIndexOnStart,
             boolean lenient,
-            MessageId.Factory messageIdFactory
+            MessageId.Factory messageIdFactory,
+            MailboxManager mailboxManager
     ) throws IOException {
-        super(factory);
+        super(factory, mailboxManager);
         this.mailboxIdFactory = mailboxIdFactory;
         this.messageIdFactory = messageIdFactory;
         this.directory = directory;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
index fdcead1..5ea228c 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
@@ -102,7 +102,7 @@ public class LuceneMailboxMessageSearchIndexTest {
         id3 = factory.generate();
         id4 = factory.generate();
         id5 = factory.generate();
-        index = new LuceneMessageSearchIndex(null, new TestId.Factory(), new RAMDirectory(), true, useLenient(), factory);
+        index = new LuceneMessageSearchIndex(null, new TestId.Factory(), new RAMDirectory(), true, useLenient(), factory, null);
         index.setEnableSuffixMatch(true);
         Map<String, String> headersSubject = new HashMap<>();
         headersSubject.put("Subject", "test (fwd)");

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/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 b7ca934..b9eeaa6 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
@@ -49,7 +49,8 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
             storeMailboxManager.getQuotaRootResolver());
         LuceneMessageSearchIndex luceneMessageSearchIndex = new LuceneMessageSearchIndex(
             storeMailboxManager.getMapperFactory(), new InMemoryId.Factory(), new RAMDirectory(),
-            storeMailboxManager.getMessageIdFactory());
+            storeMailboxManager.getMessageIdFactory(),
+            storeMailboxManager);
         storeMailboxManager.setMessageSearchIndex(luceneMessageSearchIndex);
         storeMailboxManager.addGlobalListener(luceneMessageSearchIndex, new MockMailboxSession("admin"));
         this.messageSearchIndex = luceneMessageSearchIndex;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml b/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
index 1444ad6..31c5790 100644
--- a/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
+++ b/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
@@ -35,6 +35,7 @@
         <constructor-arg index="1" ref="mailboxIdFactory"/>
         <constructor-arg index="2" type="org.apache.lucene.store.Directory" ref="fsDirectory"/>
         <constructor-arg index="3" ref="messageIdFactory"/>
+        <constructor-arg index="4" ref="mailboxmanager"/>
         <property name="enableSuffixMatch" value="true"/>
     </bean>
     <bean id="fsDirectory"  class="org.apache.lucene.store.FSDirectory" factory-method="open">

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index 320c8e0..766ffd6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -61,7 +61,7 @@ public class LazyMessageSearchIndex extends ListeningMessageSearchIndex {
     
     
     public LazyMessageSearchIndex(ListeningMessageSearchIndex index) {
-        super(index.getFactory());
+        super(index.getFactory(), index.getMailboxManager());
         this.index = index;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index f194ad3..ff5ac8e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -47,9 +48,11 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
 
     public static final int UNLIMITED = -1;
     private final MessageMapperFactory factory;
+    private final MailboxManager mailboxManager;
 
-    public ListeningMessageSearchIndex(MessageMapperFactory factory) {
+    public ListeningMessageSearchIndex(MessageMapperFactory factory, MailboxManager mailboxManager) {
         this.factory = factory;
+        this.mailboxManager = mailboxManager;
     }
 
     /**
@@ -60,17 +63,24 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
     protected MessageMapperFactory getFactory() {
         return factory;
     }
-    
-    
+
+    /**
+     * Return the {@link MailboxManager}
+     *
+     * @return mailboxManager
+     */
+    protected MailboxManager getMailboxManager() {
+        return mailboxManager;
+    }
+
     /**
      * Process the {@link org.apache.james.mailbox.Event} and update the index if
      * something relevant is received
      */
     @Override
     public void event(Event event) {
-        final MailboxSession session = event.getSession();
-
         try {
+            MailboxSession session = mailboxManager.createSystemSession(event.getUser().asString());
             if (event instanceof MessageEvent) {
                 if (event instanceof EventFactory.AddedImpl) {
                     EventFactory.AddedImpl added = (EventFactory.AddedImpl) event;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 058c0c9..ac854a4 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -97,6 +97,10 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
         InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
         InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
+        this.mailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver(),
+                authenticator,
+                authorizator);
 
         ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass());
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
@@ -110,12 +114,9 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
                 ElasticSearchSearcher.DEFAULT_SEARCH_SIZE,
                 new InMemoryId.Factory(), messageIdFactory,
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticSearchConstants.MESSAGE_TYPE),
-            new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES));
+            new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES),
+            mailboxManager);
 
-        this.mailboxManager = new InMemoryIntegrationResources()
-            .createMailboxManager(new SimpleGroupMembershipResolver(),
-                authenticator,
-                authorizator);
         this.mailboxManager.setMessageSearchIndex(searchIndex);
         this.mailboxManager.addGlobalListener(searchIndex, new MockMailboxSession("admin"));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index 9161134..b33b896 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -116,7 +116,7 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
                 rightManager);
 
             FSDirectory fsDirectory = FSDirectory.open(tempFile);
-            searchIndex = new LuceneMessageSearchIndex(mapperFactory, new InMemoryId.Factory(), fsDirectory, messageIdFactory);
+            searchIndex = new LuceneMessageSearchIndex(mapperFactory, new InMemoryId.Factory(), fsDirectory, messageIdFactory, mailboxManager);
             searchIndex.setEnableSuffixMatch(true);
             mailboxManager.setMessageSearchIndex(searchIndex);
 


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


[12/19] james-project git commit: JAMES-2616 Strong Typing SessionId

Posted by bt...@apache.org.
JAMES-2616 Strong Typing SessionId


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

Branch: refs/heads/master
Commit: 713c8240f126f5299c6b58df0ced8996e5675a68
Parents: 7406e00
Author: tran tien duc <dt...@linagora.com>
Authored: Mon Dec 3 16:38:08 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/Event.java    |  6 +-
 .../apache/james/mailbox/MailboxListener.java   | 31 +++++-----
 .../apache/james/mailbox/MailboxSession.java    | 43 +++++++++++++-
 .../james/mailbox/mock/MockMailboxSession.java  |  8 +--
 .../spamassassin/SpamAssassinListenerTest.java  |  5 +-
 .../mailbox/store/SimpleMailboxSession.java     |  8 +--
 .../mailbox/store/StoreMailboxManager.java      |  6 +-
 .../james/mailbox/store/event/EventFactory.java | 61 ++++++++++++++------
 .../store/event/MailboxEventDispatcher.java     |  1 +
 .../mailbox/store/event/MessageMoveEvent.java   | 13 +++--
 .../store/MailboxEventDispatcherTest.java       |  4 +-
 .../mailbox/store/json/EventSerializerTest.java |  0
 .../processor/base/SelectedMailboxImpl.java     | 10 +++-
 .../james/imap/processor/CopyProcessorTest.java |  9 +--
 .../james/imap/processor/MoveProcessorTest.java |  9 +--
 .../processor/base/SelectedMailboxImplTest.java |  5 +-
 16 files changed, 153 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
index 7282cb9..4e80830 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.mailbox;
 
+import java.util.Optional;
+
 import org.apache.james.core.User;
 
 public interface Event {
@@ -28,7 +30,7 @@ public interface Event {
         return getSession().getUser().getCoreUser();
     }
 
-    default long getSessionId() {
-        return getSession().getSessionId();
+    default Optional<MailboxSession.SessionId> getSessionId() {
+        return Optional.ofNullable(getSession().getSessionId());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 9e9c228..eb80e4b 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -149,8 +149,8 @@ public interface MailboxListener {
             }
 
             @Override
-            public long getSessionId() {
-                return 0;
+            public SessionId getSessionId() {
+                return MailboxSession.SessionId.random();
             }
 
             @Override
@@ -198,7 +198,7 @@ public interface MailboxListener {
         private final MailboxPath path;
         private final MailboxId mailboxId;
         private final User user;
-        private final long sessionId;
+        private final Optional<MailboxSession.SessionId> sessionId;
 
         @Deprecated
         public MailboxEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
@@ -211,11 +211,10 @@ public interface MailboxListener {
                 .map(MailboxSession.User::getCoreUser)
                 .orElse(null);
             this.sessionId = Optional.ofNullable(session)
-                .map(MailboxSession::getSessionId)
-                .orElse(0L);
+                .map(MailboxSession::getSessionId);
         }
 
-        public MailboxEvent(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             this.user = user;
             this.path = path;
             this.mailboxId = mailboxId;
@@ -253,7 +252,7 @@ public interface MailboxListener {
          * @return sessionId
          */
         @Override
-        public long getSessionId() {
+        public Optional<MailboxSession.SessionId> getSessionId() {
             return sessionId;
         }
 
@@ -299,7 +298,7 @@ public interface MailboxListener {
             this.totalDeletedSize = totalDeletedSize;
         }
 
-        public MailboxDeletion(long sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
+        public MailboxDeletion(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
                                MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
             this.quotaRoot = quotaRoot;
@@ -334,7 +333,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MailboxAdded(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxAdded(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
     }
@@ -353,7 +352,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MailboxRenamed(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxRenamed(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -379,7 +378,7 @@ public interface MailboxListener {
             this.aclDiff = aclDiff;
         }
 
-        public MailboxACLUpdated(long sessionId, User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
+        public MailboxACLUpdated(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
             this.aclDiff = aclDiff;
         }
@@ -405,7 +404,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MessageEvent(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MessageEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -424,7 +423,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MetaDataHoldingEvent(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MetaDataHoldingEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -449,7 +448,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public Expunged(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public Expunged(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -477,7 +476,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public FlagsUpdated(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public FlagsUpdated(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -499,7 +498,7 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public Added(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public Added(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java
index 50136b9..e2c00f9 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxSession.java
@@ -23,12 +23,53 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
 
 /**
  * Mailbox session.
  */
 public interface MailboxSession {
 
+    class SessionId {
+
+        public static SessionId of(long sessionId) {
+            return new SessionId(sessionId);
+        }
+
+        private final long sessionId;
+
+        private SessionId(long sessionId) {
+            this.sessionId = sessionId;
+        }
+
+        public long getValue() {
+            return sessionId;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof SessionId) {
+                SessionId that = (SessionId) o;
+
+                return Objects.equals(this.sessionId, that.sessionId);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(sessionId);
+        }
+
+        @Override
+        public String toString() {
+            return MoreObjects.toStringHelper(this)
+                .add("sessionId", sessionId)
+                .toString();
+        }
+    }
 
     /**
      * Id which will be used for a System session
@@ -59,7 +100,7 @@ public interface MailboxSession {
      * 
      * @return session id
      */
-    long getSessionId();
+    SessionId getSessionId();
 
     /**
      * Is this session open?

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java b/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
index 71d32a3..608f0a3 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
@@ -32,15 +32,15 @@ public class MockMailboxSession implements MailboxSession {
     private final User user;
     private final Map<Object, Object> attrs = new HashMap<>();
     private static final Random RANDOM = new Random();
-    private final long sessionId;
+    private final SessionId sessionId;
     private final SessionType type;
     private boolean open;
     
     public MockMailboxSession(String username) {
-        this(username, RANDOM.nextLong());
+        this(username, SessionId.of(RANDOM.nextLong()));
     }
 
-    public MockMailboxSession(String username, long sessionId) {
+    public MockMailboxSession(String username, SessionId sessionId) {
         this.user = new User() {
 
             @Override
@@ -92,7 +92,7 @@ public class MockMailboxSession implements MailboxSession {
     }
 
     @Override
-    public long getSessionId() {
+    public SessionId getSessionId() {
         return sessionId;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index 19e7755..9f4c7ae 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Date;
+import java.util.Optional;
 
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
@@ -251,7 +252,7 @@ public class SpamAssassinListenerTest {
         SimpleMailboxMessage message = createMessage(inboxId);
         EventFactory eventFactory = new EventFactory();
         AddedImpl addedEvent = eventFactory.new AddedImpl(
-                MAILBOX_SESSION.getSessionId(),
+                Optional.of(MAILBOX_SESSION.getSessionId()),
                 MAILBOX_SESSION.getUser().getCoreUser(),
                 inbox,
                 ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)),
@@ -267,7 +268,7 @@ public class SpamAssassinListenerTest {
         SimpleMailboxMessage message = createMessage(mailboxId1);
         EventFactory eventFactory = new EventFactory();
         AddedImpl addedEvent = eventFactory.new AddedImpl(
-                MAILBOX_SESSION.getSessionId(),
+                Optional.of(MAILBOX_SESSION.getSessionId()),
                 MAILBOX_SESSION.getUser().getCoreUser(),
                 mailbox1,
                 ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)),

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java
index e24f6ac..3d2101c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxSession.java
@@ -40,7 +40,7 @@ public class SimpleMailboxSession implements MailboxSession, MailboxSession.User
 
     private final String personalSpace;
     
-    private final long sessionId;
+    private final SessionId sessionId;
 
     private final String userName;
     
@@ -57,12 +57,12 @@ public class SimpleMailboxSession implements MailboxSession, MailboxSession.User
     private final SessionType type;
 
     
-    public SimpleMailboxSession(long sessionId, String userName, String password,
+    public SimpleMailboxSession(SessionId sessionId, String userName, String password,
                                 List<Locale> localePreferences, char pathSeparator, SessionType type) {
         this(sessionId, userName, password, localePreferences, new ArrayList<>(), null, pathSeparator, type);
     }
 
-    public SimpleMailboxSession(long sessionId, String userName, String password,
+    public SimpleMailboxSession(SessionId sessionId, String userName, String password,
                                 List<Locale> localePreferences, List<String> sharedSpaces, String otherUsersSpace, char pathSeparator, SessionType type) {
         this.sessionId = sessionId;
         this.userName = userName;
@@ -88,7 +88,7 @@ public class SimpleMailboxSession implements MailboxSession, MailboxSession.User
     }
 
     @Override
-    public long getSessionId() {
+    public SessionId getSessionId() {
         return sessionId;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/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 7f3d040..b978ed8 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
@@ -357,7 +357,11 @@ public class StoreMailboxManager implements MailboxManager {
      */
 
     protected MailboxSession createSession(String userName, String password, SessionType type) {
-        return new SimpleMailboxSession(randomId(), userName, password, new ArrayList<>(), getDelimiter(), type);
+        return new SimpleMailboxSession(newSessionId(), userName, password, new ArrayList<>(), getDelimiter(), type);
+    }
+
+    private MailboxSession.SessionId newSessionId() {
+        return MailboxSession.SessionId.of(randomId());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 483101c..2b8632e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -21,12 +21,14 @@ package org.apache.james.mailbox.store.event;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.SortedMap;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxId;
@@ -53,7 +55,7 @@ public class EventFactory {
         private final Map<MessageUid, MailboxMessage> availableMessages;
         private final Mailbox mailbox;
 
-        public AddedImpl(long sessionId, User user, Mailbox mailbox, SortedMap<MessageUid, MessageMetaData> uids, Map<MessageUid, MailboxMessage> availableMessages) {
+        public AddedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, SortedMap<MessageUid, MessageMetaData> uids, Map<MessageUid, MailboxMessage> availableMessages) {
             super(sessionId, user, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.added = ImmutableMap.copyOf(uids);
             this.mailbox = mailbox;
@@ -84,7 +86,7 @@ public class EventFactory {
         private final Map<MessageUid, MessageMetaData> uids;
         private final Mailbox mailbox;
 
-        public ExpungedImpl(long sessionId, User user, Mailbox mailbox,  Map<MessageUid, MessageMetaData> uids) {
+        public ExpungedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox,  Map<MessageUid, MessageMetaData> uids) {
             super(sessionId, user,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.uids = ImmutableMap.copyOf(uids);
             this.mailbox = mailbox;
@@ -113,7 +115,7 @@ public class EventFactory {
 
         private final List<UpdatedFlags> uFlags;
 
-        public FlagsUpdatedImpl(long sessionId, User user, Mailbox mailbox, List<MessageUid> uids, List<UpdatedFlags> uFlags) {
+        public FlagsUpdatedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, List<MessageUid> uids, List<UpdatedFlags> uFlags) {
             super(sessionId, user, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.uids = ImmutableList.copyOf(uids);
             this.uFlags = ImmutableList.copyOf(uFlags);
@@ -140,7 +142,7 @@ public class EventFactory {
     public final class MailboxDeletionImpl extends MailboxListener.MailboxDeletion implements MailboxAware {
         private final Mailbox mailbox;
 
-        public MailboxDeletionImpl(long sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
+        public MailboxDeletionImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
             super(sessionId, user, new StoreMailboxPath(mailbox), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
             this.mailbox = mailbox;
         }
@@ -157,7 +159,7 @@ public class EventFactory {
 
         private final Mailbox mailbox;
 
-        public MailboxAddedImpl(long sessionId, User user, Mailbox mailbox) {
+        public MailboxAddedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox) {
             super(sessionId, user,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.mailbox = mailbox;
         }
@@ -175,7 +177,7 @@ public class EventFactory {
         private final MailboxPath newPath;
         private final Mailbox newMailbox;
 
-        public MailboxRenamedEventImpl(long sessionId, User user, MailboxPath oldPath, Mailbox newMailbox) {
+        public MailboxRenamedEventImpl(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath oldPath, Mailbox newMailbox) {
             super(sessionId, user, oldPath, newMailbox.getMailboxId());
             this.newPath = new StoreMailboxPath(newMailbox);
             this.newMailbox = newMailbox;
@@ -192,38 +194,63 @@ public class EventFactory {
         }
     }
 
-    public MailboxListener.Added added(long sessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
-        return new AddedImpl(sessionId, user, mailbox, uids, cachedMessages);
+    public MailboxListener.Added added(Optional<MailboxSession.SessionId> maybeSessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
+        return new AddedImpl(maybeSessionId, user, mailbox, uids, cachedMessages);
     }
 
-    public MailboxListener.Expunged expunged(long sessionId, User user,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
+    public MailboxListener.Added added(MailboxSession.SessionId sessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
+        return added(Optional.ofNullable(sessionId), user, uids, mailbox, cachedMessages);
+    }
+
+    public MailboxListener.Expunged expunged(Optional<MailboxSession.SessionId> sessionId, User user, Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         return new ExpungedImpl(sessionId, user, mailbox, uids);
     }
 
-    public MailboxListener.FlagsUpdated flagsUpdated(long sessionId, User user, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
+    public MailboxListener.Expunged expunged(MailboxSession.SessionId sessionId, User user,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
+        return expunged(Optional.ofNullable(sessionId), user, uids, mailbox);
+    }
+
+    public MailboxListener.FlagsUpdated flagsUpdated(Optional<MailboxSession.SessionId> sessionId, User user, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
         return new FlagsUpdatedImpl(sessionId, user, mailbox, uids, uflags);
     }
 
-    public MailboxListener.MailboxRenamed mailboxRenamed(long sessionId, User user, MailboxPath from, Mailbox to) {
+    public MailboxListener.FlagsUpdated flagsUpdated(MailboxSession.SessionId sessionId, User user, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
+        return flagsUpdated(Optional.ofNullable(sessionId), user, uids, mailbox, uflags);
+    }
+
+    public MailboxListener.MailboxRenamed mailboxRenamed(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath from, Mailbox to) {
         return new MailboxRenamedEventImpl(sessionId, user, from, to);
     }
 
-    public MailboxListener.MailboxDeletion mailboxDeleted(long sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
+    public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession.SessionId sessionId, User user, MailboxPath from, Mailbox to) {
+        return mailboxRenamed(Optional.ofNullable(sessionId), user, from, to);
+    }
+
+    public MailboxListener.MailboxDeletion mailboxDeleted(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
                                                           QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
         return new MailboxDeletionImpl(sessionId, user, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
     }
 
-    public MailboxListener.MailboxAdded mailboxAdded(long sessionId, User user, Mailbox mailbox) {
+    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
+                                                          QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
+        return new MailboxDeletionImpl(Optional.ofNullable(sessionId), user, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
+    }
+
+    public MailboxListener.MailboxAdded mailboxAdded(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox) {
         return new MailboxAddedImpl(sessionId, user, mailbox);
     }
 
-    public MailboxListener.MailboxACLUpdated aclUpdated(long sessionId, User user, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        return new MailboxListener.MailboxACLUpdated(sessionId, user, mailboxPath, aclDiff, mailboxId);
+    public MailboxListener.MailboxAdded mailboxAdded(MailboxSession.SessionId sessionId, User user, Mailbox mailbox) {
+        return new MailboxAddedImpl(Optional.ofNullable(sessionId), user, mailbox);
+    }
+
+    public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession.SessionId sessionId, User user, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
+        return new MailboxListener.MailboxACLUpdated(Optional.ofNullable(sessionId), user, mailboxPath, aclDiff, mailboxId);
     }
 
-    public MessageMoveEvent moved(long sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
+    public MessageMoveEvent moved(MailboxSession.SessionId sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
         return MessageMoveEvent.builder()
-                .sessionId(sessionId)
+                .sessionId(Optional.ofNullable(sessionId))
                 .user(user)
                 .messageMoves(messageMoves)
                 .messages(messages)

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index c7df6a5..1ae5ca0 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store.event;
 import java.time.Instant;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.SortedMap;
 
 import javax.inject.Inject;

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
index 3526af2..5ba1ddf 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox.store.event;
 
 import java.util.Map;
+import java.util.Optional;
 
 import org.apache.james.core.User;
 import org.apache.james.mailbox.Event;
@@ -40,7 +41,7 @@ public class MessageMoveEvent implements Event {
 
     public static class Builder {
 
-        private long sessionId;
+        private Optional<MailboxSession.SessionId> sessionId;
         private User user;
         private MessageMoves messageMoves;
         private ImmutableMap.Builder<MessageUid, MailboxMessage> messagesBuilder;
@@ -50,12 +51,12 @@ public class MessageMoveEvent implements Event {
         }
 
         public Builder session(MailboxSession session) {
-            this.sessionId = session.getSessionId();
+            this.sessionId = Optional.ofNullable(session.getSessionId());
             this.user = session.getUser().getCoreUser();
             return this;
         }
 
-        public Builder sessionId(long sessionId) {
+        public Builder sessionId(Optional<MailboxSession.SessionId> sessionId) {
             this.sessionId = sessionId;
             return this;
         }
@@ -86,13 +87,13 @@ public class MessageMoveEvent implements Event {
         }
     }
 
-    private final long sessionId;
+    private final Optional<MailboxSession.SessionId> sessionId;
     private final User user;
     private final MessageMoves messageMoves;
     private final Map<MessageUid, MailboxMessage> messages;
 
     @VisibleForTesting
-    MessageMoveEvent(long sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
+    MessageMoveEvent(Optional<MailboxSession.SessionId> sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
         this.sessionId = sessionId;
         this.user = user;
         this.messageMoves = messageMoves;
@@ -114,7 +115,7 @@ public class MessageMoveEvent implements Event {
     }
 
     @Override
-    public long getSessionId() {
+    public Optional<MailboxSession.SessionId> getSessionId() {
         return sessionId;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
index d67b242..691ec79 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
@@ -48,7 +48,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
 public class MailboxEventDispatcherTest {
-    private static final int sessionId = 10;
+    private static final MailboxSession.SessionId SESSION_ID = MailboxSession.SessionId.of(10);
     private static final int MOD_SEQ = -1;
     public static final Condition<Event> INSTANCE_OF_EVENT_FLAGS_UPDATED = new Condition<Event>() {
         @Override
@@ -64,7 +64,7 @@ public class MailboxEventDispatcherTest {
     private MessageResult result;
     private Mailbox mailbox;
 
-    private MailboxSession session = new MockMailboxSession("test", sessionId);
+    private MailboxSession session = new MockMailboxSession("test", SESSION_ID);
 
     @Before
     public void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/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 31a43d4..0ebaac5 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
@@ -66,7 +66,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
 
     private final ImapSession session;
 
-    private final long sessionId;
+    private final MailboxSession.SessionId sessionId;
     private final Set<MessageUid> flagUpdateUids = new TreeSet<>();
     private final Flags.Flag uninterestingFlag = Flags.Flag.RECENT;
     private final Set<MessageUid> expungedUids = new TreeSet<>();
@@ -329,7 +329,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
     private void mailboxEvent(MailboxEvent mailboxEvent) {
         // Check if the event was for the mailbox we are observing
         if (mailboxEvent.getMailboxId().equals(getMailboxId())) {
-            final long eventSessionId = mailboxEvent.getSessionId();
+            MailboxSession.SessionId eventSessionId = extractSessionId(mailboxEvent);
             if (mailboxEvent instanceof MessageEvent) {
                 final MessageEvent messageEvent = (MessageEvent) mailboxEvent;
                 if (messageEvent instanceof Added) {
@@ -407,6 +407,12 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
         }
     }
 
+    private MailboxSession.SessionId extractSessionId(MailboxEvent mailboxEvent) {
+        return mailboxEvent.getSessionId()
+            .orElseThrow(() -> new RuntimeException(String.format("Event of of mailbox %s does not carry sessionId",
+                mailboxEvent.getMailboxId().serialize())));
+    }
+
     @Override
     public synchronized int msn(MessageUid uid) {
         return uidMsnConverter.getMsn(uid).orElse(NO_SUCH_MESSAGE);

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
index db5e8c4..245f90f 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
@@ -57,6 +57,7 @@ import com.google.common.collect.Lists;
 public class CopyProcessorTest {
 
     public static final String TAG = "TAG";
+    private static final MailboxSession.SessionId SESSION_ID_42 = MailboxSession.SessionId.of(42L);
 
     private CopyProcessor testee;
     private ImapProcessor mockNextProcessor;
@@ -85,7 +86,7 @@ public class CopyProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
@@ -123,7 +124,7 @@ public class CopyProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
@@ -160,7 +161,7 @@ public class CopyProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
@@ -191,7 +192,7 @@ public class CopyProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
index fd9785b..38fb706 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -60,6 +60,7 @@ import com.google.common.collect.Lists;
 public class MoveProcessorTest {
 
     public static final String TAG = "TAG";
+    private static final MailboxSession.SessionId SESSION_ID_42 = MailboxSession.SessionId.of(42L);
 
     private MoveProcessor testee;
     private ImapProcessor mockNextProcessor;
@@ -102,7 +103,7 @@ public class MoveProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
@@ -142,7 +143,7 @@ public class MoveProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
@@ -180,7 +181,7 @@ public class MoveProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
@@ -211,7 +212,7 @@ public class MoveProcessorTest {
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
         when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(42L);
+        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
         when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
         MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/713c8240/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 d05ccf3..dfb1797 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
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.security.SecureRandom;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.TreeMap;
@@ -166,8 +167,10 @@ public class SelectedMailboxImplTest {
     }
 
     private void emitEvent(MailboxListener mailboxListener) {
+        SecureRandom random = new SecureRandom();
         TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>();
         result.put(EMITTED_EVENT_UID, new SimpleMessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()));
-        mailboxListener.event(new EventFactory().added(0L, mock(User.class), result, mailbox, ImmutableMap.of()));
+        mailboxListener.event(new EventFactory().added(MailboxSession.SessionId.of(random.nextLong()),
+            mock(User.class), result, mailbox, ImmutableMap.of()));
     }
 }


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


[03/19] james-project git commit: JAMES-2616 replace getSession() in PropagateLookupRightListener

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in PropagateLookupRightListener


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

Branch: refs/heads/master
Commit: 4602954081b787e908336575642c4bb99e73d39f
Parents: 2cc43bc
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:56:12 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:50 2018 +0700

----------------------------------------------------------------------
 .../james/jmap/event/PropagateLookupRightListener.java  | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/46029540/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
index 88b4b48..cdf1701 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
@@ -44,7 +44,7 @@ public class PropagateLookupRightListener implements MailboxListener {
     private final MailboxManager mailboxManager;
 
     @Inject
-    PropagateLookupRightListener(RightManager rightManager, MailboxManager mailboxManager) {
+    public PropagateLookupRightListener(RightManager rightManager, MailboxManager mailboxManager) {
         this.rightManager = rightManager;
         this.mailboxManager = mailboxManager;
     }
@@ -57,7 +57,7 @@ public class PropagateLookupRightListener implements MailboxListener {
     @Override
     public void event(Event event) {
         try {
-            MailboxSession mailboxSession = event.getSession();
+            MailboxSession mailboxSession = createMailboxSession(event);
 
             if (event instanceof MailboxACLUpdated) {
                 MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event;
@@ -73,6 +73,14 @@ public class PropagateLookupRightListener implements MailboxListener {
         }
     }
 
+    private MailboxSession createMailboxSession(Event event) {
+        try {
+            return mailboxManager.createSystemSession(event.getUser().asString());
+        } catch (MailboxException e) {
+            throw new RuntimeException("unable to create system session of user:" + event.getUser().toString(), e);
+        }
+    }
+
     private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) throws MailboxException {
         MailboxACL acl = rightManager.listRights(path, session);
         listAncestors(session, path)


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


[09/19] james-project git commit: JAMES-2616 Deprecated constructors which will be removed

Posted by bt...@apache.org.
JAMES-2616 Deprecated constructors which will be removed


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

Branch: refs/heads/master
Commit: 7406e0056e2546815ba31d4c6f3ea15ae740e568
Parents: c81c2ae
Author: tran tien duc <dt...@linagora.com>
Authored: Mon Dec 3 17:54:44 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/MailboxListener.java    | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7406e005/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index c44597f..9e9c228 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -200,6 +200,7 @@ public interface MailboxListener {
         private final User user;
         private final long sessionId;
 
+        @Deprecated
         public MailboxEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             this.session = session;
             this.path = path;
@@ -289,6 +290,7 @@ public interface MailboxListener {
         private final QuotaCount deletedMessageCOunt;
         private final QuotaSize totalDeletedSize;
 
+        @Deprecated
         public MailboxDeletion(MailboxSession session, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
                                MailboxId mailboxId) {
             super(session, path, mailboxId);
@@ -327,6 +329,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public MailboxAdded(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
@@ -345,6 +348,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public MailboxRenamed(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
@@ -369,6 +373,7 @@ public interface MailboxListener {
         private final ACLDiff aclDiff;
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public MailboxACLUpdated(MailboxSession session, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
             super(session, path, mailboxId);
             this.aclDiff = aclDiff;
@@ -395,6 +400,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public MessageEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
@@ -413,6 +419,7 @@ public interface MailboxListener {
 
     abstract class MetaDataHoldingEvent extends MessageEvent {
 
+        @Deprecated
         public MetaDataHoldingEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
@@ -437,6 +444,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public Expunged(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
@@ -464,6 +472,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public FlagsUpdated(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
@@ -485,6 +494,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
+        @Deprecated
         public Added(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }


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


[08/19] james-project git commit: JAMES-2616 replace getSession() in QuotaThresholdCrossingListener

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in QuotaThresholdCrossingListener


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

Branch: refs/heads/master
Commit: 7a7996993f3142efc663fb03f61bfc767a26a515
Parents: 4602954
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:57:00 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../QuotaThresholdCrossingListener.java         | 10 +---
 .../QuotaThresholdConfigurationChangesTest.java | 50 ++++++++---------
 .../QuotaThresholdMailingIntegrationTest.java   | 56 ++++++++++----------
 .../quota/model/QuotaThresholdFixture.java      |  4 +-
 .../ElasticSearchQuotaMailboxListenerTest.java  |  4 +-
 .../json/QuotaRatioToElasticSearchJsonTest.java |  6 +--
 .../james/quota/search/QuotaSearchFixture.java  |  4 +-
 7 files changed, 63 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
index d669cba..3f421c3 100644
--- a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
+++ b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
@@ -70,7 +70,7 @@ public class QuotaThresholdCrossingListener implements MailboxListener {
     public void event(Event event) {
         try {
             if (event instanceof QuotaUsageUpdatedEvent) {
-                handleEvent(getUser(event), (QuotaUsageUpdatedEvent) event);
+                handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
             }
         } catch (Exception e) {
             LOGGER.error("Can not re-emmit quota threshold events", e);
@@ -81,12 +81,4 @@ public class QuotaThresholdCrossingListener implements MailboxListener {
         eventSourcingSystem.dispatch(
             new DetectThresholdCrossing(user, event.getCountQuota(), event.getSizeQuota(), event.getInstant()));
     }
-
-    private User getUser(Event event) {
-        return User.fromUsername(
-            event.getSession()
-                .getUser()
-                .getUserName());
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
index 4876b3a..87d720d 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
@@ -19,7 +19,7 @@
 
 package org.apache.james.mailbox.quota.mailing.listeners;
 
-import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.BOB_SESSION;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.BOB_USER;
 import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.GRACE_PERIOD;
 import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.NOW;
 import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.QUOTAROOT;
@@ -57,12 +57,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -72,12 +72,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -87,12 +87,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -102,12 +102,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -117,12 +117,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -132,12 +132,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -147,13 +147,13 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -163,13 +163,13 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -179,13 +179,13 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -196,12 +196,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -212,12 +212,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -228,12 +228,12 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
index 0409a45..f1a8343 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
@@ -19,7 +19,7 @@
 
 package org.apache.james.mailbox.quota.mailing.listeners;
 
-import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.BOB_SESSION;
+import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.BOB_USER;
 import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.DEFAULT_CONFIGURATION;
 import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.GRACE_PERIOD;
 import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.TestConstants.NOW;
@@ -53,7 +53,7 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -62,10 +62,10 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenNoThresholdUpdate(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -74,11 +74,11 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenThresholdOverPassedRecently(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, TWELVE_HOURS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_HOURS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, TWELVE_HOURS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_HOURS_AGO));
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -88,7 +88,7 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -97,9 +97,9 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendDuplicates(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -108,9 +108,9 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotifySeparatelyCountAndSize(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._60_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(2);
     }
@@ -120,7 +120,7 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -129,11 +129,11 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldSendMailWhenThresholdOverPassedOverGracePeriod(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, TWELVE_DAYS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_DAYS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, TWELVE_DAYS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_DAYS_AGO));
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -142,10 +142,10 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenNoThresholdUpdateForCount(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._32_PERCENT, Sizes._55_PERCENT, TWO_DAYS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._32_PERCENT, Sizes._55_PERCENT, TWO_DAYS_AGO));
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, TWO_DAYS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, TWO_DAYS_AGO));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -154,11 +154,11 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenThresholdOverPassedRecentlyForCount(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_HOURS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_HOURS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_HOURS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_HOURS_AGO));
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -168,7 +168,7 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_HOURS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_HOURS_AGO));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -177,11 +177,11 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldSendMailWhenThresholdOverPassedOverGracePeriodForCount(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_DAYS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_DAYS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_DAYS_AGO));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_DAYS_AGO));
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -195,8 +195,8 @@ public interface QuotaThresholdMailingIntegrationTest {
                 .gracePeriod(GRACE_PERIOD)
                 .build());
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._85_PERCENT, Sizes._42_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._85_PERCENT, Sizes._42_PERCENT, NOW));
 
         assertThat(mailetContext.getSentMails())
             .hasSize(2);
@@ -212,7 +212,7 @@ public interface QuotaThresholdMailingIntegrationTest {
                 .build());
 
         ConcurrentTestRunner.builder()
-            .operation((threadNb, step) -> testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW)))
+            .operation((threadNb, step) -> testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW)))
             .threadCount(10)
             .runSuccessfullyWithin(Duration.ofMinutes(1));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
index d5ed137..01f1e0a 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
@@ -23,7 +23,7 @@ import java.time.Duration;
 import java.time.Instant;
 import java.util.Optional;
 
-import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.core.User;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
 import org.apache.mailet.base.MailAddressFixture;
@@ -45,7 +45,7 @@ public interface QuotaThresholdFixture {
             .gracePeriod(GRACE_PERIOD)
             .build();
         String BOB = "bob@domain";
-        MockMailboxSession BOB_SESSION = new MockMailboxSession(BOB);
+        User BOB_USER = User.fromUsername(BOB);
         Instant NOW = Instant.now();
         QuotaRoot QUOTAROOT = QuotaRoot.quotaRoot("any", Optional.empty());
         Instant ONE_HOUR_AGO = NOW.minus(Duration.ofHours(1));

http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
index dabec13..d515147 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
@@ -19,7 +19,7 @@
 
 package org.apache.james.quota.search.elasticsearch.events;
 
-import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.BOB_SESSION;
+import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.BOB_USER;
 import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.NOW;
 import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.QUOTAROOT;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -94,7 +94,7 @@ public class ElasticSearchQuotaMailboxListenerTest {
 
     @Test
     public void eventShouldIndexEventWhenQuotaEvent() throws Exception {
-        quotaMailboxListener.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
+        quotaMailboxListener.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
 
         embeddedElasticSearch.awaitForElasticSearch();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
index 6684a16..4564be1 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
@@ -26,8 +26,8 @@ import java.time.Instant;
 import java.util.Optional;
 
 import org.apache.james.core.Domain;
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
-import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.QuotaFixture;
 import org.apache.james.util.ClassLoaderUtils;
@@ -39,7 +39,7 @@ public class QuotaRatioToElasticSearchJsonTest {
     public void quotaRatioShouldBeWellConvertedToJson() throws IOException {
         String user = "user@domain.org";
         QuotaUsageUpdatedEvent event = new QuotaUsageUpdatedEvent(
-                new MockMailboxSession(user), 
+                User.fromUsername(user),
                 QuotaRoot.quotaRoot("any", Optional.of(Domain.of("domain.org"))),
                 QuotaFixture.Counts._52_PERCENT,
                 QuotaFixture.Sizes._55_PERCENT,
@@ -58,7 +58,7 @@ public class QuotaRatioToElasticSearchJsonTest {
     public void quotaRatioShouldBeWellConvertedToJsonWhenNoDomain() throws IOException {
         String user = "user";
         QuotaUsageUpdatedEvent event = new QuotaUsageUpdatedEvent(
-                new MockMailboxSession(user),
+                User.fromUsername(user),
                 QuotaRoot.quotaRoot("any", Optional.empty()),
                 QuotaFixture.Counts._52_PERCENT,
                 QuotaFixture.Sizes._55_PERCENT,

http://git-wip-us.apache.org/repos/asf/james-project/blob/7a799699/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
index 515a004..c291bfa 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
@@ -22,14 +22,14 @@ package org.apache.james.quota.search;
 import java.time.Instant;
 import java.util.Optional;
 
-import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.core.User;
 import org.apache.james.mailbox.model.QuotaRoot;
 
 public interface QuotaSearchFixture {
 
     interface TestConstants {
         String BOB = "bob@domain";
-        MockMailboxSession BOB_SESSION = new MockMailboxSession(BOB);
+        User BOB_USER = User.fromUsername(BOB);
         Instant NOW = Instant.now();
         QuotaRoot QUOTAROOT = QuotaRoot.quotaRoot("any", Optional.empty());
     }


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


[10/19] james-project git commit: JAMES-2616 replace getSession() in SpamAssassinListener

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in SpamAssassinListener


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

Branch: refs/heads/master
Commit: 508d544ffb06f06157afb6b6edef76785e91554e
Parents: 7a79969
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:58:12 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/SystemMailboxesProvider.java       |  7 ++++---
 .../mailbox/spamassassin/SpamAssassinListener.java   | 15 ++++++++-------
 .../spamassassin/SpamAssassinListenerTest.java       |  7 ++++++-
 .../mailbox/store/SystemMailboxesProviderImpl.java   | 11 +++++++----
 .../store/SystemMailboxesProviderImplTest.java       |  6 ++++--
 .../apache/james/jmap/methods/SendMDNProcessor.java  |  2 +-
 .../jmap/methods/SetMessagesCreationProcessor.java   |  2 +-
 .../jmap/methods/SetMessagesUpdateProcessor.java     |  4 ++--
 .../apache/james/jmap/send/PostDequeueDecorator.java |  4 ++--
 .../methods/SetMessagesCreationProcessorTest.java    |  3 ++-
 10 files changed, 37 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java b/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
index 2b2dd9f..f593aad 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
@@ -21,14 +21,15 @@ package org.apache.james.mailbox;
 
 import java.util.stream.Stream;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxRoleNotFoundException;
 
 public interface SystemMailboxesProvider {
-    Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException;
+    Stream<MessageManager> getMailboxByRole(Role aRole, User user) throws MailboxException;
 
-    default MessageManager findMailbox(Role role, MailboxSession session) throws MailboxException {
-        return getMailboxByRole(role, session).findAny()
+    default MessageManager findMailbox(Role role, User user) throws MailboxException {
+        return getMailboxByRole(role, user).findAny()
             .orElseThrow(() -> new MailboxRoleNotFoundException(role));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
index 04fd6c8..9bf3657 100644
--- a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
+++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
@@ -68,16 +68,17 @@ public class SpamAssassinListener implements SpamEventListener {
 
     @Override
     public void event(Event event) {
+        String username = event.getUser().asString();
         if (event instanceof MessageMoveEvent) {
             MessageMoveEvent messageMoveEvent = (MessageMoveEvent) event;
             if (isMessageMovedToSpamMailbox(messageMoveEvent)) {
                 LOGGER.debug("Spam event detected");
                 ImmutableList<InputStream> messages = retrieveMessages(messageMoveEvent);
-                spamAssassin.learnSpam(messages, messageMoveEvent.getSession().getUser().getUserName());
+                spamAssassin.learnSpam(messages, username);
             }
             if (isMessageMovedOutOfSpamMailbox(messageMoveEvent)) {
                 ImmutableList<InputStream> messages = retrieveMessages(messageMoveEvent);
-                spamAssassin.learnHam(messages, messageMoveEvent.getSession().getUser().getUserName());
+                spamAssassin.learnHam(messages, username);
             }
         }
         if (event instanceof EventFactory.AddedImpl) {
@@ -88,14 +89,14 @@ public class SpamAssassinListener implements SpamEventListener {
                     .stream()
                     .map(Throwing.function(MailboxMessage::getFullContent))
                     .collect(Guavate.toImmutableList());
-                spamAssassin.learnHam(contents, addedEvent.getSession().getUser().getUserName());
+                spamAssassin.learnHam(contents, username);
             }
         }
     }
 
     private boolean isAppendedToInbox(EventFactory.AddedImpl addedEvent) {
         try {
-            return systemMailboxesProvider.findMailbox(Role.INBOX, addedEvent.getSession())
+            return systemMailboxesProvider.findMailbox(Role.INBOX, addedEvent.getUser())
                 .getId().equals(addedEvent.getMailboxId());
         } catch (MailboxException e) {
             LOGGER.warn("Could not resolve Inbox mailbox", e);
@@ -114,7 +115,7 @@ public class SpamAssassinListener implements SpamEventListener {
     @VisibleForTesting
     boolean isMessageMovedToSpamMailbox(MessageMoveEvent event) {
         try {
-            MailboxId spamMailboxId = systemMailboxesProvider.findMailbox(Role.SPAM, event.getSession()).getId();
+            MailboxId spamMailboxId = systemMailboxesProvider.findMailbox(Role.SPAM, event.getUser()).getId();
 
             return event.getMessageMoves().addedMailboxIds().contains(spamMailboxId);
         } catch (MailboxException e) {
@@ -126,8 +127,8 @@ public class SpamAssassinListener implements SpamEventListener {
     @VisibleForTesting
     boolean isMessageMovedOutOfSpamMailbox(MessageMoveEvent event) {
         try {
-            MailboxId spamMailboxId = systemMailboxesProvider.findMailbox(Role.SPAM, event.getSession()).getId();
-            MailboxId trashMailboxId = systemMailboxesProvider.findMailbox(Role.TRASH, event.getSession()).getId();
+            MailboxId spamMailboxId = systemMailboxesProvider.findMailbox(Role.SPAM, event.getUser()).getId();
+            MailboxId trashMailboxId = systemMailboxesProvider.findMailbox(Role.TRASH, event.getUser()).getId();
 
             return event.getMessageMoves().removedMailboxIds().contains(spamMailboxId)
                 && !event.getMessageMoves().addedMailboxIds().contains(trashMailboxId);

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index 37d0162..d1ba383 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -21,8 +21,10 @@ package org.apache.james.mailbox.spamassassin;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Date;
@@ -61,6 +63,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSortedMap;
 
 public class SpamAssassinListenerTest {
+
     public static final String USER = "user";
     private static final MockMailboxSession MAILBOX_SESSION = new MockMailboxSession(USER);
     private static final int UID_VALIDITY = 43;
@@ -78,8 +81,10 @@ public class SpamAssassinListenerTest {
 
     @Before
     public void setup() throws Exception {
-        StoreMailboxManager mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver());
+        StoreMailboxManager mailboxManager = spy(new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver()));
         SystemMailboxesProviderImpl systemMailboxesProvider = new SystemMailboxesProviderImpl(mailboxManager);
+        when(mailboxManager.createSystemSession(USER))
+            .thenReturn(MAILBOX_SESSION);
 
         spamAssassin = mock(SpamAssassin.class);
         MailboxSessionMapperFactory mapperFactory = mailboxManager.getMapperFactory();

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
index 0045d70..977a63a 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
@@ -23,6 +23,7 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -50,12 +51,13 @@ public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
     }
 
     @Override
-    public Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException {
-        MailboxPath mailboxPath = MailboxPath.forUser(session.getUser().getUserName(), aRole.getDefaultMailbox());
+    public Stream<MessageManager> getMailboxByRole(Role aRole, User user) throws MailboxException {
+        MailboxSession session = mailboxManager.createSystemSession(user.asString());
+        MailboxPath mailboxPath = MailboxPath.forUser(user.asString(), aRole.getDefaultMailbox());
         try {
             return Stream.of(mailboxManager.getMailbox(mailboxPath, session));
         } catch (MailboxNotFoundException e) {
-            return searchMessageManagerByMailboxRole(aRole, session);
+            return searchMessageManagerByMailboxRole(aRole, user);
         }
     }
 
@@ -65,7 +67,8 @@ public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
             .orElse(false);
     }
 
-    private Stream<MessageManager> searchMessageManagerByMailboxRole(Role aRole, MailboxSession session) throws MailboxException {
+    private Stream<MessageManager> searchMessageManagerByMailboxRole(Role aRole, User user) throws MailboxException {
+        MailboxSession session = mailboxManager.createSystemSession(user.asString());
         ThrowingFunction<MailboxPath, MessageManager> loadMailbox = path -> mailboxManager.getMailbox(path, session);
         MailboxQuery mailboxQuery = MailboxQuery.privateMailboxesBuilder(session)
             .expression(new PrefixedWildcard(aRole.getDefaultMailbox()))

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
index f100a27..0041f07 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
@@ -58,16 +58,18 @@ public class SystemMailboxesProviderImplTest {
 
     @Test
     public void getMailboxByRoleShouldReturnEmptyWhenNoMailbox() throws Exception {
+        when(mailboxManager.createSystemSession(MailboxFixture.ALICE)).thenReturn(mailboxSession);
         when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenThrow(MailboxNotFoundException.class);
 
-        assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession)).isEmpty();
+        assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession.getUser().getCoreUser())).isEmpty();
     }
 
     @Test
     public void getMailboxByRoleShouldReturnMailboxByRole() throws Exception {
+        when(mailboxManager.createSystemSession(MailboxFixture.ALICE)).thenReturn(mailboxSession);
         when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenReturn(inboxMessageManager);
 
-        assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession))
+        assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession.getUser().getCoreUser()))
             .hasSize(1)
             .containsOnly(inboxMessageManager);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
index 7f71259..086c7dd 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
@@ -189,7 +189,7 @@ public class SendMDNProcessor implements SetMessagesProcessor {
 
 
     private MessageManager getOutbox(MailboxSession mailboxSession) throws MailboxException {
-        return systemMailboxesProvider.getMailboxByRole(Role.OUTBOX, mailboxSession)
+        return systemMailboxesProvider.getMailboxByRole(Role.OUTBOX, mailboxSession.getUser().getCoreUser())
             .findAny()
             .orElseThrow(() -> new IllegalStateException("User don't have an Outbox"));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index f4f30ef..dc135e6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -309,7 +309,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
     }
 
     private Optional<MessageManager> getMailboxWithRole(MailboxSession mailboxSession, Role role) throws MailboxException {
-        return systemMailboxesProvider.getMailboxByRole(role, mailboxSession).findFirst();
+        return systemMailboxesProvider.getMailboxByRole(role, mailboxSession.getUser().getCoreUser()).findFirst();
     }
     
     private SetError buildSetErrorFromValidationResult(List<ValidationResult> validationErrors) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index f183f9e..17a081a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -245,7 +245,7 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
     }
 
     private List<MailboxId> mailboxIdFor(Role role, MailboxSession session) throws MailboxException {
-        return systemMailboxesProvider.getMailboxByRole(role, session)
+        return systemMailboxesProvider.getMailboxByRole(role, session.getUser().getCoreUser())
             .map(MessageManager::getId)
             .collect(Guavate.toImmutableList());
     }
@@ -273,7 +273,7 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
     }
 
     private Set<MailboxId> listMailboxIdsForRole(MailboxSession session, Role role) throws MailboxException {
-        return systemMailboxesProvider.getMailboxByRole(role, session)
+        return systemMailboxesProvider.getMailboxByRole(role, session.getUser().getCoreUser())
             .map(MessageManager::getId)
             .collect(Guavate.toImmutableSet());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
index a42af65..54b5bb7 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
@@ -137,12 +137,12 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
     }
 
     private MailboxId getSentMailboxId(MailboxSession session) throws MailboxRoleNotFoundException, MailboxException {
-        return systemMailboxesProvider.findMailbox(Role.SENT, session)
+        return systemMailboxesProvider.findMailbox(Role.SENT, session.getUser().getCoreUser())
             .getId();
     }
     
     private MailboxId getOutboxMailboxId(MailboxSession session) throws MailboxRoleNotFoundException, MailboxException {
-        return systemMailboxesProvider.findMailbox(Role.OUTBOX, session)
+        return systemMailboxesProvider.findMailbox(Role.OUTBOX, session.getUser().getCoreUser())
             .getId();
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/508d544f/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
index b93ed0f..f64a6ea 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
@@ -33,6 +33,7 @@ import java.util.Optional;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 
+import org.apache.james.core.User;
 import org.apache.james.jmap.exceptions.MailboxNotOwnedException;
 import org.apache.james.jmap.model.CreationMessage;
 import org.apache.james.jmap.model.CreationMessage.DraftEmailer;
@@ -390,7 +391,7 @@ public class SetMessagesCreationProcessorTest {
         }
 
         @Override
-        public Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) {
+        public Stream<MessageManager> getMailboxByRole(Role aRole, User user) {
             if (aRole.equals(Role.OUTBOX)) {
                 return OptionalUtils.toStream(outboxSupplier.get());
             } else if (aRole.equals(Role.DRAFTS)) {


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


[11/19] james-project git commit: JAMES-2616 replace getSession() in MessageMoveEventTest

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in MessageMoveEventTest


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

Branch: refs/heads/master
Commit: b90fcbaecafd2cce1d49fb2a5579d2ba6ad51b5b
Parents: 508d544
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 13:38:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/store/event/MessageMoveEventTest.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b90fcbae/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MessageMoveEventTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MessageMoveEventTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MessageMoveEventTest.java
index 33239d4..70ac645 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MessageMoveEventTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MessageMoveEventTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
 
 import java.util.Map;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MessageMoves;
@@ -87,7 +88,8 @@ public class MessageMoveEventTest {
 
     @Test
     public void builderShouldBuildWhenFieldsAreGiven() {
-        MockMailboxSession session = new MockMailboxSession("user@james.org");
+        String username = "user@james.org";
+        MockMailboxSession session = new MockMailboxSession(username);
         MessageMoves messageMoves = MessageMoves.builder()
             .targetMailboxIds(TestId.of(2))
             .previousMailboxIds(TestId.of(1))
@@ -100,7 +102,7 @@ public class MessageMoveEventTest {
             .messages(messages)
             .build();
 
-        softly.assertThat(event.getSession()).isEqualTo(session);
+        softly.assertThat(event.getUser()).isEqualTo(User.fromUsername(username));
         softly.assertThat(event.getMessageMoves()).isEqualTo(messageMoves);
         softly.assertThat(event.getMessages()).isEqualTo(messages);
     }


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


[16/19] james-project git commit: JAMES-2616 Completely remove mailbox session in events

Posted by bt...@apache.org.
JAMES-2616 Completely remove mailbox session in events


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

Branch: refs/heads/master
Commit: 262e206e22e656456926f775069efd517d07829e
Parents: 713c824
Author: tran tien duc <dt...@linagora.com>
Authored: Mon Dec 3 17:22:05 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/Event.java    |   8 +-
 .../apache/james/mailbox/MailboxListener.java   | 137 +------------------
 .../ElasticSearchQuotaMailboxListenerTest.java  |   7 +-
 .../mailbox/store/event/MessageMoveEvent.java   |   5 -
 .../quota/ListeningCurrentQuotaUpdater.java     |   6 +-
 .../event/AsynchronousEventDeliveryTest.java    |  18 ++-
 .../DefaultDelegatingMailboxListenerTest.java   |  25 ++--
 .../event/MailboxAnnotationListenerTest.java    |   2 +-
 .../store/event/MixedEventDeliveryTest.java     |   8 +-
 .../event/SynchronousEventDeliveryTest.java     |   9 +-
 .../base/FakeMailboxListenerAdded.java          |   6 +-
 .../base/FakeMailboxListenerFlagsUpdate.java    |   8 +-
 .../base/MailboxEventAnalyserTest.java          |  12 +-
 13 files changed, 65 insertions(+), 186 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
index 4e80830..51c1078 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
@@ -24,13 +24,9 @@ import org.apache.james.core.User;
 
 public interface Event {
 
-    MailboxSession getSession();
-
-    default User getUser() {
-        return getSession().getUser().getCoreUser();
-    }
+    User getUser();
 
     default Optional<MailboxSession.SessionId> getSessionId() {
-        return Optional.ofNullable(getSession().getSessionId());
+        return Optional.empty();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index eb80e4b..91c94af 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -21,9 +21,7 @@ package org.apache.james.mailbox;
 
 import java.io.Serializable;
 import java.time.Instant;
-import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 
@@ -75,6 +73,7 @@ public interface MailboxListener {
     }
 
     class QuotaUsageUpdatedEvent implements QuotaEvent, Serializable {
+
         private final User user;
         private final QuotaRoot quotaRoot;
         private final Quota<QuotaCount> countQuota;
@@ -89,10 +88,6 @@ public interface MailboxListener {
             this.instant = instant;
         }
 
-        @Override
-        public MailboxSession getSession() {
-            throw new UnsupportedOperationException("this method will be removed");
-        }
 
         @Override
         public User getUser() {
@@ -141,84 +136,16 @@ public interface MailboxListener {
      * A mailbox event.
      */
     abstract class MailboxEvent implements Event, Serializable {
-        public static class DummyMailboxSession implements MailboxSession {
-
-            @Override
-            public SessionType getType() {
-                return null;
-            }
-
-            @Override
-            public SessionId getSessionId() {
-                return MailboxSession.SessionId.random();
-            }
-
-            @Override
-            public boolean isOpen() {
-                return false;
-            }
-
-            @Override
-            public void close() {
-
-            }
-
-            @Override
-            public User getUser() {
-                return null;
-            }
-
-            @Override
-            public String getPersonalSpace() {
-                return null;
-            }
-
-            @Override
-            public String getOtherUsersSpace() {
-                return null;
-            }
-
-            @Override
-            public Collection<String> getSharedSpaces() {
-                return null;
-            }
-
-            @Override
-            public Map<Object, Object> getAttributes() {
-                return null;
-            }
 
-            @Override
-            public char getPathDelimiter() {
-                return 0;
-            }
-        }
-
-        private final MailboxSession session;
         private final MailboxPath path;
         private final MailboxId mailboxId;
         private final User user;
         private final Optional<MailboxSession.SessionId> sessionId;
 
-        @Deprecated
-        public MailboxEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            this.session = session;
-            this.path = path;
-            this.mailboxId = mailboxId;
-            // To pass some tests, which pass null MailboxSession to the constructors
-            this.user = Optional.ofNullable(session)
-                .map(MailboxSession::getUser)
-                .map(MailboxSession.User::getCoreUser)
-                .orElse(null);
-            this.sessionId = Optional.ofNullable(session)
-                .map(MailboxSession::getSessionId);
-        }
-
         public MailboxEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             this.user = user;
             this.path = path;
             this.mailboxId = mailboxId;
-            this.session = new DummyMailboxSession();
             this.sessionId = sessionId;
         }
 
@@ -233,18 +160,6 @@ public interface MailboxListener {
             return user;
         }
 
-
-        /**
-         * Gets the {@link MailboxSession} in which's context the {@link MailboxEvent}
-         * happened
-         *
-         * @return session
-         */
-        @Override
-        public MailboxSession getSession() {
-            return session;
-        }
-
         /**
          * Gets the sessionId in which's context the {@link MailboxEvent}
          * happened
@@ -289,15 +204,6 @@ public interface MailboxListener {
         private final QuotaCount deletedMessageCOunt;
         private final QuotaSize totalDeletedSize;
 
-        @Deprecated
-        public MailboxDeletion(MailboxSession session, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
-                               MailboxId mailboxId) {
-            super(session, path, mailboxId);
-            this.quotaRoot = quotaRoot;
-            this.deletedMessageCOunt = deletedMessageCOunt;
-            this.totalDeletedSize = totalDeletedSize;
-        }
-
         public MailboxDeletion(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
                                MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
@@ -328,11 +234,6 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public MailboxAdded(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public MailboxAdded(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
@@ -347,11 +248,6 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public MailboxRenamed(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public MailboxRenamed(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
@@ -372,12 +268,6 @@ public interface MailboxListener {
         private final ACLDiff aclDiff;
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public MailboxACLUpdated(MailboxSession session, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-            this.aclDiff = aclDiff;
-        }
-
         public MailboxACLUpdated(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
             this.aclDiff = aclDiff;
@@ -399,11 +289,6 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public MessageEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public MessageEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
@@ -418,11 +303,6 @@ public interface MailboxListener {
 
     abstract class MetaDataHoldingEvent extends MessageEvent {
 
-        @Deprecated
-        public MetaDataHoldingEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public MetaDataHoldingEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
@@ -443,11 +323,6 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public Expunged(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public Expunged(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
@@ -471,11 +346,6 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public FlagsUpdated(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public FlagsUpdated(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
@@ -493,11 +363,6 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        @Deprecated
-        public Added(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
-            super(session, path, mailboxId);
-        }
-
         public Added(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
index d515147..d749146 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
@@ -24,6 +24,7 @@ import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.NOW
 import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.QUOTAROOT;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.mockito.Mockito.mock;
 
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
@@ -34,7 +35,6 @@ import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.quota.QuotaFixture.Counts;
 import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
 import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
@@ -52,8 +52,7 @@ import org.junit.rules.TemporaryFolder;
 public class ElasticSearchQuotaMailboxListenerTest {
 
     private static final int BATCH_SIZE = 1;
-    private static final MailboxSession MAILBOX_SESSION = null;
-    private static final Event EVENT = () -> MAILBOX_SESSION;
+    private static final Event DUMB_EVENT = mock(Event.class);
 
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
@@ -80,7 +79,7 @@ public class ElasticSearchQuotaMailboxListenerTest {
 
     @Test
     public void eventShouldDoNothingWhenNoQuotaEvent() throws Exception {
-        quotaMailboxListener.event(EVENT);
+        quotaMailboxListener.event(DUMB_EVENT);
 
         embeddedElasticSearch.awaitForElasticSearch();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
index 5ba1ddf..cb504c9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
@@ -105,11 +105,6 @@ public class MessageMoveEvent implements Event {
     }
 
     @Override
-    public MailboxSession getSession() {
-        throw new UnsupportedOperationException("wiil be removed");
-    }
-
-    @Override
     public User getUser() {
         return user;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index e8f4e54..d08afda 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -87,7 +87,8 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.decrease(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(expunged.getUser(),
+        dispatcher.quota(
+            expunged.getUser(),
             quotaRoot,
             quotaManager.getMessageQuota(quotaRoot),
             quotaManager.getStorageQuota(quotaRoot));
@@ -104,7 +105,8 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.increase(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(added.getUser(),
+        dispatcher.quota(
+            added.getUser(),
             quotaRoot,
             quotaManager.getMessageQuota(quotaRoot),
             quotaManager.getStorageQuota(quotaRoot));

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
index 44ffae0..45ef1ea 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
@@ -24,10 +24,10 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.After;
@@ -53,23 +53,27 @@ public class AsynchronousEventDeliveryTest {
     }
 
     @Test
-    public void deliverShouldWork() throws Exception {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
+    public void deliverShouldWork() {
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
         asynchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener, timeout(ONE_MINUTE)).event(event);
     }
 
     @Test
-    public void deliverShouldNotPropagateException() throws Exception {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(new MockMailboxSession("test"), null, null) {};
+    public void deliverShouldNotPropagateException() {
+        MockMailboxSession session = new MockMailboxSession("test");
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(session.getSessionId()),
+            session.getUser().getCoreUser(), null, null) {};
         doThrow(new RuntimeException()).when(mailboxListener).event(event);
         asynchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener, timeout(ONE_MINUTE)).event(event);
     }
 
     @Test
-    public void deliverShouldWorkWhenThePoolIsFull() throws Exception {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(new MockMailboxSession("test"), null, null) {};
+    public void deliverShouldWorkWhenThePoolIsFull() {
+        MockMailboxSession session = new MockMailboxSession("test");
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(session.getSessionId()),
+            session.getUser().getCoreUser(), null, null) {};
         int operationCount = 10;
         for (int i = 0; i < operationCount; i++) {
             asynchronousEventDelivery.deliver(mailboxListener, event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/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 7442a98..87ce925 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
@@ -83,7 +83,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -92,7 +92,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -104,9 +104,9 @@ public class DefaultDelegatingMailboxListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount deletedMessageCount = QuotaCount.count(123);
         QuotaSize totalDeletedSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion((MailboxSession) null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(Optional.empty(), null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -118,9 +118,9 @@ public class DefaultDelegatingMailboxListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion((MailboxSession) null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(Optional.empty(), null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent((MailboxSession) null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(Optional.empty(), null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -130,7 +130,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldWork() {
         defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -140,7 +140,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldNotRemoveAListenerFromADifferentPath() {
         defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -150,7 +150,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForONCE() {
         defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).isEmpty();
@@ -158,9 +158,9 @@ public class DefaultDelegatingMailboxListenerTest {
     }
 
     @Test
-    public void removeGlobalListenerShouldWorkForEACH_NODE() {
+    public void removeGlobalListenerShouldWorkForEACH_NODE() throws Exception {
         defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -170,7 +170,8 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void listenersErrorsShouldNotBePropageted() throws Exception {
         MailboxSession session = new MockMailboxSession("benwa");
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(session, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.of(session.getSessionId()),
+            session.getUser().getCoreUser(), MAILBOX_PATH, MAILBOX_ID) {};
         MailboxListener mockedListener = mock(MailboxListener.class);
         when(mockedListener.getType()).thenReturn(MailboxListener.ListenerType.ONCE);
         doThrow(new RuntimeException()).when(mockedListener).event(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index f9e1ec1..ea6f4bd 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -96,7 +96,7 @@ public class MailboxAnnotationListenerTest {
 
     @Test
     public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
         listener.event(event);
 
         verifyNoMoreInteractions(mailboxSessionMapperFactory);

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
index c2cc095..8c19b3a 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
@@ -25,11 +25,11 @@ import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.After;
 import org.junit.Before;
@@ -59,14 +59,14 @@ public class MixedEventDeliveryTest {
     @Test
     public void deliverShouldWorkOnSynchronousListeners() {
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
         mixedEventDelivery.deliver(listener, event);
         verify(listener).event(event);
     }
 
     @Test
     public void deliverShouldEventuallyDeliverOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         mixedEventDelivery.deliver(listener, event);
         verify(listener, timeout(DELIVERY_DELAY * 10)).event(event);
@@ -74,7 +74,7 @@ public class MixedEventDeliveryTest {
 
     @Test(timeout = ONE_MINUTE)
     public void deliverShouldNotBlockOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         final CountDownLatch latch = new CountDownLatch(1);
         doAnswer(invocation -> {

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
index 4a1ebda..64ad475 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
@@ -23,8 +23,9 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.util.Optional;
+
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.Before;
@@ -43,14 +44,16 @@ public class SynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
         synchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener).event(event);
     }
 
     @Test
     public void deliverShouldNotPropagateException() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(new MockMailboxSession("test"), null, null) {};
+        MockMailboxSession session = new MockMailboxSession("test");
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(session.getSessionId()),
+            session.getUser().getCoreUser(),null, null) {};
         doThrow(new RuntimeException()).when(mailboxListener).event(event);
         synchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener).event(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
index c80b019..320fd36 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
@@ -21,9 +21,11 @@ package org.apache.james.imap.processor.base;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
 import javax.mail.Flags;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
@@ -36,8 +38,8 @@ public class FakeMailboxListenerAdded extends MailboxListener.Added {
 
     public List<MessageUid> uids;
 
-    public FakeMailboxListenerAdded(MailboxSession session, List<MessageUid> uids, MailboxPath path, MailboxId mailboxId) {
-        super(session, path, mailboxId);
+    public FakeMailboxListenerAdded(MailboxSession.SessionId sessionId, User user, List<MessageUid> uids, MailboxPath path, MailboxId mailboxId) {
+        super(Optional.ofNullable(sessionId), user, path, mailboxId);
         this.uids = uids;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
index dbedabe..2ca6120 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
@@ -20,7 +20,9 @@
 package org.apache.james.imap.processor.base;
 
 import java.util.List;
+import java.util.Optional;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener.FlagsUpdated;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
@@ -35,7 +37,11 @@ public class FakeMailboxListenerFlagsUpdate extends FlagsUpdated {
     public List<UpdatedFlags> flags;
 
     public FakeMailboxListenerFlagsUpdate(MailboxSession session, List<MessageUid> uids, List<UpdatedFlags> flags, MailboxPath path, MailboxId mailboxId) {
-        super(session, path, mailboxId);
+        this(session.getSessionId(), session.getUser().getCoreUser(), uids, flags, path, mailboxId);
+    }
+
+    FakeMailboxListenerFlagsUpdate(MailboxSession.SessionId sessionId, User user, List<MessageUid> uids, List<UpdatedFlags> flags, MailboxPath path, MailboxId mailboxId) {
+        super(Optional.ofNullable(sessionId), user, path, mailboxId);
         this.uids = uids;
         this.flags = flags;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/262e206e/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 5cd3449..5774f57 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -24,6 +24,8 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.util.Optional;
+
 import javax.mail.Flags;
 
 import org.apache.commons.lang3.NotImplementedException;
@@ -124,7 +126,8 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldBeNoSizeChangeOnOtherEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(MAILBOX_SESSION, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(MAILBOX_SESSION.getSessionId()),
+            MAILBOX_SESSION.getUser().getCoreUser(), MAILBOX_PATH, MAILBOX_ID) {};
       
         testee.event(event);
 
@@ -133,13 +136,16 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldBeNoSizeChangeOnAdded() {
-        testee.event(new FakeMailboxListenerAdded(MAILBOX_SESSION, ImmutableList.of(MessageUid.of(11)), MAILBOX_PATH, MAILBOX_ID));
+        testee.event(new FakeMailboxListenerAdded(MAILBOX_SESSION.getSessionId(),
+            MAILBOX_SESSION.getUser().getCoreUser(),
+            ImmutableList.of(MessageUid.of(11)), MAILBOX_PATH, MAILBOX_ID));
         assertThat(testee.isSizeChanged()).isTrue();
     }
 
     @Test
     public void testShouldNoSizeChangeAfterReset() {
-        testee.event(new FakeMailboxListenerAdded(MAILBOX_SESSION, ImmutableList.of(MessageUid.of(11)), MAILBOX_PATH, MAILBOX_ID));
+        testee.event(new FakeMailboxListenerAdded(MAILBOX_SESSION.getSessionId(),
+            MAILBOX_SESSION.getUser().getCoreUser(), ImmutableList.of(MessageUid.of(11)), MAILBOX_PATH, MAILBOX_ID));
         testee.resetEvents();
 
         assertThat(testee.isSizeChanged()).isFalse();


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


[15/19] james-project git commit: JAMES-2616 SpamAssassin learns james User not String

Posted by bt...@apache.org.
JAMES-2616 SpamAssassin learns james User not String


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

Branch: refs/heads/master
Commit: 372930cd3f64cb9e65cac0d52527feee7656e6f1
Parents: 262e206
Author: tran tien duc <dt...@linagora.com>
Authored: Tue Dec 4 15:44:03 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/spamassassin/SpamAssassin.java       |  5 +++--
 .../mailbox/spamassassin/SpamAssassinListener.java     |  7 +++----
 .../apache/james/transport/mailets/SpamAssassin.java   |  3 ++-
 third-party/spamassassin/pom.xml                       |  4 ++++
 .../apache/james/spamassassin/SpamAssassinInvoker.java | 13 +++++++------
 .../james/spamassassin/SpamAssassinInvokerTest.java    |  3 ++-
 6 files changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/372930cd/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassin.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassin.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassin.java
index b86fe28..a654666 100644
--- a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassin.java
+++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassin.java
@@ -23,6 +23,7 @@ import java.util.List;
 
 import javax.inject.Inject;
 
+import org.apache.james.core.User;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.spamassassin.SpamAssassinInvoker;
 import org.apache.james.util.Host;
@@ -40,7 +41,7 @@ public class SpamAssassin {
         this.spamAssassinConfiguration = spamAssassinConfiguration;
     }
 
-    public void learnSpam(List<InputStream> messages, String user) {
+    public void learnSpam(List<InputStream> messages, User user) {
         if (spamAssassinConfiguration.isEnable()) {
             Host host = spamAssassinConfiguration.getHost().get();
             SpamAssassinInvoker invoker = new SpamAssassinInvoker(metricFactory, host.getHostName(), host.getPort());
@@ -49,7 +50,7 @@ public class SpamAssassin {
         }
     }
 
-    public void learnHam(List<InputStream> messages, String user) {
+    public void learnHam(List<InputStream> messages, User user) {
         if (spamAssassinConfiguration.isEnable()) {
             Host host = spamAssassinConfiguration.getHost().get();
             SpamAssassinInvoker invoker = new SpamAssassinInvoker(metricFactory, host.getHostName(), host.getPort());

http://git-wip-us.apache.org/repos/asf/james-project/blob/372930cd/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
index 9bf3657..74443c9 100644
--- a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
+++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
@@ -68,17 +68,16 @@ public class SpamAssassinListener implements SpamEventListener {
 
     @Override
     public void event(Event event) {
-        String username = event.getUser().asString();
         if (event instanceof MessageMoveEvent) {
             MessageMoveEvent messageMoveEvent = (MessageMoveEvent) event;
             if (isMessageMovedToSpamMailbox(messageMoveEvent)) {
                 LOGGER.debug("Spam event detected");
                 ImmutableList<InputStream> messages = retrieveMessages(messageMoveEvent);
-                spamAssassin.learnSpam(messages, username);
+                spamAssassin.learnSpam(messages, event.getUser());
             }
             if (isMessageMovedOutOfSpamMailbox(messageMoveEvent)) {
                 ImmutableList<InputStream> messages = retrieveMessages(messageMoveEvent);
-                spamAssassin.learnHam(messages, username);
+                spamAssassin.learnHam(messages, event.getUser());
             }
         }
         if (event instanceof EventFactory.AddedImpl) {
@@ -89,7 +88,7 @@ public class SpamAssassinListener implements SpamEventListener {
                     .stream()
                     .map(Throwing.function(MailboxMessage::getFullContent))
                     .collect(Guavate.toImmutableList());
-                spamAssassin.learnHam(contents, username);
+                spamAssassin.learnHam(contents, event.getUser());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/372930cd/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
index f9f2634..adda4b7 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
@@ -26,6 +26,7 @@ import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.MailAddress;
+import org.apache.james.core.User;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.spamassassin.SpamAssassinInvoker;
 import org.apache.james.spamassassin.SpamAssassinResult;
@@ -106,7 +107,7 @@ public class SpamAssassin extends GenericMailet {
     }
 
     private void querySpamAssassin(Mail mail, MimeMessage message, SpamAssassinInvoker sa, MailAddress recipient) throws MessagingException, UsersRepositoryException {
-        SpamAssassinResult result = sa.scanMail(message, usersRepository.getUser(recipient));
+        SpamAssassinResult result = sa.scanMail(message, User.fromUsername(usersRepository.getUser(recipient)));
 
         // Add headers per recipient to mail object
         for (String key : result.getHeadersAsAttribute().keySet()) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/372930cd/third-party/spamassassin/pom.xml
----------------------------------------------------------------------
diff --git a/third-party/spamassassin/pom.xml b/third-party/spamassassin/pom.xml
index 3079b24..06a0576 100644
--- a/third-party/spamassassin/pom.xml
+++ b/third-party/spamassassin/pom.xml
@@ -31,6 +31,10 @@
     <dependencies>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-testing</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/372930cd/third-party/spamassassin/src/main/java/org/apache/james/spamassassin/SpamAssassinInvoker.java
----------------------------------------------------------------------
diff --git a/third-party/spamassassin/src/main/java/org/apache/james/spamassassin/SpamAssassinInvoker.java b/third-party/spamassassin/src/main/java/org/apache/james/spamassassin/SpamAssassinInvoker.java
index 1a97bf8..0a686b1 100644
--- a/third-party/spamassassin/src/main/java/org/apache/james/spamassassin/SpamAssassinInvoker.java
+++ b/third-party/spamassassin/src/main/java/org/apache/james/spamassassin/SpamAssassinInvoker.java
@@ -35,6 +35,7 @@ import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.core.User;
 import org.apache.james.metrics.api.MetricFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -92,12 +93,12 @@ public class SpamAssassinInvoker {
      * @throws MessagingException
      *             if an error on scanning is detected
      */
-    public SpamAssassinResult scanMail(MimeMessage message, String user) throws MessagingException {
+    public SpamAssassinResult scanMail(MimeMessage message, User user) throws MessagingException {
         return metricFactory.runPublishingTimerMetric(
             "spamAssassin-check",
             Throwing.supplier(
                 () -> scanMailWithAdditionalHeaders(message,
-                    "User: " + user))
+                    "User: " + user.asString()))
                 .sneakyThrow());
     }
 
@@ -187,7 +188,7 @@ public class SpamAssassinInvoker {
      * @throws MessagingException
      *             if an error occured during learning.
      */
-    public boolean learnAsSpam(InputStream message, String user) throws MessagingException {
+    public boolean learnAsSpam(InputStream message, User user) throws MessagingException {
         return metricFactory.runPublishingTimerMetric(
             "spamAssassin-spam-report",
             Throwing.supplier(
@@ -203,7 +204,7 @@ public class SpamAssassinInvoker {
      * @throws MessagingException
      *             if an error occured during learning.
      */
-    public boolean learnAsHam(InputStream message, String user) throws MessagingException {
+    public boolean learnAsHam(InputStream message, User user) throws MessagingException {
         return metricFactory.runPublishingTimerMetric(
             "spamAssassin-ham-report",
             Throwing.supplier(
@@ -211,7 +212,7 @@ public class SpamAssassinInvoker {
                 .sneakyThrow());
     }
 
-    private boolean reportMessageAs(InputStream message, String user, MessageClass messageClass) throws MessagingException {
+    private boolean reportMessageAs(InputStream message, User user, MessageClass messageClass) throws MessagingException {
         try (Socket socket = new Socket(spamdHost, spamdPort);
              OutputStream out = socket.getOutputStream();
              BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(out);
@@ -227,7 +228,7 @@ public class SpamAssassinInvoker {
             writer.write(CRLF);
             writer.write("Set: local, remote");
             writer.write(CRLF);
-            writer.write("User: " + user);
+            writer.write("User: " + user.asString());
             writer.write(CRLF);
             writer.write(CRLF);
             writer.flush();

http://git-wip-us.apache.org/repos/asf/james-project/blob/372930cd/third-party/spamassassin/src/test/java/org/apache/james/spamassassin/SpamAssassinInvokerTest.java
----------------------------------------------------------------------
diff --git a/third-party/spamassassin/src/test/java/org/apache/james/spamassassin/SpamAssassinInvokerTest.java b/third-party/spamassassin/src/test/java/org/apache/james/spamassassin/SpamAssassinInvokerTest.java
index 473c6bf..f712572 100644
--- a/third-party/spamassassin/src/test/java/org/apache/james/spamassassin/SpamAssassinInvokerTest.java
+++ b/third-party/spamassassin/src/test/java/org/apache/james/spamassassin/SpamAssassinInvokerTest.java
@@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
 
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.core.User;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.spamassassin.SpamAssassinExtension.SpamAssassin;
 import org.apache.james.util.MimeMessageUtil;
@@ -35,7 +36,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 @ExtendWith(SpamAssassinExtension.class)
 public class SpamAssassinInvokerTest {
 
-    public static final String USER = "any@james";
+    public static final User USER = User.fromUsername("any@james");
     private SpamAssassin spamAssassin;
     private SpamAssassinInvoker testee;
 


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


[14/19] james-project git commit: JAMES-2616 replace getSession() in MailboxEvent Serializing

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in MailboxEvent Serializing

Adding getSessionId() api into Events, SelectedMailbox Listener requires sessionId
from events.


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

Branch: refs/heads/master
Commit: c81c2ae98b80dd1459bcf471888e5041430dc43a
Parents: 9ce7667
Author: tran tien duc <dt...@linagora.com>
Authored: Mon Dec 3 13:30:36 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 84 ++++++++++++--------
 .../spamassassin/SpamAssassinListenerTest.java  |  6 +-
 .../james/mailbox/store/event/EventFactory.java | 59 +++++++-------
 .../store/event/MailboxEventDispatcher.java     | 16 ++--
 .../mailbox/store/event/MessageMoveEvent.java   | 42 ++++++++--
 .../event/MailboxAnnotationListenerTest.java    |  3 +-
 .../mailbox/store/json/EventSerializerTest.java |  0
 .../processor/base/SelectedMailboxImplTest.java |  3 +-
 8 files changed, 130 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 02c5856..c44597f 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -64,12 +64,12 @@ public interface MailboxListener {
 
     /**
      * Informs this listener about the given event.
-     * 
+     *
      * @param event
      *            not null
      */
     void event(Event event);
-    
+
     interface QuotaEvent extends Event {
         QuotaRoot getQuotaRoot();
     }
@@ -198,6 +198,7 @@ public interface MailboxListener {
         private final MailboxPath path;
         private final MailboxId mailboxId;
         private final User user;
+        private final long sessionId;
 
         public MailboxEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             this.session = session;
@@ -208,13 +209,17 @@ public interface MailboxListener {
                 .map(MailboxSession::getUser)
                 .map(MailboxSession.User::getCoreUser)
                 .orElse(null);
+            this.sessionId = Optional.ofNullable(session)
+                .map(MailboxSession::getSessionId)
+                .orElse(0L);
         }
 
-        public MailboxEvent(User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxEvent(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             this.user = user;
             this.path = path;
             this.mailboxId = mailboxId;
             this.session = new DummyMailboxSession();
+            this.sessionId = sessionId;
         }
 
         /**
@@ -232,7 +237,7 @@ public interface MailboxListener {
         /**
          * Gets the {@link MailboxSession} in which's context the {@link MailboxEvent}
          * happened
-         * 
+         *
          * @return session
          */
         @Override
@@ -241,8 +246,19 @@ public interface MailboxListener {
         }
 
         /**
+         * Gets the sessionId in which's context the {@link MailboxEvent}
+         * happened
+         *
+         * @return sessionId
+         */
+        @Override
+        public long getSessionId() {
+            return sessionId;
+        }
+
+        /**
          * Return the path of the Mailbox this event belongs to.
-         * 
+         *
          * @return path
          */
         public MailboxPath getMailboxPath() {
@@ -265,7 +281,7 @@ public interface MailboxListener {
     class MailboxDeletion extends MailboxEvent {
 
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -281,9 +297,9 @@ public interface MailboxListener {
             this.totalDeletedSize = totalDeletedSize;
         }
 
-        public MailboxDeletion(User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
+        public MailboxDeletion(long sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
                                MailboxId mailboxId) {
-            super(user, path, mailboxId);
+            super(sessionId, user, path, mailboxId);
             this.quotaRoot = quotaRoot;
             this.deletedMessageCOunt = deletedMessageCOunt;
             this.totalDeletedSize = totalDeletedSize;
@@ -307,7 +323,7 @@ public interface MailboxListener {
      */
     class MailboxAdded extends MailboxEvent {
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -315,8 +331,8 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MailboxAdded(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public MailboxAdded(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
     }
 
@@ -325,7 +341,7 @@ public interface MailboxListener {
      */
     abstract class MailboxRenamed extends MailboxEvent {
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -333,13 +349,13 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MailboxRenamed(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public MailboxRenamed(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
 
         /**
          * Gets the new name for this mailbox.
-         * 
+         *
          * @return name, not null
          */
         public abstract MailboxPath getNewPath();
@@ -358,8 +374,8 @@ public interface MailboxListener {
             this.aclDiff = aclDiff;
         }
 
-        public MailboxACLUpdated(User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public MailboxACLUpdated(long sessionId, User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
             this.aclDiff = aclDiff;
         }
 
@@ -368,14 +384,14 @@ public interface MailboxListener {
         }
 
     }
-    
+
     /**
      * A mailbox event related to a message.
      */
     abstract class MessageEvent extends MailboxEvent {
 
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -383,13 +399,13 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MessageEvent(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public MessageEvent(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
 
         /**
          * Gets the message UIDs for the subject of this event.
-         * 
+         *
          * @return message uids
          */
         public abstract List<MessageUid> getUids();
@@ -401,8 +417,8 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public MetaDataHoldingEvent(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public MetaDataHoldingEvent(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
 
         /**
@@ -417,7 +433,7 @@ public interface MailboxListener {
     abstract class Expunged extends MetaDataHoldingEvent {
 
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -425,13 +441,13 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public Expunged(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public Expunged(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
 
         /**
          * Return the flags which were set for the added message
-         * 
+         *
          * @return flags
          */
         @Override
@@ -444,7 +460,7 @@ public interface MailboxListener {
     abstract class FlagsUpdated extends MessageEvent {
 
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -452,8 +468,8 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public FlagsUpdated(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public FlagsUpdated(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
 
         public abstract List<UpdatedFlags> getUpdatedFlags();
@@ -465,7 +481,7 @@ public interface MailboxListener {
     abstract class Added extends MetaDataHoldingEvent {
 
         /**
-         * 
+         *
          */
         private static final long serialVersionUID = 1L;
 
@@ -473,8 +489,8 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
-        public Added(User user, MailboxPath path, MailboxId mailboxId) {
-            super(user, path, mailboxId);
+        public Added(long sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+            super(sessionId, user, path, mailboxId);
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index d1ba383..19e7755 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -251,7 +251,8 @@ public class SpamAssassinListenerTest {
         SimpleMailboxMessage message = createMessage(inboxId);
         EventFactory eventFactory = new EventFactory();
         AddedImpl addedEvent = eventFactory.new AddedImpl(
-                MAILBOX_SESSION,
+                MAILBOX_SESSION.getSessionId(),
+                MAILBOX_SESSION.getUser().getCoreUser(),
                 inbox,
                 ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)),
                 ImmutableMap.of(MessageUid.of(45), message));
@@ -266,7 +267,8 @@ public class SpamAssassinListenerTest {
         SimpleMailboxMessage message = createMessage(mailboxId1);
         EventFactory eventFactory = new EventFactory();
         AddedImpl addedEvent = eventFactory.new AddedImpl(
-                MAILBOX_SESSION,
+                MAILBOX_SESSION.getSessionId(),
+                MAILBOX_SESSION.getUser().getCoreUser(),
                 mailbox1,
                 ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)),
                 ImmutableMap.of(MessageUid.of(45), message));

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 2af8b42..483101c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -23,10 +23,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxId;
@@ -53,8 +53,8 @@ public class EventFactory {
         private final Map<MessageUid, MailboxMessage> availableMessages;
         private final Mailbox mailbox;
 
-        public AddedImpl(MailboxSession session, Mailbox mailbox, SortedMap<MessageUid, MessageMetaData> uids, Map<MessageUid, MailboxMessage> availableMessages) {
-            super(session, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
+        public AddedImpl(long sessionId, User user, Mailbox mailbox, SortedMap<MessageUid, MessageMetaData> uids, Map<MessageUid, MailboxMessage> availableMessages) {
+            super(sessionId, user, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.added = ImmutableMap.copyOf(uids);
             this.mailbox = mailbox;
             this.availableMessages = ImmutableMap.copyOf(availableMessages);
@@ -84,8 +84,8 @@ public class EventFactory {
         private final Map<MessageUid, MessageMetaData> uids;
         private final Mailbox mailbox;
 
-        public ExpungedImpl(MailboxSession session, Mailbox mailbox,  Map<MessageUid, MessageMetaData> uids) {
-            super(session,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
+        public ExpungedImpl(long sessionId, User user, Mailbox mailbox,  Map<MessageUid, MessageMetaData> uids) {
+            super(sessionId, user,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.uids = ImmutableMap.copyOf(uids);
             this.mailbox = mailbox;
         }
@@ -113,8 +113,8 @@ public class EventFactory {
 
         private final List<UpdatedFlags> uFlags;
 
-        public FlagsUpdatedImpl(MailboxSession session, Mailbox mailbox, List<MessageUid> uids, List<UpdatedFlags> uFlags) {
-            super(session, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
+        public FlagsUpdatedImpl(long sessionId, User user, Mailbox mailbox, List<MessageUid> uids, List<UpdatedFlags> uFlags) {
+            super(sessionId, user, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.uids = ImmutableList.copyOf(uids);
             this.uFlags = ImmutableList.copyOf(uFlags);
             this.mailbox = mailbox;
@@ -140,8 +140,8 @@ public class EventFactory {
     public final class MailboxDeletionImpl extends MailboxListener.MailboxDeletion implements MailboxAware {
         private final Mailbox mailbox;
 
-        public MailboxDeletionImpl(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-            super(session, new StoreMailboxPath(mailbox), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
+        public MailboxDeletionImpl(long sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
+            super(sessionId, user, new StoreMailboxPath(mailbox), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
             this.mailbox = mailbox;
         }
 
@@ -157,8 +157,8 @@ public class EventFactory {
 
         private final Mailbox mailbox;
 
-        public MailboxAddedImpl(MailboxSession session, Mailbox mailbox) {
-            super(session,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
+        public MailboxAddedImpl(long sessionId, User user, Mailbox mailbox) {
+            super(sessionId, user,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.mailbox = mailbox;
         }
 
@@ -175,8 +175,8 @@ public class EventFactory {
         private final MailboxPath newPath;
         private final Mailbox newMailbox;
 
-        public MailboxRenamedEventImpl(MailboxSession session, MailboxPath oldPath, Mailbox newMailbox) {
-            super(session, oldPath, newMailbox.getMailboxId());
+        public MailboxRenamedEventImpl(long sessionId, User user, MailboxPath oldPath, Mailbox newMailbox) {
+            super(sessionId, user, oldPath, newMailbox.getMailboxId());
             this.newPath = new StoreMailboxPath(newMailbox);
             this.newMailbox = newMailbox;
         }
@@ -192,38 +192,39 @@ public class EventFactory {
         }
     }
 
-    public MailboxListener.Added added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
-        return new AddedImpl(session, mailbox, uids, cachedMessages);
+    public MailboxListener.Added added(long sessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
+        return new AddedImpl(sessionId, user, mailbox, uids, cachedMessages);
     }
 
-    public MailboxListener.Expunged expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return new ExpungedImpl(session, mailbox, uids);
+    public MailboxListener.Expunged expunged(long sessionId, User user,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
+        return new ExpungedImpl(sessionId, user, mailbox, uids);
     }
 
-    public MailboxListener.FlagsUpdated flagsUpdated(MailboxSession session, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        return new FlagsUpdatedImpl(session, mailbox, uids, uflags);
+    public MailboxListener.FlagsUpdated flagsUpdated(long sessionId, User user, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
+        return new FlagsUpdatedImpl(sessionId, user, mailbox, uids, uflags);
     }
 
-    public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        return new MailboxRenamedEventImpl(session, from, to);
+    public MailboxListener.MailboxRenamed mailboxRenamed(long sessionId, User user, MailboxPath from, Mailbox to) {
+        return new MailboxRenamedEventImpl(sessionId, user, from, to);
     }
 
-    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot,
+    public MailboxListener.MailboxDeletion mailboxDeleted(long sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
                                                           QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return new MailboxDeletionImpl(session, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
+        return new MailboxDeletionImpl(sessionId, user, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
     }
 
-    public MailboxListener.MailboxAdded mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        return new MailboxAddedImpl(session, mailbox);
+    public MailboxListener.MailboxAdded mailboxAdded(long sessionId, User user, Mailbox mailbox) {
+        return new MailboxAddedImpl(sessionId, user, mailbox);
     }
 
-    public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        return new MailboxListener.MailboxACLUpdated(session, mailboxPath, aclDiff, mailboxId);
+    public MailboxListener.MailboxACLUpdated aclUpdated(long sessionId, User user, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
+        return new MailboxListener.MailboxACLUpdated(sessionId, user, mailboxPath, aclDiff, mailboxId);
     }
 
-    public MessageMoveEvent moved(MailboxSession session, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
+    public MessageMoveEvent moved(long sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
         return MessageMoveEvent.builder()
-                .session(session)
+                .sessionId(sessionId)
+                .user(user)
                 .messageMoves(messageMoves)
                 .messages(messages)
                 .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index 206e8b7..c7df6a5 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -82,7 +82,7 @@ public class MailboxEventDispatcher {
      * @param mailbox The mailbox
      */
     public void added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
-        listener.event(eventFactory.added(session, uids, mailbox, cachedMessages));
+        listener.event(eventFactory.added(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox, cachedMessages));
     }
 
     public void added(MailboxSession session, Mailbox mailbox, MailboxMessage mailboxMessage) {
@@ -110,7 +110,7 @@ public class MailboxEventDispatcher {
      */
     public void expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         if (!uids.isEmpty()) {
-            listener.event(eventFactory.expunged(session, uids, mailbox));
+            listener.event(eventFactory.expunged(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox));
         }
     }
 
@@ -127,7 +127,7 @@ public class MailboxEventDispatcher {
      */
     public void flagsUpdated(MailboxSession session, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
         if (!uids.isEmpty()) {
-            listener.event(eventFactory.flagsUpdated(session, uids, mailbox, uflags));
+            listener.event(eventFactory.flagsUpdated(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox, uflags));
         }
     }
 
@@ -140,7 +140,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        listener.event(eventFactory.mailboxRenamed(session, from, to));
+        listener.event(eventFactory.mailboxRenamed(session.getSessionId(), session.getUser().getCoreUser(), from, to));
     }
 
     /**
@@ -148,7 +148,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        listener.event(eventFactory.mailboxDeleted(session, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize));
+        listener.event(eventFactory.mailboxDeleted(session.getSessionId(), session.getUser().getCoreUser(), mailbox, quotaRoot, deletedMessageCount, totalDeletedSize));
     }
 
     /**
@@ -156,15 +156,15 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        listener.event(eventFactory.mailboxAdded(session, mailbox));
+        listener.event(eventFactory.mailboxAdded(session.getSessionId(), session.getUser().getCoreUser(), mailbox));
     }
 
     public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        listener.event(eventFactory.aclUpdated(session, mailboxPath, aclDiff, mailboxId));
+        listener.event(eventFactory.aclUpdated(session.getSessionId(), session.getUser().getCoreUser(), mailboxPath, aclDiff, mailboxId));
     }
 
     public void moved(MailboxSession session, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
-        MessageMoveEvent moveEvent = eventFactory.moved(session, messageMoves, messages);
+        MessageMoveEvent moveEvent = eventFactory.moved(session.getSessionId(), session.getUser().getCoreUser(), messageMoves, messages);
         if (!moveEvent.isNoop()) {
             listener.event(moveEvent);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
index 06221c9..3526af2 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
@@ -20,6 +20,7 @@ package org.apache.james.mailbox.store.event;
 
 import java.util.Map;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
@@ -39,7 +40,8 @@ public class MessageMoveEvent implements Event {
 
     public static class Builder {
 
-        private MailboxSession session;
+        private long sessionId;
+        private User user;
         private MessageMoves messageMoves;
         private ImmutableMap.Builder<MessageUid, MailboxMessage> messagesBuilder;
 
@@ -48,7 +50,18 @@ public class MessageMoveEvent implements Event {
         }
 
         public Builder session(MailboxSession session) {
-            this.session = session;
+            this.sessionId = session.getSessionId();
+            this.user = session.getUser().getCoreUser();
+            return this;
+        }
+
+        public Builder sessionId(long sessionId) {
+            this.sessionId = sessionId;
+            return this;
+        }
+
+        public Builder user(User user) {
+            this.user = user;
             return this;
         }
 
@@ -63,22 +76,25 @@ public class MessageMoveEvent implements Event {
         }
 
         public MessageMoveEvent build() {
-            Preconditions.checkNotNull(session, "'session' is mandatory");
+            Preconditions.checkNotNull(sessionId, "'sessionId' is mandatory");
+            Preconditions.checkNotNull(user, "'user' is mandatory");
             Preconditions.checkNotNull(messageMoves, "'messageMoves' is mandatory");
 
             ImmutableMap<MessageUid, MailboxMessage> messages = messagesBuilder.build();
 
-            return new MessageMoveEvent(session, messageMoves, messages);
+            return new MessageMoveEvent(sessionId, user, messageMoves, messages);
         }
     }
 
-    private final MailboxSession session;
+    private final long sessionId;
+    private final User user;
     private final MessageMoves messageMoves;
     private final Map<MessageUid, MailboxMessage> messages;
 
     @VisibleForTesting
-    MessageMoveEvent(MailboxSession session, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
-        this.session = session;
+    MessageMoveEvent(long sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
+        this.sessionId = sessionId;
+        this.user = user;
         this.messageMoves = messageMoves;
         this.messages = messages;
     }
@@ -89,7 +105,17 @@ public class MessageMoveEvent implements Event {
 
     @Override
     public MailboxSession getSession() {
-        return session;
+        throw new UnsupportedOperationException("wiil be removed");
+    }
+
+    @Override
+    public User getUser() {
+        return user;
+    }
+
+    @Override
+    public long getSessionId() {
+        return sessionId;
     }
 
     public MessageMoves getMessageMoves() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 9a62834..f9e1ec1 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -86,7 +86,8 @@ public class MailboxAnnotationListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
-        deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, quotaSize);
+        deleteEvent = eventFactory.mailboxDeleted(mailboxSession.getSessionId(), mailboxSession.getUser().getCoreUser(),
+            mailbox, quotaRoot, quotaCount, quotaSize);
 
         when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))
             .thenReturn(mailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/james-project/blob/c81c2ae9/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 ef8d5b9..d05ccf3 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
@@ -36,6 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.mail.Flags;
 
+import org.apache.james.core.User;
 import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.mailbox.MailboxListener;
@@ -167,6 +168,6 @@ public class SelectedMailboxImplTest {
     private void emitEvent(MailboxListener mailboxListener) {
         TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>();
         result.put(EMITTED_EVENT_UID, new SimpleMessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()));
-        mailboxListener.event(new EventFactory().added(mock(MailboxSession.class), result, mailbox, ImmutableMap.of()));
+        mailboxListener.event(new EventFactory().added(0L, mock(User.class), result, mailbox, ImmutableMap.of()));
     }
 }


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


[13/19] james-project git commit: JAMES-2616 replace getSession() in SelectedMailboxImpl

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in SelectedMailboxImpl


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

Branch: refs/heads/master
Commit: fd2005d7b2e2082d69d0062076e4e10df33686f5
Parents: 6ae22a2
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 15:15:16 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 mailbox/api/src/main/java/org/apache/james/mailbox/Event.java    | 4 ++++
 .../apache/james/imap/processor/base/SelectedMailboxImpl.java    | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fd2005d7/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
index 5d72aa2..7282cb9 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
@@ -27,4 +27,8 @@ public interface Event {
     default User getUser() {
         return getSession().getUser().getCoreUser();
     }
+
+    default long getSessionId() {
+        return getSession().getSessionId();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd2005d7/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 d2aabf1..31a43d4 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
@@ -329,7 +329,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
     private void mailboxEvent(MailboxEvent mailboxEvent) {
         // Check if the event was for the mailbox we are observing
         if (mailboxEvent.getMailboxId().equals(getMailboxId())) {
-            final long eventSessionId = mailboxEvent.getSession().getSessionId();
+            final long eventSessionId = mailboxEvent.getSessionId();
             if (mailboxEvent instanceof MessageEvent) {
                 final MessageEvent messageEvent = (MessageEvent) mailboxEvent;
                 if (messageEvent instanceof Added) {


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


[19/19] james-project git commit: JAMES-2525 Use a separate Cached ThreadPool for ObjectStorage execution

Posted by bt...@apache.org.
JAMES-2525 Use a separate Cached ThreadPool for ObjectStorage execution


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

Branch: refs/heads/master
Commit: 8c99d0d9e3a86922ef4e426b574e23b1fe017d1c
Parents: 4734f2d
Author: tran tien duc <dt...@linagora.com>
Authored: Tue Nov 27 16:51:53 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 08:01:17 2018 +0700

----------------------------------------------------------------------
 .../james/blob/objectstorage/ObjectStorageBlobsDAO.java  | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8c99d0d9/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 00b9b97..1409aaf 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
@@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.blob.api.BlobId;
@@ -31,6 +33,7 @@ import org.apache.james.blob.api.ObjectStoreException;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage;
+import org.apache.james.util.concurrent.NamedThreadFactory;
 import org.jclouds.blobstore.domain.Blob;
 import org.jclouds.blobstore.options.CopyOptions;
 import org.jclouds.domain.Location;
@@ -54,6 +57,7 @@ public class ObjectStorageBlobsDAO implements BlobStore {
     private final ContainerName containerName;
     private final org.jclouds.blobstore.BlobStore blobStore;
     private final PayloadCodec payloadCodec;
+    private final Executor executor;
 
     ObjectStorageBlobsDAO(ContainerName containerName, BlobId.Factory blobIdFactory,
                           org.jclouds.blobstore.BlobStore blobStore, PayloadCodec payloadCodec) {
@@ -61,6 +65,7 @@ public class ObjectStorageBlobsDAO implements BlobStore {
         this.containerName = containerName;
         this.blobStore = blobStore;
         this.payloadCodec = payloadCodec;
+        this.executor = Executors.newCachedThreadPool(NamedThreadFactory.withClassName(getClass()));
     }
 
     public static ObjectStorageBlobsDAOBuilder.RequireContainerName builder(SwiftTempAuthObjectStorage.Configuration testConfig) {
@@ -102,7 +107,7 @@ public class ObjectStorageBlobsDAO implements BlobStore {
     private CompletableFuture<BlobId> updateBlobId(BlobId from, BlobId to) {
         String containerName = this.containerName.value();
         return CompletableFuture
-            .supplyAsync(() -> blobStore.copyBlob(containerName, from.asString(), containerName, to.asString(), CopyOptions.NONE))
+            .supplyAsync(() -> blobStore.copyBlob(containerName, from.asString(), containerName, to.asString(), CopyOptions.NONE), executor)
             .thenAcceptAsync(any -> blobStore.removeBlob(containerName, from.asString()))
             .thenApply(any -> to);
     }
@@ -114,14 +119,14 @@ public class ObjectStorageBlobsDAO implements BlobStore {
         Blob blob = blobStore.blobBuilder(id.asString()).payload(payload).build();
 
         return CompletableFuture
-            .supplyAsync(() -> blobStore.putBlob(containerName, blob))
+            .supplyAsync(() -> blobStore.putBlob(containerName, blob), executor)
             .thenApply(any -> blobIdFactory.from(hashingInputStream.hash().toString()));
     }
 
     @Override
     public CompletableFuture<byte[]> readBytes(BlobId blobId) {
         return CompletableFuture
-            .supplyAsync(Throwing.supplier(() -> IOUtils.toByteArray(read(blobId))).sneakyThrow());
+            .supplyAsync(Throwing.supplier(() -> IOUtils.toByteArray(read(blobId))).sneakyThrow(), executor);
     }
 
     @Override


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


[18/19] james-project git commit: JAMES-2616 putting User into MailboxEvent, create a DummyMailboxSession to avoid compilation error

Posted by bt...@apache.org.
JAMES-2616 putting User into MailboxEvent, create a DummyMailboxSession to avoid compilation error

And duplicate Constructor for each MailboxEvent impl to expose constructors
with user.


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

Branch: refs/heads/master
Commit: 6ae22a22fe58ee4aaa555a38e62a128a7309c4e7
Parents: b90fcba
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 14:00:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 131 ++++++++++++++++++-
 .../event/AsynchronousEventDeliveryTest.java    |   3 +-
 .../DefaultDelegatingMailboxListenerTest.java   |  20 +--
 .../event/MailboxAnnotationListenerTest.java    |   2 +-
 .../store/event/MixedEventDeliveryTest.java     |   7 +-
 .../event/SynchronousEventDeliveryTest.java     |   3 +-
 6 files changed, 148 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index b38de49..02c5856 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -21,8 +21,11 @@ package org.apache.james.mailbox;
 
 import java.io.Serializable;
 import java.time.Instant;
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
@@ -91,6 +94,11 @@ public interface MailboxListener {
             throw new UnsupportedOperationException("this method will be removed");
         }
 
+        @Override
+        public User getUser() {
+            return user;
+        }
+
         public Quota<QuotaCount> getCountQuota() {
             return countQuota;
         }
@@ -133,17 +141,95 @@ public interface MailboxListener {
      * A mailbox event.
      */
     abstract class MailboxEvent implements Event, Serializable {
+        public static class DummyMailboxSession implements MailboxSession {
+
+            @Override
+            public SessionType getType() {
+                return null;
+            }
+
+            @Override
+            public long getSessionId() {
+                return 0;
+            }
+
+            @Override
+            public boolean isOpen() {
+                return false;
+            }
+
+            @Override
+            public void close() {
+
+            }
+
+            @Override
+            public User getUser() {
+                return null;
+            }
+
+            @Override
+            public String getPersonalSpace() {
+                return null;
+            }
+
+            @Override
+            public String getOtherUsersSpace() {
+                return null;
+            }
+
+            @Override
+            public Collection<String> getSharedSpaces() {
+                return null;
+            }
+
+            @Override
+            public Map<Object, Object> getAttributes() {
+                return null;
+            }
+
+            @Override
+            public char getPathDelimiter() {
+                return 0;
+            }
+        }
+
         private final MailboxSession session;
         private final MailboxPath path;
         private final MailboxId mailboxId;
+        private final User user;
 
         public MailboxEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             this.session = session;
             this.path = path;
             this.mailboxId = mailboxId;
+            // To pass some tests, which pass null MailboxSession to the constructors
+            this.user = Optional.ofNullable(session)
+                .map(MailboxSession::getUser)
+                .map(MailboxSession.User::getCoreUser)
+                .orElse(null);
+        }
+
+        public MailboxEvent(User user, MailboxPath path, MailboxId mailboxId) {
+            this.user = user;
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.session = new DummyMailboxSession();
         }
 
         /**
+         * Gets the {@link User} in which's context the {@link MailboxEvent}
+         * happened
+         *
+         * @return user
+         */
+        @Override
+        public User getUser() {
+            return user;
+        }
+
+
+        /**
          * Gets the {@link MailboxSession} in which's context the {@link MailboxEvent}
          * happened
          * 
@@ -195,6 +281,14 @@ public interface MailboxListener {
             this.totalDeletedSize = totalDeletedSize;
         }
 
+        public MailboxDeletion(User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
+                               MailboxId mailboxId) {
+            super(user, path, mailboxId);
+            this.quotaRoot = quotaRoot;
+            this.deletedMessageCOunt = deletedMessageCOunt;
+            this.totalDeletedSize = totalDeletedSize;
+        }
+
         public QuotaRoot getQuotaRoot() {
             return quotaRoot;
         }
@@ -220,6 +314,10 @@ public interface MailboxListener {
         public MailboxAdded(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
+
+        public MailboxAdded(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
     }
 
     /**
@@ -235,6 +333,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public MailboxRenamed(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Gets the new name for this mailbox.
          * 
@@ -256,6 +358,11 @@ public interface MailboxListener {
             this.aclDiff = aclDiff;
         }
 
+        public MailboxACLUpdated(User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+            this.aclDiff = aclDiff;
+        }
+
         public ACLDiff getAclDiff() {
             return aclDiff;
         }
@@ -276,6 +383,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public MessageEvent(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Gets the message UIDs for the subject of this event.
          * 
@@ -290,6 +401,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public MetaDataHoldingEvent(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Return the flags which were set for the afected message
          *
@@ -309,7 +424,11 @@ public interface MailboxListener {
         public Expunged(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
-        
+
+        public Expunged(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Return the flags which were set for the added message
          * 
@@ -333,6 +452,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public FlagsUpdated(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         public abstract List<UpdatedFlags> getUpdatedFlags();
     }
 
@@ -349,7 +472,11 @@ public interface MailboxListener {
         public Added(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
-        
+
+        public Added(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Return the flags which were set for the added message
          * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
index 7cd2176..44ffae0 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.verify;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.After;
@@ -53,7 +54,7 @@ public class AsynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() throws Exception {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
         asynchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener, timeout(ONE_MINUTE)).event(event);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/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 c9a411a..7442a98 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
@@ -83,7 +83,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -92,7 +92,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -104,9 +104,9 @@ public class DefaultDelegatingMailboxListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount deletedMessageCount = QuotaCount.count(123);
         QuotaSize totalDeletedSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion((MailboxSession) null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -118,9 +118,9 @@ public class DefaultDelegatingMailboxListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion((MailboxSession) null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent((MailboxSession) null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -130,7 +130,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldWork() {
         defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -140,7 +140,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldNotRemoveAListenerFromADifferentPath() {
         defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -150,7 +150,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForONCE() {
         defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).isEmpty();
@@ -160,7 +160,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForEACH_NODE() {
         defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 2f77a8b..9a62834 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -95,7 +95,7 @@ public class MailboxAnnotationListenerTest {
 
     @Test
     public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, MAILBOX_PATH, MAILBOX_ID) {};
         listener.event(event);
 
         verifyNoMoreInteractions(mailboxSessionMapperFactory);

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
index 7eecc59..c2cc095 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
@@ -29,6 +29,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.After;
 import org.junit.Before;
@@ -58,14 +59,14 @@ public class MixedEventDeliveryTest {
     @Test
     public void deliverShouldWorkOnSynchronousListeners() {
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
         mixedEventDelivery.deliver(listener, event);
         verify(listener).event(event);
     }
 
     @Test
     public void deliverShouldEventuallyDeliverOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         mixedEventDelivery.deliver(listener, event);
         verify(listener, timeout(DELIVERY_DELAY * 10)).event(event);
@@ -73,7 +74,7 @@ public class MixedEventDeliveryTest {
 
     @Test(timeout = ONE_MINUTE)
     public void deliverShouldNotBlockOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         final CountDownLatch latch = new CountDownLatch(1);
         doAnswer(invocation -> {

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
index 2b3e90a..4a1ebda 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.Before;
@@ -42,7 +43,7 @@ public class SynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession) null, null, null) {};
         synchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener).event(event);
     }


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


[05/19] james-project git commit: JAMES-2616 replace getSession() in ListeningCurrentQuotaUpdater

Posted by bt...@apache.org.
JAMES-2616 replace getSession() in ListeningCurrentQuotaUpdater


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

Branch: refs/heads/master
Commit: 9ac7d7ae03e622baad9861d95db785a625a18d55
Parents: 543284e
Author: tran tien duc <dt...@linagora.com>
Authored: Fri Nov 30 11:42:17 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:50 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 13 ++++----
 .../james/mailbox/quota/QuotaRootResolver.java  |  2 +-
 .../CassandraMailboxManagerProvider.java        |  2 +-
 .../cassandra/CassandraTestSystemFixture.java   |  5 +--
 .../manager/InMemoryIntegrationResources.java   |  2 +-
 .../InMemoryMessageIdManagerSideEffectTest.java |  2 +-
 .../main/resources/META-INF/spring/quota.xml    |  3 +-
 .../mailbox/store/StoreMailboxManager.java      |  2 +-
 .../store/event/MailboxEventDispatcher.java     |  5 +--
 .../quota/DefaultUserQuotaRootResolver.java     | 10 ++++--
 .../quota/ListeningCurrentQuotaUpdater.java     |  8 ++---
 .../quota/DefaultUserQuotaRootResolverTest.java | 21 +++++++-----
 .../quota/ListeningCurrentQuotaUpdaterTest.java | 35 ++++++++++----------
 .../cassandra/host/CassandraHostSystem.java     |  2 +-
 .../host/ElasticSearchHostSystem.java           |  2 +-
 .../inmemory/host/InMemoryHostSystem.java       |  2 +-
 .../mpt/imapmailbox/jpa/host/JPAHostSystem.java |  2 +-
 .../host/LuceneSearchHostSystem.java            |  4 +--
 .../maildir/host/MaildirHostSystem.java         |  4 +--
 .../transport/matchers/IsOverQuotaTest.java     |  2 +-
 20 files changed, 69 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 5e52828..b38de49 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -24,6 +24,7 @@ import java.time.Instant;
 import java.util.List;
 import java.util.Objects;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.acl.ACLDiff;
@@ -71,14 +72,14 @@ public interface MailboxListener {
     }
 
     class QuotaUsageUpdatedEvent implements QuotaEvent, Serializable {
-        private final MailboxSession session;
+        private final User user;
         private final QuotaRoot quotaRoot;
         private final Quota<QuotaCount> countQuota;
         private final Quota<QuotaSize> sizeQuota;
         private final Instant instant;
 
-        public QuotaUsageUpdatedEvent(MailboxSession session, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota, Instant instant) {
-            this.session = session;
+        public QuotaUsageUpdatedEvent(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota, Instant instant) {
+            this.user = user;
             this.quotaRoot = quotaRoot;
             this.countQuota = countQuota;
             this.sizeQuota = sizeQuota;
@@ -87,7 +88,7 @@ public interface MailboxListener {
 
         @Override
         public MailboxSession getSession() {
-            return session;
+            throw new UnsupportedOperationException("this method will be removed");
         }
 
         public Quota<QuotaCount> getCountQuota() {
@@ -112,7 +113,7 @@ public interface MailboxListener {
             if (o instanceof QuotaUsageUpdatedEvent) {
                 QuotaUsageUpdatedEvent that = (QuotaUsageUpdatedEvent) o;
 
-                return Objects.equals(this.session, that.session)
+                return Objects.equals(this.user, that.user)
                     && Objects.equals(this.quotaRoot, that.quotaRoot)
                     && Objects.equals(this.countQuota, that.countQuota)
                     && Objects.equals(this.sizeQuota, that.sizeQuota)
@@ -123,7 +124,7 @@ public interface MailboxListener {
 
         @Override
         public final int hashCode() {
-            return Objects.hash(session, quotaRoot, countQuota, sizeQuota, instant);
+            return Objects.hash(user, quotaRoot, countQuota, sizeQuota, instant);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
index 38aa4e6..6adff1e 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
@@ -38,7 +38,7 @@ public interface QuotaRootResolver {
      */
     QuotaRoot getQuotaRoot(MailboxPath mailboxPath) throws MailboxException;
 
-    QuotaRoot getQuotaRoot(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException;
+    QuotaRoot getQuotaRoot(MailboxId mailboxId) throws MailboxException;
 
     QuotaRoot fromString(String serializedQuotaRoot) throws MailboxException;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/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 569def8..8f66335 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
@@ -79,7 +79,7 @@ public class CassandraMailboxManagerProvider {
             new CassandraGlobalMaxQuotaDao(session));
         CassandraCurrentQuotaManager currentQuotaUpdater = new CassandraCurrentQuotaManager(session);
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaUpdater, maxQuotaManager);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(manager, mapperFactory);
 
         ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaUpdater, quotaRootResolver, mailboxEventDispatcher, storeQuotaManager);
         manager.setQuotaManager(storeQuotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/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 f89c251..6e70274 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
@@ -73,13 +73,14 @@ public class CassandraTestSystemFixture {
     }
 
     public static StoreMessageIdManager createMessageIdManager(CassandraMailboxSessionMapperFactory mapperFactory, QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception {
+        CassandraMailboxManager mailboxManager = createMailboxManager(mapperFactory);
         return new StoreMessageIdManager(
-            createMailboxManager(mapperFactory),
+            mailboxManager,
             mapperFactory,
             dispatcher,
             new CassandraMessageId.Factory(),
             quotaManager,
-            new DefaultUserQuotaRootResolver(mapperFactory));
+            new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory));
     }
 
     public static MaxQuotaManager createMaxQuotaManager(CassandraCluster cassandra) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/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 e6d6ee8..4255f82 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
@@ -251,7 +251,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
     @Override
     public DefaultUserQuotaRootResolver createQuotaRootResolver(StoreMailboxManager mailboxManager) {
         if (quotaRootResolver == null) {
-            quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
+            quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
         }
         return quotaRootResolver;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
index 43295bd..feba1f4 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
@@ -76,7 +76,7 @@ public class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdMan
             dispatcher,
             messageIdFactory,
             quotaManager,
-            new DefaultUserQuotaRootResolver(mapperFactory));
+            new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory));
         return new MessageIdManagerTestSystem(messageIdManager, messageIdFactory, mapperFactory, mailboxManager);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
index a43f300..faae187 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
@@ -26,7 +26,8 @@
         <constructor-arg index="0" ref="entityManagerFactory" />
     </bean>
     <bean id="defaultQuotaRootResolver" class="org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver" lazy-init="true">
-        <constructor-arg index="0" ref="messageMapperFactory"/>
+        <constructor-arg index="0" ref="mailboxmanager"/>
+        <constructor-arg index="1" ref="messageMapperFactory"/>
     </bean>
 
     <bean id="currentQuotaCalculator" class="org.apache.james.mailbox.store.quota.CurrentQuotaCalculator" lazy-init="true">

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/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 63c30ef..a8fda79 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
@@ -236,7 +236,7 @@ public class StoreMailboxManager implements MailboxManager {
             quotaManager = new NoQuotaManager();
         }
         if (quotaRootResolver == null) {
-            quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxSessionMapperFactory);
+            quotaRootResolver = new DefaultUserQuotaRootResolver(this, mailboxSessionMapperFactory);
         }
         if (quotaUpdater != null && quotaUpdater instanceof MailboxListener) {
             this.addGlobalListener((MailboxListener) quotaUpdater, session);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index d6eee58..206e8b7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -26,6 +26,7 @@ import java.util.SortedMap;
 
 import javax.inject.Inject;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.Event;
@@ -169,8 +170,8 @@ public class MailboxEventDispatcher {
         }
     }
 
-    public void quota(MailboxSession session, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota) {
-        listener.event(new MailboxListener.QuotaUsageUpdatedEvent(session, quotaRoot, countQuota, sizeQuota, Instant.now()));
+    public void quota(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota) {
+        listener.event(new MailboxListener.QuotaUsageUpdatedEvent(user, quotaRoot, countQuota, sizeQuota, Instant.now()));
     }
 
     public void event(Event event) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
index 2340ff1..3d86e2d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
@@ -25,6 +25,7 @@ import java.util.Optional;
 import javax.inject.Inject;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -43,10 +44,12 @@ public class DefaultUserQuotaRootResolver implements UserQuotaRootResolver {
 
     public static final String SEPARATOR = "&"; // Character illegal for mailbox naming in regard of RFC 3501 section 5.1
 
+    private final MailboxManager mailboxManager;
     private final MailboxSessionMapperFactory factory;
 
     @Inject
-    public DefaultUserQuotaRootResolver(MailboxSessionMapperFactory factory) {
+    public DefaultUserQuotaRootResolver(MailboxManager mailboxManager, MailboxSessionMapperFactory factory) {
+        this.mailboxManager = mailboxManager;
         this.factory = factory;
     }
 
@@ -69,9 +72,10 @@ public class DefaultUserQuotaRootResolver implements UserQuotaRootResolver {
     }
 
     @Override
-    public QuotaRoot getQuotaRoot(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
+    public QuotaRoot getQuotaRoot(MailboxId mailboxId) throws MailboxException {
+        MailboxSession session = mailboxManager.createSystemSession("DefaultUserQuotaRootResolver");
         User user = User.fromUsername(
-            factory.getMailboxMapper(mailboxSession)
+            factory.getMailboxMapper(session)
                 .findMailboxById(mailboxId)
                 .generateAssociatedPath()
                 .getUser());

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index 5f9da05..e8f4e54 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -60,11 +60,11 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         try {
             if (event instanceof Added) {
                 Added addedEvent = (Added) event;
-                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId(), event.getSession());
+                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId());
                 handleAddedEvent(addedEvent, quotaRoot);
             } else if (event instanceof Expunged) {
                 Expunged expungedEvent = (Expunged) event;
-                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId(), event.getSession());
+                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId());
                 handleExpungedEvent(expungedEvent, quotaRoot);
             } else if (event instanceof MailboxDeletion) {
                 MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event;
@@ -87,7 +87,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.decrease(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(expunged.getSession(),
+        dispatcher.quota(expunged.getUser(),
             quotaRoot,
             quotaManager.getMessageQuota(quotaRoot),
             quotaManager.getStorageQuota(quotaRoot));
@@ -104,7 +104,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.increase(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(added.getSession(),
+        dispatcher.quota(added.getUser(),
             quotaRoot,
             quotaManager.getMessageQuota(quotaRoot),
             quotaManager.getStorageQuota(quotaRoot));

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
index f5f98ff..52ee7b3 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
@@ -20,11 +20,13 @@
 package org.apache.james.mailbox.store.quota;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.util.Optional;
 
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
@@ -41,7 +43,7 @@ import com.google.common.collect.Lists;
 
 public class DefaultUserQuotaRootResolverTest {
 
-    public static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("benwa", "INBOX");
+    private static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("benwa", "INBOX");
     public static final SimpleMailbox MAILBOX = new SimpleMailbox(MAILBOX_PATH, 10);
     private static final MailboxPath PATH_LIKE = MailboxPath.forUser("benwa", "%");
     private static final MailboxPath MAILBOX_PATH_2 = MailboxPath.forUser("benwa", "test");
@@ -55,8 +57,9 @@ public class DefaultUserQuotaRootResolverTest {
 
     @Before
     public void setUp() {
+        MailboxManager mailboxManager = mock(MailboxManager.class);
         mockedFactory = mock(MailboxSessionMapperFactory.class);
-        testee = new DefaultUserQuotaRootResolver(mockedFactory);
+        testee = new DefaultUserQuotaRootResolver(mailboxManager, mockedFactory);
     }
 
     @Test
@@ -90,18 +93,18 @@ public class DefaultUserQuotaRootResolverTest {
         assertThat(testee.retrieveAssociatedMailboxes(QUOTA_ROOT, MAILBOX_SESSION)).containsOnly(MAILBOX_PATH, MAILBOX_PATH_2);
     }
 
+    @Test(expected = MailboxException.class)
+    public void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times() throws Exception {
+        testee.retrieveAssociatedMailboxes(QuotaRoot.quotaRoot("#private&be&nwa", Optional.empty()), MAILBOX_SESSION);
+    }
+
     @Test
     public void getQuotaRootShouldReturnUserValueWhenCalledWithMailboxId() throws Exception {
         MailboxMapper mockedMapper = mock(MailboxMapper.class);
-        when(mockedFactory.getMailboxMapper(MAILBOX_SESSION)).thenReturn(mockedMapper);
+        when(mockedFactory.getMailboxMapper(any())).thenReturn(mockedMapper);
         when(mockedMapper.findMailboxById(MAILBOX_ID)).thenReturn(MAILBOX);
 
-        assertThat(testee.getQuotaRoot(MAILBOX_ID, MAILBOX_SESSION)).isEqualTo(QUOTA_ROOT);
-    }
-
-    @Test(expected = MailboxException.class)
-    public void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times() throws Exception {
-        testee.retrieveAssociatedMailboxes(QuotaRoot.quotaRoot("#private&be&nwa", Optional.empty()), MAILBOX_SESSION);
+        assertThat(testee.getQuotaRoot(MAILBOX_ID)).isEqualTo(QUOTA_ROOT);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index a14dd30..241b62b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.mailbox.store.quota;
 
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -32,12 +31,11 @@ import java.util.Optional;
 
 import javax.mail.Flags;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
@@ -55,8 +53,9 @@ public class ListeningCurrentQuotaUpdaterTest {
 
     private static final int SIZE = 45;
     private static final MailboxId MAILBOX_ID = TestId.of(42);
-    private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa", Optional.empty());
-    private static final MailboxSession MAILBOX_SESSION = new MockMailboxSession("benwa");
+    private static final String BENWA = "benwa";
+    private static final User USER_BENWA = User.fromUsername(BENWA);
+    private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot(BENWA, Optional.empty());
 
     private StoreCurrentQuotaManager mockedCurrentQuotaManager;
     private QuotaRootResolver mockedQuotaRootResolver;
@@ -73,12 +72,12 @@ public class ListeningCurrentQuotaUpdaterTest {
     @Test
     public void addedEventShouldIncreaseCurrentQuotaValues() throws Exception {
         MailboxListener.Added added = mock(MailboxListener.Added.class);
+        when(added.getMailboxId()).thenReturn(MAILBOX_ID);
         when(added.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
         when(added.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
         when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
-        when(added.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(added.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(added.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(added);
 
@@ -92,8 +91,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         when(expunged.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
         when(expunged.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
         when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(expunged.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(expunged.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(expunged);
 
@@ -105,8 +104,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         MailboxListener.Expunged expunged = mock(MailboxListener.Expunged.class);
         when(expunged.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
         when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(expunged.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(expunged.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(expunged);
 
@@ -118,8 +117,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         MailboxListener.Added added = mock(MailboxListener.Added.class);
         when(added.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
         when(added.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(added.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(added.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(added);
 
@@ -133,8 +132,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(10));
         when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(5));
         when(deletion.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(deletion.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(deletion.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(deletion);
 
@@ -148,8 +147,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(0));
         when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(0));
         when(deletion.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(deletion.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(deletion.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(deletion);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index f40a588..6df19d7 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -92,7 +92,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
         mailboxManager = new CassandraMailboxManager(mapperFactory, authenticator, authorizator,
             new JVMMailboxPathLocker(), new MessageParser(), messageIdFactory,
             mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory);
 
         perUserMaxQuotaManager = new CassandraPerUserMaxQuotaManager(
             new CassandraPerUserMaxQuotaDao(session),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 4186ee9..058c0c9 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -123,7 +123,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
             DefaultImapProcessorFactory.createDefaultProcessor(this.mailboxManager,
                 new StoreSubscriptionManager(factory),
                 new NoQuotaManager(),
-                new DefaultUserQuotaRootResolver(factory),
+                new DefaultUserQuotaRootResolver(mailboxManager, factory),
                 new DefaultMetricFactory());
         configure(new DefaultImapDecoderFactory().buildImapDecoder(),
             new DefaultImapEncoderFactory().buildImapEncoder(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index 2de23d3..3c36732 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -65,7 +65,7 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
         super.beforeTest();
         this.mailboxManager = new InMemoryIntegrationResources()
             .createMailboxManager(new SimpleGroupMembershipResolver(), authenticator, authorizator);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
 
         perUserMaxQuotaManager = new InMemoryPerUserMaxQuotaManager();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
index 3c78b0a..c540145 100644
--- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
+++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
@@ -104,7 +104,7 @@ public class JPAHostSystem extends JamesImapHostSystem {
             messageParser, new DefaultMessageId.Factory(), delegatingListener,
             mailboxEventDispatcher, annotationManager, storeRightManager);
 
-        DefaultUserQuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+        DefaultUserQuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory);
         JpaCurrentQuotaManager currentQuotaManager = new JpaCurrentQuotaManager(entityManagerFactory);
         maxQuotaManager = new JPAPerUserMaxQuotaManager(new JPAPerUserMaxQuotaDAO(entityManagerFactory));
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index 6ebc72f..9161134 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -124,12 +124,12 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
 
             SubscriptionManager subscriptionManager = new StoreSubscriptionManager(mapperFactory);
 
-            final ImapProcessor defaultImapProcessorFactory =
+            ImapProcessor defaultImapProcessorFactory =
                 DefaultImapProcessorFactory.createDefaultProcessor(
                     mailboxManager,
                     subscriptionManager,
                     new NoQuotaManager(),
-                    new DefaultUserQuotaRootResolver(mapperFactory),
+                    new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory),
                     new DefaultMetricFactory());
 
             configure(new DefaultImapDecoderFactory().buildImapDecoder(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
index 4587a5a..a55cf7b 100644
--- a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
+++ b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
@@ -84,12 +84,12 @@ public class MaildirHostSystem extends JamesImapHostSystem {
             mailboxEventDispatcher, delegatingListener, storeRightManager);
         mailboxManager.init();
 
-        final ImapProcessor defaultImapProcessorFactory = 
+        ImapProcessor defaultImapProcessorFactory =
                 DefaultImapProcessorFactory.createDefaultProcessor(
                         mailboxManager, 
                         sm, 
                         new NoQuotaManager(), 
-                        new DefaultUserQuotaRootResolver(mailboxSessionMapperFactory),
+                        new DefaultUserQuotaRootResolver(mailboxManager, mailboxSessionMapperFactory),
                         new DefaultMetricFactory());
         configure(new DefaultImapDecoderFactory().buildImapDecoder(),
                 new DefaultImapEncoderFactory().buildImapEncoder(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
index 25e021f..b25da39 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
@@ -56,7 +56,7 @@ public class IsOverQuotaTest {
     public void setUp() throws Exception {
         mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver());
 
-        quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
+        quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
         maxQuotaManager = new InMemoryPerUserMaxQuotaManager();
         CurrentQuotaCalculator quotaCalculator = new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), quotaRootResolver);
         InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(quotaCalculator, mailboxManager);


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


[06/19] james-project git commit: JAMES-2616 Only MailboxEvent need sessionId, moved sessionId to MailboxEvent

Posted by bt...@apache.org.
JAMES-2616 Only MailboxEvent need sessionId, moved sessionId to MailboxEvent


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

Branch: refs/heads/master
Commit: 4734f2daac49f81c782fb82e7dd4d34e5c8a9358
Parents: d242d9b
Author: tran tien duc <dt...@linagora.com>
Authored: Tue Dec 4 18:35:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/Event.java    |  6 --
 .../apache/james/mailbox/MailboxListener.java   | 26 ++++----
 .../spamassassin/SpamAssassinListenerTest.java  |  5 +-
 .../james/mailbox/store/event/EventFactory.java | 62 ++++++++++----------
 .../store/event/MailboxEventDispatcher.java     | 17 +++---
 .../mailbox/store/event/MessageMoveEvent.java   | 20 +------
 .../event/AsynchronousEventDeliveryTest.java    |  7 +--
 .../DefaultDelegatingMailboxListenerTest.java   | 28 ++++-----
 .../event/MailboxAnnotationListenerTest.java    |  5 +-
 .../store/event/MixedEventDeliveryTest.java     |  7 +--
 .../event/SynchronousEventDeliveryTest.java     |  6 +-
 .../processor/base/SelectedMailboxImpl.java     |  8 +--
 .../base/FakeMailboxListenerAdded.java          |  3 +-
 .../base/FakeMailboxListenerFlagsUpdate.java    |  3 +-
 .../base/MailboxEventAnalyserTest.java          |  4 +-
 15 files changed, 83 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
index 51c1078..bd8073d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/Event.java
@@ -18,15 +18,9 @@
  ****************************************************************/
 package org.apache.james.mailbox;
 
-import java.util.Optional;
-
 import org.apache.james.core.User;
 
 public interface Event {
 
     User getUser();
-
-    default Optional<MailboxSession.SessionId> getSessionId() {
-        return Optional.empty();
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 91c94af..906532e 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -23,7 +23,6 @@ import java.io.Serializable;
 import java.time.Instant;
 import java.util.List;
 import java.util.Objects;
-import java.util.Optional;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
@@ -140,9 +139,9 @@ public interface MailboxListener {
         private final MailboxPath path;
         private final MailboxId mailboxId;
         private final User user;
-        private final Optional<MailboxSession.SessionId> sessionId;
+        private final MailboxSession.SessionId sessionId;
 
-        public MailboxEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxEvent(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             this.user = user;
             this.path = path;
             this.mailboxId = mailboxId;
@@ -166,8 +165,7 @@ public interface MailboxListener {
          *
          * @return sessionId
          */
-        @Override
-        public Optional<MailboxSession.SessionId> getSessionId() {
+        public MailboxSession.SessionId getSessionId() {
             return sessionId;
         }
 
@@ -204,7 +202,7 @@ public interface MailboxListener {
         private final QuotaCount deletedMessageCOunt;
         private final QuotaSize totalDeletedSize;
 
-        public MailboxDeletion(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
+        public MailboxDeletion(MailboxSession.SessionId sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
                                MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
             this.quotaRoot = quotaRoot;
@@ -234,7 +232,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public MailboxAdded(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxAdded(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
     }
@@ -248,7 +246,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public MailboxRenamed(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MailboxRenamed(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -268,7 +266,7 @@ public interface MailboxListener {
         private final ACLDiff aclDiff;
         private static final long serialVersionUID = 1L;
 
-        public MailboxACLUpdated(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
+        public MailboxACLUpdated(MailboxSession.SessionId sessionId, User user, MailboxPath path, ACLDiff aclDiff, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
             this.aclDiff = aclDiff;
         }
@@ -289,7 +287,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public MessageEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MessageEvent(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -303,7 +301,7 @@ public interface MailboxListener {
 
     abstract class MetaDataHoldingEvent extends MessageEvent {
 
-        public MetaDataHoldingEvent(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public MetaDataHoldingEvent(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -323,7 +321,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public Expunged(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public Expunged(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -346,7 +344,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public FlagsUpdated(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public FlagsUpdated(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 
@@ -363,7 +361,7 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public Added(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath path, MailboxId mailboxId) {
+        public Added(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index 9f4c7ae..19e7755 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Date;
-import java.util.Optional;
 
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
@@ -252,7 +251,7 @@ public class SpamAssassinListenerTest {
         SimpleMailboxMessage message = createMessage(inboxId);
         EventFactory eventFactory = new EventFactory();
         AddedImpl addedEvent = eventFactory.new AddedImpl(
-                Optional.of(MAILBOX_SESSION.getSessionId()),
+                MAILBOX_SESSION.getSessionId(),
                 MAILBOX_SESSION.getUser().getCoreUser(),
                 inbox,
                 ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)),
@@ -268,7 +267,7 @@ public class SpamAssassinListenerTest {
         SimpleMailboxMessage message = createMessage(mailboxId1);
         EventFactory eventFactory = new EventFactory();
         AddedImpl addedEvent = eventFactory.new AddedImpl(
-                Optional.of(MAILBOX_SESSION.getSessionId()),
+                MAILBOX_SESSION.getSessionId(),
                 MAILBOX_SESSION.getUser().getCoreUser(),
                 mailbox1,
                 ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)),

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 2b8632e..dd47954 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.store.event;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.SortedMap;
 
 import org.apache.james.core.User;
@@ -55,7 +54,7 @@ public class EventFactory {
         private final Map<MessageUid, MailboxMessage> availableMessages;
         private final Mailbox mailbox;
 
-        public AddedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, SortedMap<MessageUid, MessageMetaData> uids, Map<MessageUid, MailboxMessage> availableMessages) {
+        public AddedImpl(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, SortedMap<MessageUid, MessageMetaData> uids, Map<MessageUid, MailboxMessage> availableMessages) {
             super(sessionId, user, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.added = ImmutableMap.copyOf(uids);
             this.mailbox = mailbox;
@@ -86,7 +85,7 @@ public class EventFactory {
         private final Map<MessageUid, MessageMetaData> uids;
         private final Mailbox mailbox;
 
-        public ExpungedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox,  Map<MessageUid, MessageMetaData> uids) {
+        public ExpungedImpl(MailboxSession.SessionId sessionId, User user, Mailbox mailbox,  Map<MessageUid, MessageMetaData> uids) {
             super(sessionId, user,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.uids = ImmutableMap.copyOf(uids);
             this.mailbox = mailbox;
@@ -115,7 +114,7 @@ public class EventFactory {
 
         private final List<UpdatedFlags> uFlags;
 
-        public FlagsUpdatedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, List<MessageUid> uids, List<UpdatedFlags> uFlags) {
+        public FlagsUpdatedImpl(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, List<MessageUid> uids, List<UpdatedFlags> uFlags) {
             super(sessionId, user, new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.uids = ImmutableList.copyOf(uids);
             this.uFlags = ImmutableList.copyOf(uFlags);
@@ -142,7 +141,7 @@ public class EventFactory {
     public final class MailboxDeletionImpl extends MailboxListener.MailboxDeletion implements MailboxAware {
         private final Mailbox mailbox;
 
-        public MailboxDeletionImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
+        public MailboxDeletionImpl(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
             super(sessionId, user, new StoreMailboxPath(mailbox), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
             this.mailbox = mailbox;
         }
@@ -159,7 +158,7 @@ public class EventFactory {
 
         private final Mailbox mailbox;
 
-        public MailboxAddedImpl(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox) {
+        public MailboxAddedImpl(MailboxSession.SessionId sessionId, User user, Mailbox mailbox) {
             super(sessionId, user,  new StoreMailboxPath(mailbox), mailbox.getMailboxId());
             this.mailbox = mailbox;
         }
@@ -177,7 +176,7 @@ public class EventFactory {
         private final MailboxPath newPath;
         private final Mailbox newMailbox;
 
-        public MailboxRenamedEventImpl(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath oldPath, Mailbox newMailbox) {
+        public MailboxRenamedEventImpl(MailboxSession.SessionId sessionId, User user, MailboxPath oldPath, Mailbox newMailbox) {
             super(sessionId, user, oldPath, newMailbox.getMailboxId());
             this.newPath = new StoreMailboxPath(newMailbox);
             this.newMailbox = newMailbox;
@@ -194,64 +193,67 @@ public class EventFactory {
         }
     }
 
-    public MailboxListener.Added added(Optional<MailboxSession.SessionId> maybeSessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
-        return new AddedImpl(maybeSessionId, user, mailbox, uids, cachedMessages);
+    public MailboxListener.Added added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
+        return added(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox, cachedMessages);
     }
 
     public MailboxListener.Added added(MailboxSession.SessionId sessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
-        return added(Optional.ofNullable(sessionId), user, uids, mailbox, cachedMessages);
+        return new AddedImpl(sessionId, user, mailbox, uids, cachedMessages);
     }
 
-    public MailboxListener.Expunged expunged(Optional<MailboxSession.SessionId> sessionId, User user, Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return new ExpungedImpl(sessionId, user, mailbox, uids);
+    public MailboxListener.Expunged expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
+        return expunged(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox);
     }
 
-    public MailboxListener.Expunged expunged(MailboxSession.SessionId sessionId, User user,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return expunged(Optional.ofNullable(sessionId), user, uids, mailbox);
+    public MailboxListener.Expunged expunged(MailboxSession.SessionId sessionId, User user, Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
+        return new ExpungedImpl(sessionId, user, mailbox, uids);
     }
 
-    public MailboxListener.FlagsUpdated flagsUpdated(Optional<MailboxSession.SessionId> sessionId, User user, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        return new FlagsUpdatedImpl(sessionId, user, mailbox, uids, uflags);
+    public MailboxListener.FlagsUpdated flagsUpdated(MailboxSession session, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
+        return flagsUpdated(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox, uflags);
     }
 
     public MailboxListener.FlagsUpdated flagsUpdated(MailboxSession.SessionId sessionId, User user, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        return flagsUpdated(Optional.ofNullable(sessionId), user, uids, mailbox, uflags);
+        return new FlagsUpdatedImpl(sessionId, user, mailbox, uids, uflags);
     }
 
-    public MailboxListener.MailboxRenamed mailboxRenamed(Optional<MailboxSession.SessionId> sessionId, User user, MailboxPath from, Mailbox to) {
-        return new MailboxRenamedEventImpl(sessionId, user, from, to);
+    public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
+        return mailboxRenamed(session.getSessionId(), session.getUser().getCoreUser(), from, to);
     }
 
     public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession.SessionId sessionId, User user, MailboxPath from, Mailbox to) {
-        return mailboxRenamed(Optional.ofNullable(sessionId), user, from, to);
+        return new MailboxRenamedEventImpl(sessionId, user, from, to);
     }
 
-    public MailboxListener.MailboxDeletion mailboxDeleted(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
+    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot,
                                                           QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return new MailboxDeletionImpl(sessionId, user, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
+        return mailboxDeleted(session.getSessionId(), session.getUser().getCoreUser(), mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
     }
 
     public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
                                                           QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return new MailboxDeletionImpl(Optional.ofNullable(sessionId), user, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
+        return new MailboxDeletionImpl(sessionId, user, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
     }
 
-    public MailboxListener.MailboxAdded mailboxAdded(Optional<MailboxSession.SessionId> sessionId, User user, Mailbox mailbox) {
-        return new MailboxAddedImpl(sessionId, user, mailbox);
+    public MailboxListener.MailboxAdded mailboxAdded(MailboxSession session, Mailbox mailbox) {
+        return mailboxAdded(session.getSessionId(), session.getUser().getCoreUser(), mailbox);
     }
 
     public MailboxListener.MailboxAdded mailboxAdded(MailboxSession.SessionId sessionId, User user, Mailbox mailbox) {
-        return new MailboxAddedImpl(Optional.ofNullable(sessionId), user, mailbox);
+        return new MailboxAddedImpl(sessionId, user, mailbox);
+    }
+
+    public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
+        return aclUpdated(session.getSessionId(), session.getUser().getCoreUser(), mailboxPath, aclDiff, mailboxId);
     }
 
     public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession.SessionId sessionId, User user, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        return new MailboxListener.MailboxACLUpdated(Optional.ofNullable(sessionId), user, mailboxPath, aclDiff, mailboxId);
+        return new MailboxListener.MailboxACLUpdated(sessionId, user, mailboxPath, aclDiff, mailboxId);
     }
 
-    public MessageMoveEvent moved(MailboxSession.SessionId sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
+    public MessageMoveEvent moved(MailboxSession session, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
         return MessageMoveEvent.builder()
-                .sessionId(Optional.ofNullable(sessionId))
-                .user(user)
+                .user(session.getUser().getCoreUser())
                 .messageMoves(messageMoves)
                 .messages(messages)
                 .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index 1ae5ca0..206e8b7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.store.event;
 import java.time.Instant;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.SortedMap;
 
 import javax.inject.Inject;
@@ -83,7 +82,7 @@ public class MailboxEventDispatcher {
      * @param mailbox The mailbox
      */
     public void added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox, Map<MessageUid, MailboxMessage> cachedMessages) {
-        listener.event(eventFactory.added(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox, cachedMessages));
+        listener.event(eventFactory.added(session, uids, mailbox, cachedMessages));
     }
 
     public void added(MailboxSession session, Mailbox mailbox, MailboxMessage mailboxMessage) {
@@ -111,7 +110,7 @@ public class MailboxEventDispatcher {
      */
     public void expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         if (!uids.isEmpty()) {
-            listener.event(eventFactory.expunged(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox));
+            listener.event(eventFactory.expunged(session, uids, mailbox));
         }
     }
 
@@ -128,7 +127,7 @@ public class MailboxEventDispatcher {
      */
     public void flagsUpdated(MailboxSession session, List<MessageUid> uids, Mailbox mailbox, List<UpdatedFlags> uflags) {
         if (!uids.isEmpty()) {
-            listener.event(eventFactory.flagsUpdated(session.getSessionId(), session.getUser().getCoreUser(), uids, mailbox, uflags));
+            listener.event(eventFactory.flagsUpdated(session, uids, mailbox, uflags));
         }
     }
 
@@ -141,7 +140,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        listener.event(eventFactory.mailboxRenamed(session.getSessionId(), session.getUser().getCoreUser(), from, to));
+        listener.event(eventFactory.mailboxRenamed(session, from, to));
     }
 
     /**
@@ -149,7 +148,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        listener.event(eventFactory.mailboxDeleted(session.getSessionId(), session.getUser().getCoreUser(), mailbox, quotaRoot, deletedMessageCount, totalDeletedSize));
+        listener.event(eventFactory.mailboxDeleted(session, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize));
     }
 
     /**
@@ -157,15 +156,15 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        listener.event(eventFactory.mailboxAdded(session.getSessionId(), session.getUser().getCoreUser(), mailbox));
+        listener.event(eventFactory.mailboxAdded(session, mailbox));
     }
 
     public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        listener.event(eventFactory.aclUpdated(session.getSessionId(), session.getUser().getCoreUser(), mailboxPath, aclDiff, mailboxId));
+        listener.event(eventFactory.aclUpdated(session, mailboxPath, aclDiff, mailboxId));
     }
 
     public void moved(MailboxSession session, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
-        MessageMoveEvent moveEvent = eventFactory.moved(session.getSessionId(), session.getUser().getCoreUser(), messageMoves, messages);
+        MessageMoveEvent moveEvent = eventFactory.moved(session, messageMoves, messages);
         if (!moveEvent.isNoop()) {
             listener.event(moveEvent);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
index cb504c9..022303e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MessageMoveEvent.java
@@ -19,7 +19,6 @@
 package org.apache.james.mailbox.store.event;
 
 import java.util.Map;
-import java.util.Optional;
 
 import org.apache.james.core.User;
 import org.apache.james.mailbox.Event;
@@ -41,7 +40,6 @@ public class MessageMoveEvent implements Event {
 
     public static class Builder {
 
-        private Optional<MailboxSession.SessionId> sessionId;
         private User user;
         private MessageMoves messageMoves;
         private ImmutableMap.Builder<MessageUid, MailboxMessage> messagesBuilder;
@@ -51,16 +49,10 @@ public class MessageMoveEvent implements Event {
         }
 
         public Builder session(MailboxSession session) {
-            this.sessionId = Optional.ofNullable(session.getSessionId());
             this.user = session.getUser().getCoreUser();
             return this;
         }
 
-        public Builder sessionId(Optional<MailboxSession.SessionId> sessionId) {
-            this.sessionId = sessionId;
-            return this;
-        }
-
         public Builder user(User user) {
             this.user = user;
             return this;
@@ -77,24 +69,21 @@ public class MessageMoveEvent implements Event {
         }
 
         public MessageMoveEvent build() {
-            Preconditions.checkNotNull(sessionId, "'sessionId' is mandatory");
             Preconditions.checkNotNull(user, "'user' is mandatory");
             Preconditions.checkNotNull(messageMoves, "'messageMoves' is mandatory");
 
             ImmutableMap<MessageUid, MailboxMessage> messages = messagesBuilder.build();
 
-            return new MessageMoveEvent(sessionId, user, messageMoves, messages);
+            return new MessageMoveEvent(user, messageMoves, messages);
         }
     }
 
-    private final Optional<MailboxSession.SessionId> sessionId;
     private final User user;
     private final MessageMoves messageMoves;
     private final Map<MessageUid, MailboxMessage> messages;
 
     @VisibleForTesting
-    MessageMoveEvent(Optional<MailboxSession.SessionId> sessionId, User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
-        this.sessionId = sessionId;
+    MessageMoveEvent(User user, MessageMoves messageMoves, Map<MessageUid, MailboxMessage> messages) {
         this.user = user;
         this.messageMoves = messageMoves;
         this.messages = messages;
@@ -109,11 +98,6 @@ public class MessageMoveEvent implements Event {
         return user;
     }
 
-    @Override
-    public Optional<MailboxSession.SessionId> getSessionId() {
-        return sessionId;
-    }
-
     public MessageMoves getMessageMoves() {
         return messageMoves;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
index 45ef1ea..7331968 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 
-import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
@@ -54,7 +53,7 @@ public class AsynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null, null) {};
         asynchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener, timeout(ONE_MINUTE)).event(event);
     }
@@ -62,7 +61,7 @@ public class AsynchronousEventDeliveryTest {
     @Test
     public void deliverShouldNotPropagateException() {
         MockMailboxSession session = new MockMailboxSession("test");
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(session.getSessionId()),
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(session.getSessionId(),
             session.getUser().getCoreUser(), null, null) {};
         doThrow(new RuntimeException()).when(mailboxListener).event(event);
         asynchronousEventDelivery.deliver(mailboxListener, event);
@@ -72,7 +71,7 @@ public class AsynchronousEventDeliveryTest {
     @Test
     public void deliverShouldWorkWhenThePoolIsFull() {
         MockMailboxSession session = new MockMailboxSession("test");
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(session.getSessionId()),
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(session.getSessionId(),
             session.getUser().getCoreUser(), null, null) {};
         int operationCount = 10;
         for (int i = 0; i < operationCount; i++) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/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 87ce925..a5657de 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
@@ -24,8 +24,6 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.util.Optional;
-
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
@@ -83,7 +81,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -92,7 +90,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -101,12 +99,12 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void mailboxDeletionShouldUnregisterMAILBOXListeners() {
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", null);
         QuotaCount deletedMessageCount = QuotaCount.count(123);
         QuotaSize totalDeletedSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(Optional.empty(), null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -115,12 +113,12 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() {
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", null);
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(Optional.empty(), null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(Optional.empty(), null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -130,7 +128,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldWork() {
         defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -140,7 +138,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldNotRemoveAListenerFromADifferentPath() {
         defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -150,7 +148,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForONCE() {
         defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).isEmpty();
@@ -160,7 +158,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForEACH_NODE() throws Exception {
         defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -170,7 +168,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void listenersErrorsShouldNotBePropageted() throws Exception {
         MailboxSession session = new MockMailboxSession("benwa");
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.of(session.getSessionId()),
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(session.getSessionId(),
             session.getUser().getCoreUser(), MAILBOX_PATH, MAILBOX_ID) {};
         MailboxListener mockedListener = mock(MailboxListener.class);
         when(mockedListener.getType()).thenReturn(MailboxListener.ListenerType.ONCE);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index ea6f4bd..933ed28 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -86,8 +86,7 @@ public class MailboxAnnotationListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
-        deleteEvent = eventFactory.mailboxDeleted(mailboxSession.getSessionId(), mailboxSession.getUser().getCoreUser(),
-            mailbox, quotaRoot, quotaCount, quotaSize);
+        deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, quotaSize);
 
         when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))
             .thenReturn(mailboxSession);
@@ -96,7 +95,7 @@ public class MailboxAnnotationListenerTest {
 
     @Test
     public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, MAILBOX_PATH, MAILBOX_ID) {};
         listener.event(event);
 
         verifyNoMoreInteractions(mailboxSessionMapperFactory);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
index 8c19b3a..3c44dda 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -59,14 +58,14 @@ public class MixedEventDeliveryTest {
     @Test
     public void deliverShouldWorkOnSynchronousListeners() {
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null, null) {};
         mixedEventDelivery.deliver(listener, event);
         verify(listener).event(event);
     }
 
     @Test
     public void deliverShouldEventuallyDeliverOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         mixedEventDelivery.deliver(listener, event);
         verify(listener, timeout(DELIVERY_DELAY * 10)).event(event);
@@ -74,7 +73,7 @@ public class MixedEventDeliveryTest {
 
     @Test(timeout = ONE_MINUTE)
     public void deliverShouldNotBlockOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         final CountDownLatch latch = new CountDownLatch(1);
         doAnswer(invocation -> {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
index 64ad475..cbe0c0a 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
@@ -23,8 +23,6 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import java.util.Optional;
-
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
@@ -44,7 +42,7 @@ public class SynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.empty(), null, null, null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null, null, null) {};
         synchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener).event(event);
     }
@@ -52,7 +50,7 @@ public class SynchronousEventDeliveryTest {
     @Test
     public void deliverShouldNotPropagateException() {
         MockMailboxSession session = new MockMailboxSession("test");
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(session.getSessionId()),
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(session.getSessionId(),
             session.getUser().getCoreUser(),null, null) {};
         doThrow(new RuntimeException()).when(mailboxListener).event(event);
         synchronousEventDelivery.deliver(mailboxListener, event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/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 0ebaac5..23ab486 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
@@ -329,7 +329,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
     private void mailboxEvent(MailboxEvent mailboxEvent) {
         // Check if the event was for the mailbox we are observing
         if (mailboxEvent.getMailboxId().equals(getMailboxId())) {
-            MailboxSession.SessionId eventSessionId = extractSessionId(mailboxEvent);
+            MailboxSession.SessionId eventSessionId = mailboxEvent.getSessionId();
             if (mailboxEvent instanceof MessageEvent) {
                 final MessageEvent messageEvent = (MessageEvent) mailboxEvent;
                 if (messageEvent instanceof Added) {
@@ -407,12 +407,6 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
         }
     }
 
-    private MailboxSession.SessionId extractSessionId(MailboxEvent mailboxEvent) {
-        return mailboxEvent.getSessionId()
-            .orElseThrow(() -> new RuntimeException(String.format("Event of of mailbox %s does not carry sessionId",
-                mailboxEvent.getMailboxId().serialize())));
-    }
-
     @Override
     public synchronized int msn(MessageUid uid) {
         return uidMsnConverter.getMsn(uid).orElse(NO_SUCH_MESSAGE);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
index 320fd36..ac82d1f 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor.base;
 
 import java.util.Date;
 import java.util.List;
-import java.util.Optional;
 
 import javax.mail.Flags;
 
@@ -39,7 +38,7 @@ public class FakeMailboxListenerAdded extends MailboxListener.Added {
     public List<MessageUid> uids;
 
     public FakeMailboxListenerAdded(MailboxSession.SessionId sessionId, User user, List<MessageUid> uids, MailboxPath path, MailboxId mailboxId) {
-        super(Optional.ofNullable(sessionId), user, path, mailboxId);
+        super(sessionId, user, path, mailboxId);
         this.uids = uids;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
index 2ca6120..61ef7fa 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
@@ -20,7 +20,6 @@
 package org.apache.james.imap.processor.base;
 
 import java.util.List;
-import java.util.Optional;
 
 import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener.FlagsUpdated;
@@ -41,7 +40,7 @@ public class FakeMailboxListenerFlagsUpdate extends FlagsUpdated {
     }
 
     FakeMailboxListenerFlagsUpdate(MailboxSession.SessionId sessionId, User user, List<MessageUid> uids, List<UpdatedFlags> flags, MailboxPath path, MailboxId mailboxId) {
-        super(Optional.ofNullable(sessionId), user, path, mailboxId);
+        super(sessionId, user, path, mailboxId);
         this.uids = uids;
         this.flags = flags;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4734f2da/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 5774f57..9d836c2 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -24,8 +24,6 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.util.Optional;
-
 import javax.mail.Flags;
 
 import org.apache.commons.lang3.NotImplementedException;
@@ -126,7 +124,7 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldBeNoSizeChangeOnOtherEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(Optional.ofNullable(MAILBOX_SESSION.getSessionId()),
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(MAILBOX_SESSION.getSessionId(),
             MAILBOX_SESSION.getUser().getCoreUser(), MAILBOX_PATH, MAILBOX_ID) {};
       
         testee.event(event);


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