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 723d53d1ec Add test with attachment regarding EmailSubmission/set
723d53d1ec is described below

commit 723d53d1ecebdc6f685a9b40040eafacb6fb1ff0
Author: Rene Cordier <rcord...@linagora.com>
AuthorDate: Fri Aug 22 17:16:14 2025 +0700

    Add test with attachment regarding EmailSubmission/set
---
 .../EmailSubmissionSetMethodContract.scala         | 160 ++++++++++++++++++++-
 1 file changed, 159 insertions(+), 1 deletion(-)

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/EmailSubmissionSetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
index 85515ba42f..046187459a 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSubmissionSetMethodContract.scala
@@ -27,7 +27,7 @@ import io.restassured.RestAssured.{`given`, 
requestSpecification}
 import io.restassured.builder.ResponseSpecBuilder
 import io.restassured.http.ContentType.JSON
 import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
-import org.apache.http.HttpStatus.SC_OK
+import org.apache.http.HttpStatus.{SC_CREATED, SC_OK}
 import org.apache.james.GuiceJamesServer
 import org.apache.james.jmap.core.ResponseObject.SESSION_STATE
 import org.apache.james.jmap.core.UuidState.INSTANCE
@@ -43,6 +43,7 @@ import org.apache.james.utils.DataProbeImpl
 import org.awaitility.Awaitility
 import org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS
 import org.junit.jupiter.api.{BeforeEach, Test}
+import play.api.libs.json.{JsString, Json}
 
 trait EmailSubmissionSetMethodContract {
   private lazy val slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS
@@ -2246,4 +2247,161 @@ trait EmailSubmissionSetMethodContract {
                     |  ]
                     |}""".stripMargin)
   }
+
+  @Test
+  def 
emailSubmissionSetShouldSetCorrectlyHasAttachmentPropertyOnMessageInSentMailbox(server:
 GuiceJamesServer): Unit = {
+    val bobDraftsPath = MailboxPath.forUser(BOB, DefaultMailboxes.DRAFTS)
+    val draftId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobDraftsPath)
+    val bobInboxId: MailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.inbox(BOB))
+    val bobSentId: MailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB,
 DefaultMailboxes.SENT))
+
+    val payload = "123456789\r\n".getBytes(StandardCharsets.UTF_8)
+
+    val uploadResponse: String = `given`
+      .basePath("")
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .contentType("text/plain")
+      .body(payload)
+    .when
+      .post(s"/upload/$ACCOUNT_ID")
+    .`then`
+      .statusCode(SC_CREATED)
+      .extract
+      .body
+      .asString
+
+    val blobId: String = 
Json.parse(uploadResponse).\("blobId").get.asInstanceOf[JsString].value
+
+    val requestBob =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", 
"urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
+         |  "methodCalls": [
+         |    ["Email/set", {
+         |      "accountId": "$ACCOUNT_ID",
+         |      "create": {
+         |        "e1526":{
+         |          "mailboxIds": {"${draftId.serialize}": true},
+         |          "to": [{"email": "${BOB.asString}"}],
+         |          "from": [{"email": "${BOB.asString}"}],
+         |          "subject": "World domination",
+         |          "attachments": [
+         |            {
+         |              "blobId": "$blobId",
+         |              "type":"text/plain",
+         |              "charset":"UTF-8",
+         |              "disposition": "attachment",
+         |              "language": ["fr", "en"],
+         |              "location": "http://125.26.23.36/content";
+         |            }
+         |          ]
+         |        }
+         |      }
+         |     }, "c0"],
+         |     ["EmailSubmission/set", {
+         |       "accountId": "$ACCOUNT_ID",
+         |       "create": {
+         |         "k1490": {
+         |           "emailId": "#e1526",
+         |           "envelope": {
+         |             "mailFrom": {"email": "${BOB.asString}"},
+         |             "rcptTo": [{"email": "${BOB.asString}"}]
+         |           }
+         |         }
+         |      },
+         |      "onSuccessUpdateEmail": {
+         |         "#k1490": {
+         |           "mailboxIds/${bobSentId.serialize}": true,
+         |           "mailboxIds/${draftId.serialize}": null,
+         |           "keywords/$$seen": true,
+         |           "keywords/$$draft": null
+         |         }
+         |       }
+         |    }, "c1"]]
+         |}""".stripMargin
+
+    `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(requestBob)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+
+    val requestQueryMailBob =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": "$ACCOUNT_ID",
+         |      "filter": {"inMailbox": "${bobSentId.serialize}"}
+         |    },
+         |    "c0"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val responseBob = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(requestQueryMailBob)
+      .when
+        .post
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(responseBob)
+        .inPath("methodResponses[0][1].ids")
+        .isArray
+        .hasSize(1)
+    }
+
+    val requestReadMailBob =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": "$ACCOUNT_ID",
+         |      "filter": {"inMailbox": "${bobSentId.serialize}"}
+         |    },
+         |    "c0"],
+         |    [
+         |      "Email/get",
+         |      {
+         |        "accountId": "$ACCOUNT_ID",
+         |        "#ids": {
+         |          "resultOf": "c0",
+         |          "name": "Email/query",
+         |          "path": "/ids/*"
+         |        },
+         |        "properties": [
+         |          "id",
+         |          "hasAttachment"
+         |        ]
+         |      }, "c1"]]
+         |}""".stripMargin
+
+    val response = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(requestReadMailBob)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .whenIgnoringPaths("methodResponses[1][1].list[0].id")
+      .inPath(s"methodResponses[1][1].list")
+      .isEqualTo(
+        s"""[{
+           |  "hasAttachment": true
+           |}]""".stripMargin)
+  }
 }


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

Reply via email to