You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/05/10 03:27:05 UTC
[james-project] 04/07: JAMES-2743 JMAP Search Doesn't support From
field with UTF8 characters
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 1b19a733a9c7f2720a9b9d949ee1461c6fc5e9c6
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Apr 26 17:47:25 2019 +0700
JAMES-2743 JMAP Search Doesn't support From field with UTF8 characters
---
.../elasticsearch/json/HeaderCollectionTest.java | 29 ++++++--
.../integration/GetMessageListMethodTest.java | 78 ++++++++++++++++++++++
2 files changed, 103 insertions(+), 4 deletions(-)
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollectionTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollectionTest.java
index 586ab14..db73f08 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollectionTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollectionTest.java
@@ -23,11 +23,30 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.time.format.DateTimeFormatter;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
class HeaderCollectionTest {
+ static class UTF8FromHeaderTestSource implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
+ return Stream.of(
+ Arguments.of("=?UTF-8?B?RnLDqWTDqXJpYyBNQVJUSU4=?= <fm...@linagora.com>, Graham CROSMARIE <gc...@linagora.com>", "Frédéric MARTIN"),
+ Arguments.of("=?UTF-8?Q?=C3=9Csteli=C4=9Fhan_Ma=C5=9Frapa?= <us...@domain.tld>", "Üsteliğhan Maşrapa"),
+ Arguments.of("=?UTF-8?Q?Ke=C5=9Ffet_Turizm?= <ke...@domain.tld>", "Keşfet Turizm"),
+ Arguments.of("=?UTF-8?Q?MODAL=C4=B0F?= <mo...@domain.tld>", "MODALİF"));
+ }
+ }
+
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
@Test
@@ -75,15 +94,17 @@ class HeaderCollectionTest {
.containsOnly(new EMailer("Christophe Hamerling", "chri.hamerling@linagora.com"));
}
- @Test
- void displayNamesShouldBeRetrievedWhenEncodedWord() {
+ @Disabled("JAMES-2743 HeaderCollection doesn't support Q encoding")
+ @ParameterizedTest
+ @ArgumentsSource(UTF8FromHeaderTestSource.class)
+ void displayNamesShouldBeRetrievedWhenEncodedWord(String encodedFromHeader, String nameOfFromAddress) {
HeaderCollection headerCollection = HeaderCollection.builder()
- .add(new FieldImpl("From", "=?UTF-8?B?RnLDqWTDqXJpYyBNQVJUSU4=?= <fr...@linagora.com>, Graham CROSMARIE <gr...@linagora.com>"))
+ .add(new FieldImpl("From", encodedFromHeader))
.build();
assertThat(headerCollection.getFromAddressSet())
.extracting(EMailer::getName)
- .contains("Frédéric MARTIN");
+ .contains(nameOfFromAddress);
}
@Test
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
index 640d893..ce45654 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
@@ -22,6 +22,7 @@ package org.apache.james.jmap.methods.integration;
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.with;
import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
import static org.apache.james.jmap.JmapURIBuilder.baseUri;
import static org.apache.james.jmap.TestingConstants.ALICE;
import static org.apache.james.jmap.TestingConstants.ALICE_PASSWORD;
@@ -33,6 +34,7 @@ import static org.apache.james.jmap.TestingConstants.NAME;
import static org.apache.james.jmap.TestingConstants.calmlyAwait;
import static org.apache.james.jmap.TestingConstants.jmapRequestSpecBuilder;
import static org.apache.james.transport.mailets.remote.delivery.HeloNameProvider.LOCALHOST;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -57,6 +59,7 @@ import org.apache.james.jmap.api.access.AccessToken;
import org.apache.james.jmap.categories.BasicFeature;
import org.apache.james.jmap.categories.CassandraAndElasticSearchCategory;
import org.apache.james.jmap.model.Number;
+import org.apache.james.mailbox.DefaultMailboxes;
import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.model.ComposedMessageId;
@@ -80,6 +83,8 @@ import org.apache.james.util.date.ImapDateTimeFormatter;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.IMAPMessageReader;
import org.apache.james.utils.JmapGuiceProbe;
+import org.awaitility.Duration;
+import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -206,6 +211,79 @@ public abstract class GetMessageListMethodTest {
.body(ARGUMENTS + ".messageIds", contains(messageId));
}
+ @Category(BasicFeature.class)
+ @Test
+ public void searchByFromFieldDoesntSupportUTF8FromName() throws Exception {
+ String toUsername = "username1@" + DOMAIN;
+ String password = "password";
+ dataProbe.addUser(toUsername, password);
+ mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, toUsername, DefaultMailboxes.INBOX);
+
+ String messageCreationId = "creationId1337";
+ String fromName = "Üsteliğhan Maşrapa";
+ String fromAddress = ALICE;
+ String requestBody = "[" +
+ " [" +
+ " \"setMessages\"," +
+ " {" +
+ " \"create\": { \"" + messageCreationId + "\" : {" +
+ " \"from\": { \"name\": \"" + fromName + "\", \"email\": \"" + fromAddress + "\"}," +
+ " \"to\": [{ \"name\": \"BOB\", \"email\": \"" + BOB + "\"}]," +
+ " \"subject\": \"Thank you for joining example.com!\"," +
+ " \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+ " \"mailboxIds\": [\"" + getOutboxId(aliceAccessToken) + "\"]" +
+ " }}" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ String messageId = with()
+ .header("Authorization", aliceAccessToken.serialize())
+ .body(requestBody)
+ .post("/jmap")
+ .then()
+ .extract()
+ .body()
+ .path(ARGUMENTS + ".created." + messageCreationId + ".id");
+
+ calmlyAwait.atMost(Duration.TEN_SECONDS)
+ .until(() -> searchFirstMessageByFromField(fromAddress), Matchers.notNullValue());
+
+ assertThat(searchFirstMessageByFromField(fromName))
+ .isNull();
+ }
+
+ private String searchFirstMessageByFromField(String from) {
+ String searchRequest = "[" +
+ " [" +
+ " \"getMessageList\"," +
+ " {" +
+ " \"filter\": {" +
+ " \"from\": \"" + from + "\"" +
+ " }," +
+ " \"sort\": [" +
+ " \"date desc\"" +
+ " ]," +
+ " \"collapseThreads\": false," +
+ " \"fetchMessages\": false," +
+ " \"position\": 0," +
+ " \"limit\": 1" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ return with()
+ .header("Authorization", aliceAccessToken.serialize())
+ .body(searchRequest)
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .extract()
+ .path(ARGUMENTS + ".messageIds[0]");
+ }
+
@Test
public void getMessageListShouldListMessageThatHasBeenMovedInAMailboxWhereTheUserHasOnlyReadRight() throws Exception {
MailboxId delegatedMailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, BOB, "delegated");
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org