You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/04/02 01:29:56 UTC

[james-project] branch 3.6.x updated (665261f -> 1c7b459)

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

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


    from 665261f  [RELEASE] Documentation should mention 3.6.0
     new b695254  JAMES-3481 s/maxChanged/maxChanges/
     new 1654bf1  JAMES-3472 s/maxChanged/maxChanges/
     new 1c7b459  JAMES-3472 Factorize limit reads

The 3 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:
 .../contract/EmailChangesMethodContract.scala      | 66 +++++++++++++++++++
 .../contract/MailboxChangesMethodContract.scala    | 77 ++++++++++++++++++++++
 .../james/jmap/json/EmailGetSerializer.scala       |  6 --
 .../apache/james/jmap/json/MailboxSerializer.scala |  7 --
 .../scala/org/apache/james/jmap/json/package.scala |  6 ++
 .../org/apache/james/jmap/mail/EmailGet.scala      |  4 +-
 .../org/apache/james/jmap/mail/MailboxGet.scala    |  2 +-
 .../james/jmap/method/EmailChangesMethod.scala     |  4 +-
 .../james/jmap/method/MailboxChangesMethod.scala   |  6 +-
 9 files changed, 157 insertions(+), 21 deletions(-)

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


[james-project] 03/03: JAMES-3472 Factorize limit reads

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

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

commit 1c7b4597845f427254da92ffa27bc055851ed0c2
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 31 17:21:36 2021 +0700

    JAMES-3472 Factorize limit reads
---
 .../main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala | 6 ------
 .../main/scala/org/apache/james/jmap/json/MailboxSerializer.scala  | 7 -------
 .../src/main/scala/org/apache/james/jmap/json/package.scala        | 6 ++++++
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala
index 4a45e02..edc3392 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala
@@ -19,7 +19,6 @@
 
 package org.apache.james.jmap.json
 
-import org.apache.james.jmap.api.change.Limit
 import org.apache.james.jmap.api.model.Preview
 import org.apache.james.jmap.core.{Properties, State}
 import org.apache.james.jmap.mail.Email.Size
@@ -110,11 +109,6 @@ object EmailGetSerializer {
   private implicit val headersWrites: Writes[EmailHeader] = Json.writes[EmailHeader]
   private implicit val bodyValueWrites: Writes[EmailBodyValue] = Json.writes[EmailBodyValue]
   private implicit val emailIdsReads: Reads[EmailIds] = Json.valueReads[EmailIds]
-  private implicit val limitReads: Reads[Limit] = {
-    case JsNumber(underlying) if underlying > 0 => JsSuccess(Limit.of(underlying.intValue))
-    case JsNumber(underlying) if underlying <= 0 => JsError("Expecting a positive integer as Limit")
-    case _ => JsError("Expecting a number as Limit")
-  }
   private implicit val emailGetRequestReads: Reads[EmailGetRequest] = Json.reads[EmailGetRequest]
 
   private implicit val emailChangesRequestReads: Reads[EmailChangesRequest] = Json.reads[EmailChangesRequest]
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
index 90ef9e9..90f1a09 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala
@@ -23,7 +23,6 @@ import eu.timepit.refined._
 import eu.timepit.refined.collection.NonEmpty
 import javax.inject.Inject
 import org.apache.james.core.{Domain, Username}
-import org.apache.james.jmap.api.change.Limit
 import org.apache.james.jmap.core.CapabilityIdentifier.CapabilityIdentifier
 import org.apache.james.jmap.core.{ClientId, Properties, SetError, State}
 import org.apache.james.jmap.mail.MailboxGet.{UnparsedMailboxId, UnparsedMailboxIdConstraint}
@@ -114,12 +113,6 @@ class MailboxSerializer @Inject()(mailboxIdFactory: MailboxId.Factory) {
 
   private implicit val mailboxGetRequest: Reads[MailboxGetRequest] = Json.reads[MailboxGetRequest]
 
-  private implicit val limitReads: Reads[Limit] = {
-    case JsNumber(underlying) if underlying > 0 => JsSuccess(Limit.of(underlying.intValue))
-    case JsNumber(underlying) if underlying <= 0 => JsError("Expecting a positive integer as Limit")
-    case _ => JsError("Expecting a number as Limit")
-  }
-
   private implicit val mailboxChangesRequest: Reads[MailboxChangesRequest] = Json.reads[MailboxChangesRequest]
 
   private implicit val mailboxRemoveEmailsOnDestroy: Reads[RemoveEmailsOnDestroy] = Json.valueFormat[RemoveEmailsOnDestroy]
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala
index fb77977..28e3668 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala
@@ -24,6 +24,7 @@ import java.time.format.DateTimeFormatter
 
 import eu.timepit.refined.api.{RefType, Validate}
 import org.apache.james.core.MailAddress
+import org.apache.james.jmap.api.change.Limit
 import org.apache.james.jmap.core.SetError.SetErrorDescription
 import org.apache.james.jmap.core.{AccountId, Properties, SetError, State, UTCDate}
 import org.apache.james.jmap.mail.HasMoreChanges
@@ -95,4 +96,9 @@ package object json {
   private[json] implicit val utcDateWrites: Writes[UTCDate] =
     utcDate => JsString(utcDate.asUTC.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX")))
   private[json] implicit val hasMoreChangesWrites: Writes[HasMoreChanges] = Json.valueWrites[HasMoreChanges]
+  private[json] implicit val limitReads: Reads[Limit] = {
+    case JsNumber(underlying) if underlying > 0 => JsSuccess(Limit.of(underlying.intValue))
+    case JsNumber(underlying) if underlying <= 0 => JsError("Expecting a positive integer as Limit")
+    case _ => JsError("Expecting a number as Limit")
+  }
 }

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


[james-project] 01/03: JAMES-3481 s/maxChanged/maxChanges/

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

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

commit b695254f24c7ef2bc4da762c0fcb7ea8d62f4156
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 31 17:07:58 2021 +0700

    JAMES-3481 s/maxChanged/maxChanges/
---
 .../contract/MailboxChangesMethodContract.scala    | 77 ++++++++++++++++++++++
 .../org/apache/james/jmap/mail/MailboxGet.scala    |  2 +-
 .../james/jmap/method/MailboxChangesMethod.scala   |  6 +-
 3 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala
index e0a0aa1..f4cdb93 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala
@@ -1277,6 +1277,83 @@ trait MailboxChangesMethodContract {
   }
 
   @Test
+  def maxChangesShouldBeTakenIntoAccount(server: GuiceJamesServer): Unit = {
+    val mailboxProbe: MailboxProbeImpl = server.getProbe(classOf[MailboxProbeImpl])
+
+    val provisioningState: State = provisionSystemMailboxes(server)
+
+    val mailboxId1: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox1"))
+      .serialize
+
+    val mailboxId2: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox2"))
+      .serialize
+
+    val mailboxId3: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox3"))
+      .serialize
+
+    val mailboxId4: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox4"))
+      .serialize
+
+    val mailboxId5: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox5"))
+      .serialize
+
+    val mailboxId6: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox6"))
+      .serialize
+
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Mailbox/changes",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "sinceState": "${provisioningState.getValue}",
+         |      "maxChanges": 38
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response)
+        .whenIgnoringPaths("methodResponses[0][1].newState")
+        .withOptions(new Options(IGNORING_ARRAY_ORDER))
+        .isEqualTo(
+          s"""{
+             |    "sessionState": "${SESSION_STATE.value}",
+             |    "methodResponses": [
+             |      [ "Mailbox/changes", {
+             |        "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+             |        "oldState": "${provisioningState.getValue}",
+             |        "hasMoreChanges": false,
+             |        "updatedProperties": null,
+             |        "created": ["$mailboxId1", "$mailboxId2", "$mailboxId3", "$mailboxId4", "$mailboxId5", "$mailboxId6"],
+             |        "updated": [],
+             |        "destroyed": []
+             |      }, "c1"]
+             |    ]
+             |}""".stripMargin)
+    }
+  }
+
+  @Test
   def mailboxChangesShouldFailWhenAccountIdNotFound(server: GuiceJamesServer): Unit = {
     val jmapGuiceProbe:JmapGuiceProbe = server.getProbe(classOf[JmapGuiceProbe])
     val oldState: State = jmapGuiceProbe.getLatestMailboxState(AccountId.fromUsername(BOB))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala
index 7f9fd33..37bf418 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala
@@ -75,7 +75,7 @@ case class HasMoreChanges(value: Boolean) extends AnyVal
 
 case class MailboxChangesRequest(accountId: AccountId,
                                  sinceState: State,
-                                 maxChanged: Option[Limit]) extends WithAccountId
+                                 maxChanges: Option[Limit]) extends WithAccountId
 
 case class MailboxChangesResponse(accountId: AccountId,
                                   oldState: State,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala
index 9fb7c6c..d96361b 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
+import javax.inject.Inject
 import org.apache.james.jmap.api.change.{MailboxChangeRepository, MailboxChanges, State => JavaState}
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_MAIL}
@@ -34,7 +35,6 @@ import org.apache.james.metrics.api.MetricFactory
 import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.SMono
 
-import javax.inject.Inject
 import scala.jdk.CollectionConverters._
 import scala.jdk.OptionConverters._
 
@@ -54,9 +54,9 @@ class MailboxChangesMethod @Inject()(mailboxSerializer: MailboxSerializer,
       val accountId: JavaAccountId = JavaAccountId.fromUsername(mailboxSession.getUser)
       val state: JavaState = JavaState.of(request.sinceState.value)
       if (capabilities.contains(CapabilityIdentifier.JAMES_SHARES)) {
-        mailboxChangeRepository.getSinceStateWithDelegation(accountId, state, request.maxChanged.toJava)
+        mailboxChangeRepository.getSinceStateWithDelegation(accountId, state, request.maxChanges.toJava)
       } else {
-        mailboxChangeRepository.getSinceState(accountId, state, request.maxChanged.toJava)
+        mailboxChangeRepository.getSinceState(accountId, state, request.maxChanges.toJava)
       }})
       .map(mailboxChanges => MailboxChangesResponse(
         accountId = request.accountId,

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


[james-project] 02/03: JAMES-3472 s/maxChanged/maxChanges/

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

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

commit 1654bf1d957116d5089f2f5b22e564da79523b2f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 31 17:13:05 2021 +0700

    JAMES-3472 s/maxChanged/maxChanges/
---
 .../contract/EmailChangesMethodContract.scala      | 66 ++++++++++++++++++++++
 .../org/apache/james/jmap/mail/EmailGet.scala      |  4 +-
 .../james/jmap/method/EmailChangesMethod.scala     |  4 +-
 3 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailChangesMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailChangesMethodContract.scala
index 87cb3c5..7a2936c 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailChangesMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailChangesMethodContract.scala
@@ -863,6 +863,72 @@ trait EmailChangesMethodContract {
   }
 
   @Test
+  def maxChangesShouldBeTakenIntoAccount(server: GuiceJamesServer): Unit = {
+    val mailboxProbe: MailboxProbeImpl = server.getProbe(classOf[MailboxProbeImpl])
+    val path: MailboxPath = MailboxPath.forUser(BOB, "mailbox1")
+
+    mailboxProbe.createMailbox(path)
+
+    val message: Message = Message.Builder
+      .of
+      .setSubject("test")
+      .setBody("testmail", StandardCharsets.UTF_8)
+      .build
+
+    val messageId1: String = mailboxProbe.appendMessage(BOB.asString(), path, AppendCommand.from(message)).getMessageId.serialize
+    val messageId2: String = mailboxProbe.appendMessage(BOB.asString(), path, AppendCommand.from(message)).getMessageId.serialize
+    val messageId3: String = mailboxProbe.appendMessage(BOB.asString(), path, AppendCommand.from(message)).getMessageId.serialize
+    val messageId4: String = mailboxProbe.appendMessage(BOB.asString(), path, AppendCommand.from(message)).getMessageId.serialize
+    val messageId5: String = mailboxProbe.appendMessage(BOB.asString(), path, AppendCommand.from(message)).getMessageId.serialize
+    val messageId6: String = mailboxProbe.appendMessage(BOB.asString(), path, AppendCommand.from(message)).getMessageId.serialize
+
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/changes",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "sinceState": "${State.INITIAL.getValue}",
+         |      "maxChanges": 38
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response)
+        .whenIgnoringPaths("methodResponses[0][1].newState")
+        .withOptions(new Options(IGNORING_ARRAY_ORDER))
+        .isEqualTo(
+          s"""{
+             |    "sessionState": "${SESSION_STATE.value}",
+             |    "methodResponses": [
+             |      [ "Email/changes", {
+             |        "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+             |        "oldState": "${State.INITIAL.getValue}",
+             |        "hasMoreChanges": false,
+             |        "created": ["$messageId1", "$messageId2", "$messageId3", "$messageId4", "$messageId5", "$messageId6"],
+             |        "updated": [],
+             |        "destroyed": []
+             |      }, "c1"]
+             |    ]
+             |}""".stripMargin)
+    }
+  }
+
+  @Test
   def emailChangesShouldReturnNoChangesWhenNoNewerState(server: GuiceJamesServer): Unit = {
     val request =
       s"""{
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala
index a3d63dc..27f7ef2 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala
@@ -113,8 +113,8 @@ case class SpecificHeaderRequest(property: NonEmptyString, headerName: String, p
 }
 
 case class EmailChangesRequest(accountId: AccountId,
-                                sinceState: State,
-                                maxChanged: Option[Limit]) extends WithAccountId
+                               sinceState: State,
+                               maxChanges: Option[Limit]) extends WithAccountId
 
 
 case class EmailChangesResponse(accountId: AccountId,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailChangesMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailChangesMethod.scala
index 8f67520..d33a3c6 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailChangesMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailChangesMethod.scala
@@ -47,9 +47,9 @@ class EmailChangesMethod @Inject()(val metricFactory: MetricFactory,
     SMono({
       val accountId: JavaAccountId = JavaAccountId.fromUsername(mailboxSession.getUser)
       if (capabilities.contains(JAMES_SHARES)) {
-        SMono[EmailChanges](emailChangeRepository.getSinceStateWithDelegation(accountId, JavaState.of(request.sinceState.value), request.maxChanged.toJava))
+        SMono[EmailChanges](emailChangeRepository.getSinceStateWithDelegation(accountId, JavaState.of(request.sinceState.value), request.maxChanges.toJava))
       } else {
-        SMono[EmailChanges](emailChangeRepository.getSinceState(accountId, JavaState.of(request.sinceState.value), request.maxChanged.toJava))
+        SMono[EmailChanges](emailChangeRepository.getSinceState(accountId, JavaState.of(request.sinceState.value), request.maxChanges.toJava))
       }
     })
       .map(emailChanges => EmailChangesResponse(

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