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:29 UTC
[james-project] 04/10: JAMES-3436 Email/set create: Multiple Sender
addresses should be supported
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 370abe372817223e6513797360c01b0439733dc9
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Oct 27 09:00:37 2020 +0700
JAMES-3436 Email/set create: Multiple Sender addresses should be supported
---
.../rfc8621/contract/EmailGetMethodContract.scala | 8 +++-
.../rfc8621/contract/EmailSetMethodContract.scala | 52 ++++++++++++++++++++++
.../scala/org/apache/james/jmap/mail/Email.scala | 7 ++-
3 files changed, 63 insertions(+), 4 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 47a5c3e..01ae19e 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
@@ -2010,7 +2010,7 @@ trait EmailGetMethodContract {
}
@Test
- def senderPropertyShouldKeepFirstValue(server: GuiceJamesServer): Unit = {
+ def senderPropertyShouldDisplayBothValues(server: GuiceJamesServer): Unit = {
val message: Message = Message.Builder
.of
.addField(new RawField("Sender",
@@ -2056,7 +2056,11 @@ trait EmailGetMethodContract {
| {
| "name": "user1",
| "email": "user1@domain.tld"
+ | },
+ | {
+ | "email": "user2@domain.tld"
| }
+ |
| ]
|}""".stripMargin)
}
@@ -6223,7 +6227,7 @@ trait EmailGetMethodContract {
| "c1"]]
|}""".stripMargin)
.when
- .post.prettyPeek
+ .post
.`then`
.statusCode(SC_OK)
.contentType(JSON)
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 b04ca96..9cfbeec 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
@@ -299,6 +299,58 @@ trait EmailSetMethodContract {
}
@Test
+ def createWithMultipleSenderShouldNotCrash(server: GuiceJamesServer): Unit = {
+ val bobPath = MailboxPath.inbox(BOB)
+ val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(bobPath)
+
+ 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},
+ | "sender": [{"email": "rcpt4@apache.org"}, {"email": "rcpt3@apache.org"}]
+ | }
+ | }
+ | }, "c1"],
+ | ["Email/get",
+ | {
+ | "accountId": "$ACCOUNT_ID",
+ | "ids": ["#aaaaaa"],
+ | "properties": ["sender"]
+ | },
+ | "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"""[{
+ | "sender": [{"email": "rcpt4@apache.org"}, {"email": "rcpt3@apache.org"}]
+ |}]""".stripMargin)
+ }
+
+ @Test
def createShouldSupportKeywords(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/mail/Email.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
index 0804583..42c2358 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
@@ -45,8 +45,9 @@ import org.apache.james.mailbox.{MailboxSession, MessageIdManager}
import org.apache.james.mime4j.codec.DecodeMonitor
import org.apache.james.mime4j.dom.field.{AddressListField, DateTimeField, MailboxField, MailboxListField}
import org.apache.james.mime4j.dom.{Header, Message}
+import org.apache.james.mime4j.field.AddressListFieldLenientImpl
import org.apache.james.mime4j.message.DefaultMessageBuilder
-import org.apache.james.mime4j.stream.{Field, MimeConfig}
+import org.apache.james.mime4j.stream.{Field, MimeConfig, RawFieldParser}
import org.apache.james.mime4j.util.MimeUtil
import org.slf4j.{Logger, LoggerFactory}
import reactor.core.scala.publisher.{SFlux, SMono}
@@ -286,7 +287,9 @@ object EmailHeaders {
.flatMap {
case f: AddressListField => Some(AddressesHeaderValue(EmailAddress.from(f.getAddressList)))
case f: MailboxListField => Some(AddressesHeaderValue(EmailAddress.from(f.getMailboxList)))
- case f: MailboxField => Some(AddressesHeaderValue(List(EmailAddress.from(f.getMailbox).toOption).flatten))
+ case f: MailboxField =>
+ val asMailboxListField = AddressListFieldLenientImpl.PARSER.parse(RawFieldParser.DEFAULT.parseField(f.getRaw), DecodeMonitor.SILENT)
+ Some(AddressesHeaderValue(EmailAddress.from(asMailboxListField.getAddressList)))
case _ => None
}
.filter(_.value.nonEmpty)
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org