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 2020/09/14 02:53:52 UTC
[james-project] 10/23: JAMES-3369 Email/get cc property
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 32b43f474d6adfe0a79d1a892f1cb19a9738081a
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Sep 9 17:47:39 2020 +0700
JAMES-3369 Email/get cc property
---
.../rfc8621/contract/EmailGetMethodContract.scala | 99 ++++++++++++++++++++++
.../scala/org/apache/james/jmap/mail/Email.scala | 5 +-
.../org/apache/james/jmap/mail/EmailGet.scala | 3 +-
3 files changed, 104 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/EmailGetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
index 6be5b7c..2da1cab 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
@@ -502,6 +502,105 @@ trait EmailGetMethodContract {
}
@Test
+ def ccPropertyShouldBeSupported(server: GuiceJamesServer): Unit = {
+ val message: Message = Message.Builder
+ .of
+ .addField(new RawField("Cc",
+ "\"user1\" <us...@domain.tld>, user2@domain.tld"))
+ .setSubject("test")
+ .setBody("testmail", StandardCharsets.UTF_8)
+ .build
+ server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.inbox(BOB))
+ val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl])
+ .appendMessage(BOB.asString, MailboxPath.inbox(BOB), AppendCommand.from(message))
+ .getMessageId
+
+ val request =
+ s"""{
+ | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+ | "methodCalls": [[
+ | "Email/get",
+ | {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "ids": ["${messageId.serialize()}"],
+ | "properties": ["cc"]
+ | },
+ | "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].list[0]")
+ .isEqualTo(
+ s"""{
+ | "id": "${messageId.serialize()}",
+ | "cc": [
+ | {
+ | "name": "user1",
+ | "email": "user1@domain.tld"
+ | },
+ | {
+ | "email": "user2@domain.tld"
+ | }
+ | ]
+ |}""".stripMargin)
+ }
+
+ @Test
+ def ccPropertyShouldBeNullWhenMissing(server: GuiceJamesServer): Unit = {
+ val message: Message = Message.Builder
+ .of
+ .setSubject("test")
+ .setBody("testmail", StandardCharsets.UTF_8)
+ .build
+ server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.inbox(BOB))
+ val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl])
+ .appendMessage(BOB.asString, MailboxPath.inbox(BOB), AppendCommand.from(message))
+ .getMessageId
+
+ val request =
+ s"""{
+ | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+ | "methodCalls": [[
+ | "Email/get",
+ | {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "ids": ["${messageId.serialize()}"],
+ | "properties": ["cc"]
+ | },
+ | "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].list[0]")
+ .isEqualTo(
+ s"""{
+ | "id": "${messageId.serialize()}"
+ |}""".stripMargin)
+ }
+
+ @Test
def messageIdShouldReturnNullWhenNone(server: GuiceJamesServer): Unit = {
val path = MailboxPath.inbox(BOB)
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
index 9b36cde..3ead08f 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
@@ -40,7 +40,7 @@ object Email {
val defaultProperties: Properties = Properties("id", "size")
val allowedProperties: Properties = Properties("id", "size", "bodyStructure", "textBody", "htmlBody",
- "attachments", "headers", "bodyValues", "messageId", "inReplyTo", "references", "to")
+ "attachments", "headers", "bodyValues", "messageId", "inReplyTo", "references", "to", "cc")
val idProperty: Properties = Properties("id")
def asUnparsed(messageId: MessageId): Try[UnparsedEmailId] =
@@ -85,4 +85,5 @@ case class Email(id: MessageId,
messageId: Option[List[HeaderMessageId]],
inReplyTo: Option[List[HeaderMessageId]],
references: Option[List[HeaderMessageId]],
- to: Option[List[EmailAddress]])
+ to: Option[List[EmailAddress]],
+ cc: Option[List[EmailAddress]])
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala
index cc4ecbf..f94050a 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailGet.scala
@@ -85,7 +85,8 @@ case class EmailGetRequest(accountId: AccountId,
messageId = extractMessageId(mime4JMessage, "Message-Id"),
inReplyTo = extractMessageId(mime4JMessage, "In-Reply-To"),
references = extractMessageId(mime4JMessage, "References"),
- to = Option(mime4JMessage.getTo).map(EmailAddress.from))
+ to = Option(mime4JMessage.getTo).map(EmailAddress.from),
+ cc = Option(mime4JMessage.getCc).map(EmailAddress.from))
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org