Arsnael commented on a change in pull request #710:
URL: https://github.com/apache/james-project/pull/710#discussion_r735316755



##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}",
+         |        "after": 
"${UTCDate(requestDate).asUTC.format(UTC_DATE_FORMAT)}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()

Review comment:
       debug spotted

##########
File path: 
server/apps/memory-app/src/main/java/org/apache/james/MemoryJamesServerMain.java
##########
@@ -77,8 +76,7 @@
         new MailboxRoutesModule(),
         new MailQueueRoutesModule(),
         new MailRepositoriesRoutesModule(),
-        new SieveRoutesModule(),
-        new SwaggerRoutesModule());

Review comment:
       Thought that was removed in the swagger removal PR already?

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}",
+         |        "after": 
"${UTCDate(requestDate).asUTC.format(UTC_DATE_FORMAT)}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response).isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [[
+           |            "Email/query",
+           |            {
+           |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |                "queryState": "${generateQueryState(messageId4, 
messageId3)}",
+           |                "canCalculateChanges": false,
+           |                "position": 0,
+           |                "limit": 256,
+           |                "ids": ["${messageId4.serialize}", 
"${messageId3.serialize}"]
+           |            },
+           |            "c1"
+           |        ]]
+           |}""".stripMargin)
+    }
+  }
+
+  @Test
+  def test2(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe

Review comment:
       space after `=`

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}",
+         |        "after": 
"${UTCDate(requestDate).asUTC.format(UTC_DATE_FORMAT)}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response).isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [[
+           |            "Email/query",
+           |            {
+           |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |                "queryState": "${generateQueryState(messageId4, 
messageId3)}",
+           |                "canCalculateChanges": false,
+           |                "position": 0,
+           |                "limit": 256,
+           |                "ids": ["${messageId4.serialize}", 
"${messageId3.serialize}"]
+           |            },
+           |            "c1"
+           |        ]]
+           |}""".stripMargin)
+    }
+  }
+
+  @Test
+  def test2(server: GuiceJamesServer): Unit = {

Review comment:
       test name?

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe

Review comment:
       space after `=`

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe

Review comment:
       space after `=`

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe

Review comment:
       space after `=`

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {

Review comment:
       test name?

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}",
+         |        "after": 
"${UTCDate(requestDate).asUTC.format(UTC_DATE_FORMAT)}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response).isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [[
+           |            "Email/query",
+           |            {
+           |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |                "queryState": "${generateQueryState(messageId4, 
messageId3)}",
+           |                "canCalculateChanges": false,
+           |                "position": 0,
+           |                "limit": 256,
+           |                "ids": ["${messageId4.serialize}", 
"${messageId3.serialize}"]
+           |            },
+           |            "c1"
+           |        ]]
+           |}""".stripMargin)
+    }
+  }
+
+  @Test
+  def test2(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()

Review comment:
       debug spotted

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}",
+         |        "after": 
"${UTCDate(requestDate).asUTC.format(UTC_DATE_FORMAT)}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response).isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [[
+           |            "Email/query",
+           |            {
+           |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |                "queryState": "${generateQueryState(messageId4, 
messageId3)}",
+           |                "canCalculateChanges": false,
+           |                "position": 0,
+           |                "limit": 256,
+           |                "ids": ["${messageId4.serialize}", 
"${messageId3.serialize}"]
+           |            },
+           |            "c1"
+           |        ]]
+           |}""".stripMargin)
+    }
+  }
+
+  @Test
+  def test2(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe

Review comment:
       space after `=`

##########
File path: 
server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/EmailQueryViewContract.java
##########
@@ -227,6 +227,26 @@ default void 
listMailboxContentSinceSentAtShouldNotReturnDeletedContent() {
             .containsExactly(messageId3());
     }
 
+    @Test
+    default void 
listMailboxContentSortedByReceivedAtShouldBeSortedByReceivedAt() {
+        testee().save(mailboxId1(), DATE_1, DATE_4, messageId1()).block();
+        testee().save(mailboxId1(), DATE_2, DATE_3, messageId2()).block();
+        testee().save(mailboxId1(), DATE_5, DATE_6, messageId3()).block();
+
+        assertThat(testee().listMailboxContentSortedByReceivedAt(mailboxId1(), 
Limit.limit(12)).collectList().block())
+            .containsExactly(messageId3(), messageId1(), messageId2());
+    }
+
+    @Test
+    default void 
listMailboxContentSinceSortedByReceivedAtShouldBeSortedByReceivedAt() {
+        testee().save(mailboxId1(), DATE_1, DATE_4, messageId1()).block();
+        testee().save(mailboxId1(), DATE_2, DATE_3, messageId2()).block();
+        testee().save(mailboxId1(), DATE_5, DATE_6, messageId3()).block();
+
+        
assertThat(testee().listMailboxContentSinceReceivedAtSortedByReceivedAt(mailboxId1(),
 DATE_4, Limit.limit(12)).collectList().block())
+            .containsExactly(messageId3(), messageId1());
+    }

Review comment:
       Should we test the limit works too?

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+          .withInternalDate(beforeRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val messageId3: MessageId = mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(afterRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId4: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB), 
AppendCommand.builder()
+        .withInternalDate(afterRequestDate2)
+        
.build(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "inMailbox": "${mailboxId.serialize()}",
+         |        "after": 
"${UTCDate(requestDate).asUTC.format(UTC_DATE_FORMAT)}"
+         |       },
+         |      "sort": [{
+         |        "property":"receivedAt",
+         |        "isAscending": false
+         |      }]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post.prettyPeek()
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response).isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [[
+           |            "Email/query",
+           |            {
+           |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |                "queryState": "${generateQueryState(messageId4, 
messageId3)}",
+           |                "canCalculateChanges": false,
+           |                "position": 0,
+           |                "limit": 256,
+           |                "ids": ["${messageId4.serialize}", 
"${messageId3.serialize}"]
+           |            },
+           |            "c1"
+           |        ]]
+           |}""".stripMargin)
+    }
+  }
+
+  @Test
+  def test2(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe

Review comment:
       space after `=`

##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
##########
@@ -1510,6 +1510,181 @@ trait EmailQueryMethodContract {
     }
   }
 
+  @Test
+  def test(server: GuiceJamesServer): Unit = {
+    val beforeRequestDate1 = 
Date.from(ZonedDateTime.now().minusDays(3).toInstant)
+    val beforeRequestDate2 = 
Date.from(ZonedDateTime.now().minusDays(2).toInstant)
+    val requestDate = ZonedDateTime.now().minusDays(1)
+    val afterRequestDate1 = Date.from(ZonedDateTime.now().toInstant)
+    val afterRequestDate2 = 
Date.from(ZonedDateTime.now().plusDays(1).toInstant)
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId = mailboxProbe.createMailbox(MailboxPath.inbox(BOB))
+    val messageId1: MessageId =mailboxProbe
+      .appendMessage(BOB.asString, MailboxPath.inbox(BOB),
+        AppendCommand.builder()
+          .withInternalDate(beforeRequestDate1)
+          .build(buildTestMessage))
+      .getMessageId
+
+    val messageId2: MessageId =mailboxProbe

Review comment:
       space after `=`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to