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

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


The following commit(s) were added to refs/heads/master by this push:
     new 452efc9390 [FIX] Email/set should allow creating an email with 
attachment of a destroyed message
452efc9390 is described below

commit 452efc9390b6a95b08554f69a7679540f5ed9fb4
Author: Benoit TELLIER <[email protected]>
AuthorDate: Mon Feb 12 21:11:06 2024 +0100

    [FIX] Email/set should allow creating an email with attachment of a 
destroyed message
    
    Twake mail relies on this for updating a draft message
---
 .../rfc8621/contract/EmailSetMethodContract.scala  | 57 ++++++++++++++++++++++
 .../apache/james/jmap/method/EmailSetMethod.scala  |  4 +-
 .../james/jmap/method/MailboxSetMethod.scala       |  2 +-
 3 files changed, 60 insertions(+), 3 deletions(-)

diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
index f302bb2a58..614b72dfd9 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
@@ -52,6 +52,7 @@ import org.apache.james.mailbox.model.{ComposedMessageId, 
MailboxACL, MailboxCon
 import org.apache.james.mailbox.probe.MailboxProbe
 import org.apache.james.mime4j.dom.Message
 import org.apache.james.modules.{ACLProbeImpl, MailboxProbeImpl, 
QuotaProbesImpl}
+import org.apache.james.util.ClassLoaderUtils
 import org.apache.james.utils.DataProbeImpl
 import org.assertj.core.api.Assertions.assertThat
 import org.awaitility.Awaitility
@@ -436,6 +437,62 @@ trait EmailSetMethodContract {
       .isEqualTo("[\"${json-unit.ignore}\"]")
   }
 
+  @Test
+  def shouldCombineCreateAndUpdateInASingleMethodCall(server: 
GuiceJamesServer): Unit = {
+    val bobPath = MailboxPath.inbox(BOB)
+    val mailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobPath)
+    val messageId = 
server.getProbe(classOf[MailboxProbeImpl]).appendMessage(BOB.asString(), 
bobPath,
+        
AppendCommand.from(ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_complex.eml")))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", 
"urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [
+         |    ["Email/set", {
+         |      "accountId": "$ACCOUNT_ID",
+         |      "destroy": ["${messageId.serialize()}"],
+         |      "create": {
+         |        "aaaaaa":{
+         |          "mailboxIds": {
+         |             "${mailboxId.serialize}": true
+         |          },
+         |          "keywords":{},
+         |          "attachments": [
+         |            {
+         |              "blobId": "${messageId.serialize()}_5",
+         |              "type":"text/plain",
+         |              "charset":"UTF-8",
+         |              "disposition": "attachment"
+         |            }
+         |          ],
+         |          "to": [{"email": "[email protected]"}, {"email": 
"[email protected]"}],
+         |          "from": [{"email": "${BOB.asString}"}]
+         |        }
+         |      }
+         |    }, "c1"]]
+         |}""".stripMargin
+
+    val response = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .inPath("methodResponses[0][1].destroyed[0]")
+      .isPresent
+    assertThatJson(response)
+      .inPath("methodResponses[0][1].created.aaaaaa")
+      .isPresent
+  }
+
   @Test
   def createShouldFailWhenBadJsonPayloadForSpecificHeader(server: 
GuiceJamesServer): Unit = {
     val bobPath = MailboxPath.inbox(BOB)
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 b6f0e7eef2..c6861b923a 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
@@ -49,9 +49,9 @@ class EmailSetMethod @Inject()(serializer: EmailSetSerializer,
   override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: 
InvocationWithContext, mailboxSession: MailboxSession, request: 
EmailSetRequest): SMono[InvocationWithContext] = {
     for {
       oldState <- retrieveState(capabilities, mailboxSession)
-      destroyResults <- deletePerformer.destroy(request, mailboxSession)
-      updateResults <- updatePerformer.update(request, mailboxSession)
       created <- createPerformer.create(request, mailboxSession)
+      updateResults <- updatePerformer.update(request, mailboxSession)
+      destroyResults <- deletePerformer.destroy(request, mailboxSession)
       newState <- retrieveState(capabilities, mailboxSession)
     } yield InvocationWithContext(
       invocation = Invocation(
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 2de517584b..3f5d6d52ee 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
@@ -58,8 +58,8 @@ class MailboxSetMethod @Inject()(serializer: 
MailboxSerializer,
   override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: 
InvocationWithContext, mailboxSession: MailboxSession, request: 
MailboxSetRequest): SMono[InvocationWithContext] = for {
     oldState <- retrieveState(capabilities, mailboxSession)
     creationResults <- createPerformer.createMailboxes(mailboxSession, 
request, invocation.processingContext)
-    deletionResults <- deletePerformer.deleteMailboxes(mailboxSession, request)
     updateResults <- updatePerformer.updateMailboxes(mailboxSession, request, 
capabilities)
+    deletionResults <- deletePerformer.deleteMailboxes(mailboxSession, request)
     newState <- retrieveState(capabilities, mailboxSession)
     response = createResponse(capabilities, invocation.invocation, request, 
creationResults._1, deletionResults, updateResults, oldState, newState)
   } yield InvocationWithContext(response, creationResults._2)


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

Reply via email to