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 rc...@apache.org on 2020/05/04 10:01:47 UTC

[james-project] branch master updated (ca5389a -> 80d6c1e)

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from ca5389a  JAMES-3105 Expose trustMessageDenormalization over webadmin
     new f7ac1ed  [Refactoring] fix some typos
     new f24e920  [Refactoring] simplify test by leveraging assertj support for java.time types
     new a899a73  [Refactoring] remove formatter from DateResolutionFormatter
     new 4d69f39  [Refactoring] simplify conversion to from Date to Instant
     new a9a8202  [Refactoring] remove javatuples library and replace its single usage by an ad hoc piece of code
     new 117ee4e  [Refactoring] remove joda-time as we don't use it anymore
     new 42f7bc9  [Refactoring] replace a lang3.time.FastDateFormat with a java.time.format.DateTimeFormatter
     new ba70efe  [Refactoring] replace a String[] API with a Set<String> one in some Mailets
     new ea55e5a  [REFACTORING] GetMessagesMethod IntelliJ warnings
     new bc16be7  JAMES-3149 Reactify GetMessages JMAP layer
     new 03ceedd  JAMES-3149 Reactify GetMessages mailbox store layer
     new 4524f2a  JAMES-3149 Reactify MessageViewFactory
     new f3ade3b  JAMES-3149 MessageFastViewProjection should not specify a scheduler
     new 80d6c1e  JAMES-3149 Fix GetMessages method accountId handling

The 14 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/james/mailbox/MessageIdManager.java | 11 ++++
 .../org/apache/james/mailbox/RightManager.java     | 10 +++-
 .../cassandra/mail/CassandraMessageIdMapper.java   | 12 ++--
 .../cassandra/CassandraTestSystemFixture.java      |  1 -
 .../elasticsearch/json/IndexableMessage.java       |  8 ++-
 .../elasticsearch/query/CriterionConverter.java    | 13 +++--
 ...nFormater.java => DateResolutionFormatter.java} |  8 +--
 ...rTest.java => DateResolutionFormatterTest.java} | 53 ++++++-----------
 .../manager/InMemoryIntegrationResources.java      |  2 +-
 .../james/mailbox/store/StoreMailboxManager.java   |  5 ++
 .../james/mailbox/store/StoreMessageIdManager.java | 43 +++++++++-----
 .../james/mailbox/store/StoreRightManager.java     | 13 +++++
 .../james/mailbox/store/mail/MessageIdMapper.java  |  6 ++
 .../java/org/apache/mailet/base/DateFormats.java   | 16 ++----
 .../java/org/apache/mailet/base/GenericMailet.java | 42 +++++---------
 .../james/transport/mailets/AbstractSign.java      |  5 +-
 .../apache/james/transport/mailets/SMIMESign.java  |  9 ++-
 .../org/apache/james/transport/mailets/Sign.java   |  9 ++-
 .../apache/james/transport/mailets/ClamAVScan.java |  8 ++-
 .../cassandra/host/CassandraHostSystem.java        |  2 +-
 pom.xml                                            |  5 --
 .../api/projections/MessageFastViewProjection.java |  4 +-
 .../org/apache/james/transport/mailets/Bounce.java |  8 ++-
 .../apache/james/transport/mailets/DSNBounce.java  | 19 ++++---
 .../apache/james/transport/mailets/Forward.java    |  8 ++-
 .../james/transport/mailets/NotifyPostmaster.java  |  8 ++-
 .../james/transport/mailets/NotifySender.java      |  8 ++-
 .../apache/james/transport/mailets/Redirect.java   |  8 ++-
 .../org/apache/james/transport/mailets/Resend.java |  8 ++-
 .../james/transport/mailets/WhiteListManager.java  |  3 +-
 .../transport/mailets/redirect/MailModifier.java   |  4 +-
 .../transport/mailets/redirect/RedirectNotify.java |  3 +-
 .../james/transport/mailets/DSNBounceTest.java     |  4 +-
 .../jmap-draft-integration-testing-common/pom.xml  |  5 --
 .../cucumber/GetMessagesMethodStepdefs.java        | 13 +----
 .../jmap/draft/methods/GetMessagesMethod.java      | 62 +++++++++-----------
 .../james/jmap/draft/methods/RequestHandler.java   | 22 +++-----
 .../methods/SetMessagesCreationProcessor.java      |  4 +-
 .../model/message/view/MessageFastViewFactory.java | 42 +++++++-------
 .../model/message/view/MessageFullViewFactory.java | 37 +++++++-----
 .../message/view/MessageHeaderViewFactory.java     | 28 +++++----
 .../message/view/MessageMetadataViewFactory.java   | 14 +++--
 .../model/message/view/MessageViewFactory.java     | 41 +++++++-------
 .../jmap/draft/methods/GetMessagesMethodTest.java  |  6 +-
 .../jmap/draft/methods/MessageSenderTest.java      |  2 +-
 .../message/view/MessageFastViewFactoryTest.java   | 19 ++++---
 .../message/view/MessageFullViewFactoryTest.java   | 66 +++++++++++-----------
 .../message/view/MessageHeaderViewFactoryTest.java |  4 +-
 .../view/MessageMetadataViewFactoryTest.java       |  4 +-
 ...mputeMessageFastViewProjectionListenerTest.java |  7 ++-
 50 files changed, 385 insertions(+), 357 deletions(-)
 rename mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/{DateResolutionFormater.java => DateResolutionFormatter.java} (89%)
 rename mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/{DateResolutionFormaterTest.java => DateResolutionFormatterTest.java} (52%)


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


[james-project] 06/14: [Refactoring] remove joda-time as we don't use it anymore

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 117ee4e2732950ac1a53d7666c271f7831106bee
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 22:20:17 2020 +0200

    [Refactoring] remove joda-time as we don't use it anymore
---
 pom.xml | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7b747ff..9524e11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1972,11 +1972,6 @@
             </dependency>
             <dependency>
                 <groupId>com.fasterxml.jackson.datatype</groupId>
-                <artifactId>jackson-datatype-joda</artifactId>
-                <version>${jackson.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>com.fasterxml.jackson.datatype</groupId>
                 <artifactId>jackson-datatype-jsr310</artifactId>
                 <version>${jackson.version}</version>
             </dependency>


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


[james-project] 04/14: [Refactoring] simplify conversion to from Date to Instant

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4d69f39985792e421255996e0e7dd92982e09c58
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 21:30:21 2020 +0200

    [Refactoring] simplify conversion to from Date to Instant
---
 .../james/mailbox/elasticsearch/query/DateResolutionFormatter.java     | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
index 0f88ba2..9528cc0 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.mailbox.elasticsearch.query;
 
-import java.time.Instant;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.temporal.ChronoUnit;
@@ -65,6 +64,6 @@ public class DateResolutionFormatter {
     }
 
     public static ZonedDateTime convertDateToZonedDateTime(Date date) {
-        return ZonedDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
+        return ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
     }
 }
\ No newline at end of file


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


[james-project] 07/14: [Refactoring] replace a lang3.time.FastDateFormat with a java.time.format.DateTimeFormatter

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 42f7bc9064fa27c032cc301554abdb0b7829a49f
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 22:59:04 2020 +0200

    [Refactoring] replace a lang3.time.FastDateFormat with a java.time.format.DateTimeFormatter
---
 .../main/java/org/apache/mailet/base/DateFormats.java    | 16 ++++------------
 .../org/apache/james/transport/mailets/DSNBounce.java    | 13 ++++++++-----
 .../apache/james/transport/mailets/WhiteListManager.java |  3 ++-
 .../james/transport/mailets/redirect/MailModifier.java   |  4 ++--
 .../apache/james/transport/mailets/DSNBounceTest.java    |  4 ++--
 5 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java b/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
index 90abbb1..53d99d0 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
@@ -20,20 +20,12 @@
 
 package org.apache.mailet.base;
 
+import java.time.format.DateTimeFormatter;
 import java.util.Locale;
-import java.util.TimeZone;
 
-import org.apache.commons.lang3.time.FastDateFormat;
+public interface DateFormats {
 
-public class DateFormats {
-
-    public static FastDateFormat getRFC822FormatForTimeZone(TimeZone timeZone) {
-        return FastDateFormat.getInstance("EEE, d MMM yyyy HH:mm:ss 'XXXXX' (z)", timeZone, Locale.US);
-    }
-
-    public static FastDateFormat RFC822_DATE_FORMAT = FastDateFormat.getInstance("EEE, d MMM yyyy HH:mm:ss 'XXXXX' (z)", Locale.US);
-    public static FastDateFormat RFC977_SHORT_DATE_FORMAT = FastDateFormat.getInstance("yyMMdd HHmmss", Locale.US);
-    public static FastDateFormat RFC977_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMdd HHmmss", Locale.US);
-    public static FastDateFormat RFC2980_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss", Locale.US);
+    DateTimeFormatter RFC822_DATE_FORMAT =
+        DateTimeFormatter.ofPattern("EEE, d MMM yyyy HH:mm:ss 'XXXXX' (z)", Locale.US);
 }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
index b916db0..423da7b 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
@@ -21,6 +21,10 @@ package org.apache.james.transport.mailets;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
@@ -33,7 +37,6 @@ import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.james.core.MailAddress;
 import org.apache.james.core.MaybeSender;
 import org.apache.james.dnsservice.api.DNSService;
@@ -119,7 +122,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify {
     private static final AttributeName DELIVERY_ERROR = AttributeName.of("delivery-error");
 
     private final DNSService dns;
-    private final FastDateFormat dateFormatter;
+    private final DateTimeFormatter dateFormatter;
     private String messageString = null;
 
     @Inject
@@ -127,7 +130,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify {
         this(dns, DateFormats.RFC822_DATE_FORMAT);
     }
 
-    public DSNBounce(DNSService dns, FastDateFormat dateFormatter) {
+    public DSNBounce(DNSService dns, DateTimeFormatter dateFormatter) {
         this.dns = dns;
         this.dateFormatter = dateFormatter;
     }
@@ -295,7 +298,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify {
     private String getDateHeader(Mail originalMail) throws MessagingException {
         String[] date = originalMail.getMessage().getHeader(RFC2822Headers.DATE);
         if (date == null) {
-            return dateFormatter.format(new Date());
+            return dateFormatter.format(LocalDateTime.now());
         }
         return date[0];
     }
@@ -415,7 +418,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify {
         buffer.append("Action: failed").append(LINE_BREAK);
         buffer.append("Status: " + deliveryError).append(LINE_BREAK);
         buffer.append("Diagnostic-Code: " + getDiagnosticType(deliveryError) + "; " + deliveryError).append(LINE_BREAK);
-        buffer.append("Last-Attempt-Date: " + dateFormatter.format(lastUpdated))
+        buffer.append("Last-Attempt-Date: " + dateFormatter.format(ZonedDateTime.ofInstant(lastUpdated.toInstant(), ZoneId.systemDefault())))
             .append(LINE_BREAK);
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
index 4e78ea1..2d17c4a 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
@@ -28,6 +28,7 @@ import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.time.LocalDateTime;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -687,7 +688,7 @@ public class WhiteListManager extends GenericMailet {
 
             // Set additional headers
             if (reply.getHeader(RFC2822Headers.DATE) == null) {
-                reply.setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new java.util.Date()));
+                reply.setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(LocalDateTime.now()));
             }
             String subject = message.getSubject();
             if (subject == null) {
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
index cdad611..aa2b79e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
@@ -19,7 +19,7 @@
 package org.apache.james.transport.mailets.redirect;
 
 import java.net.UnknownHostException;
-import java.util.Date;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Optional;
 
@@ -213,7 +213,7 @@ public class MailModifier {
 
     public void initializeDateIfNotPresent() throws MessagingException {
         if (mail.getMessage().getHeader(RFC2822Headers.DATE) == null) {
-            mail.getMessage().setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new Date()));
+            mail.getMessage().setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(LocalDateTime.now()));
         }
     }
 
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
index e3dcd68..176eb60 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
@@ -27,9 +27,9 @@ import static org.mockito.Mockito.when;
 import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
 import java.time.Instant;
+import java.time.ZoneId;
 import java.util.Date;
 import java.util.List;
-import java.util.TimeZone;
 
 import javax.mail.BodyPart;
 import javax.mail.MessagingException;
@@ -74,7 +74,7 @@ public class DSNBounceTest {
         postmaster = new MailAddress("postmaster@domain.com");
         
         DNSService dnsService = mock(DNSService.class);
-        dsnBounce = new DSNBounce(dnsService, DateFormats.getRFC822FormatForTimeZone(TimeZone.getTimeZone("UTC")));
+        dsnBounce = new DSNBounce(dnsService, DateFormats.RFC822_DATE_FORMAT.withZone(ZoneId.of("UTC")));
         fakeMailContext = FakeMailContext.builder().postmaster(postmaster).build();
 
         InetAddress localHost = InetAddress.getLocalHost();


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


[james-project] 02/14: [Refactoring] simplify test by leveraging assertj support for java.time types

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f24e9206cbb3d1a1009c2860244e88cf720134fd
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 21:24:02 2020 +0200

    [Refactoring] simplify test by leveraging assertj support for java.time types
---
 .../query/DateResolutionFormatterTest.java         | 51 +++++++---------------
 1 file changed, 15 insertions(+), 36 deletions(-)

diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java
index 4b6932c..3487439 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java
@@ -30,69 +30,48 @@ import org.junit.jupiter.api.Test;
 
 class DateResolutionFormatterTest {
 
-    final String dateString = "2014-01-02T15:15:15Z";
+    final ZonedDateTime date = ZonedDateTime.parse("2014-01-02T15:15:15Z");
 
     @Test
     void calculateUpperDateShouldReturnDateUpToTheNextMinuteUsingMinuteUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Minute)
-            )
-        ).isEqualTo("2014-01-02T15:16:00Z");
+        assertThat(DateResolutionFormatter.computeUpperDate(date, SearchQuery.DateResolution.Minute))
+            .isEqualTo("2014-01-02T15:16:00Z");
     }
 
     @Test
     void calculateUpperDateShouldReturnDateUpToTheNextHourUsingHourUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Hour)
-            )
-        ).isEqualTo("2014-01-02T16:00:00Z");
+        assertThat(DateResolutionFormatter.computeUpperDate(date, SearchQuery.DateResolution.Hour))
+            .isEqualTo("2014-01-02T16:00:00Z");
     }
 
     @Test
     void calculateUpperDateShouldReturnDateUpToTheNextMonthUsingMonthUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Month)
-            )
-        ).isEqualTo("2014-02-01T00:00:00Z");
+        assertThat(DateResolutionFormatter.computeUpperDate(date, SearchQuery.DateResolution.Month))
+            .isEqualTo("2014-02-01T00:00:00Z");
     }
 
     @Test
     void calculateUpperDateShouldReturnDateUpToTheNextYearUsingYearUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Year)
-            )
-        ).isEqualTo("2015-01-01T00:00:00Z");
+        assertThat(DateResolutionFormatter.computeUpperDate(date, SearchQuery.DateResolution.Year))
+            .isEqualTo("2015-01-01T00:00:00Z");
     }
 
     @Test
     void calculateUpperDateShouldReturnDateUpToTheNextDayUsingDayUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Day)
-            )
-        ).isEqualTo("2014-01-03T00:00:00Z");
+        assertThat(DateResolutionFormatter.computeUpperDate(date, SearchQuery.DateResolution.Day))
+            .isEqualTo("2014-01-03T00:00:00Z");
     }
 
     @Test
     void calculateLowerDateShouldReturnDateUpToThePreviousMinuteUsingMinuteUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeLowerDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Minute)
-            )
-        ).isEqualTo("2014-01-02T15:15:00Z");
+        assertThat(DateResolutionFormatter.computeLowerDate(date, SearchQuery.DateResolution.Minute))
+            .isEqualTo("2014-01-02T15:15:00Z");
     }
 
     @Test
     void calculateLowerDateShouldReturnDateUpToThePreviousDayUsingDayUnit() {
-        assertThat(
-            ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormatter.computeLowerDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Day)
-            )
-        ).isEqualTo("2014-01-02T00:00:00Z");
+        assertThat(DateResolutionFormatter.computeLowerDate(date, SearchQuery.DateResolution.Day))
+            .isEqualTo("2014-01-02T00:00:00Z");
     }
 
 }


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


[james-project] 14/14: JAMES-3149 Fix GetMessages method accountId handling

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 80d6c1eafe70567641a9186406aaa5bce03457a5
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Apr 28 12:01:06 2020 +0700

    JAMES-3149 Fix GetMessages method accountId handling
---
 .../jmap/draft/methods/GetMessagesMethod.java      |  2 +-
 .../james/jmap/draft/methods/RequestHandler.java   | 22 +++++++++-------------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
index dafb5a0..59f2731 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
@@ -114,7 +114,7 @@ public class GetMessagesMethod implements Method {
     }
 
     private Mono<GetMessagesResponse> getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
-        getMessagesRequest.getAccountId().ifPresent((input) -> notImplemented("accountId"));
+        getMessagesRequest.getAccountId().ifPresent(input -> notImplemented("accountId"));
 
         MessageProperties.ReadProfile readProfile = getMessagesRequest.getProperties().computeReadLevel();
         MessageViewFactory<? extends MessageView> factory = messageViewFactory.getFactory(readProfile);
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/RequestHandler.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/RequestHandler.java
index 2b71839..c895a3a 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/RequestHandler.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/RequestHandler.java
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
 
 public class RequestHandler {
 
@@ -75,19 +76,14 @@ public class RequestHandler {
     
     private Function<Method, Flux<JmapResponse>> extractAndProcess(AuthenticatedRequest request) {
         MailboxSession mailboxSession = request.getMailboxSession();
-        return (Method method) -> {
-                    try {
-                        JmapRequest jmapRequest = jmapRequestParser.extractJmapRequest(request, method.requestType());
-                        return method.process(jmapRequest, request.getMethodCallId(), mailboxSession)
-                            .onErrorResume(JmapFieldNotSupportedException.class, e -> errorNotImplemented(e, request));
-                    } catch (IOException e) {
-                        LOGGER.error("Error occured while parsing the request.", e);
-                        if (e.getCause() instanceof JmapFieldNotSupportedException) {
-                            return errorNotImplemented((JmapFieldNotSupportedException) e.getCause(), request);
-                        }
-                        return error(request, generateInvalidArgumentError(e.getMessage()));
-                    }
-                };
+        return (Method method) ->
+            Mono.fromCallable(() -> jmapRequestParser.extractJmapRequest(request, method.requestType()))
+                .flatMapMany(jmapRequest -> method.process(jmapRequest, request.getMethodCallId(), mailboxSession))
+                .onErrorResume(JmapFieldNotSupportedException.class, e -> errorNotImplemented(e, request))
+                .onErrorResume(
+                    e -> e.getCause() instanceof JmapFieldNotSupportedException,
+                    e -> errorNotImplemented((JmapFieldNotSupportedException) e.getCause(), request))
+                .onErrorResume(IOException.class, e -> error(request, generateInvalidArgumentError(e.getMessage())));
     }
 
     public ErrorResponse generateInvalidArgumentError(String description) {


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


[james-project] 10/14: JAMES-3149 Reactify GetMessages JMAP layer

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit bc16be7d001995c4598072eb053b4d9deca9ea68
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Apr 15 10:45:57 2020 +0700

    JAMES-3149 Reactify GetMessages JMAP layer
---
 .../org/apache/james/mailbox/MessageIdManager.java | 10 +++++
 .../jmap/draft/methods/GetMessagesMethod.java      | 52 +++++++++++-----------
 .../model/message/view/MessageFastViewFactory.java | 26 +++++------
 .../model/message/view/MessageFullViewFactory.java |  5 ++-
 .../message/view/MessageHeaderViewFactory.java     |  6 ++-
 .../message/view/MessageMetadataViewFactory.java   |  7 +--
 .../model/message/view/MessageViewFactory.java     | 27 ++++++-----
 7 files changed, 70 insertions(+), 63 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java
index a4548be..b91ec24 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java
@@ -35,6 +35,8 @@ import org.apache.james.mailbox.model.MessageResult;
 
 import com.google.common.collect.ImmutableList;
 
+import reactor.core.publisher.Flux;
+
 public interface MessageIdManager {
 
     Set<MessageId> accessibleMessages(Collection<MessageId> messageIds, final MailboxSession mailboxSession) throws MailboxException;
@@ -43,6 +45,14 @@ public interface MessageIdManager {
 
     List<MessageResult> getMessages(Collection<MessageId> messageIds, FetchGroup minimal, MailboxSession mailboxSession) throws MailboxException;
 
+    default Flux<MessageResult> getMessagesReactive(Collection<MessageId> messageIds, FetchGroup minimal, MailboxSession mailboxSession) {
+        try {
+            return Flux.fromIterable(getMessages(messageIds, minimal, mailboxSession));
+        } catch (MailboxException e) {
+            return Flux.error(e);
+        }
+    }
+
     DeleteResult delete(MessageId messageId, List<MailboxId> mailboxIds, MailboxSession mailboxSession) throws MailboxException;
 
     DeleteResult delete(List<MessageId> messageId, MailboxSession mailboxSession) throws MailboxException;
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
index 2b9a3ab..dafb5a0 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
@@ -19,9 +19,10 @@
 
 package org.apache.james.jmap.draft.methods;
 
+import static org.apache.james.util.ReactorUtils.context;
+
 import java.util.List;
 import java.util.Optional;
-import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
@@ -36,12 +37,8 @@ import org.apache.james.jmap.draft.model.message.view.MessageView;
 import org.apache.james.jmap.draft.model.message.view.MessageViewFactory;
 import org.apache.james.jmap.draft.model.message.view.MetaMessageViewFactory;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageIdManager;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.databind.ser.PropertyFilter;
 import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
@@ -49,6 +46,9 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
 public class GetMessagesMethod implements Method {
 
     public static final String HEADERS_FILTER = "headersFilter";
@@ -75,7 +75,7 @@ public class GetMessagesMethod implements Method {
     }
     
     @Override
-    public Stream<JmapResponse> processToStream(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) {
+    public Flux<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) {
         Preconditions.checkNotNull(request);
         Preconditions.checkNotNull(mailboxSession);
         Preconditions.checkArgument(request instanceof GetMessagesRequest);
@@ -83,21 +83,23 @@ public class GetMessagesMethod implements Method {
         GetMessagesRequest getMessagesRequest = (GetMessagesRequest) request;
         MessageProperties outputProperties = getMessagesRequest.getProperties().toOutputProperties();
 
+        return metricFactory.runPublishingTimerMetricLogP99(JMAP_PREFIX + METHOD_NAME.getName(),
+            () -> Flux.from(getMessagesResponse(mailboxSession, getMessagesRequest)
+                .map(response -> JmapResponse.builder().methodCallId(methodCallId)
+                    .response(response)
+                    .responseName(RESPONSE_NAME)
+                    .properties(outputProperties.getOptionalMessageProperties())
+                    .filterProvider(buildOptionalHeadersFilteringFilterProvider(outputProperties))
+                    .build()))
+            .subscriberContext(context("GET_MESSAGES", mdc(getMessagesRequest))));
+    }
 
+    private MDCBuilder mdc(GetMessagesRequest getMessagesRequest) {
         return MDCBuilder.create()
             .addContext(MDCBuilder.ACTION, "GET_MESSAGES")
             .addContext("accountId", getMessagesRequest.getAccountId())
             .addContext("ids", getMessagesRequest.getIds())
-            .addContext("properties", getMessagesRequest.getProperties())
-            .wrapArround(
-                () -> metricFactory.runPublishingTimerMetricLogP99(JMAP_PREFIX + METHOD_NAME.getName(),
-                    () -> Stream.of(JmapResponse.builder().methodCallId(methodCallId)
-                        .response(getMessagesResponse(mailboxSession, getMessagesRequest))
-                        .responseName(RESPONSE_NAME)
-                        .properties(outputProperties.getOptionalMessageProperties())
-                        .filterProvider(buildOptionalHeadersFilteringFilterProvider(outputProperties))
-                        .build())))
-            .get();
+            .addContext("properties", getMessagesRequest.getProperties());
     }
 
     private Optional<SimpleFilterProvider> buildOptionalHeadersFilteringFilterProvider(MessageProperties properties) {
@@ -111,21 +113,19 @@ public class GetMessagesMethod implements Method {
         return new FieldNamePropertyFilter((fieldName) -> headerProperties.contains(HeaderProperty.fromFieldName(fieldName)));
     }
 
-    private GetMessagesResponse getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
+    private Mono<GetMessagesResponse> getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
         getMessagesRequest.getAccountId().ifPresent((input) -> notImplemented("accountId"));
 
-        try {
-            MessageProperties.ReadProfile readProfile = getMessagesRequest.getProperties().computeReadLevel();
-            MessageViewFactory<? extends MessageView> factory = messageViewFactory.getFactory(readProfile);
-            List<? extends MessageView> messageViews = factory.fromMessageIds(getMessagesRequest.getIds(), mailboxSession);
+        MessageProperties.ReadProfile readProfile = getMessagesRequest.getProperties().computeReadLevel();
+        MessageViewFactory<? extends MessageView> factory = messageViewFactory.getFactory(readProfile);
+        Mono<? extends List<? extends MessageView>> messageViewsMono = factory.fromMessageIds(getMessagesRequest.getIds(), mailboxSession)
+            .collectList();
 
-            return GetMessagesResponse.builder()
+        return messageViewsMono.map(messageViews ->
+            GetMessagesResponse.builder()
                 .messages(messageViews)
                 .expectedMessageIds(getMessagesRequest.getIds())
-                .build();
-        } catch (MailboxException e) {
-            throw new RuntimeException(e);
-        }
+                .build());
     }
 
     private static void notImplemented(String field) {
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
index cbf3c3c..514e666 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
@@ -46,13 +46,11 @@ import org.slf4j.LoggerFactory;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
 
 public class MessageFastViewFactory implements MessageViewFactory<MessageFastView> {
 
@@ -118,13 +116,10 @@ public class MessageFastViewFactory implements MessageViewFactory<MessageFastVie
     }
 
     @Override
-    public List<MessageFastView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
+    public Flux<MessageFastView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
         ImmutableSet<MessageId> messageIdSet = ImmutableSet.copyOf(messageIds);
         return Mono.from(fastViewProjection.retrieve(messageIds))
-            .flatMapMany(fastProjections -> gatherMessageViews(messageIdSet, mailboxSession, fastProjections))
-            .collectList()
-            .subscribeOn(Schedulers.elastic())
-            .block();
+            .flatMapMany(fastProjections -> gatherMessageViews(messageIdSet, mailboxSession, fastProjections));
     }
 
     private Flux<MessageFastView> gatherMessageViews(Set<MessageId> messageIds, MailboxSession mailboxSession,
@@ -132,21 +127,20 @@ public class MessageFastViewFactory implements MessageViewFactory<MessageFastVie
         Set<MessageId> withProjectionEntry = fastProjections.keySet();
         Set<MessageId> withoutProjectionEntry = Sets.difference(messageIds, withProjectionEntry);
         return Flux.merge(
-                fetch(withProjectionEntry, FetchGroup.HEADERS, mailboxSession)
-                    .map(messageResults -> Helpers.toMessageViews(messageResults, new FromMessageResultAndPreview(blobManager, fastProjections))),
-                fetch(withoutProjectionEntry, FetchGroup.FULL_CONTENT, mailboxSession)
-                    .map(messageResults -> Helpers.toMessageViews(messageResults, messageFullViewFactory::fromMessageResults)))
-            .flatMap(Flux::fromIterable);
+            Helpers.toMessageViews(fetch(withProjectionEntry, FetchGroup.HEADERS, mailboxSession),
+                new FromMessageResultAndPreview(blobManager, fastProjections)),
+            Helpers.toMessageViews(fetch(withoutProjectionEntry, FetchGroup.FULL_CONTENT, mailboxSession),
+                messageFullViewFactory::fromMessageResults));
     }
 
-    private Mono<List<MessageResult>> fetch(Collection<MessageId> messageIds, FetchGroup fetchGroup, MailboxSession mailboxSession) {
+    private Flux<MessageResult> fetch(Collection<MessageId> messageIds, FetchGroup fetchGroup, MailboxSession mailboxSession) {
         if (messageIds.isEmpty()) {
-            return Mono.empty();
+            return Flux.empty();
         }
-        return Mono.fromCallable(() -> messageIdManager.getMessages(messageIds, fetchGroup, mailboxSession))
+        return messageIdManager.getMessagesReactive(messageIds, fetchGroup, mailboxSession)
             .onErrorResume(MailboxException.class, ex -> {
                 LOGGER.error("cannot read messages {}", messageIds, ex);
-                return Mono.just(ImmutableList.of());
+                return Flux.empty();
             });
     }
 }
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
index 027090a..ee61d4f 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
@@ -61,6 +61,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.Sets;
 
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
 
@@ -86,8 +87,8 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
     }
 
     @Override
-    public List<MessageFullView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) throws MailboxException {
-        List<MessageResult> messages = messageIdManager.getMessages(messageIds, FetchGroup.FULL_CONTENT, mailboxSession);
+    public Flux<MessageFullView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
+        Flux<MessageResult> messages = messageIdManager.getMessagesReactive(messageIds, FetchGroup.FULL_CONTENT, mailboxSession);
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
index 05f548d..89c6398 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
@@ -40,6 +40,8 @@ import org.apache.james.mime4j.dom.Message;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 
+import reactor.core.publisher.Flux;
+
 public class MessageHeaderViewFactory implements MessageViewFactory<MessageHeaderView> {
     private final BlobManager blobManager;
     private final MessageIdManager messageIdManager;
@@ -52,8 +54,8 @@ public class MessageHeaderViewFactory implements MessageViewFactory<MessageHeade
     }
 
     @Override
-    public List<MessageHeaderView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) throws MailboxException {
-        List<MessageResult> messages = messageIdManager.getMessages(messageIds, FetchGroup.HEADERS, mailboxSession);
+    public Flux<MessageHeaderView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
+        Flux<MessageResult> messages = messageIdManager.getMessagesReactive(messageIds, FetchGroup.HEADERS, mailboxSession);
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
index c17e9dc..3c9d2cf 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
@@ -28,7 +28,6 @@ import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.mailbox.BlobManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
@@ -36,6 +35,8 @@ import org.apache.james.mailbox.model.MessageResult;
 
 import com.google.common.annotations.VisibleForTesting;
 
+import reactor.core.publisher.Flux;
+
 public class MessageMetadataViewFactory implements MessageViewFactory<MessageMetadataView> {
 
     private final BlobManager blobManager;
@@ -49,8 +50,8 @@ public class MessageMetadataViewFactory implements MessageViewFactory<MessageMet
     }
 
     @Override
-    public List<MessageMetadataView> fromMessageIds(List<MessageId> messageIds, MailboxSession session) throws MailboxException {
-        List<MessageResult> messages = messageIdManager.getMessages(messageIds, FetchGroup.MINIMAL, session);
+    public Flux<MessageMetadataView> fromMessageIds(List<MessageId> messageIds, MailboxSession session) {
+        Flux<MessageResult> messages = messageIdManager.getMessagesReactive(messageIds, FetchGroup.MINIMAL, session);
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
index 0025f19..76b8c9a 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
@@ -29,7 +29,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import org.apache.james.jmap.draft.model.Keywords;
 import org.apache.james.jmap.draft.utils.KeywordsCombiner;
@@ -50,6 +49,9 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Multimaps;
 
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
 public interface MessageViewFactory<T extends MessageView> {
 
     Logger LOGGER = LoggerFactory.getLogger(MessageViewFactory.class);
@@ -58,7 +60,7 @@ public interface MessageViewFactory<T extends MessageView> {
     Keywords.KeywordsFactory KEYWORDS_FACTORY = Keywords.lenientFactory();
     String JMAP_MULTIVALUED_FIELD_DELIMITER = "\n";
 
-    List<T> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) throws MailboxException;
+    Flux<T> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession);
 
     class Helpers {
         interface FromMessageResult<T extends MessageView> {
@@ -117,26 +119,23 @@ public interface MessageViewFactory<T extends MessageView> {
                 .collect(Guavate.toImmutableMap(Map.Entry::getKey, bodyConcatenator));
         }
 
-        static <T extends MessageView>  Function<Collection<MessageResult>, Stream<T>> toMessageViews(FromMessageResult<T> converter) {
+        static <T extends MessageView>  Function<Collection<MessageResult>, Mono<T>> toMessageViews(FromMessageResult<T> converter) {
             return messageResults -> {
                 try {
-                    return Stream.of(converter.fromMessageResults(messageResults));
+                    return Mono.just(converter.fromMessageResults(messageResults));
                 } catch (Exception e) {
                     LOGGER.error("Can not convert MessageResults to Message for {}", messageResults.iterator().next().getMessageId().serialize(), e);
-                    return Stream.of();
+                    return Mono.empty();
                 }
             };
         }
 
-        static <T extends MessageView> List<T> toMessageViews(List<MessageResult> messageResults, FromMessageResult<T> converter) {
-            return messageResults.stream()
-                .collect(Guavate.toImmutableListMultimap(MessageResult::getMessageId))
-                .asMap()
-                .values()
-                .stream()
-                .filter(collection -> !collection.isEmpty())
-                .flatMap(toMessageViews(converter))
-                .collect(Guavate.toImmutableList());
+        static <T extends MessageView> Flux<T> toMessageViews(Flux<MessageResult> messageResults, FromMessageResult<T> converter) {
+            return messageResults
+                .groupBy(MessageResult::getMessageId)
+                .filterWhen(Flux::hasElements)
+                .flatMap(Flux::collectList)
+                .flatMap(toMessageViews(converter));
         }
 
         static Instant getDateFromHeaderOrInternalDateOtherwise(Message mimeMessage, MessageResult message) {


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


[james-project] 09/14: [REFACTORING] GetMessagesMethod IntelliJ warnings

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ea55e5a76a45f8f6d9d840ce1d8aae25a00e4343
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Apr 15 10:24:44 2020 +0700

    [REFACTORING] GetMessagesMethod IntelliJ warnings
---
 .../org/apache/james/jmap/draft/methods/GetMessagesMethod.java    | 8 +-------
 .../apache/james/jmap/draft/methods/GetMessagesMethodTest.java    | 2 +-
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
index d16367f..2b9a3ab 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
@@ -53,20 +53,14 @@ public class GetMessagesMethod implements Method {
 
     public static final String HEADERS_FILTER = "headersFilter";
     private static final String ISSUER = "GetMessagesMethod";
-    private static final Logger LOGGER = LoggerFactory.getLogger(GetMessagesMethod.class);
     private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMessages");
     private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messages");
     private final MetaMessageViewFactory messageViewFactory;
-    private final MessageIdManager messageIdManager;
     private final MetricFactory metricFactory;
 
     @Inject
-    @VisibleForTesting GetMessagesMethod(
-            MetaMessageViewFactory messageViewFactory,
-            MessageIdManager messageIdManager,
-            MetricFactory metricFactory) {
+    @VisibleForTesting GetMessagesMethod(MetaMessageViewFactory messageViewFactory, MetricFactory metricFactory) {
         this.messageViewFactory = messageViewFactory;
-        this.messageIdManager = messageIdManager;
         this.metricFactory = metricFactory;
     }
     
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
index 4103ff3..ce487b4 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
@@ -134,7 +134,7 @@ public class GetMessagesMethodTest {
             new MessageHeaderViewFactory(blobManager, messageIdManager),
             messageMetadataViewFactory,
             messageFastViewFactory);
-        testee = new GetMessagesMethod(metaMessageViewFactory, messageIdManager, new DefaultMetricFactory());
+        testee = new GetMessagesMethod(metaMessageViewFactory, new DefaultMetricFactory());
 
         messageContent1 = org.apache.james.mime4j.dom.Message.Builder.of()
             .setSubject("message 1 subject")


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


[james-project] 01/14: [Refactoring] fix some typos

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f7ac1ed343e60389dfde9e5eee2443621443ab51
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 21:09:13 2020 +0200

    [Refactoring] fix some typos
---
 .../mailbox/elasticsearch/json/IndexableMessage.java     |  6 +++---
 .../mailbox/elasticsearch/query/CriterionConverter.java  | 12 ++++++------
 ...olutionFormater.java => DateResolutionFormatter.java} |  4 ++--
 ...ormaterTest.java => DateResolutionFormatterTest.java} | 16 ++++++++--------
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
index 62df164..edd1ad3 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
@@ -30,7 +30,7 @@ import java.util.stream.Stream;
 
 import org.apache.james.mailbox.ModSeq;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.query.DateResolutionFormater;
+import org.apache.james.mailbox.elasticsearch.query.DateResolutionFormatter;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.model.MessageAttachmentMetadata;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -116,7 +116,7 @@ public class IndexableMessage {
             EMailers to = EMailers.from(headerCollection.getToAddressSet());
             EMailers cc = EMailers.from(headerCollection.getCcAddressSet());
             EMailers bcc = EMailers.from(headerCollection.getBccAddressSet());
-            String sentDate = DateResolutionFormater.DATE_TIME_FOMATTER.format(headerCollection.getSentDate().orElse(internalDate));
+            String sentDate = DateResolutionFormatter.DATE_TIME_FORMATTER.format(headerCollection.getSentDate().orElse(internalDate));
             Optional<String> mimeMessageID = headerCollection.getMessageID();
 
             String text = Stream.of(from.serialize(),
@@ -133,7 +133,7 @@ public class IndexableMessage {
             String mailboxId = message.getMailboxId().serialize();
             ModSeq modSeq = message.getModSeq();
             long size = message.getFullContentOctets();
-            String date = DateResolutionFormater.DATE_TIME_FOMATTER.format(getSanitizedInternalDate(message, zoneId));
+            String date = DateResolutionFormatter.DATE_TIME_FORMATTER.format(getSanitizedInternalDate(message, zoneId));
             String mediaType = message.getMediaType();
             String subType = message.getSubType();
             boolean isAnswered = message.isAnswered();
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index bd9bd11..202c27f 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -186,13 +186,13 @@ public class CriterionConverter {
         return boolQuery().filter(
             convertDateOperator(field,
                 dateOperator.getType(),
-                DateResolutionFormater.DATE_TIME_FOMATTER.format(
-                    DateResolutionFormater.computeLowerDate(
-                        DateResolutionFormater.convertDateToZonedDateTime(dateOperator.getDate()),
+                DateResolutionFormatter.DATE_TIME_FORMATTER.format(
+                    DateResolutionFormatter.computeLowerDate(
+                        DateResolutionFormatter.convertDateToZonedDateTime(dateOperator.getDate()),
                         dateOperator.getDateResultion())),
-                DateResolutionFormater.DATE_TIME_FOMATTER.format(
-                    DateResolutionFormater.computeUpperDate(
-                        DateResolutionFormater.convertDateToZonedDateTime(dateOperator.getDate()),
+                DateResolutionFormatter.DATE_TIME_FORMATTER.format(
+                    DateResolutionFormatter.computeUpperDate(
+                        DateResolutionFormatter.convertDateToZonedDateTime(dateOperator.getDate()),
                         dateOperator.getDateResultion()))));
     }
 
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
similarity index 95%
rename from mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java
rename to mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
index 830086f..55b026e 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
@@ -29,9 +29,9 @@ import java.util.Date;
 
 import org.apache.james.mailbox.model.SearchQuery;
 
-public class DateResolutionFormater {
+public class DateResolutionFormatter {
 
-    public static DateTimeFormatter DATE_TIME_FOMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
+    public static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
 
     public static ZonedDateTime computeUpperDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
         return computeLowerDate(date, resolution).plus(1, convertDateResolutionField(resolution));
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java
similarity index 74%
rename from mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
rename to mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java
index f21add2..4b6932c 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatterTest.java
@@ -28,7 +28,7 @@ import org.apache.james.mailbox.model.SearchQuery;
 import org.junit.jupiter.api.Test;
 
 
-class DateResolutionFormaterTest {
+class DateResolutionFormatterTest {
 
     final String dateString = "2014-01-02T15:15:15Z";
 
@@ -36,7 +36,7 @@ class DateResolutionFormaterTest {
     void calculateUpperDateShouldReturnDateUpToTheNextMinuteUsingMinuteUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Minute)
+                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Minute)
             )
         ).isEqualTo("2014-01-02T15:16:00Z");
     }
@@ -45,7 +45,7 @@ class DateResolutionFormaterTest {
     void calculateUpperDateShouldReturnDateUpToTheNextHourUsingHourUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Hour)
+                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Hour)
             )
         ).isEqualTo("2014-01-02T16:00:00Z");
     }
@@ -54,7 +54,7 @@ class DateResolutionFormaterTest {
     void calculateUpperDateShouldReturnDateUpToTheNextMonthUsingMonthUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Month)
+                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Month)
             )
         ).isEqualTo("2014-02-01T00:00:00Z");
     }
@@ -63,7 +63,7 @@ class DateResolutionFormaterTest {
     void calculateUpperDateShouldReturnDateUpToTheNextYearUsingYearUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Year)
+                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Year)
             )
         ).isEqualTo("2015-01-01T00:00:00Z");
     }
@@ -72,7 +72,7 @@ class DateResolutionFormaterTest {
     void calculateUpperDateShouldReturnDateUpToTheNextDayUsingDayUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Day)
+                DateResolutionFormatter.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Day)
             )
         ).isEqualTo("2014-01-03T00:00:00Z");
     }
@@ -81,7 +81,7 @@ class DateResolutionFormaterTest {
     void calculateLowerDateShouldReturnDateUpToThePreviousMinuteUsingMinuteUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeLowerDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Minute)
+                DateResolutionFormatter.computeLowerDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Minute)
             )
         ).isEqualTo("2014-01-02T15:15:00Z");
     }
@@ -90,7 +90,7 @@ class DateResolutionFormaterTest {
     void calculateLowerDateShouldReturnDateUpToThePreviousDayUsingDayUnit() {
         assertThat(
             ISO_OFFSET_DATE_TIME.format(
-                DateResolutionFormater.computeLowerDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Day)
+                DateResolutionFormatter.computeLowerDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Day)
             )
         ).isEqualTo("2014-01-02T00:00:00Z");
     }


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


[james-project] 11/14: JAMES-3149 Reactify GetMessages mailbox store layer

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 03ceeddc552c456c9956ce1c1c19a89591f661ed
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Apr 15 11:00:46 2020 +0700

    JAMES-3149 Reactify GetMessages mailbox store layer
---
 .../org/apache/james/mailbox/MessageIdManager.java |  3 +-
 .../org/apache/james/mailbox/RightManager.java     | 10 +++--
 .../cassandra/mail/CassandraMessageIdMapper.java   | 12 ++++--
 .../cassandra/CassandraTestSystemFixture.java      |  1 -
 .../manager/InMemoryIntegrationResources.java      |  2 +-
 .../james/mailbox/store/StoreMailboxManager.java   |  5 +++
 .../james/mailbox/store/StoreMessageIdManager.java | 43 ++++++++++++++--------
 .../james/mailbox/store/StoreRightManager.java     | 13 +++++++
 .../james/mailbox/store/mail/MessageIdMapper.java  |  6 +++
 .../cassandra/host/CassandraHostSystem.java        |  2 +-
 .../model/message/view/MessageFastViewFactory.java |  2 +-
 .../model/message/view/MessageFullViewFactory.java |  2 +-
 .../message/view/MessageHeaderViewFactory.java     |  2 +-
 .../message/view/MessageMetadataViewFactory.java   |  2 +-
 .../model/message/view/MessageViewFactory.java     |  2 +-
 .../message/view/MessageFastViewFactoryTest.java   | 19 ++++++----
 .../message/view/MessageFullViewFactoryTest.java   |  4 +-
 .../message/view/MessageHeaderViewFactoryTest.java |  4 +-
 .../view/MessageMetadataViewFactoryTest.java       |  4 +-
 ...mputeMessageFastViewProjectionListenerTest.java |  7 ++--
 20 files changed, 97 insertions(+), 48 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java
index b91ec24..92895c4 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageIdManager.java
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageResult;
+import org.reactivestreams.Publisher;
 
 import com.google.common.collect.ImmutableList;
 
@@ -45,7 +46,7 @@ public interface MessageIdManager {
 
     List<MessageResult> getMessages(Collection<MessageId> messageIds, FetchGroup minimal, MailboxSession mailboxSession) throws MailboxException;
 
-    default Flux<MessageResult> getMessagesReactive(Collection<MessageId> messageIds, FetchGroup minimal, MailboxSession mailboxSession) {
+    default Publisher<MessageResult> getMessagesReactive(Collection<MessageId> messageIds, FetchGroup minimal, MailboxSession mailboxSession) {
         try {
             return Flux.fromIterable(getMessages(messageIds, minimal, mailboxSession));
         } catch (MailboxException e) {
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
index 9ba7f87..b37b212 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
@@ -21,9 +21,11 @@ package org.apache.james.mailbox;
 
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.reactivestreams.Publisher;
 
 public interface RightManager {
     /**
@@ -76,7 +78,7 @@ public interface RightManager {
      * @return result suitable for the LISTRIGHTS IMAP command
      * @throws MailboxException in case of unknown mailbox or unsupported right
      */
-    MailboxACL.Rfc4314Rights[] listRights(MailboxPath mailboxPath, MailboxACL.EntryKey identifier, MailboxSession session) throws MailboxException;
+    Rfc4314Rights[] listRights(MailboxPath mailboxPath, MailboxACL.EntryKey identifier, MailboxSession session) throws MailboxException;
 
     MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException;
 
@@ -91,7 +93,7 @@ public interface RightManager {
      *         {@code session.getUser()} is null.
      * @throws MailboxException in case of unknown mailbox or unsupported right
      */
-    MailboxACL.Rfc4314Rights myRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException;
+    Rfc4314Rights myRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException;
 
 
     /**
@@ -105,7 +107,9 @@ public interface RightManager {
      *         {@code session.getUser()} is null.
      * @throws MailboxException in case of unknown mailbox or unsupported right
      */
-    MailboxACL.Rfc4314Rights myRights(MailboxId mailboxId, MailboxSession session) throws MailboxException;
+    Rfc4314Rights myRights(MailboxId mailboxId, MailboxSession session) throws MailboxException;
+
+    Publisher<Rfc4314Rights> myRightsReactive(MailboxId mailboxId, MailboxSession session);
 
     /**
      * Update the Mailbox ACL of the designated mailbox. We can either ADD REPLACE or REMOVE entries.
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
index 25c473c..43b3c7c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
@@ -92,15 +92,19 @@ public class CassandraMessageIdMapper implements MessageIdMapper {
 
     @Override
     public List<MailboxMessage> find(Collection<MessageId> messageIds, FetchType fetchType) {
+        return findReactive(messageIds, fetchType)
+            .collectList()
+            .block();
+    }
+
+    @Override
+    public Flux<MailboxMessage> findReactive(Collection<MessageId> messageIds, FetchType fetchType) {
         return Flux.fromStream(messageIds.stream())
-            .publishOn(Schedulers.elastic())
             .flatMap(messageId -> imapUidDAO.retrieve((CassandraMessageId) messageId, Optional.empty()), cassandraConfiguration.getMessageReadChunkSize())
             .flatMap(composedMessageId -> messageDAO.retrieveMessage(composedMessageId, fetchType), cassandraConfiguration.getMessageReadChunkSize())
             .flatMap(messageRepresentation -> attachmentLoader.addAttachmentToMessage(messageRepresentation, fetchType), cassandraConfiguration.getMessageReadChunkSize())
             .groupBy(MailboxMessage::getMailboxId)
-            .flatMap(this::keepMessageIfMailboxExists)
-            .collectList()
-            .block();
+            .flatMap(this::keepMessageIfMailboxExists);
     }
 
     private Flux<MailboxMessage> keepMessageIfMailboxExists(GroupedFlux<MailboxId, MailboxMessage> groupedFlux) {
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 bf2c2e8..6524206 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
@@ -91,7 +91,6 @@ public class CassandraTestSystemFixture {
             mailboxManager,
             mapperFactory,
             eventBus,
-            new CassandraMessageId.Factory(),
             quotaManager,
             new DefaultUserQuotaRootResolver(mailboxManager.getSessionProvider(), mapperFactory),
             preDeletionHooks);
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 0160d39..a80ff7a 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
@@ -317,7 +317,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
             MailboxManagerPreInstanciationStage preInstanciationStage = new MailboxManagerPreInstanciationStage(mailboxSessionMapperFactory, sessionProvider);
             PreDeletionHooks hooks = createHooks(preInstanciationStage);
             StoreMessageIdManager messageIdManager = new StoreMessageIdManager(storeRightManager, mailboxSessionMapperFactory,
-                eventBus, messageIdFactory, quotaManager, quotaRootResolver, hooks);
+                eventBus, quotaManager, quotaRootResolver, hooks);
 
             StoreAttachmentManager attachmentManager = new StoreAttachmentManager(mailboxSessionMapperFactory, messageIdManager);
             MailboxManagerSearchIndexStage searchIndexStage = new MailboxManagerSearchIndexStage(mailboxSessionMapperFactory, sessionProvider, attachmentManager);
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 165cda0..1f72b2c 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
@@ -773,6 +773,11 @@ public class StoreMailboxManager implements MailboxManager {
     }
 
     @Override
+    public Mono<Rfc4314Rights> myRightsReactive(MailboxId mailboxId, MailboxSession session) {
+        return storeRightManager.myRightsReactive(mailboxId, session);
+    }
+
+    @Override
     public Rfc4314Rights[] listRights(MailboxPath mailboxPath, MailboxACL.EntryKey key, MailboxSession session) throws MailboxException {
         return storeRightManager.listRights(mailboxPath, key, session);
     }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 086cb43..707924a 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.function.Function;
 import java.util.function.Predicate;
 
 import javax.inject.Inject;
@@ -94,19 +95,17 @@ public class StoreMessageIdManager implements MessageIdManager {
     private final RightManager rightManager;
     private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
     private final EventBus eventBus;
-    private final MessageId.Factory messageIdFactory;
     private final QuotaManager quotaManager;
     private final QuotaRootResolver quotaRootResolver;
     private final PreDeletionHooks preDeletionHooks;
 
     @Inject
     public StoreMessageIdManager(RightManager rightManager, MailboxSessionMapperFactory mailboxSessionMapperFactory,
-                                 EventBus eventBus, MessageId.Factory messageIdFactory,
-                                 QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, PreDeletionHooks preDeletionHooks) {
+                                 EventBus eventBus, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver,
+                                 PreDeletionHooks preDeletionHooks) {
         this.rightManager = rightManager;
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
         this.eventBus = eventBus;
-        this.messageIdFactory = messageIdFactory;
         this.quotaManager = quotaManager;
         this.quotaRootResolver = quotaRootResolver;
         this.preDeletionHooks = preDeletionHooks;
@@ -138,18 +137,26 @@ public class StoreMessageIdManager implements MessageIdManager {
     }
 
     @Override
-    public List<MessageResult> getMessages(Collection<MessageId> messageIds, FetchGroup fetchGroup, MailboxSession mailboxSession) throws MailboxException {
-        MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
-
-        MessageMapper.FetchType fetchType = FetchGroupConverter.getFetchType(fetchGroup);
-        List<MailboxMessage> messageList = messageIdMapper.find(messageIds, fetchType);
-
-        ImmutableSet<MailboxId> allowedMailboxIds = getAllowedMailboxIds(mailboxSession, messageList, Right.Read);
+    public List<MessageResult> getMessages(Collection<MessageId> messageIds, FetchGroup fetchGroup, MailboxSession mailboxSession) {
+        return getMessagesReactive(messageIds, fetchGroup, mailboxSession)
+            .collectList()
+            .block();
+    }
 
-        return messageList.stream()
-            .filter(inMailboxes(allowedMailboxIds))
-            .map(Throwing.function(messageResultConverter(fetchGroup)).sneakyThrow())
-            .collect(Guavate.toImmutableList());
+    @Override
+    public Flux<MessageResult> getMessagesReactive(Collection<MessageId> messageIds, FetchGroup fetchGroup, MailboxSession mailboxSession) {
+        try {
+            MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
+
+            MessageMapper.FetchType fetchType = FetchGroupConverter.getFetchType(fetchGroup);
+            return messageIdMapper.findReactive(messageIds, fetchType)
+                .groupBy(MailboxMessage::getMailboxId)
+                .filterWhen(groupedFlux -> hasRightsOnMailboxReactive(mailboxSession, Right.Read).apply(groupedFlux.key()))
+                .flatMap(Function.identity())
+                .map(Throwing.function(messageResultConverter(fetchGroup)).sneakyThrow());
+        } catch (MailboxException e) {
+            return Flux.error(e);
+        }
     }
 
     private ImmutableSet<MailboxId> getAllowedMailboxIds(MailboxSession mailboxSession, List<MailboxMessage> messageList, Right... rights) {
@@ -426,6 +433,12 @@ public class StoreMessageIdManager implements MessageIdManager {
             .fallbackTo(any -> false);
     }
 
+    private Function<MailboxId, Mono<Boolean>> hasRightsOnMailboxReactive(MailboxSession session, Right... rights) {
+        return mailboxId -> Mono.from(rightManager.myRightsReactive(mailboxId, session))
+            .map(myRights -> myRights.contains(rights))
+            .onErrorResume(any -> Mono.just(false));
+    }
+
     private void assertRightsOnMailboxes(Collection<MailboxId> mailboxIds, MailboxSession mailboxSession, Right... rights) throws MailboxNotFoundException {
         Optional<MailboxId> mailboxForbidden = mailboxIds.stream()
             .filter(hasRightsOnMailbox(mailboxSession, rights).negate())
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index 5707f15..1d33f99 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -53,6 +53,8 @@ import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
 
+import reactor.core.publisher.Mono;
+
 public class StoreRightManager implements RightManager {
     public static final boolean GROUP_FOLDER = true;
 
@@ -100,6 +102,17 @@ public class StoreRightManager implements RightManager {
         return myRights(mailbox, session);
     }
 
+    @Override
+    public Mono<Rfc4314Rights> myRightsReactive(MailboxId mailboxId, MailboxSession session) {
+        try {
+            MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
+            return mapper.findMailboxByIdReactive(mailboxId)
+                .map(Throwing.function(mailbox -> myRights(mailbox, session)));
+        } catch (MailboxException e) {
+            return Mono.error(e);
+        }
+    }
+
     public Rfc4314Rights myRights(Mailbox mailbox, MailboxSession session) throws UnsupportedRightException {
         Username username = session.getUser();
 
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
index 094ce72..eeecd30 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
@@ -34,10 +34,16 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 
 import com.google.common.collect.Multimap;
 
+import reactor.core.publisher.Flux;
+
 public interface MessageIdMapper {
 
     List<MailboxMessage> find(Collection<MessageId> messageIds, FetchType fetchType);
 
+    default Flux<MailboxMessage> findReactive(Collection<MessageId> messageIds, FetchType fetchType) {
+        return Flux.fromIterable(find(messageIds, fetchType));
+    }
+
     List<MailboxId> findMailboxes(MessageId messageId);
 
     void save(MailboxMessage mailboxMessage) throws MailboxNotFoundException, MailboxException;
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 4cb76d0..9bd072b 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
@@ -111,7 +111,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
         ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, eventBus, quotaManager);
         QuotaComponents quotaComponents = new QuotaComponents(perUserMaxQuotaManager, quotaManager, quotaRootResolver);
 
-        StoreMessageIdManager messageIdManager = new StoreMessageIdManager(storeRightManager, mapperFactory, eventBus, messageIdFactory, quotaManager, quotaRootResolver, PreDeletionHooks.NO_PRE_DELETION_HOOK);
+        StoreMessageIdManager messageIdManager = new StoreMessageIdManager(storeRightManager, mapperFactory, eventBus, quotaManager, quotaRootResolver, PreDeletionHooks.NO_PRE_DELETION_HOOK);
         StoreAttachmentManager attachmentManager = new StoreAttachmentManager(mapperFactory, messageIdManager);
 
         MessageSearchIndex index = new SimpleMessageSearchIndex(mapperFactory, mapperFactory, new DefaultTextExtractor(), attachmentManager);
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
index 514e666..5de639c 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
@@ -137,7 +137,7 @@ public class MessageFastViewFactory implements MessageViewFactory<MessageFastVie
         if (messageIds.isEmpty()) {
             return Flux.empty();
         }
-        return messageIdManager.getMessagesReactive(messageIds, fetchGroup, mailboxSession)
+        return Flux.from(messageIdManager.getMessagesReactive(messageIds, fetchGroup, mailboxSession))
             .onErrorResume(MailboxException.class, ex -> {
                 LOGGER.error("cannot read messages {}", messageIds, ex);
                 return Flux.empty();
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
index ee61d4f..2752b79 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
@@ -88,7 +88,7 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
 
     @Override
     public Flux<MessageFullView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
-        Flux<MessageResult> messages = messageIdManager.getMessagesReactive(messageIds, FetchGroup.FULL_CONTENT, mailboxSession);
+        Flux<MessageResult> messages = Flux.from(messageIdManager.getMessagesReactive(messageIds, FetchGroup.FULL_CONTENT, mailboxSession));
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
index 89c6398..4d4df61 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
@@ -55,7 +55,7 @@ public class MessageHeaderViewFactory implements MessageViewFactory<MessageHeade
 
     @Override
     public Flux<MessageHeaderView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
-        Flux<MessageResult> messages = messageIdManager.getMessagesReactive(messageIds, FetchGroup.HEADERS, mailboxSession);
+        Flux<MessageResult> messages = Flux.from(messageIdManager.getMessagesReactive(messageIds, FetchGroup.HEADERS, mailboxSession));
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
index 3c9d2cf..15ce8ee 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
@@ -51,7 +51,7 @@ public class MessageMetadataViewFactory implements MessageViewFactory<MessageMet
 
     @Override
     public Flux<MessageMetadataView> fromMessageIds(List<MessageId> messageIds, MailboxSession session) {
-        Flux<MessageResult> messages = messageIdManager.getMessagesReactive(messageIds, FetchGroup.MINIMAL, session);
+        Flux<MessageResult> messages = Flux.from(messageIdManager.getMessagesReactive(messageIds, FetchGroup.MINIMAL, session));
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
index 76b8c9a..88b8efe 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
@@ -133,8 +133,8 @@ public interface MessageViewFactory<T extends MessageView> {
         static <T extends MessageView> Flux<T> toMessageViews(Flux<MessageResult> messageResults, FromMessageResult<T> converter) {
             return messageResults
                 .groupBy(MessageResult::getMessageId)
-                .filterWhen(Flux::hasElements)
                 .flatMap(Flux::collectList)
+                .filter(list -> !list.isEmpty())
                 .flatMap(toMessageViews(converter));
         }
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactoryTest.java
index 3c4d2de..8db9d4a 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactoryTest.java
@@ -27,7 +27,7 @@ import static org.apache.james.jmap.draft.model.message.view.MessageViewFixture.
 import static org.apache.james.jmap.draft.model.message.view.MessageViewFixture.JACOB_EMAIL;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
 import java.util.List;
@@ -64,6 +64,7 @@ import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 class MessageFastViewFactoryTest {
@@ -152,7 +153,7 @@ class MessageFastViewFactoryTest {
 
     @Test
     void fromMessageIdsShouldReturnAMessageWithComputedFastProperties() throws Exception {
-        MessageFastView actual = messageFastViewFactory.fromMessageIds(ImmutableList.of(previewComputedMessage1.getMessageId()), session).get(0);
+        MessageFastView actual = messageFastViewFactory.fromMessageIds(ImmutableList.of(previewComputedMessage1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(actual.getId()).isEqualTo(previewComputedMessage1.getMessageId());
             softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId());
@@ -177,7 +178,7 @@ class MessageFastViewFactoryTest {
 
     @Test
     void fromMessageIdsShouldReturnAMessageWithPropertiesComputedFromFullMessageWhenNotPreComputed() throws Exception {
-        MessageFastView actual = messageFastViewFactory.fromMessageIds(ImmutableList.of(missingPreviewComputedMessage1.getMessageId()), session).get(0);
+        MessageFastView actual = messageFastViewFactory.fromMessageIds(ImmutableList.of(missingPreviewComputedMessage1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(actual.getId()).isEqualTo(missingPreviewComputedMessage1.getMessageId());
             softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId());
@@ -208,7 +209,7 @@ class MessageFastViewFactoryTest {
                     previewComputedMessage3.getMessageId(),
                     missingPreviewComputedMessage1.getMessageId(),
                     previewComputedMessage1.getMessageId()),
-                session);
+                session).collectList().block();
 
         assertThat(actual)
             .hasSize(4)
@@ -221,16 +222,18 @@ class MessageFastViewFactoryTest {
     }
 
     @Test
-    void fromMessageIdsShouldKeepProcessingEvenWhenFetchingFail() throws Exception {
-        doThrow(new MailboxException("mock exception"))
+    void fromMessageIdsShouldKeepProcessingEvenWhenFetchingFail() {
+        doReturn(Flux.error(new MailboxException("mock exception")))
             .doCallRealMethod()
-            .when(messageIdManager).getMessages(any(), any(), any());
+            .when(messageIdManager).getMessagesReactive(any(), any(), any());
 
         List<MessageFastView> actual = messageFastViewFactory
             .fromMessageIds(ImmutableList.of(
                     missingPreviewComputedMessage1.getMessageId(),
                     previewComputedMessage1.getMessageId()),
-                session);
+                session)
+            .collectList().block();
+
 
         assertThat(actual)
             .hasSize(1)
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
index 02b67d2..67eeb92 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
@@ -132,7 +132,7 @@ class MessageFullViewFactoryTest {
 
     @Test
     void fromMessageResultsShouldReturnCorrectView() throws Exception {
-        MessageFullView actual = messageFullViewFactory.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).get(0);
+        MessageFullView actual = messageFullViewFactory.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
             softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId());
@@ -163,7 +163,7 @@ class MessageFullViewFactoryTest {
         messageIdManager.setInMailboxes(message1.getMessageId(), ImmutableList.of(bobInbox.getId(), bobMailbox.getId()), session);
         bobMailbox.setFlags(new Flags(Flags.Flag.FLAGGED), MessageManager.FlagsUpdateMode.REPLACE, MessageRange.all(), session);
 
-        MessageFullView actual = messageFullViewFactory.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).get(0);
+        MessageFullView actual = messageFullViewFactory.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
             softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN, Keyword.FLAGGED).asMap());
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
index b10f4fc..9eda7bc 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
@@ -81,7 +81,7 @@ class MessageHeaderViewFactoryTest {
 
     @Test
     void fromMessageResultsShouldReturnCorrectView() throws Exception {
-        MessageHeaderView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).get(0);
+        MessageHeaderView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
             softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId());
@@ -106,7 +106,7 @@ class MessageHeaderViewFactoryTest {
         messageIdManager.setInMailboxes(message1.getMessageId(), ImmutableList.of(bobInbox.getId(), bobMailbox.getId()), session);
         bobMailbox.setFlags(new Flags(Flags.Flag.FLAGGED), MessageManager.FlagsUpdateMode.REPLACE, MessageRange.all(), session);
 
-        MessageHeaderView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).get(0);
+        MessageHeaderView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
             softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
             softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN, Keyword.FLAGGED).asMap());
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
index 5297c72..19651ec 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
@@ -73,7 +73,7 @@ class MessageMetadataViewFactoryTest {
 
     @Test
     void fromMessageResultsShouldReturnCorrectView() throws Exception {
-        MessageMetadataView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).get(0);
+        MessageMetadataView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
            softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
            softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId());
@@ -89,7 +89,7 @@ class MessageMetadataViewFactoryTest {
         messageIdManager.setInMailboxes(message1.getMessageId(), ImmutableList.of(bobInbox.getId(), bobMailbox.getId()), session);
         bobMailbox.setFlags(new Flags(Flags.Flag.FLAGGED), MessageManager.FlagsUpdateMode.REPLACE, MessageRange.all(), session);
 
-        MessageMetadataView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).get(0);
+        MessageMetadataView actual = testee.fromMessageIds(ImmutableList.of(message1.getMessageId()), session).collectList().block().get(0);
         SoftAssertions.assertSoftly(softly -> {
            softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
            softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN, Keyword.FLAGGED).asMap());
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java
index 98794c1..d6affb2 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java
@@ -21,6 +21,7 @@ package org.apache.james.jmap.event;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.spy;
 
@@ -65,6 +66,7 @@ import org.assertj.core.api.SoftAssertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 class ComputeMessageFastViewProjectionListenerTest {
@@ -266,9 +268,8 @@ class ComputeMessageFastViewProjectionListenerTest {
 
     @Test
     void shouldStoreEventInDeadLettersWhenGetMessagesException() throws Exception {
-        doThrow(new MailboxException())
-            .when(messageIdManager)
-            .getMessages(any(), any(), any());
+        doReturn(Flux.error(new MailboxException("mock exception")))
+            .when(messageIdManager).getMessagesReactive(any(), any(), any());
 
         inboxMessageManager.appendMessage(
             MessageManager.AppendCommand.builder()


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


[james-project] 13/14: JAMES-3149 MessageFastViewProjection should not specify a scheduler

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f3ade3bcd851baafe7dfae91d7f9b608b2367ebb
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Apr 28 11:49:34 2020 +0700

    JAMES-3149 MessageFastViewProjection should not specify a scheduler
---
 .../apache/james/jmap/api/projections/MessageFastViewProjection.java  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjection.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjection.java
index afc3e15..dda6417 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjection.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjection.java
@@ -30,7 +30,6 @@ import com.google.common.base.Preconditions;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
 
 public interface MessageFastViewProjection {
 
@@ -52,7 +51,6 @@ public interface MessageFastViewProjection {
         return Flux.fromIterable(messageIds)
             .flatMap(messageId -> Mono.from(this.retrieve(messageId))
                 .map(preview -> Pair.of(messageId, preview)))
-            .collectMap(Pair::getLeft, Pair::getRight)
-            .subscribeOn(Schedulers.elastic());
+            .collectMap(Pair::getLeft, Pair::getRight);
     }
 }


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


[james-project] 12/14: JAMES-3149 Reactify MessageViewFactory

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4524f2a393a8eb60ab57cf1990d9fd6f004b0f64
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Apr 28 11:48:15 2020 +0700

    JAMES-3149 Reactify MessageViewFactory
---
 .../methods/SetMessagesCreationProcessor.java      |  4 +-
 .../model/message/view/MessageFastViewFactory.java | 16 ++++--
 .../model/message/view/MessageFullViewFactory.java | 32 ++++++-----
 .../message/view/MessageHeaderViewFactory.java     | 22 +++++---
 .../message/view/MessageMetadataViewFactory.java   |  7 +--
 .../model/message/view/MessageViewFactory.java     | 18 +++----
 .../jmap/draft/methods/GetMessagesMethodTest.java  |  4 +-
 .../jmap/draft/methods/MessageSenderTest.java      |  2 +-
 .../message/view/MessageFullViewFactoryTest.java   | 62 +++++++++++-----------
 9 files changed, 95 insertions(+), 72 deletions(-)

diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessor.java
index 09904d6..77c53b6 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessor.java
@@ -287,7 +287,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
     private MessageWithId handleOutboxMessages(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MessagingException, IOException {
         assertUserCanSendFrom(session.getUser(), entry.getValue().getFrom());
         MetaDataWithContent newMessage = messageAppender.appendMessageInMailboxes(entry, toMailboxIds(entry), session);
-        MessageFullView jmapMessage = messageFullViewFactory.fromMetaDataWithContent(newMessage);
+        MessageFullView jmapMessage = messageFullViewFactory.fromMetaDataWithContent(newMessage).block();
         Envelope envelope = EnvelopeUtils.fromMessage(jmapMessage);
         messageSender.sendMessage(newMessage, envelope, session);
         referenceUpdater.updateReferences(entry.getValue().getHeaders(), session);
@@ -306,7 +306,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
 
     private MessageWithId handleDraftMessages(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MessagingException, IOException {
         MetaDataWithContent newMessage = messageAppender.appendMessageInMailboxes(entry, toMailboxIds(entry), session);
-        MessageFullView jmapMessage = messageFullViewFactory.fromMetaDataWithContent(newMessage);
+        MessageFullView jmapMessage = messageFullViewFactory.fromMetaDataWithContent(newMessage).block();
         return new ValueWithId.MessageWithId(entry.getCreationId(), jmapMessage);
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
index 5de639c..fdebb16 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.jmap.draft.model.message.view;
 
-import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -66,16 +65,23 @@ public class MessageFastViewFactory implements MessageViewFactory<MessageFastVie
         }
 
         @Override
-        public MessageFastView fromMessageResults(Collection<MessageResult> messageResults) throws MailboxException, IOException {
+        public Mono<MessageFastView> fromMessageResults(Collection<MessageResult> messageResults) {
             Helpers.assertOneMessageId(messageResults);
             MessageResult firstMessageResult = messageResults.iterator().next();
             Preconditions.checkArgument(fastProjections.containsKey(firstMessageResult.getMessageId()),
                 "FromMessageResultAndPreview usage requires a precomputed preview");
-            MessageFastViewPrecomputedProperties messageProjection = fastProjections.get(firstMessageResult.getMessageId());
-            List<MailboxId> mailboxIds = Helpers.getMailboxIds(messageResults);
 
-            Message mimeMessage = Helpers.parse(firstMessageResult.getFullContent().getInputStream());
+            return Mono.fromCallable(() -> {
+                MessageFastViewPrecomputedProperties messageProjection = fastProjections.get(firstMessageResult.getMessageId());
+                List<MailboxId> mailboxIds = Helpers.getMailboxIds(messageResults);
 
+                Message mimeMessage = Helpers.parse(firstMessageResult.getFullContent().getInputStream());
+
+                return instanciateFastView(messageResults, firstMessageResult, messageProjection, mailboxIds, mimeMessage);
+            });
+        }
+
+        private MessageFastView instanciateFastView(Collection<MessageResult> messageResults, MessageResult firstMessageResult, MessageFastViewPrecomputedProperties messageProjection, List<MailboxId> mailboxIds, Message mimeMessage) {
             return MessageFastView.builder()
                 .id(firstMessageResult.getMessageId())
                 .mailboxIds(mailboxIds)
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
index 2752b79..3f38ad3 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
@@ -56,6 +56,7 @@ import org.apache.james.util.mime.MessageContentExtractor.MessageContent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
@@ -92,18 +93,23 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
-    public MessageFullView fromMetaDataWithContent(MetaDataWithContent message) throws IOException {
-        Message mimeMessage = Helpers.parse(message.getContent());
+    public Mono<MessageFullView> fromMetaDataWithContent(MetaDataWithContent message) {
+        return Mono.fromCallable(() -> Helpers.parse(message.getContent()))
+            .flatMap(Throwing.function(mimeMessage -> fromMetaDataWithContent(message, mimeMessage)));
+    }
+
+    private Mono<MessageFullView> fromMetaDataWithContent(MetaDataWithContent message, Message mimeMessage) throws IOException {
         MessageContent messageContent = messageContentExtractor.extract(mimeMessage);
         Optional<String> htmlBody = messageContent.getHtmlBody();
         Optional<String> mainTextContent = messageContent.extractMainTextContent(htmlTextExtractor);
         Optional<String> textBody = computeTextBodyIfNeeded(messageContent, mainTextContent);
 
-        MessageFastViewPrecomputedProperties messageProjection = retrieveProjection(
-            messageContent,
-            message.getMessageId(),
-            () -> MessageFullView.hasAttachment(getAttachments(message.getAttachments())));
+        return retrieveProjection(messageContent, message.getMessageId(),
+                () -> MessageFullView.hasAttachment(getAttachments(message.getAttachments())))
+            .map(messageProjection -> instanciateMessageFullView(message, mimeMessage, htmlBody, textBody, messageProjection));
+    }
 
+    private MessageFullView instanciateMessageFullView(MetaDataWithContent message, Message mimeMessage, Optional<String> htmlBody, Optional<String> textBody, MessageFastViewPrecomputedProperties messageProjection) {
         return MessageFullView.builder()
                 .id(message.getMessageId())
                 .blobId(BlobId.of(blobManager.toBlobId(message.getMessageId())))
@@ -127,13 +133,11 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
                 .build();
     }
 
-    private MessageFastViewPrecomputedProperties retrieveProjection(MessageContent messageContent,
+    private Mono<MessageFastViewPrecomputedProperties> retrieveProjection(MessageContent messageContent,
                                                                     MessageId messageId, Supplier<Boolean> hasAttachments) {
         return Mono.from(fastViewProjection.retrieve(messageId))
             .onErrorResume(throwable -> fallBackToCompute(messageContent, hasAttachments, throwable))
-            .switchIfEmpty(computeThenStoreAsync(messageContent, messageId, hasAttachments))
-            .subscribeOn(Schedulers.elastic())
-            .block();
+            .switchIfEmpty(computeThenStoreAsync(messageContent, messageId, hasAttachments));
     }
 
     private Mono<MessageFastViewPrecomputedProperties> fallBackToCompute(MessageContent messageContent,
@@ -169,8 +173,12 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
             .orElse(message.getInternalDate());
     }
 
-    public MessageFullView fromMessageResults(Collection<MessageResult> messageResults) throws MailboxException, IOException {
-        return fromMetaDataWithContent(toMetaDataWithContent(messageResults));
+    Mono<MessageFullView> fromMessageResults(Collection<MessageResult> messageResults) {
+        try {
+            return fromMetaDataWithContent(toMetaDataWithContent(messageResults));
+        } catch (MailboxException e) {
+            return Mono.error(e);
+        }
     }
 
     private MetaDataWithContent toMetaDataWithContent(Collection<MessageResult> messageResults) throws MailboxException {
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
index 4d4df61..808f7b8 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.jmap.draft.model.message.view;
 
-import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 
@@ -30,17 +29,18 @@ import org.apache.james.jmap.draft.model.Emailer;
 import org.apache.james.mailbox.BlobManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mime4j.dom.Message;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 
 import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
 
 public class MessageHeaderViewFactory implements MessageViewFactory<MessageHeaderView> {
     private final BlobManager blobManager;
@@ -59,15 +59,21 @@ public class MessageHeaderViewFactory implements MessageViewFactory<MessageHeade
         return Helpers.toMessageViews(messages, this::fromMessageResults);
     }
 
-    private MessageHeaderView fromMessageResults(Collection<MessageResult> messageResults) throws MailboxException, IOException {
+    private Mono<MessageHeaderView> fromMessageResults(Collection<MessageResult> messageResults) {
         Helpers.assertOneMessageId(messageResults);
 
-        MessageResult firstMessageResult = messageResults.iterator().next();
-        List<MailboxId> mailboxIds = Helpers.getMailboxIds(messageResults);
 
-        Message mimeMessage = Helpers.parse(firstMessageResult.getFullContent().getInputStream());
+        return Mono.fromCallable(() -> messageResults.iterator().next())
+            .flatMap(Throwing.function(firstMessageResult -> {
+                List<MailboxId> mailboxIds = Helpers.getMailboxIds(messageResults);
+                Message mimeMessage = Helpers.parse(firstMessageResult.getFullContent().getInputStream());
+                return instanciateHeaderView(messageResults, firstMessageResult, mailboxIds, mimeMessage);
+            }));
+    }
 
-        return MessageHeaderView.messageHeaderBuilder()
+    private Mono<MessageHeaderView> instanciateHeaderView(Collection<MessageResult> messageResults, MessageResult firstMessageResult,
+                                                          List<MailboxId> mailboxIds, Message mimeMessage) {
+        return Mono.just(MessageHeaderView.messageHeaderBuilder()
             .id(firstMessageResult.getMessageId())
             .mailboxIds(mailboxIds)
             .blobId(BlobId.of(blobManager.toBlobId(firstMessageResult.getMessageId())))
@@ -83,6 +89,6 @@ public class MessageHeaderViewFactory implements MessageViewFactory<MessageHeade
             .bcc(Emailer.fromAddressList(mimeMessage.getBcc()))
             .replyTo(Emailer.fromAddressList(mimeMessage.getReplyTo()))
             .date(Helpers.getDateFromHeaderOrInternalDateOtherwise(mimeMessage, firstMessageResult))
-            .build();
+            .build());
     }
 }
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
index 15ce8ee..0114837 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactory.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.model.MessageResult;
 import com.google.common.annotations.VisibleForTesting;
 
 import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
 
 public class MessageMetadataViewFactory implements MessageViewFactory<MessageMetadataView> {
 
@@ -56,20 +57,20 @@ public class MessageMetadataViewFactory implements MessageViewFactory<MessageMet
     }
 
     @VisibleForTesting
-    public MessageMetadataView fromMessageResults(Collection<MessageResult> messageResults) {
+    public Mono<MessageMetadataView> fromMessageResults(Collection<MessageResult> messageResults) {
         Helpers.assertOneMessageId(messageResults);
 
         MessageResult firstMessageResult = messageResults.iterator().next();
         List<MailboxId> mailboxIds = Helpers.getMailboxIds(messageResults);
 
-        return MessageMetadataView.messageMetadataBuilder()
+        return Mono.just(MessageMetadataView.messageMetadataBuilder()
             .id(firstMessageResult.getMessageId())
             .mailboxIds(mailboxIds)
             .blobId(BlobId.of(blobManager.toBlobId(firstMessageResult.getMessageId())))
             .threadId(firstMessageResult.getMessageId().serialize())
             .keywords(Helpers.getKeywords(messageResults))
             .size(firstMessageResult.getSize())
-            .build();
+            .build());
     }
 
 }
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
index 88b8efe..11c9cd3 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageViewFactory.java
@@ -33,7 +33,6 @@ import java.util.stream.Collectors;
 import org.apache.james.jmap.draft.model.Keywords;
 import org.apache.james.jmap.draft.utils.KeywordsCombiner;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageResult;
@@ -41,6 +40,7 @@ import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.MimeConfig;
 import org.apache.james.mime4j.util.MimeUtil;
+import org.apache.james.util.ReactorUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -64,7 +64,7 @@ public interface MessageViewFactory<T extends MessageView> {
 
     class Helpers {
         interface FromMessageResult<T extends MessageView> {
-            T fromMessageResults(Collection<MessageResult> messageResults) throws MailboxException, IOException;
+            Mono<T> fromMessageResults(Collection<MessageResult> messageResults);
         }
 
         static void assertOneMessageId(Collection<MessageResult> messageResults) {
@@ -120,14 +120,12 @@ public interface MessageViewFactory<T extends MessageView> {
         }
 
         static <T extends MessageView>  Function<Collection<MessageResult>, Mono<T>> toMessageViews(FromMessageResult<T> converter) {
-            return messageResults -> {
-                try {
-                    return Mono.just(converter.fromMessageResults(messageResults));
-                } catch (Exception e) {
-                    LOGGER.error("Can not convert MessageResults to Message for {}", messageResults.iterator().next().getMessageId().serialize(), e);
-                    return Mono.empty();
-                }
-            };
+            return messageResults ->
+                converter.fromMessageResults(messageResults)
+                    .doOnEach(ReactorUtils.logOnError(e -> LOGGER.error("Can not convert MessageResults to Message for {}",
+                        messageResults.iterator().next().getMessageId().serialize(),
+                        e)))
+                    .onErrorResume(e -> Mono.empty());
         }
 
         static <T extends MessageView> Flux<T> toMessageViews(Flux<MessageResult> messageResults, FromMessageResult<T> converter) {
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
index ce487b4..9c3554f 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
@@ -89,6 +89,8 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 import com.jayway.jsonpath.JsonPath;
 
+import reactor.core.publisher.Mono;
+
 public class GetMessagesMethodTest {
     private static final String FORWARDED = "forwarded";
     private static final Username ROBERT = Username.of("robert");
@@ -615,7 +617,7 @@ public class GetMessagesMethodTest {
         ComposedMessageId message2 = inbox.appendMessage(AppendCommand.from(messageContent), session).getId();
 
         doCallRealMethod()
-            .doThrow(new RuntimeException())
+            .doReturn(Mono.error(new RuntimeException()))
             .when(messageMetadataViewFactory)
             .fromMessageResults(any());
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java
index fdd95e3..11ce067 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java
@@ -94,7 +94,7 @@ class MessageSenderTest {
         MessageIdManager messageIdManager = mock(MessageIdManager.class);
         MessageFullViewFactory messageFullViewFactory = new MessageFullViewFactory(blobManager, messageContentExtractor, htmlTextExtractor, messageIdManager,
             new MemoryMessageFastViewProjection(new RecordingMetricFactory()));
-        jmapMessage = messageFullViewFactory.fromMetaDataWithContent(message);
+        jmapMessage = messageFullViewFactory.fromMetaDataWithContent(message).block();
         envelope = EnvelopeUtils.fromMessage(jmapMessage);
     }
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
index 67eeb92..975911b 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
@@ -183,7 +183,7 @@ class MessageFullViewFactoryTest {
                 .messageId(TestMessageId.of(2))
                 .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getSize, MessageFullView::getSubject, MessageFullView::getHeaders, MessageFullView::getDate)
             .containsExactly(PreviewDTO.of(""), Number.ZERO, "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
@@ -201,7 +201,7 @@ class MessageFullViewFactoryTest {
                 .mailboxId(MAILBOX_ID)
                 .messageId(TestMessageId.of(2))
                 .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee)
             .extracting(MessageFullView::isIsUnread, MessageFullView::isIsFlagged, MessageFullView::isIsAnswered, MessageFullView::isIsDraft, MessageFullView::isIsForwarded)
             .containsExactly(true, true, true, true, true);
@@ -249,7 +249,7 @@ class MessageFullViewFactoryTest {
                 .put("MIME-Version", "1.0")
                 .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         MessageFullView expected = MessageFullView.builder()
                 .id(TestMessageId.of(2))
                 .blobId(BlobId.of("2"))
@@ -304,7 +304,7 @@ class MessageFullViewFactoryTest {
             .put("To", "user1 <us...@domain>, user2 <us...@domain>")
             .put("MIME-Version", "1.0")
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         MessageFullView expected = MessageFullView.builder()
             .id(TestMessageId.of(2))
             .blobId(BlobId.of("2"))
@@ -355,7 +355,7 @@ class MessageFullViewFactoryTest {
             .put("To", "user1 <us...@domain>")
             .put("MIME-Version", "1.0")
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         MessageFullView expected = MessageFullView.builder()
             .id(TestMessageId.of(2))
             .blobId(BlobId.of("2"))
@@ -393,7 +393,7 @@ class MessageFullViewFactoryTest {
                 .mailboxId(MAILBOX_ID)
                 .messageId(TestMessageId.of(2))
                 .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee.getTextBody()).hasValue("Mail body");
     }
 
@@ -426,7 +426,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getTextBody())
             .isPresent()
@@ -455,7 +455,7 @@ class MessageFullViewFactoryTest {
                 .mailboxId(MAILBOX_ID)
                 .messageId(TestMessageId.of(2))
                 .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee.getPreview())
             .isEqualTo(expectedPreview);
     }
@@ -472,7 +472,7 @@ class MessageFullViewFactoryTest {
                 .mailboxId(MAILBOX_ID)
                 .messageId(TestMessageId.of(2))
                 .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee.getAttachments()).isEmpty();
     }
     
@@ -507,7 +507,7 @@ class MessageFullViewFactoryTest {
                 .messageId(TestMessageId.of(2))
                 .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getAttachments()).hasSize(1);
         assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment);
@@ -531,7 +531,7 @@ class MessageFullViewFactoryTest {
             .messageId(new TestMessageId.Factory().generate())
             .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         Emailer user = Emailer.builder().name("user").email("userdomain").allowInvalid().build();
         Emailer user1 = Emailer.builder().name("user1").email("user1domain").allowInvalid().build();
@@ -560,7 +560,7 @@ class MessageFullViewFactoryTest {
             .messageId(new TestMessageId.Factory().generate())
             .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getFrom()).isEmpty();
     }
@@ -585,7 +585,7 @@ class MessageFullViewFactoryTest {
             .messageId(new TestMessageId.Factory().generate())
             .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getDate())
             .isEqualTo(Instant.parse("2017-05-17T11:18:52.000Z"));
@@ -611,7 +611,7 @@ class MessageFullViewFactoryTest {
             .messageId(new TestMessageId.Factory().generate())
             .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getDate())
             .isEqualTo(Instant.parse("2017-05-17T11:18:52.000Z"));
@@ -636,7 +636,7 @@ class MessageFullViewFactoryTest {
             .messageId(new TestMessageId.Factory().generate())
             .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getDate()).isEqualTo(INTERNAL_DATE);
     }
@@ -654,7 +654,7 @@ class MessageFullViewFactoryTest {
                 .messageId(TestMessageId.of(2))
                 .build();
 
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getSize, MessageFullView::getSubject, MessageFullView::getHeaders, MessageFullView::getDate)
             .containsExactly(PreviewDTO.of(""), Number.fromLong(1010L), "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
@@ -676,7 +676,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getPreview())
             .isEqualTo(PreviewDTO.of("my HTML message"));
@@ -698,7 +698,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getPreview()).isEqualTo(PreviewDTO.of(""));
         assertThat(testee.getHtmlBody()).contains("");
@@ -730,7 +730,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getPreview())
             .isEqualTo(PreviewDTO.of(expected));
@@ -753,7 +753,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee.getPreview())
             .isEqualTo(PreviewDTO.of("My plain text"));
@@ -773,7 +773,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
@@ -797,7 +797,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
@@ -833,7 +833,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
@@ -854,7 +854,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee.getKeywords()).containsAllEntriesOf(keywords.asMap());
     }
 
@@ -872,7 +872,7 @@ class MessageFullViewFactoryTest {
             .mailboxId(MAILBOX_ID)
             .messageId(TestMessageId.of(2))
             .build();
-        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
+        MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail).block();
         assertThat(testee.getKeywords()).containsAllEntriesOf(keywords.asMap());
     }
 
@@ -883,10 +883,12 @@ class MessageFullViewFactoryTest {
         void fromMessageResultsShouldComputeWhenProjectionReturnEmpty() throws Exception {
             List<MessageResult> messages = messageIdManager
                 .getMessages(ImmutableList.of(message1.getMessageId()), FetchGroup.FULL_CONTENT, session);
-            messageFullViewFactory.fromMessageResults(messages);
+            messageFullViewFactory.fromMessageResults(messages).block();
 
             AWAIT_CONDITION.untilAsserted(() ->
-                assertThat(Mono.from(fastViewProjection.retrieve(message1.getMessageId())).block())
+                assertThat(fastViewProjection.retrieve(message1.getMessageId()).blockOptional())
+                    .isPresent()
+                    .get()
                     .extracting(MessageFastViewPrecomputedProperties::getPreview)
                     .isEqualTo(DEFAULT_PREVIEW));
         }
@@ -903,7 +905,7 @@ class MessageFullViewFactoryTest {
             List<MessageResult> messages = messageIdManager
                 .getMessages(ImmutableList.of(message1.getMessageId()), FetchGroup.FULL_CONTENT, session);
 
-            assertThat(messageFullViewFactory.fromMessageResults(messages))
+            assertThat(messageFullViewFactory.fromMessageResults(messages).block())
                 .extracting(MessageFullView::getPreview)
                 .isEqualTo(PreviewDTO.of(preview));
         }
@@ -916,7 +918,7 @@ class MessageFullViewFactoryTest {
             List<MessageResult> messages = messageIdManager
                 .getMessages(ImmutableList.of(message1.getMessageId()), FetchGroup.FULL_CONTENT, session);
 
-            assertThat(messageFullViewFactory.fromMessageResults(messages))
+            assertThat(messageFullViewFactory.fromMessageResults(messages).block())
                 .extracting(MessageFullView::getPreview)
                 .isEqualTo(PreviewDTO.of(DEFAULT_PREVIEW_AS_STRING));
         }
@@ -929,7 +931,7 @@ class MessageFullViewFactoryTest {
             List<MessageResult> messages = messageIdManager
                 .getMessages(ImmutableList.of(message1.getMessageId()), FetchGroup.FULL_CONTENT, session);
 
-            assertThat(messageFullViewFactory.fromMessageResults(messages))
+            assertThat(messageFullViewFactory.fromMessageResults(messages).block())
                 .extracting(MessageFullView::getPreview)
                 .isEqualTo(PreviewDTO.of(DEFAULT_PREVIEW_AS_STRING));
         }


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


[james-project] 08/14: [Refactoring] replace a String[] API with a Set one in some Mailets

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ba70efe8a6e450ecf0887a4932ff5408a931684e
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 23:18:51 2020 +0200

    [Refactoring] replace a String[] API with a Set<String> one in some Mailets
---
 .../java/org/apache/mailet/base/GenericMailet.java | 42 +++++++---------------
 .../james/transport/mailets/AbstractSign.java      |  5 +--
 .../apache/james/transport/mailets/SMIMESign.java  |  9 +++--
 .../org/apache/james/transport/mailets/Sign.java   |  9 +++--
 .../apache/james/transport/mailets/ClamAVScan.java |  8 +++--
 .../org/apache/james/transport/mailets/Bounce.java |  8 +++--
 .../apache/james/transport/mailets/DSNBounce.java  |  6 ++--
 .../apache/james/transport/mailets/Forward.java    |  8 +++--
 .../james/transport/mailets/NotifyPostmaster.java  |  8 +++--
 .../james/transport/mailets/NotifySender.java      |  8 +++--
 .../apache/james/transport/mailets/Redirect.java   |  8 +++--
 .../org/apache/james/transport/mailets/Resend.java |  8 +++--
 .../transport/mailets/redirect/RedirectNotify.java |  3 +-
 13 files changed, 69 insertions(+), 61 deletions(-)

diff --git a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
index 70488b0..dbc167e 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
@@ -20,13 +20,11 @@
 
 package org.apache.mailet.base;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
+import static java.util.function.Predicate.not;
+
 import java.util.Iterator;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.mail.MessagingException;
 
@@ -38,8 +36,10 @@ import org.apache.mailet.MailetContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
+import com.google.common.collect.Streams;
 
 /**
  * GenericMailet makes writing mailets easier. It provides simple
@@ -290,34 +290,18 @@ public abstract class GenericMailet implements Mailet, MailetConfig {
     
     /**
      * Utility method: Checks if there are unallowed init parameters specified in the 
-     * configuration file against the String[] allowedInitParameters.
-     * @param allowedArray array of strings containing the allowed parameter names
+     * configuration file against the allowedInitParameters.
+     * @param allowed List of strings containing the allowed parameter names
      * @throws MessagingException if an unknown parameter name is found
      */
-    protected final void checkInitParameters(String[] allowedArray) throws MessagingException {
-        // if null then no check is requested
-        if (allowedArray == null) {
-            return;
-        }
-        
-        Collection<String> allowed = new HashSet<>();
-        Collection<String> bad = new ArrayList<>();
+    protected final void checkInitParameters(Set<String> allowed) throws MessagingException {
+        Set<String> bad = Streams.stream(getInitParameterNames())
+            .filter(not(allowed::contains))
+            .collect(Guavate.toImmutableSet());
 
-        Collections.addAll(allowed, allowedArray);
-        
-        Iterator<String> iterator = getInitParameterNames();
-        while (iterator.hasNext()) {
-            String parameter = iterator.next();
-            if (!allowed.contains(parameter)) {
-                bad.add(parameter);
-            }
-        }
-        
-        if (bad.size() > 0) {
-            throw new MessagingException("Unexpected init parameters found: " + Arrays.toString(bad.toArray()));
+        if (!bad.isEmpty()) {
+            throw new MessagingException("Unexpected init parameters found: " + bad);
         }
     }
 
 }
-
-
diff --git a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
index 6de0ef5..34a65d7 100644
--- a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
+++ b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.util.Enumeration;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -161,9 +162,9 @@ public abstract class AbstractSign extends GenericMailet {
     
     /**
      * Gets the expected init parameters.
-     * @return An array containing the parameter names allowed for this mailet.
+     * @return A set containing the parameter names allowed for this mailet.
      */
-    protected abstract String[] getAllowedInitParameters();
+    protected abstract Set<String> getAllowedInitParameters();
     
     /* ******************************************************************** */
     /* ****************** Begin of setters and getters ******************** */
diff --git a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/SMIMESign.java b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/SMIMESign.java
index 4ac3061..5a2f8b5 100644
--- a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/SMIMESign.java
+++ b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/SMIMESign.java
@@ -22,6 +22,7 @@
 package org.apache.james.transport.mailets;
 
 import java.io.IOException;
+import java.util.Set;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
@@ -32,6 +33,8 @@ import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * <p>Puts a <I>server-side</I> SMIME signature on a message.
  * It is a concrete subclass of {@link Sign}, with very few modifications to it,
@@ -68,8 +71,8 @@ public class SMIMESign extends Sign {
     }
     
     @Override
-    protected  String[] getAllowedInitParameters() {
-        return new String[]{
+    protected Set<String> getAllowedInitParameters() {
+        return ImmutableSet.of(
             "debug",
             "keyStoreFileName",
             "keyStorePassword",
@@ -80,7 +83,7 @@ public class SMIMESign extends Sign {
             "postmasterSigns",
             "rebuildFrom",
             "explanationText"
-        };
+        );
     }
     
     /* ******************************************************************** */
diff --git a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/Sign.java b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/Sign.java
index 1ea3f84..3f31bdc 100644
--- a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/Sign.java
+++ b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/Sign.java
@@ -22,6 +22,7 @@
 package org.apache.james.transport.mailets;
 
 import java.io.IOException;
+import java.util.Set;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
@@ -32,6 +33,8 @@ import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * <p>Puts a <I>server-side</I> signature on a message.
  * It is a concrete subclass of {@link AbstractSign}, with very few modifications to it.</p>
@@ -74,8 +77,8 @@ public class Sign extends AbstractSign {
     }
     
     @Override
-    protected  String[] getAllowedInitParameters() {
-        return new String[]{
+    protected Set<String> getAllowedInitParameters() {
+        return ImmutableSet.of(
             "keyHolderClass",
             "debug",
             "keyStoreFileName",
@@ -87,7 +90,7 @@ public class Sign extends AbstractSign {
             "postmasterSigns",
             "rebuildFrom",
             "explanationText"
-        };
+        );
     }
     
     /* ******************************************************************** */
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
index 007d468..9ad2565 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
@@ -50,6 +50,8 @@ import org.apache.mailet.base.RFC2822Headers;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableSet;
+
 
 /**
  * <P>Does an antivirus scan check using a ClamAV daemon (CLAMD)</P>
@@ -253,8 +255,8 @@ public class ClamAVScan extends GenericMailet {
     /**
      * Gets the expected init parameters.
      */
-    protected String[] getAllowedInitParameters() {
-        return new String[]{
+    protected Set<String> getAllowedInitParameters() {
+        return ImmutableSet.of(
                 //            "static",
                 "debug",
                 "host",
@@ -262,7 +264,7 @@ public class ClamAVScan extends GenericMailet {
                 "maxPings",
                 "pingIntervalMilli",
                 "streamBufferSize"
-        };
+        );
     }
 
     /**
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
index f2072d8..436d910 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -47,6 +48,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -125,8 +127,8 @@ import com.google.common.collect.ImmutableList;
 public class Bounce extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(Bounce.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[] {
-            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of(
+            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError");
     private static final List<MailAddress> RECIPIENTS = ImmutableList.of(SpecialAddress.REVERSE_PATH);
     private static final List<InternetAddress> TO = ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress());
     private final DNSService dns;
@@ -147,7 +149,7 @@ public class Bounce extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
index 423da7b..6354d32 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
@@ -28,6 +28,7 @@ import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import javax.inject.Inject;
@@ -67,6 +68,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -111,7 +113,7 @@ import com.google.common.collect.ImmutableList;
 public class DSNBounce extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(DSNBounce.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[]{ "debug", "passThrough", "messageString", "attachment", "sender", "prefix" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of("debug", "passThrough", "messageString", "attachment", "sender", "prefix");
     private static final List<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableList.of(SpecialAddress.REVERSE_PATH);
     private static final List<InternetAddress> TO_INTERNET_ADDRESSES = ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress());
 
@@ -165,7 +167,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
index 517a2ae..60b0a60 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -47,6 +48,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -95,8 +97,8 @@ import com.google.common.collect.ImmutableList;
 public class Forward extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(Forward.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[] {
-            "debug", "passThrough", "fakeDomainCheck", "forwardto", "forwardTo" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of(
+            "debug", "passThrough", "fakeDomainCheck", "forwardto", "forwardTo");
     private static final List<String> ALLOWED_SPECIALS = ImmutableList.of(
             "postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null");
     private final DNSService dns;
@@ -117,7 +119,7 @@ public class Forward extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
index ec6cdcf..58035e4 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -49,6 +50,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -125,8 +127,8 @@ import com.google.common.collect.ImmutableList;
 public class NotifyPostmaster extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(NotifyPostmaster.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[]{
-            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", "to" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of(
+            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", "to");
     private static final List<String> ALLOWED_SPECIALS = ImmutableList.of("postmaster", "unaltered");
 
     private final DNSService dns;
@@ -154,7 +156,7 @@ public class NotifyPostmaster extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
index 6a9d22b..eae9b49 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -49,6 +50,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -124,8 +126,8 @@ import com.google.common.collect.ImmutableList;
 public class NotifySender extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(NotifySender.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[]{
-            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", "to" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of(
+            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", "to");
     private static final List<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableList.of(SpecialAddress.SENDER);
     private static final List<String> ALLOWED_SPECIALS = ImmutableList.of("sender", "unaltered", "from");
 
@@ -154,7 +156,7 @@ public class NotifySender extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
index ae941e1..c4fd907 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -48,6 +49,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -303,8 +305,8 @@ import com.google.common.collect.ImmutableList;
 public class Redirect extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(Redirect.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[] {
-            "static", "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "recipients", "to", "replyTo", "replyto", "reversePath", "sender", "subject", "prefix", "attachError", "isReply" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of(
+            "static", "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "recipients", "to", "replyTo", "replyto", "reversePath", "sender", "subject", "prefix", "attachError", "isReply");
     private static final List<String> ALLOWED_SPECIALS = ImmutableList.of(
             "postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null");
     private final DNSService dns;
@@ -325,7 +327,7 @@ public class Redirect extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
index 1975c9a..1b13c81 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -47,6 +48,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * <p>
@@ -298,8 +300,8 @@ import com.google.common.collect.ImmutableList;
 public class Resend extends GenericMailet implements RedirectNotify {
     private static final Logger LOGGER = LoggerFactory.getLogger(Resend.class);
 
-    private static final String[] CONFIGURABLE_PARAMETERS = new String[] {
-            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "recipients", "to", "replyTo", "replyto", "reversePath", "sender", "subject", "prefix", "attachError", "isReply" };
+    private static final ImmutableSet<String> CONFIGURABLE_PARAMETERS = ImmutableSet.of(
+            "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "recipients", "to", "replyTo", "replyto", "reversePath", "sender", "subject", "prefix", "attachError", "isReply");
     private final DNSService dns;
 
     @Inject
@@ -318,7 +320,7 @@ public class Resend extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public String[] getAllowedInitParameters() {
+    public Set<String> getAllowedInitParameters() {
         return CONFIGURABLE_PARAMETERS;
     }
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
index 0bf1d25..4089d88 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets.redirect;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetAddress;
@@ -141,7 +142,7 @@ public interface RedirectNotify extends Mailet, MailetConfig {
 
     InitParameters getInitParameters();
 
-    String[] getAllowedInitParameters();
+    Set<String> getAllowedInitParameters();
 
     DNSService getDNSService();
 


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


[james-project] 03/14: [Refactoring] remove formatter from DateResolutionFormatter

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a899a7362b9bddf276edc712e5254f8479ccb4c4
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 21:30:04 2020 +0200

    [Refactoring] remove formatter from DateResolutionFormatter
---
 .../apache/james/mailbox/elasticsearch/json/IndexableMessage.java | 8 +++++---
 .../james/mailbox/elasticsearch/query/CriterionConverter.java     | 5 +++--
 .../mailbox/elasticsearch/query/DateResolutionFormatter.java      | 3 ---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
index edd1ad3..82dc941 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.time.Instant;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -30,7 +31,6 @@ import java.util.stream.Stream;
 
 import org.apache.james.mailbox.ModSeq;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.query.DateResolutionFormatter;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.model.MessageAttachmentMetadata;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -45,6 +45,8 @@ import com.google.common.collect.ImmutableList;
 
 public class IndexableMessage {
 
+    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
+
     public static class Builder {
         private static ZonedDateTime getSanitizedInternalDate(MailboxMessage message, ZoneId zoneId) {
             if (message.getInternalDate() == null) {
@@ -116,7 +118,7 @@ public class IndexableMessage {
             EMailers to = EMailers.from(headerCollection.getToAddressSet());
             EMailers cc = EMailers.from(headerCollection.getCcAddressSet());
             EMailers bcc = EMailers.from(headerCollection.getBccAddressSet());
-            String sentDate = DateResolutionFormatter.DATE_TIME_FORMATTER.format(headerCollection.getSentDate().orElse(internalDate));
+            String sentDate = DATE_TIME_FORMATTER.format(headerCollection.getSentDate().orElse(internalDate));
             Optional<String> mimeMessageID = headerCollection.getMessageID();
 
             String text = Stream.of(from.serialize(),
@@ -133,7 +135,7 @@ public class IndexableMessage {
             String mailboxId = message.getMailboxId().serialize();
             ModSeq modSeq = message.getModSeq();
             long size = message.getFullContentOctets();
-            String date = DateResolutionFormatter.DATE_TIME_FORMATTER.format(getSanitizedInternalDate(message, zoneId));
+            String date = DATE_TIME_FORMATTER.format(getSanitizedInternalDate(message, zoneId));
             String mediaType = message.getMediaType();
             String subType = message.getSubType();
             boolean isAnswered = message.isAnswered();
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 202c27f..0d6c24a 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -28,6 +28,7 @@ import static org.elasticsearch.index.query.QueryBuilders.nestedQuery;
 import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
 import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 
+import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Locale;
@@ -186,11 +187,11 @@ public class CriterionConverter {
         return boolQuery().filter(
             convertDateOperator(field,
                 dateOperator.getType(),
-                DateResolutionFormatter.DATE_TIME_FORMATTER.format(
+                DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
                     DateResolutionFormatter.computeLowerDate(
                         DateResolutionFormatter.convertDateToZonedDateTime(dateOperator.getDate()),
                         dateOperator.getDateResultion())),
-                DateResolutionFormatter.DATE_TIME_FORMATTER.format(
+                DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
                     DateResolutionFormatter.computeUpperDate(
                         DateResolutionFormatter.convertDateToZonedDateTime(dateOperator.getDate()),
                         dateOperator.getDateResultion()))));
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
index 55b026e..0f88ba2 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormatter.java
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.elasticsearch.query;
 import java.time.Instant;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.TemporalUnit;
 import java.util.Date;
@@ -31,8 +30,6 @@ import org.apache.james.mailbox.model.SearchQuery;
 
 public class DateResolutionFormatter {
 
-    public static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
-
     public static ZonedDateTime computeUpperDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
         return computeLowerDate(date, resolution).plus(1, convertDateResolutionField(resolution));
     }


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


[james-project] 05/14: [Refactoring] remove javatuples library and replace its single usage by an ad hoc piece of code

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a9a82028e2e7a52b6d9485e0a79078dd5c61dbb5
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 28 22:14:09 2020 +0200

    [Refactoring] remove javatuples library and replace its single usage by an ad hoc piece of code
---
 .../jmap-draft-integration-testing-common/pom.xml           |  5 -----
 .../integration/cucumber/GetMessagesMethodStepdefs.java     | 13 +------------
 2 files changed, 1 insertion(+), 17 deletions(-)

diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml
index d776d7f..249a54d 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml
@@ -160,11 +160,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.javatuples</groupId>
-            <artifactId>javatuples</artifactId>
-            <version>1.2</version>
-        </dependency>
-        <dependency>
             <groupId>org.testcontainers</groupId>
             <artifactId>testcontainers</artifactId>
             <scope>test</scope>
diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index 6d9c865..0033481 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -52,11 +52,9 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.util.ClassLoaderUtils;
 import org.apache.james.utils.SMTPMessageSender;
-import org.javatuples.Pair;
 
 import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
-import com.google.common.base.Joiner;
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;
 
@@ -199,8 +197,7 @@ public class GetMessagesMethodStepdefs {
 
     private Function<Set<Entry<String, String>>, String> entriesToString() {
         return entries -> entries.stream()
-            .map(this::entryToPair)
-            .map(this::joinKeyValue)
+            .map(entry -> entry.getKey() + ": " + entry.getValue())
             .collect(Collectors.joining("\r\n", "", "\r\n"));
     }
 
@@ -529,14 +526,6 @@ public class GetMessagesMethodStepdefs {
         httpClient.post("[[\"getMessages\", {\"ids\": " + serializedIds + ", \"properties\": " + serializedProperties + "}, \"#0\"]]");
     }
 
-    private Pair<String, String> entryToPair(Map.Entry<String, String> entry) {
-        return Pair.with(entry.getKey(), entry.getValue());
-    }
-
-    private String joinKeyValue(Pair<String, String> pair) {
-        return Joiner.on(": ").join(pair);
-    }
-
     @Then("^an error \"([^\"]*)\" with type \"([^\"]*)\" is returned$")
     public void error(String description, String type) {
         assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200);


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