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

commit c8523074e9e3d5563ad64404622050c92f829fb4
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri Oct 2 11:01:40 2020 +0700

    JAMES-3377 Text should match From field
    
    Also enhence address field matching as part of text field
---
 .../contract/EmailQueryMethodContract.scala        | 58 ++++++++++++++++++++++
 .../james/jmap/utils/search/MailboxFilter.scala    |  8 +--
 2 files changed, 62 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/EmailQueryMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
index f01989d..3465b6a 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailQueryMethodContract.scala
@@ -4775,6 +4775,64 @@ trait EmailQueryMethodContract {
   }
 
   @Test
+  def textShouldMatchFromField(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[MailboxProbeImpl]).createMailbox(inbox(BOB))
+    val messageId1: MessageId = server.getProbe(classOf[MailboxProbeImpl])
+      .appendMessage(BOB.asString, inbox(BOB), 
AppendCommand.from(Message.Builder
+        .of
+        .addField(new RawField("From", "[email protected]"))
+        .setSubject("a mail")
+        .setBody("This is a test body", StandardCharsets.UTF_8)
+        .build))
+      .getMessageId
+
+    server.getProbe(classOf[MailboxProbeImpl])
+      .appendMessage(BOB.asString, inbox(BOB), 
AppendCommand.from(Message.Builder
+        .of
+        .setSubject("should not be found mail")
+        .setBody("lorem ipsum", StandardCharsets.UTF_8)
+        .build))
+      .getMessageId
+
+    val request =
+      s"""{
+         |  "using": [
+         |    "urn:ietf:params:jmap:core",
+         |    "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Email/query",
+         |    {
+         |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "filter": {
+         |        "text": "[email protected]"
+         |      }
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      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].ids")
+        .isEqualTo(
+          s"""[
+             |  "${messageId1.serialize}"
+             |]""".stripMargin)
+    }
+  }
+
+  @Test
   def emailQueryShouldSupportTextFilterForHtmlBody(server: GuiceJamesServer): 
Unit = {
     server.getProbe(classOf[MailboxProbeImpl]).createMailbox(inbox(BOB))
     val messageId1: MessageId = server.getProbe(classOf[MailboxProbeImpl])
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/utils/search/MailboxFilter.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/utils/search/MailboxFilter.scala
index db3ed96..c76e3ff 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/utils/search/MailboxFilter.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/utils/search/MailboxFilter.scala
@@ -231,10 +231,10 @@ object MailboxFilter {
       filterCondition.text match {
         case Some(text) =>
           Right(List(SearchQuery.or(
-            List(SearchQuery.headerContains("From", text.value),
-              SearchQuery.headerContains("To", text.value),
-              SearchQuery.headerContains("Cc", text.value),
-              SearchQuery.headerContains("Bcc", text.value),
+            List(SearchQuery.address(AddressType.To, text.value),
+              SearchQuery.address(AddressType.Cc, text.value),
+              SearchQuery.address(AddressType.Bcc, text.value),
+              SearchQuery.address(AddressType.From, text.value),
               SearchQuery.headerContains("Subject", text.value),
               SearchQuery.bodyContains(text.value))
             .asJava)))


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to