You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/02/17 01:46:50 UTC
[james-project] 12/13: JAMES-2884 Attachment should not be created
with Content-Transfer-Encoding
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 23d2ebcddce70b59f67b4324575b1afce94b8e4c
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Feb 9 14:37:16 2021 +0700
JAMES-2884 Attachment should not be created with Content-Transfer-Encoding
https://jmap.io/spec-mail.html#properties-of-the-email-object
4.1.4
Within an EmailBodyPart [...] A Content-Transfer-Encoding
header field MUST NOT be given.
---
.../rfc8621/contract/EmailSetMethodContract.scala | 68 ++++++++++++++++++++++
.../james/jmap/json/EmailSetSerializer.scala | 8 ++-
2 files changed, 75 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/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 2cd0870..8807ba3 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
@@ -2106,6 +2106,74 @@ trait EmailSetMethodContract {
}
@Test
+ def rejectAttahmentCreationRequestWithContentTransferEncoding(server: GuiceJamesServer): Unit = {
+ val bobPath = MailboxPath.inbox(BOB)
+ val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobPath)
+ 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 request =
+ s"""{
+ | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+ | "methodCalls": [
+ | ["Email/set", {
+ | "accountId": "$ACCOUNT_ID",
+ | "create": {
+ | "aaaaaa": {
+ | "mailboxIds": {
+ | "${mailboxId.serialize}": true
+ | },
+ | "subject": "World domination",
+ | "attachments": [
+ | {
+ | "blobId": "$blobId",
+ | "type":"text/plain",
+ | "charset":"UTF-8",
+ | "header:Content-Transfer-Encoding:asText":"7bit"
+ | }
+ | ]
+ | }
+ | }
+ | }, "c1"]
+ | ]
+ |}""".stripMargin
+
+ val response = `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post.prettyPeek()
+ .`then`
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ .extract
+ .body
+ .asString
+
+ assertThatJson(response)
+ .inPath("methodResponses[0][1].notCreated.aaaaaa")
+ .isEqualTo(
+ s"""{
+ | "type": "invalidArguments",
+ | "description": "List((/attachments(0),List(JsonValidationError(List(Content-Transfer-Encoding should not be specified on attachment),List()))))"
+ |}""".stripMargin)
+ }
+
+ @Test
def createShouldSupportAttachmentAndHtmlBody(server: GuiceJamesServer): Unit = {
val bobPath = MailboxPath.inbox(BOB)
val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobPath)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala
index 83fa593..af3693b 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala
@@ -351,7 +351,13 @@ class EmailSetSerializer @Inject()(messageIdFactory: MessageId.Factory, mailboxI
private implicit val languagesWrites: Format[Languages] = Json.valueFormat[Languages]
private implicit val locationReads: Reads[Location] = Json.valueReads[Location]
private implicit val cidFormat: Format[ClientCid] = Json.valueFormat[ClientCid]
- private implicit val attachmentReads: Reads[Attachment] = Json.reads[Attachment]
+ private implicit val attachmentReads: Reads[Attachment] = {
+ case JsObject(keys) if keys.keys.exists(_.contains("header:Content-Transfer-Encoding")) =>
+ JsError("Content-Transfer-Encoding should not be specified on attachment")
+ case JsObject(keys) if keys.keys.exists(_.startsWith("header:Content-Transfer-Encoding:")) =>
+ JsError("Content-Transfer-Encoding should not be specified on attachment")
+ case jsValue: JsValue => Json.reads[Attachment].reads(jsValue)
+ }
private implicit val emailCreationRequestWithoutHeadersReads: Reads[EmailCreationRequestWithoutHeaders] = Json.reads[EmailCreationRequestWithoutHeaders]
private implicit val emailCreationRequestReads: Reads[EmailCreationRequest] = {
case o: JsObject =>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org