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/10/28 04:53:30 UTC
[james-project] 05/10: JAMES-3436 Email/set create: Support sentAt
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 f781ad0c310f5941f6df56de3bccb007a0706706
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Oct 27 09:32:12 2020 +0700
JAMES-3436 Email/set create: Support sentAt
---
.../rfc8621/contract/EmailSetMethodContract.scala | 58 ++++++++++++++++++++++
.../org/apache/james/jmap/mail/EmailSet.scala | 3 ++
2 files changed, 61 insertions(+)
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 9cfbeec..c5ed96d 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
@@ -472,6 +472,64 @@ trait EmailSetMethodContract {
}
@Test
+ def createShouldSupportSentAt(server: GuiceJamesServer): Unit = {
+ val bobPath = MailboxPath.inbox(BOB)
+ val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobPath)
+ val sentAt = ZonedDateTime.now().minusDays(1)
+
+ 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
+ | },
+ | "sentAt": "${UTCDate(sentAt).asUTC.format(UTC_DATE_FORMAT)}"
+ | }
+ | }
+ | }, "c1"],
+ | ["Email/get",
+ | {
+ | "accountId": "$ACCOUNT_ID",
+ | "ids": ["#aaaaaa"],
+ | "properties": ["mailboxIds", "sentAt"]
+ | },
+ | "c2"]]
+ |}""".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)
+ .whenIgnoringPaths("methodResponses[0][1].created.aaaaaa.id")
+ .inPath("methodResponses[0][1].created.aaaaaa")
+ .isEqualTo("{}".stripMargin)
+
+ assertThatJson(response)
+ .whenIgnoringPaths("methodResponses[1][1].list[0].id")
+ .inPath(s"methodResponses[1][1].list")
+ .isEqualTo(
+ s"""[{
+ | "mailboxIds": {
+ | "${mailboxId.serialize}": true
+ | },
+ | "sentAt": "${UTCDate(sentAt).asUTC.format(UTC_DATE_FORMAT)}"
+ |}]""".stripMargin)
+ }
+
+ @Test
def createShouldFailIfForbidden(server: GuiceJamesServer): Unit = {
val andrePath = MailboxPath.inbox(ANDRE)
val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(andrePath)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala
index f64db7e..42d68fc 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala
@@ -19,6 +19,7 @@
package org.apache.james.jmap.mail
import java.nio.charset.StandardCharsets
+import java.util.Date
import eu.timepit.refined
import eu.timepit.refined.api.Refined
@@ -59,6 +60,7 @@ case class EmailCreationRequest(mailboxIds: MailboxIds,
sender: Option[AddressesHeaderValue],
replyTo: Option[AddressesHeaderValue],
subject: Option[Subject],
+ sentAt: Option[UTCDate],
keywords: Option[Keywords],
receivedAt: Option[UTCDate]) {
def toMime4JMessage: Message = {
@@ -70,6 +72,7 @@ case class EmailCreationRequest(mailboxIds: MailboxIds,
bcc.flatMap(_.asMime4JMailboxList).map(_.asJava).foreach(builder.setBcc)
sender.flatMap(_.asMime4JMailboxList).map(_.asJava).map(Fields.addressList(FieldName.SENDER, _)).foreach(builder.setField)
replyTo.flatMap(_.asMime4JMailboxList).map(_.asJava).foreach(builder.setReplyTo)
+ sentAt.map(_.asUTC).map(_.toInstant).map(Date.from).foreach(builder.setDate)
builder.setBody("", StandardCharsets.UTF_8)
builder.build()
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org