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 2021/04/02 01:34:21 UTC

[james-project] branch master updated: JAMES-1489 Failing test for UTF-8 IMAP search

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


The following commit(s) were added to refs/heads/master by this push:
     new da56bdd  JAMES-1489 Failing test for UTF-8 IMAP search
da56bdd is described below

commit da56bddcc470a888512fca526083f7f36602c18e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 26 15:09:11 2021 +0700

    JAMES-1489 Failing test for UTF-8 IMAP search
---
 .../james/imapserver/netty/IMAPServerTest.java     | 120 +++++++++++++++++++--
 1 file changed, 114 insertions(+), 6 deletions(-)

diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
index 8e30c08..2790b7e 100644
--- a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
+++ b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
@@ -24,6 +24,19 @@ import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.search.AndTerm;
+import javax.mail.search.BodyTerm;
+import javax.mail.search.FromStringTerm;
+import javax.mail.search.RecipientStringTerm;
+import javax.mail.search.SearchTerm;
+import javax.mail.search.SubjectTerm;
 
 import org.apache.commons.configuration2.XMLConfiguration;
 import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
@@ -34,15 +47,22 @@ import org.apache.james.core.Username;
 import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
 import org.apache.james.imap.main.DefaultImapDecoderFactory;
 import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.FakeAuthenticator;
 import org.apache.james.mailbox.store.FakeAuthorizator;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.apache.james.metrics.tests.RecordingMetricFactory;
+import org.apache.james.mime4j.codec.DecoderUtil;
+import org.apache.james.mime4j.codec.EncoderUtil;
+import org.apache.james.mime4j.util.MimeUtil;
 import org.apache.james.util.ClassLoaderUtils;
 import org.apache.james.utils.TestIMAPClient;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
@@ -53,6 +73,7 @@ class IMAPServerTest {
     private static final Username USER = Username.of("user@domain.org");
     private static final String USER_PASS = "pass";
     public static final String SMALL_MESSAGE = "header: value\r\n\r\nBODY";
+    private InMemoryIntegrationResources memoryIntegrationResources;
 
     private static XMLConfiguration getConfig(InputStream configStream) throws Exception {
         FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
@@ -74,7 +95,7 @@ class IMAPServerTest {
         FakeAuthenticator authenticator = new FakeAuthenticator();
         authenticator.addUser(USER, USER_PASS);
 
-        InMemoryIntegrationResources resources = InMemoryIntegrationResources.builder()
+        memoryIntegrationResources = InMemoryIntegrationResources.builder()
             .authenticator(authenticator)
             .authorizator(FakeAuthorizator.defaultReject())
             .inVmEventBus()
@@ -89,12 +110,12 @@ class IMAPServerTest {
             DefaultImapDecoderFactory.createDecoder(),
             new DefaultImapEncoderFactory().buildImapEncoder(),
             DefaultImapProcessorFactory.createXListSupportingProcessor(
-                resources.getMailboxManager(),
-                resources.getEventBus(),
-                new StoreSubscriptionManager(resources.getMailboxManager().getMapperFactory()),
+                memoryIntegrationResources.getMailboxManager(),
+                memoryIntegrationResources.getEventBus(),
+                new StoreSubscriptionManager(memoryIntegrationResources.getMailboxManager().getMapperFactory()),
                 null,
-                resources.getQuotaManager(),
-                resources.getQuotaRootResolver(),
+                memoryIntegrationResources.getQuotaManager(),
+                memoryIntegrationResources.getQuotaRootResolver(),
                 metricFactory),
             new ImapMetrics(metricFactory));
 
@@ -212,4 +233,91 @@ class IMAPServerTest {
                 .hasMessageContaining("BAD APPEND failed.");
         }
     }
+
+    @Nested
+    class Search {
+        IMAPServer imapServer;
+        private int port;
+
+        @BeforeEach
+        void beforeEach() throws Exception {
+            imapServer = createImapServer("imapServer.xml");
+            port = imapServer.getListenAddresses().get(0).getPort();
+        }
+
+        @AfterEach
+        void tearDown() {
+            imapServer.destroy();
+        }
+
+        @Disabled("JAMES-1489 IMAP Search do not support continuation")
+        @Test
+        void searchingShouldSupportMultipleUTF8Criteria() throws Exception {
+            String host = "127.0.0.1";
+            Properties props = new Properties();
+            props.put("mail.debug", "true");
+            Session session = Session.getDefaultInstance(props, null);
+            Store store = session.getStore("imap");
+            store.connect(host, port, USER.asString(), USER_PASS);
+            Folder folder = store.getFolder("INBOX");
+            folder.open(Folder.READ_ONLY);
+
+            SearchTerm subjectTerm = new SubjectTerm("java培训");
+            SearchTerm fromTerm = new FromStringTerm("采购");
+            SearchTerm recipientTerm = new RecipientStringTerm(Message.RecipientType.TO,"张三");
+            SearchTerm ccRecipientTerm = new RecipientStringTerm(Message.RecipientType.CC,"李四");
+            SearchTerm bccRecipientTerm = new RecipientStringTerm(Message.RecipientType.BCC,"王五");
+            SearchTerm bodyTerm = new BodyTerm("天天向上");
+            SearchTerm[] searchTerms = new SearchTerm[6];
+            searchTerms[0] = subjectTerm;
+            searchTerms[1] = bodyTerm;
+            searchTerms[2] = fromTerm;
+            searchTerms[3] = recipientTerm;
+            searchTerms[4] = ccRecipientTerm;
+            searchTerms[5] = bccRecipientTerm;
+            SearchTerm andTerm = new AndTerm(searchTerms);
+
+            assertThatCode(() -> folder.search(andTerm)).doesNotThrowAnyException();
+
+            folder.close(false);
+            store.close();
+        }
+
+        @Test
+        void searchingASingleUTF8CriterionShouldComplete() throws Exception {
+            MailboxSession mailboxSession = memoryIntegrationResources.getMailboxManager().createSystemSession(USER);
+            memoryIntegrationResources.getMailboxManager()
+                .createMailbox(MailboxPath.inbox(USER), mailboxSession);
+            memoryIntegrationResources.getMailboxManager()
+                .getMailbox(MailboxPath.inbox(USER), mailboxSession)
+                .appendMessage(MessageManager.AppendCommand.builder().build("MIME-Version: 1.0\r\n" +
+                    "Content-Type: text/html; charset=UTF-8\r\n" +
+                    "Content-Transfer-Encoding: quoted-printable\r\n" +
+                    "From: =?ISO-8859-1?Q?Beno=EEt_TELLIER?= <b...@linagora.com>\r\n" +
+                    "Sender: =?ISO-8859-1?Q?Beno=EEt_TELLIER?= <b...@linagora.com>\r\n" +
+                    "Reply-To: b@linagora.com\r\n" +
+                    "To: =?ISO-8859-1?Q?Beno=EEt_TELLIER?= <b...@linagora.com>\r\n" +
+                    "Subject: Test utf-8 charset\r\n" +
+                    "Message-ID: <Mi...@linagora.com>\r\n" +
+                    "Date: Sun, 28 Mar 2021 03:58:06 +0000\r\n" +
+                    "\r\n" +
+                    "<p>=E5=A4=A9=E5=A4=A9=E5=90=91=E4=B8=8A<br></p>\r\n"), mailboxSession);
+
+            String host = "127.0.0.1";
+            Properties props = new Properties();
+            props.put("mail.debug", "true");
+            Session session = Session.getDefaultInstance(props, null);
+            Store store = session.getStore("imap");
+            store.connect(host, port, USER.asString(), USER_PASS);
+            Folder folder = store.getFolder("INBOX");
+            folder.open(Folder.READ_ONLY);
+
+            SearchTerm bodyTerm = new BodyTerm("天天向上");
+
+            assertThat(folder.search(bodyTerm)).hasSize(1);
+
+            folder.close(false);
+            store.close();
+        }
+    }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org