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 2022/11/04 02:10:23 UTC

[james-project] branch master updated (415e1896e1 -> 8ea77b7e36)

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

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


    from 415e1896e1 JAMES-3843 Rewrite VacationRelayIntegrationTest with Mock SMTP server
     new cec2fc0bca [CLEAN CODE] Jmap - Method getRequest from deserialize json
     new 8ea77b7e36 JAMES-3830 Implement JMAP Quota/changes

The 2 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:
 .../james/jmap/rfc8621/RFC8621MethodsModule.java   |   2 +
 ...java => DistributedQuotaChangesMethodTest.java} |   4 +-
 .../contract/QuotaChangesMethodContract.scala      | 528 +++++++++++++++++++++
 .../rfc8621/contract/QuotaGetMethodContract.scala  | 173 +++----
 ...Test.java => MemoryQuotaChangesMethodTest.java} |   5 +-
 .../doc/specs/spec/quotas/quota.mdown              |   4 +-
 .../apache/james/jmap/json/QuotaSerializer.scala   |  19 +-
 .../james/jmap/json/ResponseSerializer.scala       |   2 +
 .../scala/org/apache/james/jmap/mail/Quotas.scala  |  61 ++-
 .../james/jmap/method/EmailChangesMethod.scala     |   9 +-
 .../apache/james/jmap/method/EmailGetMethod.scala  |   6 +-
 .../james/jmap/method/EmailImportMethod.scala      |  10 +-
 .../james/jmap/method/EmailQueryMethod.scala       |  15 +-
 .../apache/james/jmap/method/EmailSetMethod.scala  |  10 +-
 .../james/jmap/method/IdentityGetMethod.scala      |  11 +-
 .../james/jmap/method/IdentitySetMethod.scala      |  10 +-
 .../apache/james/jmap/method/MDNParseMethod.scala  |  14 +-
 .../apache/james/jmap/method/MDNSendMethod.scala   |  15 +-
 .../james/jmap/method/MailboxChangesMethod.scala   |   9 +-
 .../james/jmap/method/MailboxGetMethod.scala       |  11 +-
 .../james/jmap/method/MailboxQueryMethod.scala     |  10 +-
 .../james/jmap/method/MailboxSetMethod.scala       |  11 +-
 .../jmap/method/PushSubscriptionGetMethod.scala    |  10 +-
 .../jmap/method/PushSubscriptionSetMethod.scala    |  10 +-
 ...hangesMethod.scala => QuotaChangesMethod.scala} |  76 ++-
 .../apache/james/jmap/method/QuotaGetMethod.scala  |  67 +--
 .../james/jmap/method/ThreadChangesMethod.scala    |  10 +-
 .../apache/james/jmap/method/ThreadGetMethod.scala |   9 +-
 .../jmap/method/VacationResponseGetMethod.scala    |  15 +-
 .../jmap/method/VacationResponseSetMethod.scala    |  16 +-
 30 files changed, 837 insertions(+), 315 deletions(-)
 copy server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/{DistributedQuotaGetMethodTest.java => DistributedQuotaChangesMethodTest.java} (94%)
 create mode 100644 server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaChangesMethodContract.scala
 copy server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/{MemoryMailboxQueryMethodTest.java => MemoryQuotaChangesMethodTest.java} (93%)
 copy server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/{EmailChangesMethod.scala => QuotaChangesMethod.scala} (50%)


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


[james-project] 01/02: [CLEAN CODE] Jmap - Method getRequest from deserialize json

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

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

commit cec2fc0bcab75c409df8e013b68181bfe6bfefc1
Author: Tung Van TRAN <vt...@linagora.com>
AuthorDate: Thu Oct 27 11:39:23 2022 +0700

    [CLEAN CODE] Jmap - Method getRequest from deserialize json
---
 .../org/apache/james/jmap/json/ResponseSerializer.scala  |  2 ++
 .../apache/james/jmap/method/EmailChangesMethod.scala    |  9 +++------
 .../org/apache/james/jmap/method/EmailGetMethod.scala    |  6 ++----
 .../org/apache/james/jmap/method/EmailImportMethod.scala | 10 ++++------
 .../org/apache/james/jmap/method/EmailQueryMethod.scala  | 15 ++++++---------
 .../org/apache/james/jmap/method/EmailSetMethod.scala    | 10 ++++------
 .../org/apache/james/jmap/method/IdentityGetMethod.scala | 11 +++++------
 .../org/apache/james/jmap/method/IdentitySetMethod.scala | 10 ++++------
 .../org/apache/james/jmap/method/MDNParseMethod.scala    | 14 ++++++--------
 .../org/apache/james/jmap/method/MDNSendMethod.scala     | 15 +++++++--------
 .../apache/james/jmap/method/MailboxChangesMethod.scala  |  9 +++------
 .../org/apache/james/jmap/method/MailboxGetMethod.scala  | 11 ++++-------
 .../apache/james/jmap/method/MailboxQueryMethod.scala    | 10 ++++------
 .../org/apache/james/jmap/method/MailboxSetMethod.scala  | 11 +++++------
 .../james/jmap/method/PushSubscriptionGetMethod.scala    | 10 ++++------
 .../james/jmap/method/PushSubscriptionSetMethod.scala    | 10 ++++------
 .../org/apache/james/jmap/method/QuotaGetMethod.scala    | 12 +++++-------
 .../apache/james/jmap/method/ThreadChangesMethod.scala   | 10 ++++------
 .../org/apache/james/jmap/method/ThreadGetMethod.scala   |  9 +++------
 .../james/jmap/method/VacationResponseGetMethod.scala    | 15 ++++++---------
 .../james/jmap/method/VacationResponseSetMethod.scala    | 16 +++++++---------
 21 files changed, 92 insertions(+), 133 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala
index a90eaa57c1..56905e9c8b 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/ResponseSerializer.scala
@@ -159,6 +159,8 @@ object ResponseSerializer {
 
   def serialize(errors: JsError): JsValue = Json.toJson(errors)
 
+  def asException(errors: scala.collection.Seq[(JsPath, scala.collection.Seq[JsonValidationError])]): IllegalArgumentException = new IllegalArgumentException(serialize(JsError(errors)).toString())
+
   def deserializeRequestObject(input: String): JsResult[RequestObject] = Json.parse(input).validate[RequestObject]
 
   def deserializeRequestObject(input: InputStream): JsResult[RequestObject] = Json.parse(input).validate[RequestObject]
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 68bc07f566..44ee6eef3f 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
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.change.{CanNotCalculateChangesException, EmailChangeRepository, EmailChanges, State => JavaState}
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JAMES_SHARES, JMAP_MAIL}
@@ -31,9 +30,9 @@ import org.apache.james.jmap.mail.{EmailChangesRequest, EmailChangesResponse, Ha
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 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._
 
@@ -74,8 +73,6 @@ class EmailChangesMethod @Inject()(val metricFactory: MetricFactory,
     }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, EmailChangesRequest] =
-    EmailGetSerializer.deserializeEmailChangesRequest(invocation.arguments.value) match {
-      case JsSuccess(emailGetRequest, _) => Right(emailGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    EmailGetSerializer.deserializeEmailChangesRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 }
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailGetMethod.scala
index 17e6776ff2..1899e0edf9 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailGetMethod.scala
@@ -92,10 +92,8 @@ class EmailGetMethod @Inject() (readerFactory: EmailViewReaderFactory,
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, EmailGetRequest] =
-    EmailGetSerializer.deserializeEmailGetRequest(invocation.arguments.value) match {
-      case JsSuccess(emailGetRequest, _) => Right(emailGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    EmailGetSerializer.deserializeEmailGetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def computeResponseInvocation(capabilities: Set[CapabilityIdentifier], request: EmailGetRequest, invocation: Invocation, mailboxSession: MailboxSession): SMono[Invocation] =
     validateProperties(request)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailImportMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailImportMethod.scala
index b15f1aac89..41bfa69be1 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailImportMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailImportMethod.scala
@@ -19,10 +19,7 @@
 
 package org.apache.james.jmap.method
 
-import java.util.Date
-
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.change.EmailChangeRepository
 import org.apache.james.jmap.api.model.Size.sanitizeSize
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
@@ -44,9 +41,10 @@ import org.apache.james.mime4j.message.DefaultMessageBuilder
 import org.apache.james.mime4j.stream.MimeConfig
 import org.apache.james.util.ReactorUtils
 import org.reactivestreams.Publisher
-import play.api.libs.json.JsError
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import java.util.Date
+import javax.inject.Inject
 import scala.util.{Try, Using}
 
 object EmailImportMethod {
@@ -91,8 +89,8 @@ class EmailImportMethod @Inject() (val metricFactory: MetricFactory,
   override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE, JMAP_MAIL)
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, EmailImportRequest] =
-    serializer.deserializeEmailImportRequest(invocation.arguments.value).asEither
-      .left.map(errors => new IllegalArgumentException(ResponseSerializer.serialize(JsError(errors)).toString))
+    serializer.deserializeEmailImportRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: InvocationWithContext, mailboxSession: MailboxSession, request: EmailImportRequest): Publisher[InvocationWithContext] =
     for {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailQueryMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailQueryMethod.scala
index 74f95966a6..454e1893df 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailQueryMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailQueryMethod.scala
@@ -18,12 +18,8 @@
  ****************************************************************/
 package org.apache.james.jmap.method
 
-import java.time.ZonedDateTime
-
 import cats.implicits._
 import eu.timepit.refined.auto._
-import javax.inject.Inject
-import javax.mail.Flags.Flag.DELETED
 import org.apache.james.jmap.JMAPConfiguration
 import org.apache.james.jmap.api.projections.EmailQueryView
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL}
@@ -41,9 +37,11 @@ import org.apache.james.mailbox.model.{MailboxId, MessageId, MultimailboxesSearc
 import org.apache.james.mailbox.{MailboxManager, MailboxSession}
 import org.apache.james.metrics.api.MetricFactory
 import org.apache.james.util.streams.{Limit => JavaLimit}
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import java.time.ZonedDateTime
+import javax.inject.Inject
+import javax.mail.Flags.Flag.DELETED
 import scala.jdk.CollectionConverters._
 
 class EmailQueryMethod @Inject() (serializer: EmailQuerySerializer,
@@ -79,10 +77,9 @@ class EmailQueryMethod @Inject() (serializer: EmailQuerySerializer,
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, EmailQueryRequest] =
-    serializer.deserializeEmailQueryRequest(invocation.arguments.value) match {
-      case JsSuccess(emailQueryRequest, _) => validateRequestParameters(emailQueryRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    serializer.deserializeEmailQueryRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
+      .flatMap(validateRequestParameters)
 
   private def validateRequestParameters(request: EmailQueryRequest): Either[Exception, EmailQueryRequest] =
     (request.anchor, request.anchorOffset) match {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetMethod.scala
index c178acc056..b428729301 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetMethod.scala
@@ -19,7 +19,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.change.EmailChangeRepository
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JAMES_SHARES, JMAP_CORE, JMAP_MAIL}
@@ -31,9 +30,10 @@ import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.mailbox.model.MessageId
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.SMono
 
+import javax.inject.Inject
+
 case class MessageNotFoundException(messageId: MessageId) extends Exception
 
 class EmailSetMethod @Inject()(serializer: EmailSetSerializer,
@@ -77,10 +77,8 @@ class EmailSetMethod @Inject()(serializer: EmailSetSerializer,
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, EmailSetRequest] =
-    serializer.deserialize(invocation.arguments.value) match {
-      case JsSuccess(emailSetRequest, _) => Right(emailSetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    serializer.deserialize(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def retrieveState(capabilities: Set[CapabilityIdentifier], mailboxSession: MailboxSession): SMono[UuidState] =
     if (capabilities.contains(JAMES_SHARES)) {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentityGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentityGetMethod.scala
index 665150b3b1..e73e4fa914 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentityGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentityGetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.identity.IdentityRepository
 import org.apache.james.jmap.api.model.{Identity, IdentityId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, EMAIL_SUBMISSION, JMAP_CORE}
@@ -32,9 +31,11 @@ import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
 import org.apache.james.util.ReactorUtils
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.Inject
+
 class IdentityGetMethod @Inject() (identityRepository: IdentityRepository,
                                    val metricFactory: MetricFactory,
                                    val sessionSupplier: SessionSupplier) extends MethodRequiringAccountId[IdentityGetRequest] {
@@ -58,10 +59,8 @@ class IdentityGetMethod @Inject() (identityRepository: IdentityRepository,
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, IdentityGetRequest] =
-    IdentitySerializer.deserialize(invocation.arguments.value) match {
-      case JsSuccess(request, _) => Right(request)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    IdentitySerializer.deserialize(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def getIdentities(request: IdentityGetRequest,
                             mailboxSession: MailboxSession): SMono[IdentityGetResponse] =
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentitySetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentitySetMethod.scala
index 8f9fd64779..2ac9f6ea80 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentitySetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/IdentitySetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, EMAIL_SUBMISSION, JMAP_CORE}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.{ClientId, Id, Invocation, ServerId, UuidState}
@@ -29,9 +28,10 @@ import org.apache.james.jmap.mail.{IdentitySetRequest, IdentitySetResponse}
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.SMono
 
+import javax.inject.Inject
+
 class IdentitySetMethod @Inject()(createPerformer: IdentitySetCreatePerformer,
                                   updatePerformer: IdentitySetUpdatePerformer,
                                   deletePerformer: IdentitySetDeletePerformer,
@@ -41,10 +41,8 @@ class IdentitySetMethod @Inject()(createPerformer: IdentitySetCreatePerformer,
   override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE, EMAIL_SUBMISSION)
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, IdentitySetRequest] =
-    IdentitySerializer.deserializeIdentitySetRequest(invocation.arguments.value) match {
-      case JsSuccess(identitySetRequest, _) => Right(identitySetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    IdentitySerializer.deserializeIdentitySetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: InvocationWithContext, mailboxSession: MailboxSession, request: IdentitySetRequest): SMono[InvocationWithContext] =
     for {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
index bc194afddf..827450390d 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNParseMethod.scala
@@ -19,10 +19,7 @@
 
 package org.apache.james.jmap.method
 
-import java.io.InputStream
-
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL, JMAP_MDN}
 import org.apache.james.jmap.core.Invocation
 import org.apache.james.jmap.core.Invocation._
@@ -36,9 +33,11 @@ import org.apache.james.mdn.fields.OriginalMessageId
 import org.apache.james.metrics.api.MetricFactory
 import org.apache.james.mime4j.dom.Message
 import org.apache.james.mime4j.message.DefaultMessageBuilder
-import play.api.libs.json.{JsError, JsObject, JsSuccess, Json}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import java.io.InputStream
+import javax.inject.Inject
 import scala.jdk.OptionConverters._
 import scala.util.{Try, Using}
 
@@ -58,10 +57,9 @@ class MDNParseMethod @Inject()(serializer: MDNSerializer,
       .map(InvocationWithContext(_, invocation.processingContext))
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, MDNParseRequest] =
-    serializer.deserializeMDNParseRequest(invocation.arguments.value) match {
-      case JsSuccess(mdnParseRequest, _) => mdnParseRequest.validate
-      case errors: JsError => Left(new IllegalArgumentException(Json.stringify(ResponseSerializer.serialize(errors))))
-    }
+    serializer.deserializeMDNParseRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
+      .flatMap(_.validate)
 
   def computeResponseInvocation(request: MDNParseRequest,
                                 invocation: Invocation,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNSendMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNSendMethod.scala
index 71db5d21d2..87b330091c 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNSendMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNSendMethod.scala
@@ -20,9 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.annotation.PreDestroy
-import javax.inject.Inject
-import javax.mail.internet.MimeMessage
 import org.apache.james.jmap.api.model.Identity
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL, JMAP_MDN}
 import org.apache.james.jmap.core.Invocation
@@ -48,9 +45,12 @@ import org.apache.james.queue.api.MailQueueFactory.SPOOL
 import org.apache.james.queue.api.{MailQueue, MailQueueFactory}
 import org.apache.james.server.core.MailImpl
 import org.apache.james.util.ReactorUtils
-import play.api.libs.json.{JsError, JsObject, JsSuccess, Json}
+import play.api.libs.json.{JsError, JsObject, JsSuccess}
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.annotation.PreDestroy
+import javax.inject.Inject
+import javax.mail.internet.MimeMessage
 import scala.jdk.CollectionConverters._
 import scala.jdk.OptionConverters._
 import scala.util.Try
@@ -104,10 +104,9 @@ class MDNSendMethod @Inject()(serializer: MDNSerializer,
       })
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, MDNSendRequest] =
-    serializer.deserializeMDNSendRequest(invocation.arguments.value) match {
-      case JsSuccess(mdnSendRequest, _) => mdnSendRequest.validate
-      case errors: JsError => Left(new IllegalArgumentException(Json.stringify(ResponseSerializer.serialize(errors))))
-    }
+    serializer.deserializeMDNSendRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
+      .flatMap(_.validate)
 
   private def create(identity: Identity,
                      request: MDNSendRequest,
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 6df3a075ea..0a04bde30c 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,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.change.{CanNotCalculateChangesException, MailboxChangeRepository, MailboxChanges, State => JavaState}
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_MAIL}
@@ -32,9 +31,9 @@ import org.apache.james.jmap.method.MailboxChangesMethod.updatedProperties
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 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._
 
@@ -83,10 +82,8 @@ class MailboxChangesMethod @Inject()(mailboxSerializer: MailboxSerializer,
     })
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, MailboxChangesRequest] =
-    mailboxSerializer.deserializeMailboxChangesRequest(invocation.arguments.value) match {
-      case JsSuccess(mailboxGetRequest, _) => Right(mailboxGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    mailboxSerializer.deserializeMailboxChangesRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def updateProperties(mailboxChanges: MailboxChanges): Option[Properties] =
     if (mailboxChanges.isCountChangesOnly) {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
index 8dcbcb8776..416b5d87a9 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.change.MailboxChangeRepository
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JAMES_SHARES, JMAP_CORE, JMAP_MAIL}
@@ -36,9 +35,10 @@ import org.apache.james.mailbox.model.search.MailboxQuery
 import org.apache.james.mailbox.model.{MailboxId, MailboxMetaData}
 import org.apache.james.mailbox.{MailboxManager, MailboxSession, SubscriptionManager}
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.Inject
 import scala.util.Try
 
 object MailboxGetResults {
@@ -101,11 +101,8 @@ class MailboxGetMethod @Inject() (serializer: MailboxSerializer,
     }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, MailboxGetRequest] =
-    serializer.deserializeMailboxGetRequest(invocation.arguments.value) match {
-    case JsSuccess(mailboxGetRequest, _) => Right(mailboxGetRequest)
-    case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-  }
-
+    serializer.deserializeMailboxGetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def getMailboxes(capabilities: Set[CapabilityIdentifier],
                            mailboxGetRequest: MailboxGetRequest,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxQueryMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxQueryMethod.scala
index 6a2a50e77c..b12feb469e 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxQueryMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxQueryMethod.scala
@@ -19,7 +19,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.{CanCalculateChanges, ErrorCode, Invocation, Limit, Position, QueryState}
@@ -28,9 +27,10 @@ import org.apache.james.jmap.mail.{MailboxQueryRequest, MailboxQueryResponse}
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.{MailboxSession, SystemMailboxesProvider}
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.Inject
+
 class MailboxQueryMethod @Inject()(systemMailboxesProvider: SystemMailboxesProvider,
                                    val metricFactory: MetricFactory,
                                    val sessionSupplier: SessionSupplier) extends MethodRequiringAccountId[MailboxQueryRequest] {
@@ -51,10 +51,8 @@ class MailboxQueryMethod @Inject()(systemMailboxesProvider: SystemMailboxesProvi
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, MailboxQueryRequest] =
-    MailboxQuerySerializer.deserialize(invocation.arguments.value) match {
-      case JsSuccess(emailQueryRequest, _) => Right(emailQueryRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    MailboxQuerySerializer.deserialize(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def processRequest(mailboxSession: MailboxSession, invocation: Invocation, request: MailboxQueryRequest): SMono[Invocation] =
     SFlux.fromPublisher(systemMailboxesProvider.getMailboxByRole(request.filter.role, mailboxSession.getUser))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
index ec90a1f533..933dcf7383 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.change.MailboxChangeRepository
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JAMES_SHARES, JMAP_CORE, JMAP_MAIL}
@@ -35,9 +34,11 @@ import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.mailbox.model.MailboxId
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.SMono
 
+import javax.inject.Inject
+
 case class MailboxHasMailException(mailboxId: MailboxId) extends Exception
 case class SystemMailboxChangeException(mailboxId: MailboxId) extends Exception
 case class LoopInMailboxGraphException(mailboxId: MailboxId) extends Exception
@@ -64,10 +65,8 @@ class MailboxSetMethod @Inject()(serializer: MailboxSerializer,
   } yield InvocationWithContext(response, creationResults._2)
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, MailboxSetRequest] =
-    serializer.deserializeMailboxSetRequest(invocation.arguments.value) match {
-      case JsSuccess(mailboxSetRequest, _) => Right(mailboxSetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    serializer.deserializeMailboxSetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def createResponse(capabilities: Set[CapabilityIdentifier],
                              invocation: Invocation,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionGetMethod.scala
index 09381a9666..0f5b8e6465 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionGetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.api.model.PushSubscriptionId
 import org.apache.james.jmap.api.pushsubscription.PushSubscriptionRepository
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE}
@@ -31,9 +30,10 @@ import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.lifecycle.api.Startable
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.Inject
 import scala.jdk.CollectionConverters._
 
 case class PushSubscriptionGetResults(results: Seq[PushSubscriptionDTO], notFound: Set[UnparsedPushSubscriptionId]) {
@@ -53,10 +53,8 @@ class PushSubscriptionGetMethod @Inject()(pushSubscriptionSerializer: PushSubscr
   override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE)
 
   override def getRequest(invocation: Invocation): Either[Exception, PushSubscriptionGetRequest] =
-    pushSubscriptionSerializer.deserializePushSubscriptionGetRequest(invocation.arguments.value) match {
-      case JsSuccess(getRequest, _) => Right(getRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    pushSubscriptionSerializer.deserializePushSubscriptionGetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   override def doProcess(invocation: InvocationWithContext, session: MailboxSession, request: PushSubscriptionGetRequest): SMono[InvocationWithContext] =
     request.validateProperties
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetMethod.scala
index d267019a05..b62243e4f2 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/PushSubscriptionSetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.{Invocation, PushSubscriptionSetRequest, PushSubscriptionSetResponse}
@@ -29,9 +28,10 @@ import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.lifecycle.api.Startable
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.SMono
 
+import javax.inject.Inject
+
 class PushSubscriptionSetMethod @Inject()(createPerformer: PushSubscriptionSetCreatePerformer,
                                           updatePerformer: PushSubscriptionUpdatePerformer,
                                           deletePerformer: PushSubscriptionSetDeletePerformer,
@@ -42,10 +42,8 @@ class PushSubscriptionSetMethod @Inject()(createPerformer: PushSubscriptionSetCr
   override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE)
 
   override def getRequest(invocation: Invocation): Either[Exception, PushSubscriptionSetRequest] =
-    pushSubscriptionSerializer.deserializePushSubscriptionSetRequest(invocation.arguments.value) match {
-      case JsSuccess(emailSetRequest, _) => Right(emailSetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    pushSubscriptionSerializer.deserializePushSubscriptionSetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   override def doProcess(invocation: InvocationWithContext, mailboxSession: MailboxSession, request: PushSubscriptionSetRequest): SMono[InvocationWithContext] =
     for {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala
index 3cd6c519f4..4c2d07dc7b 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala
@@ -22,6 +22,7 @@ package org.apache.james.jmap.method
 import eu.timepit.refined.auto._
 import org.apache.james.core.Username
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JAMES_SHARES, JMAP_CORE, JMAP_QUOTA}
+import org.apache.james.jmap.core.Id.Id
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodCallId, MethodName}
 import org.apache.james.jmap.core.{ErrorCode, Invocation, MissingCapabilityException, Properties}
 import org.apache.james.jmap.json.{QuotaSerializer, ResponseSerializer}
@@ -32,11 +33,10 @@ import org.apache.james.mailbox.MailboxSession
 import org.apache.james.mailbox.model.QuotaRoot
 import org.apache.james.mailbox.quota.{QuotaManager, UserQuotaRootResolver}
 import org.apache.james.metrics.api.MetricFactory
+import org.apache.james.util.ReactorUtils
 import org.reactivestreams.Publisher
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
-import org.apache.james.jmap.core.Id.Id
-import org.apache.james.util.ReactorUtils
 
 import javax.inject.Inject
 
@@ -72,10 +72,8 @@ class QuotaGetMethod @Inject()(val metricFactory: MetricFactory,
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, QuotaGetRequest] =
-    QuotaSerializer.deserializeQuotaGetRequest(invocation.arguments.value) match {
-      case JsSuccess(quotaGetRequest, _) => Right(quotaGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    QuotaSerializer.deserializeQuotaGetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def getQuotaGetResponse(quotaGetRequest: QuotaGetRequest, username: Username, capabilities: Set[CapabilityIdentifier]): SFlux[QuotaResponseGetResult] =
     quotaGetRequest.ids match {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadChangesMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadChangesMethod.scala
index bbb54cb05b..5f55e65fdc 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadChangesMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadChangesMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_MAIL}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.{ErrorCode, Invocation, UuidState}
@@ -29,9 +28,10 @@ import org.apache.james.jmap.mail.{HasMoreChanges, ThreadChangesRequest, ThreadC
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.SMono
 
+import javax.inject.Inject
+
 class ThreadChangesMethod @Inject()(val metricFactory: MetricFactory,
                                     val sessionSupplier: SessionSupplier) extends MethodRequiringAccountId[ThreadChangesRequest] {
   override val methodName: MethodName = MethodName("Thread/changes")
@@ -60,8 +60,6 @@ class ThreadChangesMethod @Inject()(val metricFactory: MetricFactory,
     }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, ThreadChangesRequest] =
-    ThreadSerializer.deserializeChanges(invocation.arguments.value) match {
-      case JsSuccess(threadGetRequest, _) => Right(threadGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    ThreadSerializer.deserializeChanges(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 }
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadGetMethod.scala
index 13ea9d333a..85b8362384 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/ThreadGetMethod.scala
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_MAIL}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.{AccountId, Invocation, UuidState}
@@ -31,9 +30,9 @@ import org.apache.james.mailbox.exception.ThreadNotFoundException
 import org.apache.james.mailbox.model.{ThreadId => JavaThreadId}
 import org.apache.james.mailbox.{MailboxManager, MailboxSession}
 import org.apache.james.metrics.api.MetricFactory
-import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.Inject
 import scala.util.Try
 
 object ThreadGetResult {
@@ -78,10 +77,8 @@ class ThreadGetMethod @Inject()(val metricFactory: MetricFactory,
       .map(InvocationWithContext(_, invocation.processingContext))
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, ThreadGetRequest] =
-    ThreadSerializer.deserialize(invocation.arguments.value) match {
-      case JsSuccess(threadGetRequest, _) => Right(threadGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    ThreadSerializer.deserialize(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def getThreadResponse(threadGetRequest: ThreadGetRequest,
                                 mailboxSession: MailboxSession): SFlux[ThreadGetResult] =
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseGetMethod.scala
index da59b105ff..0cee057042 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseGetMethod.scala
@@ -20,8 +20,6 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-
-import javax.inject.Inject
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_VACATION_RESPONSE}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodCallId, MethodName}
 import org.apache.james.jmap.core.UuidState.INSTANCE
@@ -32,11 +30,12 @@ import org.apache.james.jmap.vacation.VacationResponse.UNPARSED_SINGLETON
 import org.apache.james.jmap.vacation.{UnparsedVacationResponseId, VacationResponse, VacationResponseGetRequest, VacationResponseGetResponse, VacationResponseNotFound}
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import org.apache.james.vacation.api.{AccountId => JavaAccountId}
-import org.apache.james.vacation.api.VacationService
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import org.apache.james.vacation.api.{VacationService, AccountId => JavaAccountId}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.Inject
+
 object VacationResponseGetResult {
   def empty: VacationResponseGetResult = VacationResponseGetResult(Set.empty, VacationResponseNotFound(Set.empty))
   def merge(result1: VacationResponseGetResult, result2: VacationResponseGetResult): VacationResponseGetResult = result1.merge(result2)
@@ -85,10 +84,8 @@ class VacationResponseGetMethod @Inject()(vacationService: VacationService,
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, VacationResponseGetRequest] =
-    VacationSerializer.deserializeVacationResponseGetRequest(invocation.arguments.value) match {
-      case JsSuccess(vacationResponseGetRequest, _) => Right(vacationResponseGetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    VacationSerializer.deserializeVacationResponseGetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def handleRequestValidationErrors(exception: Exception, methodCallId: MethodCallId): SMono[Invocation] = exception match {
     case _: MissingCapabilityException => SMono.just(Invocation.error(ErrorCode.UnknownMethod, methodCallId))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
index 81fc9876bb..0eb3e03e1a 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala
@@ -20,27 +20,27 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
-import javax.inject.{Inject, Named}
 import org.apache.james.events.Event.EventId
 import org.apache.james.events.EventBus
 import org.apache.james.jmap.InjectionKeys
 import org.apache.james.jmap.api.model.AccountId
 import org.apache.james.jmap.change.{AccountIdRegistrationKey, StateChangeEvent, VacationResponseTypeName}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_VACATION_RESPONSE}
-import org.apache.james.jmap.core.{Invocation, UuidState}
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.core.SetError.SetErrorDescription
+import org.apache.james.jmap.core.{Invocation, UuidState}
 import org.apache.james.jmap.json.{ResponseSerializer, VacationSerializer}
 import org.apache.james.jmap.method.VacationResponseSetMethod.VACATION_RESPONSE_PATCH_OBJECT_KEY
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.jmap.vacation.{VacationResponseSetError, VacationResponseSetRequest, VacationResponseSetResponse, VacationResponseUpdateResponse}
 import org.apache.james.mailbox.MailboxSession
 import org.apache.james.metrics.api.MetricFactory
-import org.apache.james.vacation.api.{VacationPatch, VacationService}
-import org.apache.james.vacation.api.{AccountId => VacationAccountId}
-import play.api.libs.json.{JsError, JsObject, JsSuccess}
+import org.apache.james.vacation.api.{VacationPatch, VacationService, AccountId => VacationAccountId}
+import play.api.libs.json.JsObject
 import reactor.core.scala.publisher.{SFlux, SMono}
 
+import javax.inject.{Inject, Named}
+
 object VacationResponseUpdateResults {
   def empty(): VacationResponseUpdateResults = VacationResponseUpdateResults(Map(), Map())
 
@@ -97,10 +97,8 @@ class VacationResponseSetMethod @Inject()(@Named(InjectionKeys.JMAP) eventBus: E
   }
 
   override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[IllegalArgumentException, VacationResponseSetRequest] =
-    VacationSerializer.deserializeVacationResponseSetRequest(invocation.arguments.value) match {
-      case JsSuccess(vacationResponseSetRequest, _) => Right(vacationResponseSetRequest)
-      case errors: JsError => Left(new IllegalArgumentException(ResponseSerializer.serialize(errors).toString))
-    }
+    VacationSerializer.deserializeVacationResponseSetRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
 
   private def update(mailboxSession: MailboxSession, vacationResponseSetRequest: VacationResponseSetRequest): SMono[VacationResponseUpdateResults] = {
     SFlux.fromIterable(vacationResponseSetRequest.parsePatch()


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


[james-project] 02/02: JAMES-3830 Implement JMAP Quota/changes

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

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

commit 8ea77b7e361fb9f42b35262b15b8f54edba68e88
Author: Tung Van TRAN <vt...@linagora.com>
AuthorDate: Wed Oct 26 17:09:24 2022 +0700

    JAMES-3830 Implement JMAP Quota/changes
---
 .../james/jmap/rfc8621/RFC8621MethodsModule.java   |   2 +
 .../DistributedQuotaChangesMethodTest.java         |  55 +++
 .../contract/QuotaChangesMethodContract.scala      | 528 +++++++++++++++++++++
 .../rfc8621/contract/QuotaGetMethodContract.scala  | 173 +++----
 .../memory/MemoryQuotaChangesMethodTest.java       |  44 ++
 .../doc/specs/spec/quotas/quota.mdown              |   4 +-
 .../apache/james/jmap/json/QuotaSerializer.scala   |  19 +-
 .../scala/org/apache/james/jmap/mail/Quotas.scala  |  61 ++-
 .../james/jmap/method/QuotaChangesMethod.scala     |  79 +++
 .../apache/james/jmap/method/QuotaGetMethod.scala  |  55 +--
 10 files changed, 881 insertions(+), 139 deletions(-)

diff --git a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
index fbfe7c036e..571ef5434c 100644
--- a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
+++ b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/rfc8621/RFC8621MethodsModule.java
@@ -64,6 +64,7 @@ import org.apache.james.jmap.method.MailboxSetMethod;
 import org.apache.james.jmap.method.Method;
 import org.apache.james.jmap.method.PushSubscriptionGetMethod;
 import org.apache.james.jmap.method.PushSubscriptionSetMethod;
+import org.apache.james.jmap.method.QuotaChangesMethod;
 import org.apache.james.jmap.method.QuotaGetMethod;
 import org.apache.james.jmap.method.SystemZoneIdProvider;
 import org.apache.james.jmap.method.ThreadChangesMethod;
@@ -143,6 +144,7 @@ public class RFC8621MethodsModule extends AbstractModule {
         methods.addBinding().to(MDNSendMethod.class);
         methods.addBinding().to(PushSubscriptionGetMethod.class);
         methods.addBinding().to(PushSubscriptionSetMethod.class);
+        methods.addBinding().to(QuotaChangesMethod.class);
         methods.addBinding().to(QuotaGetMethod.class);
         methods.addBinding().to(ThreadChangesMethod.class);
         methods.addBinding().to(ThreadGetMethod.class);
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedQuotaChangesMethodTest.java b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedQuotaChangesMethodTest.java
new file mode 100644
index 0000000000..3f274d9523
--- /dev/null
+++ b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedQuotaChangesMethodTest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.rfc8621.distributed;
+
+import org.apache.james.CassandraExtension;
+import org.apache.james.CassandraRabbitMQJamesConfiguration;
+import org.apache.james.CassandraRabbitMQJamesServerMain;
+import org.apache.james.DockerOpenSearchExtension;
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.jmap.rfc8621.contract.QuotaChangesMethodContract;
+import org.apache.james.modules.AwsS3BlobStoreExtension;
+import org.apache.james.modules.RabbitMQExtension;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.modules.blobstore.BlobStoreConfiguration;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class DistributedQuotaChangesMethodTest implements QuotaChangesMethodContract {
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerBuilder<CassandraRabbitMQJamesConfiguration>(tmpDir ->
+        CassandraRabbitMQJamesConfiguration.builder()
+            .workingDirectory(tmpDir)
+            .configurationFromClasspath()
+            .blobStore(BlobStoreConfiguration.builder()
+                .s3()
+                .disableCache()
+                .deduplication()
+                .noCryptoConfig())
+            .build())
+        .extension(new DockerOpenSearchExtension())
+        .extension(new CassandraExtension())
+        .extension(new RabbitMQExtension())
+        .extension(new AwsS3BlobStoreExtension())
+        .server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
+            .overrideWith(new TestJMAPServerModule()))
+        .build();
+}
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/QuotaChangesMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaChangesMethodContract.scala
new file mode 100644
index 0000000000..86029b2262
--- /dev/null
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaChangesMethodContract.scala
@@ -0,0 +1,528 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.rfc8621.contract
+
+import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
+import io.restassured.RestAssured.{`given`, requestSpecification}
+import io.restassured.http.ContentType.JSON
+import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
+import org.apache.http.HttpStatus.SC_OK
+import org.apache.james.GuiceJamesServer
+import org.apache.james.core.quota.QuotaCountLimit
+import org.apache.james.jmap.core.ResponseObject.SESSION_STATE
+import org.apache.james.jmap.core.UuidState.INSTANCE
+import org.apache.james.jmap.http.UserCredential
+import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, ANDRE, ANDRE_PASSWORD, BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder}
+import org.apache.james.mailbox.MessageManager.AppendCommand
+import org.apache.james.mailbox.model.MailboxACL.Right.Read
+import org.apache.james.mailbox.model.{MailboxACL, MailboxPath}
+import org.apache.james.mime4j.dom.Message
+import org.apache.james.modules.{ACLProbeImpl, MailboxProbeImpl, QuotaProbesImpl}
+import org.apache.james.utils.DataProbeImpl
+import org.assertj.core.api.Assertions.assertThat
+import org.awaitility.Awaitility
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import java.nio.charset.StandardCharsets
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+
+
+trait QuotaChangesMethodContract {
+
+  private lazy val awaitAtMostTenSeconds = Awaitility.`with`
+    .await
+    .pollInterval(Duration.ofMillis(100))
+    .atMost(10, TimeUnit.SECONDS)
+
+  @BeforeEach
+  def setUp(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl])
+      .fluent
+      .addDomain(DOMAIN.asString)
+      .addUser(BOB.asString, BOB_PASSWORD)
+      .addUser(ANDRE.asString, ANDRE_PASSWORD)
+
+    requestSpecification = baseRequestSpecBuilder(server)
+      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .build
+  }
+
+  @Test
+  def quotaChangeShouldReturnCorrectResponse(server: GuiceJamesServer): Unit = {
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    val bobQuotaRoot = quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB))
+    quotaProbe.setMaxMessageCount(bobQuotaRoot, QuotaCountLimit.count(100L))
+
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |    "sessionState": "${SESSION_STATE.value}",
+         |    "methodResponses": [
+         |        [
+         |            "Quota/changes",
+         |            {
+         |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                "oldState": "${INSTANCE.value}",
+         |                "newState": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
+         |                "hasMoreChanges": false,
+         |                "updatedProperties": null,
+         |                "created": [],
+         |                "updated": ["08417be420b6dd6fa77d48fb2438e0d19108cd29424844bb109b52d356fab528"],
+         |                "destroyed": []
+         |            },
+         |            "c1"
+         |        ]
+         |    ]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def quotaChangeShouldReturnSameResponseWhenSameRequest(server: GuiceJamesServer): Unit = {
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    val bobQuotaRoot = quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB))
+    quotaProbe.setMaxMessageCount(bobQuotaRoot, QuotaCountLimit.count(100L))
+
+    val response1 = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    val response2 = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response1).isEqualTo(response2)
+  }
+
+  @Test
+  def hasMoreChangesShouldBeFalseWhenNoQuotaChanges(server: GuiceJamesServer): Unit = {
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    val bobQuotaRoot = quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB))
+    quotaProbe.setMaxMessageCount(bobQuotaRoot, QuotaCountLimit.count(100L))
+
+    val newState: String = getLastState()
+
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${newState}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |    "sessionState": "${SESSION_STATE.value}",
+         |    "methodResponses": [
+         |        [
+         |            "Quota/changes",
+         |            {
+         |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                "oldState": "${newState}",
+         |                "newState": "${newState}",
+         |                "hasMoreChanges": false,
+         |                "updatedProperties": null,
+         |                "created": [],
+         |                "updated": [],
+         |                "destroyed": []
+         |            },
+         |            "c1"
+         |        ]
+         |    ]
+         |}""".stripMargin)
+  }
+
+
+  @Test
+  def stateShouldBeChangedWhenQuotaIsUpdated(server: GuiceJamesServer): Unit = {
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    val bobQuotaRoot = quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB))
+    quotaProbe.setMaxMessageCount(bobQuotaRoot, QuotaCountLimit.count(100L))
+    server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.inbox(BOB))
+
+    val newState: String = getLastState()
+
+    // update quota usage
+    server.getProbe(classOf[MailboxProbeImpl])
+      .appendMessage(BOB.asString(), MailboxPath.inbox(BOB), AppendCommand.from(Message.Builder
+        .of
+        .setSubject("test")
+        .setBody("testmail", StandardCharsets.UTF_8)
+        .build))
+      .getMessageId.serialize()
+
+    awaitAtMostTenSeconds.untilAsserted(() => assertThat(getLastState())
+      .isNotEqualTo(newState))
+  }
+
+  private def getLastState(): String = {
+    `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+      .when
+      .post
+      .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract()
+      .jsonPath()
+      .get("methodResponses[0][1].newState")
+  }
+
+  @Test
+  def quotaChangesShouldFailWhenWrongAccountId(): Unit = {
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "unknownAccountId",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |  "sessionState": "${SESSION_STATE.value}",
+         |  "methodResponses": [
+         |    ["error", {
+         |      "type": "accountNotFound"
+         |    }, "c1"]
+         |  ]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def quotaChangesShouldFailWhenMissSinceState(): Unit = {
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |    "sessionState": "${SESSION_STATE.value}",
+         |    "methodResponses": [
+         |        [
+         |            "error",
+         |            {
+         |                "type": "invalidArguments",
+         |                "description": "{\\"errors\\":[{\\"path\\":\\"obj.sinceState\\",\\"messages\\":[\\"error.path.missing\\"]}]}"
+         |            },
+         |            "c1"
+         |        ]
+         |    ]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def quotaChangesShouldFailWhenSinceStateIsInvalid(): Unit = {
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "invaLid@"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |    "sessionState": "${SESSION_STATE.value}",
+         |    "methodResponses": [
+         |        [
+         |            "error",
+         |            {
+         |                "type": "invalidArguments",
+         |                "description": "{\\"errors\\":[{\\"path\\":\\"obj.sinceState\\",\\"messages\\":[\\"error.expected.uuid\\"]}]}"
+         |            },
+         |            "c1"
+         |        ]
+         |    ]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def quotaChangeShouldFailWhenOmittingOneCapability(): Unit = {
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "unknownAccountId",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |  "sessionState": "${SESSION_STATE.value}",
+         |  "methodResponses": [[
+         |    "error",
+         |    {
+         |      "type": "unknownMethod",
+         |      "description":"Missing capability(ies): urn:ietf:params:jmap:quota"
+         |    },
+         |    "c1"]]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def quotaChangesShouldFailWhenOmittingAllCapability(): Unit = {
+    val response = `given`
+      .body(
+        s"""{
+           |  "using": [],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "unknownAccountId",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |  "sessionState": "${SESSION_STATE.value}",
+         |  "methodResponses": [[
+         |    "error",
+         |    {
+         |      "type": "unknownMethod",
+         |      "description":"Missing capability(ies): urn:ietf:params:jmap:quota, urn:ietf:params:jmap:core"
+         |    },
+         |    "c1"]]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def quotaChangesShouldReturnDifferenceStateWhenProvideDelegatedMailbox(server: GuiceJamesServer): Unit = {
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    val bobQuotaRoot = quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB))
+    quotaProbe.setMaxMessageCount(bobQuotaRoot, QuotaCountLimit.count(100L))
+
+    // setup delegated Mailbox
+    val andreMailbox = MailboxPath.forUser(ANDRE, "mailbox")
+    val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(andreMailbox)
+    server.getProbe(classOf[ACLProbeImpl])
+      .replaceRights(andreMailbox, BOB.asString, new MailboxACL.Rfc4314Rights(Read))
+    quotaProbe.setMaxMessageCount(quotaProbe.getQuotaRoot(andreMailbox), QuotaCountLimit.count(88L))
+
+    val stateWithOutShareCapability: String = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract()
+      .jsonPath()
+      .get("methodResponses[0][1].newState")
+
+    val stateWithShareCapability: String = `given`
+      .body(
+        s"""{
+           |  "using": [
+           |    "urn:ietf:params:jmap:core",
+           |    "urn:ietf:params:jmap:quota",
+           |    "urn:apache:james:params:jmap:mail:shares"],
+           |  "methodCalls": [[
+           |    "Quota/changes",
+           |    {
+           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "sinceState": "${INSTANCE.value}"
+           |    },
+           |    "c1"]]
+           |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract()
+      .jsonPath()
+      .get("methodResponses[0][1].newState")
+
+    assertThat(stateWithShareCapability).isNotEqualTo(stateWithOutShareCapability)
+  }
+}
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/QuotaGetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaGetMethodContract.scala
index bd8f00ca02..3d0687a5f8 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaGetMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaGetMethodContract.scala
@@ -43,9 +43,18 @@ import org.junit.jupiter.api.{BeforeEach, Test}
 import java.nio.charset.StandardCharsets
 import org.apache.james.mailbox.model.MailboxACL.Right.Read
 import org.apache.james.mailbox.model.MailboxACL.Right.Lookup
+import org.awaitility.Awaitility
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
 
 trait QuotaGetMethodContract {
 
+  private lazy val awaitAtMostTenSeconds = Awaitility.`with`
+    .await
+    .pollInterval(Duration.ofMillis(100))
+    .atMost(10, TimeUnit.SECONDS)
+
   @BeforeEach
   def setUp(server: GuiceJamesServer): Unit = {
     server.getProbe(classOf[DataProbeImpl])
@@ -92,7 +101,7 @@ trait QuotaGetMethodContract {
          |    "Quota/get",
          |    {
          |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-         |      "state": "${INSTANCE.value}",
+         |      "state": "1a9d5db2-2c73-3993-bf0b-42f64b396873",
          |      "list": [],
          |      "notFound": []
          |    },
@@ -141,7 +150,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "6d7199ed-f1ce-31f3-8f02-c2e824004e55",
          |                "list": [
          |                    {
          |                        "used": 0,
@@ -214,7 +223,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
          |                "list": []
          |            },
          |            "c1"
@@ -262,7 +271,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [ "notfound123" ],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
          |                "list": []
          |            },
          |            "c1"
@@ -313,7 +322,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [ "notfound123" ],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "461cef39-0c47-352b-a9e9-052093c20d5d",
          |                "list": [
          |                    {
          |                        "used": 0,
@@ -386,7 +395,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [ ],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "3c51d50a-d766-38b7-9fa4-c9ff12de87a4",
          |                "list": [
          |                    {
          |                        "used": 1,
@@ -576,7 +585,7 @@ trait QuotaGetMethodContract {
          |    "Quota/get",
          |    {
          |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-         |      "state": "${INSTANCE.value}",
+         |      "state": "1a9d5db2-2c73-3993-bf0b-42f64b396873",
          |      "list": [],
          |      "notFound": []
          |    },
@@ -622,7 +631,7 @@ trait QuotaGetMethodContract {
          |    "Quota/get",
          |    {
          |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-         |      "state": "${INSTANCE.value}",
+         |      "state": "1a9d5db2-2c73-3993-bf0b-42f64b396873",
          |      "list": [],
          |      "notFound": [ "${quotaId}" ]
          |    },
@@ -667,7 +676,7 @@ trait QuotaGetMethodContract {
          |    "Quota/get",
          |    {
          |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-         |      "state": "${INSTANCE.value}",
+         |      "state": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
          |      "list": [
          |        {
          |          "id": "08417be420b6dd6fa77d48fb2438e0d19108cd29424844bb109b52d356fab528"
@@ -716,7 +725,7 @@ trait QuotaGetMethodContract {
          |    "Quota/get",
          |    {
          |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-         |      "state": "${INSTANCE.value}",
+         |      "state": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
          |      "list": [
          |        {
          |          "id": "08417be420b6dd6fa77d48fb2438e0d19108cd29424844bb109b52d356fab528",
@@ -844,73 +853,75 @@ trait QuotaGetMethodContract {
         .build))
       .getMessageId.serialize()
 
-    val response = `given`
-      .body(
-        s"""{
-           |  "using": [
-           |    "urn:ietf:params:jmap:core",
-           |    "urn:ietf:params:jmap:quota"],
-           |  "methodCalls": [[
-           |    "Quota/get",
-           |    {
-           |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-           |      "ids": null
-           |    },
-           |    "c1"]]
-           |}""".stripMargin)
-    .when
-      .post
-    .`then`
-      .statusCode(SC_OK)
-      .contentType(JSON)
-      .extract
-      .body
-      .asString
-
-    assertThatJson(response)
-      .withOptions(new Options(IGNORING_ARRAY_ORDER))
-      .isEqualTo(
-      s"""{
-         |    "sessionState": "${SESSION_STATE.value}",
-         |    "methodResponses": [
-         |        [
-         |            "Quota/get",
-         |            {
-         |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
-         |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
-         |                "list": [
-         |                    {
-         |                        "used": 1,
-         |                        "name": "#private&bob@domain.tld@domain.tld:account:count:Mail",
-         |                        "id": "08417be420b6dd6fa77d48fb2438e0d19108cd29424844bb109b52d356fab528",
-         |                        "dataTypes": [
-         |                            "Mail"
-         |                        ],
-         |                        "limit": 100,
-         |                        "warnLimit": 90,
-         |                        "resourceType": "count",
-         |                        "scope": "account"
-         |                    },
-         |                    {
-         |                        "used": 85,
-         |                        "name": "#private&bob@domain.tld@domain.tld:account:octets:Mail",
-         |                        "id": "eab6ce8ac5d9730a959e614854410cf39df98ff3760a623b8e540f36f5184947",
-         |                        "dataTypes": [
-         |                            "Mail"
-         |                        ],
-         |                        "limit": 101,
-         |                        "warnLimit": 90,
-         |                        "resourceType": "octets",
-         |                        "scope": "account"
-         |                    }
-         |                ]
-         |            },
-         |            "c1"
-         |        ]
-         |    ]
-         |}
-         |""".stripMargin)
+    awaitAtMostTenSeconds.untilAsserted(() => {
+      val response = `given`
+        .body(
+          s"""{
+             |  "using": [
+             |    "urn:ietf:params:jmap:core",
+             |    "urn:ietf:params:jmap:quota"],
+             |  "methodCalls": [[
+             |    "Quota/get",
+             |    {
+             |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+             |      "ids": null
+             |    },
+             |    "c1"]]
+             |}""".stripMargin)
+      .when
+        .post
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response)
+        .withOptions(new Options(IGNORING_ARRAY_ORDER))
+        .isEqualTo(
+          s"""{
+             |    "sessionState": "${SESSION_STATE.value}",
+             |    "methodResponses": [
+             |        [
+             |            "Quota/get",
+             |            {
+             |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+             |                "notFound": [],
+             |                "state": "7d53031b-2819-3584-9e9d-e10ac1067906",
+             |                "list": [
+             |                    {
+             |                        "used": 1,
+             |                        "name": "#private&bob@domain.tld@domain.tld:account:count:Mail",
+             |                        "id": "08417be420b6dd6fa77d48fb2438e0d19108cd29424844bb109b52d356fab528",
+             |                        "dataTypes": [
+             |                            "Mail"
+             |                        ],
+             |                        "limit": 100,
+             |                        "warnLimit": 90,
+             |                        "resourceType": "count",
+             |                        "scope": "account"
+             |                    },
+             |                    {
+             |                        "used": 85,
+             |                        "name": "#private&bob@domain.tld@domain.tld:account:octets:Mail",
+             |                        "id": "eab6ce8ac5d9730a959e614854410cf39df98ff3760a623b8e540f36f5184947",
+             |                        "dataTypes": [
+             |                            "Mail"
+             |                        ],
+             |                        "limit": 101,
+             |                        "warnLimit": 90,
+             |                        "resourceType": "octets",
+             |                        "scope": "account"
+             |                    }
+             |                ]
+             |            },
+             |            "c1"
+             |        ]
+             |    ]
+             |}
+             |""".stripMargin)
+    })
   }
 
   @Test
@@ -960,7 +971,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
          |                "list": [
          |                    {
          |                        "used": 0,
@@ -1032,7 +1043,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "5dc809dd-d059-3fab-bc7e-c0f1fcacf2f2",
          |                "list": [
          |                    {
          |                        "used": 0,
@@ -1114,7 +1125,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "84c40a2e-76a1-3f84-a1e8-862104c7a697",
          |                "list": [
          |                    {
          |                        "used": 0,
@@ -1186,7 +1197,7 @@ trait QuotaGetMethodContract {
          |            {
          |                "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "notFound": [],
-         |                "state": "${INSTANCE.value}",
+         |                "state": "5dc809dd-d059-3fab-bc7e-c0f1fcacf2f2",
          |                "list": [
          |                    {
          |                        "used": 0,
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryQuotaChangesMethodTest.java b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryQuotaChangesMethodTest.java
new file mode 100644
index 0000000000..c2606b3d9d
--- /dev/null
+++ b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryQuotaChangesMethodTest.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.rfc8621.memory;
+
+import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;
+
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.MemoryJamesConfiguration;
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.jmap.rfc8621.contract.QuotaChangesMethodContract;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class MemoryQuotaChangesMethodTest implements QuotaChangesMethodContract {
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerBuilder<MemoryJamesConfiguration>(tmpDir ->
+        MemoryJamesConfiguration.builder()
+            .workingDirectory(tmpDir)
+            .configurationFromClasspath()
+            .usersRepository(DEFAULT)
+            .build())
+        .server(configuration -> MemoryJamesServerMain.createServer(configuration)
+            .overrideWith(new TestJMAPServerModule()))
+        .build();
+}
diff --git a/server/protocols/jmap-rfc-8621/doc/specs/spec/quotas/quota.mdown b/server/protocols/jmap-rfc-8621/doc/specs/spec/quotas/quota.mdown
index 1fef9d046d..e9215e303c 100644
--- a/server/protocols/jmap-rfc-8621/doc/specs/spec/quotas/quota.mdown
+++ b/server/protocols/jmap-rfc-8621/doc/specs/spec/quotas/quota.mdown
@@ -46,8 +46,8 @@ Standard “/get” method as described in [@!RFC8620] section 5.1. The ids argu
 
 ## Quota/changes
 
-> :warning:
-> Not implemented
+> :information_source:
+> Implemented
 
 Standard “/changes” method as described in [@!RFC8620] section 5.2 but with one extra argument to the response:
 
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala
index 2ca89be9ab..bcd56b62a4 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala
@@ -22,7 +22,7 @@ package org.apache.james.jmap.json
 import eu.timepit.refined
 import org.apache.james.jmap.core.Id.IdConstraint
 import org.apache.james.jmap.core.{Properties, UuidState}
-import org.apache.james.jmap.mail.{DataType, JmapQuota, QuotaDescription, QuotaGetRequest, QuotaGetResponse, QuotaIds, QuotaName, QuotaNotFound, ResourceType, Scope, UnparsedQuotaId}
+import org.apache.james.jmap.mail.{DataType, JmapQuota, QuotaChangesRequest, QuotaChangesResponse, QuotaDescription, QuotaGetRequest, QuotaGetResponse, QuotaIds, QuotaName, QuotaNotFound, ResourceType, Scope, UnparsedQuotaId}
 import play.api.libs.json._
 
 object QuotaSerializer {
@@ -53,10 +53,25 @@ object QuotaSerializer {
     notFound => JsArray(notFound.value.toList.map(id => JsString(id.id.value)))
   private implicit val quotaGetResponseWrites: Writes[QuotaGetResponse] = Json.writes[QuotaGetResponse]
 
+  private implicit val quotaChangesRequestReads: Reads[QuotaChangesRequest] = Json.reads[QuotaChangesRequest]
+
+  private implicit val quotaChangesResponseWrites: Writes[QuotaChangesResponse] = response =>
+    Json.obj(
+      "accountId" -> response.accountId,
+      "oldState" -> response.oldState,
+      "newState" -> response.newState,
+      "hasMoreChanges" -> response.hasMoreChanges,
+      "updatedProperties" -> response.updatedProperties,
+      "created" -> response.created,
+      "updated" -> response.updated,
+      "destroyed" -> response.destroyed)
+
   def deserializeQuotaGetRequest(input: String): JsResult[QuotaGetRequest] = Json.parse(input).validate[QuotaGetRequest]
 
   def deserializeQuotaGetRequest(input: JsValue): JsResult[QuotaGetRequest] = Json.fromJson[QuotaGetRequest](input)
 
+  def deserializeQuotaChangesRequest(input: JsValue): JsResult[QuotaChangesRequest] = Json.fromJson[QuotaChangesRequest](input)
+
   def serialize(quotaGetResponse: QuotaGetResponse, properties: Properties): JsValue =
     Json.toJson(quotaGetResponse)
       .transform((__ \ "list").json.update {
@@ -70,4 +85,6 @@ object QuotaSerializer {
 
   def serialize(response: QuotaGetResponse): JsValue = Json.toJson(response)
 
+  def serializeChanges(changesResponse: QuotaChangesResponse): JsObject = Json.toJson(changesResponse).as[JsObject]
+
 }
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Quotas.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Quotas.scala
index 1c4545a5d9..d24076b1ce 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Quotas.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Quotas.scala
@@ -23,14 +23,15 @@ import com.google.common.hash.Hashing
 import eu.timepit.refined.auto._
 import org.apache.james.core.Domain
 import org.apache.james.core.quota.{QuotaCountLimit, QuotaCountUsage, QuotaSizeLimit, QuotaSizeUsage}
+import org.apache.james.jmap.api.change.Limit
 import org.apache.james.jmap.core.Id.Id
 import org.apache.james.jmap.core.UnsignedInt.UnsignedInt
-import org.apache.james.jmap.core.UuidState.INSTANCE
 import org.apache.james.jmap.core.{AccountId, Id, Properties, UnsignedInt, UuidState}
 import org.apache.james.jmap.method.WithAccountId
 import org.apache.james.mailbox.model.{Quota => ModelQuota, QuotaRoot => ModelQuotaRoot}
 
 import java.nio.charset.StandardCharsets
+import java.util.UUID
 import scala.compat.java8.OptionConverters._
 
 object QuotaRoot {
@@ -109,6 +110,10 @@ object JmapQuota {
         name = QuotaName.from(quotaRoot, AccountScope, OctetsResourceType, List(MailDataType)),
         dataTypes = List(MailDataType),
         warnLimit = Some(UnsignedInt.liftOrThrow((limit.asLong() * WARN_LIMIT_PERCENTAGE).toLong))))
+
+  def correspondingState(quotas: Seq[JmapQuota]): UuidState =
+    UuidState(UUID.nameUUIDFromBytes(s"${quotas.sortBy(_.name.string).map(_.name.string).mkString("_")}:${quotas.map(_.used.value).sum + quotas.map(_.limit.value).sum}"
+      .getBytes(StandardCharsets.UTF_8)))
 }
 
 case class JmapQuota(id: Id,
@@ -174,19 +179,49 @@ object QuotaIdFactory {
 }
 
 object QuotaResponseGetResult {
-  def empty: QuotaResponseGetResult = QuotaResponseGetResult()
-
-  def merge(result1: QuotaResponseGetResult, result2: QuotaResponseGetResult): QuotaResponseGetResult = result1.merge(result2)
-}
-
-case class QuotaResponseGetResult(jmapQuotaSet: Set[JmapQuota] = Set(), notFound: QuotaNotFound = QuotaNotFound(Set())) {
-  def merge(other: QuotaResponseGetResult): QuotaResponseGetResult =
-    QuotaResponseGetResult(this.jmapQuotaSet ++ other.jmapQuotaSet,
-      this.notFound.merge(other.notFound))
-
+  def from(quotas: Seq[JmapQuota], requestIds: Option[Set[Id]]): QuotaResponseGetResult =
+    requestIds match {
+      case None => QuotaResponseGetResult(quotas.toSet, state = JmapQuota.correspondingState(quotas))
+      case Some(value) => QuotaResponseGetResult(
+        jmapQuotaSet = quotas.filter(quota => value.contains(quota.id)).toSet,
+        notFound = QuotaNotFound(value.diff(quotas.map(_.id).toSet).map(UnparsedQuotaId)),
+        state = JmapQuota.correspondingState(quotas))
+    }
+}
+
+case class QuotaResponseGetResult(jmapQuotaSet: Set[JmapQuota] = Set(),
+                                  notFound: QuotaNotFound = QuotaNotFound(Set()),
+                                  state: UuidState) {
   def asResponse(accountId: AccountId): QuotaGetResponse =
     QuotaGetResponse(accountId = accountId,
-      state = INSTANCE,
+      state = state,
       list = jmapQuotaSet.toList,
       notFound = notFound)
-}
\ No newline at end of file
+}
+
+case class QuotaChangesRequest(accountId: AccountId,
+                               sinceState: UuidState,
+                               maxChanges: Option[Limit]) extends WithAccountId
+
+object QuotaChangesResponse {
+  def from(oldState: UuidState, newState: (UuidState, Seq[Id]), accountId: AccountId): QuotaChangesResponse =
+    QuotaChangesResponse(
+      accountId = accountId,
+      oldState = oldState,
+      newState = newState._1,
+      hasMoreChanges = HasMoreChanges(false),
+      updated = if (oldState.value.equals(newState._1.value)) {
+        Set()
+      } else {
+        newState._2.toSet
+      })
+}
+
+case class QuotaChangesResponse(accountId: AccountId,
+                                oldState: UuidState,
+                                newState: UuidState,
+                                hasMoreChanges: HasMoreChanges,
+                                updatedProperties: Option[Properties] = None,
+                                created: Set[Id] = Set(),
+                                updated: Set[Id] = Set(),
+                                destroyed: Set[Id] = Set())
\ No newline at end of file
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaChangesMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaChangesMethod.scala
new file mode 100644
index 0000000000..f451495402
--- /dev/null
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaChangesMethod.scala
@@ -0,0 +1,79 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.method
+
+
+import eu.timepit.refined.auto._
+import org.apache.james.core.Username
+import org.apache.james.jmap.api.change.CanNotCalculateChangesException
+import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_CORE, JMAP_QUOTA}
+import org.apache.james.jmap.core.Id.Id
+import org.apache.james.jmap.core.Invocation.{Arguments, MethodName}
+import org.apache.james.jmap.core.{ErrorCode, Invocation, UuidState}
+import org.apache.james.jmap.json.{QuotaSerializer, ResponseSerializer}
+import org.apache.james.jmap.mail.{JmapQuota, QuotaChangesRequest, QuotaChangesResponse}
+import org.apache.james.jmap.routes.SessionSupplier
+import org.apache.james.mailbox.MailboxSession
+import org.apache.james.mailbox.quota.{QuotaManager, UserQuotaRootResolver}
+import org.apache.james.metrics.api.MetricFactory
+import org.reactivestreams.Publisher
+import reactor.core.scala.publisher.SMono
+
+import javax.inject.Inject
+
+class QuotaChangesMethod @Inject()(val metricFactory: MetricFactory,
+                                   val sessionSupplier: SessionSupplier,
+                                   val quotaManager: QuotaManager,
+                                   val quotaRootResolver: UserQuotaRootResolver) extends MethodRequiringAccountId[QuotaChangesRequest] {
+
+  override val methodName: Invocation.MethodName = MethodName("Quota/changes")
+
+  override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_QUOTA, JMAP_CORE)
+
+  val quotaChangesResolver: QuotaChangesResolver = QuotaChangesResolver(quotaManager, quotaRootResolver)
+
+  override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: InvocationWithContext, mailboxSession: MailboxSession, request: QuotaChangesRequest): Publisher[InvocationWithContext] =
+    quotaChangesResolver.getLatestState(mailboxSession.getUser, capabilities)
+      .map(newState => QuotaChangesResponse.from(request.sinceState, newState, request.accountId))
+      .map(response => InvocationWithContext(
+        invocation = Invocation(
+          methodName = methodName,
+          arguments = Arguments(QuotaSerializer.serializeChanges(response)),
+          methodCallId = invocation.invocation.methodCallId),
+        processingContext = invocation.processingContext))
+      .onErrorResume {
+        case e: CanNotCalculateChangesException => SMono.just(InvocationWithContext(Invocation.error(ErrorCode.CannotCalculateChanges, e.getMessage, invocation.invocation.methodCallId), invocation.processingContext))
+        case e => SMono.error(e)
+      }
+
+  override def getRequest(mailboxSession: MailboxSession, invocation: Invocation): Either[Exception, QuotaChangesRequest] =
+    QuotaSerializer.deserializeQuotaChangesRequest(invocation.arguments.value)
+      .asEither.left.map(ResponseSerializer.asException)
+}
+
+case class QuotaChangesResolver(private val quotaManager: QuotaManager,
+                                private val quotaRootResolver: UserQuotaRootResolver) {
+  private val jmapQuotaManagerWrapper: JmapQuotaManagerWrapper = JmapQuotaManagerWrapper(quotaManager, quotaRootResolver)
+
+  def getLatestState(username: Username, capabilities: Set[CapabilityIdentifier]): SMono[(UuidState, Seq[Id])] =
+    jmapQuotaManagerWrapper.list(username, capabilities)
+      .collectSeq()
+      .map(quotas => (JmapQuota.correspondingState(quotas), quotas.map(_.id)))
+}
\ No newline at end of file
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala
index 4c2d07dc7b..fb339699a8 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaGetMethod.scala
@@ -26,7 +26,7 @@ import org.apache.james.jmap.core.Id.Id
 import org.apache.james.jmap.core.Invocation.{Arguments, MethodCallId, MethodName}
 import org.apache.james.jmap.core.{ErrorCode, Invocation, MissingCapabilityException, Properties}
 import org.apache.james.jmap.json.{QuotaSerializer, ResponseSerializer}
-import org.apache.james.jmap.mail.{CountResourceType, JmapQuota, OctetsResourceType, QuotaGetRequest, QuotaIdFactory, QuotaNotFound, QuotaResponseGetResult}
+import org.apache.james.jmap.mail.{CountResourceType, JmapQuota, OctetsResourceType, QuotaGetRequest, QuotaIdFactory, QuotaNotFound, QuotaResponseGetResult, UnparsedQuotaId}
 import org.apache.james.jmap.routes.SessionSupplier
 import org.apache.james.lifecycle.api.Startable
 import org.apache.james.mailbox.MailboxSession
@@ -54,7 +54,6 @@ class QuotaGetMethod @Inject()(val metricFactory: MetricFactory,
 
     (requestedProperties -- JmapQuota.allProperties match {
       case invalidProperties if invalidProperties.isEmpty() => getQuotaGetResponse(request, mailboxSession.getUser, capabilities)
-        .reduce(QuotaResponseGetResult.empty)(QuotaResponseGetResult.merge)
         .map(result => result.asResponse(accountId = request.accountId))
         .map(response => Invocation(
           methodName = methodName,
@@ -75,18 +74,10 @@ class QuotaGetMethod @Inject()(val metricFactory: MetricFactory,
     QuotaSerializer.deserializeQuotaGetRequest(invocation.arguments.value)
       .asEither.left.map(ResponseSerializer.asException)
 
-  private def getQuotaGetResponse(quotaGetRequest: QuotaGetRequest, username: Username, capabilities: Set[CapabilityIdentifier]): SFlux[QuotaResponseGetResult] =
-    quotaGetRequest.ids match {
-      case None =>
-        jmapQuotaManagerWrapper.list(username, capabilities)
-          .collectSeq()
-          .map(listJmapQuota => QuotaResponseGetResult(jmapQuotaSet = listJmapQuota.toSet))
-          .flatMapMany(result => SFlux.just(result))
-      case Some(ids) => SFlux.fromIterable(ids.value)
-        .flatMap(id => jmapQuotaManagerWrapper.get(username, id.id, capabilities)
-          .map(jmapQuota => QuotaResponseGetResult(jmapQuotaSet = Set(jmapQuota)))
-          .switchIfEmpty(SMono.just(QuotaResponseGetResult(notFound = QuotaNotFound(Set(id))))))
-    }
+  private def getQuotaGetResponse(request: QuotaGetRequest, username: Username, capabilities: Set[CapabilityIdentifier]): SMono[QuotaResponseGetResult] =
+    jmapQuotaManagerWrapper.list(username, capabilities)
+      .collectSeq()
+      .map(quotas => QuotaResponseGetResult.from(quotas, request.ids.map(_.value.map(_.id).toSet)))
 
   private def handleRequestValidationErrors(exception: Exception, methodCallId: MethodCallId): SMono[Invocation] = exception match {
     case _: MissingCapabilityException => SMono.just(Invocation.error(ErrorCode.UnknownMethod, methodCallId))
@@ -94,15 +85,11 @@ class QuotaGetMethod @Inject()(val metricFactory: MetricFactory,
   }
 }
 
-case class JmapQuotaManagerWrapper(private var quotaManager: QuotaManager,
-                                   private var quotaRootResolver: UserQuotaRootResolver) {
-  def get(username: Username, quotaId: Id, capabilities: Set[CapabilityIdentifier]): SFlux[JmapQuota] =
-    retrieveQuotaRoot(username, capabilities)
-      .flatMap(quotaRoot => getJmapQuota(quotaRoot, Some(quotaId)))
-
+case class JmapQuotaManagerWrapper(private val quotaManager: QuotaManager,
+                                   private val quotaRootResolver: UserQuotaRootResolver) {
   def list(username: Username, capabilities: Set[CapabilityIdentifier]): SFlux[JmapQuota] =
     retrieveQuotaRoot(username, capabilities)
-      .flatMap(quotaRoot => getJmapQuota(quotaRoot))
+      .flatMap(quotaRoot => getJmapQuota(quotaRoot), ReactorUtils.DEFAULT_CONCURRENCY)
 
   def retrieveQuotaRoot(username: Username, capabilities: Set[CapabilityIdentifier]): SFlux[QuotaRoot] =
     SMono.just(capabilities)
@@ -111,26 +98,10 @@ case class JmapQuotaManagerWrapper(private var quotaManager: QuotaManager,
       .flatMapMany(_ => SFlux(quotaRootResolver.listAllAccessibleQuotaRoots(username)))
       .switchIfEmpty(SFlux.just(quotaRootResolver.forUser(username)))
 
-  private def getJmapQuota(quotaRoot: QuotaRoot, quotaId: Option[Id] = None): SFlux[JmapQuota] =
-    (quotaId match {
-      case None => SMono(quotaManager.getQuotasReactive(quotaRoot))
-        .flatMapMany(quotas => SMono.fromCallable(() => JmapQuota.extractUserMessageCountQuota(quotas.getMessageQuota, QuotaIdFactory.from(quotaRoot, CountResourceType), quotaRoot))
-          .mergeWith(SMono.fromCallable(() => JmapQuota.extractUserMessageSizeQuota(quotas.getStorageQuota, QuotaIdFactory.from(quotaRoot, OctetsResourceType), quotaRoot))))
-
-      case Some(quotaIdValue) =>
-        val quotaCountPublisher = SMono.fromCallable(() => QuotaIdFactory.from(quotaRoot, CountResourceType))
-          .filter(countQuotaId => countQuotaId.value.equals(quotaIdValue.value))
-          .flatMap(_ => SMono.fromCallable(() => quotaManager.getMessageQuota(quotaRoot))
-            .subscribeOn(ReactorUtils.BLOCKING_CALL_WRAPPER))
-          .map(quota => JmapQuota.extractUserMessageCountQuota(quota, quotaIdValue, quotaRoot))
-
-        val quotaSizePublisher = SMono.fromCallable(() => QuotaIdFactory.from(quotaRoot, OctetsResourceType))
-          .filter(sizeQuotaId => sizeQuotaId.value.equals(quotaIdValue.value))
-          .flatMap(_ => SMono.fromCallable(() => quotaManager.getStorageQuota(quotaRoot))
-            .subscribeOn(ReactorUtils.BLOCKING_CALL_WRAPPER))
-          .map(quota => JmapQuota.extractUserMessageSizeQuota(quota, quotaIdValue, quotaRoot))
-
-        quotaCountPublisher.mergeWith(quotaSizePublisher)
-    }).flatMap(SMono.justOrEmpty)
+  private def getJmapQuota(quotaRoot: QuotaRoot): SFlux[JmapQuota] =
+    SMono(quotaManager.getQuotasReactive(quotaRoot))
+      .flatMapMany(quotas => SMono.fromCallable(() => JmapQuota.extractUserMessageCountQuota(quotas.getMessageQuota, QuotaIdFactory.from(quotaRoot, CountResourceType), quotaRoot))
+        .mergeWith(SMono.fromCallable(() => JmapQuota.extractUserMessageSizeQuota(quotas.getStorageQuota, QuotaIdFactory.from(quotaRoot, OctetsResourceType), quotaRoot))))
+      .flatMap(SMono.justOrEmpty)
 
 }
\ No newline at end of file


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