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 2017/06/07 10:46:11 UTC

[01/21] james-project git commit: JAMES-2044 Add constants for RECENT in MessageSearchIndex tests

Repository: james-project
Updated Branches:
  refs/heads/master a54f1ee0c -> 4ae9c8e9f


JAMES-2044 Add constants for RECENT in MessageSearchIndex tests


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4a01620b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4a01620b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4a01620b

Branch: refs/heads/master
Commit: 4a01620b62b66121c1f407f42e53339551f2a7c7
Parents: 1d306c8
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 10:33:21 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:32:51 2017 +0700

----------------------------------------------------------------------
 .../search/AbstractMessageSearchIndexTest.java  | 28 +++++++++++---------
 1 file changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4a01620b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 85b0026..080345c 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -57,6 +57,8 @@ public abstract class AbstractMessageSearchIndexTest {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AbstractMessageSearchIndexTest.class);
     public static final long LIMIT = 100L;
+    public static final boolean RECENT = true;
+    public static final boolean NOT_RECENT = false;
 
     protected MessageSearchIndex messageSearchIndex;
     protected StoreMailboxManager storeMailboxManager;
@@ -110,7 +112,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"),
             new Date(1388617200000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.DELETED));
         // sentDate: Thu, 4 Jun 2015 09:23:37 +0000
         // Internal date : 2014/02/02 00:00:00.000
@@ -118,7 +120,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/mail1.eml"),
             new Date(1391295600000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.ANSWERED));
         // sentDate: Thu, 4 Jun 2015 09:27:37 +0000
         // Internal date : 2014/03/02 00:00:00.000
@@ -126,7 +128,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/mail2.eml"),
             new Date(1393714800000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.DRAFT));
         // sentDate: Tue, 2 Jun 2015 08:16:19 +0000
         // Internal date : 2014/05/02 00:00:00.000
@@ -134,7 +136,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/mail3.eml"),
             new Date(1398981600000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.RECENT));
         // sentDate: Fri, 15 May 2015 06:35:59 +0000
         // Internal date : 2014/04/02 00:00:00.000
@@ -142,7 +144,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/mail4.eml"),
             new Date(1396389600000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.FLAGGED));
         // sentDate: Wed, 03 Jun 2015 19:14:32 +0000
         // Internal date : 2014/06/02 00:00:00.000
@@ -150,7 +152,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"),
             new Date(1401660000000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.SEEN));
         // sentDate: Thu, 04 Jun 2015 07:36:08 +0000
         // Internal date : 2014/07/02 00:00:00.000
@@ -158,7 +160,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/htmlMail.eml"),
             new Date(1404252000000L),
             session,
-            false,
+            NOT_RECENT,
             new Flags());
         // sentDate: Thu, 4 Jun 2015 06:08:41 +0200
         // Internal date : 2014/08/02 00:00:00.000
@@ -166,7 +168,7 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/mail.eml"),
             new Date(1406930400000L),
             session,
-            true,
+            RECENT,
             new Flags("Hello"));
         // sentDate: Thu, 4 Jun 2015 06:08:41 +0200
         // Internal date : 2014/08/02 00:00:00.000
@@ -174,34 +176,34 @@ public abstract class AbstractMessageSearchIndexTest {
             ClassLoader.getSystemResourceAsStream("eml/mail.eml"),
             new Date(1406930400000L),
             session,
-            true,
+            RECENT,
             new Flags(Flags.Flag.SEEN));
         m9 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/frnog.eml"),
             new Date(1409608800000L),
             session,
-            true,
+            RECENT,
             new Flags("Hello you"));
 
         mailWithAttachment = myFolderMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"),
             new Date(1409608900000L),
             session,
-            true,
+            RECENT,
             new Flags("Hello you"));
 
         mailWithInlinedAttachment = myFolderMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachment.eml"),
             new Date(1409608900000L),
             session,
-            true,
+            RECENT,
             new Flags("Hello you"));
 
         m10 = otherInboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/mail1.eml"),
             new Date(1391295600000L),
             otherSession,
-            true,
+            RECENT,
             new Flags());
         await();
     }


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


[14/21] james-project git commit: JAMES-2048 Cid should not accept blank value

Posted by bt...@apache.org.
JAMES-2048 Cid should not accept blank value


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c69c7efb
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c69c7efb
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c69c7efb

Branch: refs/heads/master
Commit: c69c7efbbbbc830a10a8bfe87037f9a1603bc5fb
Parents: d4246a0
Author: quynhn <qn...@linagora.com>
Authored: Tue Jun 6 13:40:57 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:35:47 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/mailbox/model/Cid.java     | 11 ++++++---
 .../org/apache/james/mailbox/model/CidTest.java | 24 +++++++++++++++++---
 2 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c69c7efb/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
index bfaa6cc..96440e5 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
@@ -20,14 +20,15 @@
 package org.apache.james.mailbox.model;
 
 
+import org.apache.commons.lang.StringUtils;
+
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
 public class Cid {
 
     public static Cid from(String cidAsString) {
-        Preconditions.checkNotNull(cidAsString);
-        Preconditions.checkArgument(!cidAsString.isEmpty(), "'cidAsString' is mandatory");
+        Preconditions.checkArgument(!StringUtils.isBlank(cidAsString), "'cidAsString' is mandatory");
         return new Cid(normalizedCid(cidAsString));
     }
 
@@ -39,7 +40,11 @@ public class Cid {
     }
     
     private static String unwrap(String cidAsString) {
-        return cidAsString.substring(1, cidAsString.length() - 1);
+        String unwrapCid = cidAsString.substring(1, cidAsString.length() - 1);
+        if (StringUtils.isBlank(unwrapCid)) {
+            throw new IllegalArgumentException("'cidAsString' is mandatory");
+        }
+        return unwrapCid;
     }
 
     private static boolean isWrappedWithAngleBrackets(String cidAsString) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/c69c7efb/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
index c9c9459..20163ad 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
@@ -34,7 +34,7 @@ public class CidTest {
     
     @Test
     public void fromShouldThrowWhenNull() {
-        expectedException.expect(NullPointerException.class);
+        expectedException.expect(IllegalArgumentException.class);
         Cid.from(null);
     }
     
@@ -43,7 +43,25 @@ public class CidTest {
         expectedException.expect(IllegalArgumentException.class);
         Cid.from("");
     }
-    
+
+    @Test
+    public void fromShouldThrowWhenBlank() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("    ");
+    }
+
+    @Test
+    public void fromShouldThrowWhenEmptyAfterRemoveTags() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("<>");
+    }
+
+    @Test
+    public void fromShouldThrowWhenBlankAfterRemoveTags() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("<   >");
+    }
+
     @Test
     public void fromShouldRemoveTagsWhenExists() {
         Cid cid = Cid.from("<123>");
@@ -67,7 +85,7 @@ public class CidTest {
         Cid cid = Cid.from("123>");
         assertThat(cid.getValue()).isEqualTo("123>");
     }
-    
+
     @Test
     public void shouldRespectJavaBeanContract() {
         EqualsVerifier.forClass(Cid.class).verify();


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


[10/21] james-project git commit: JAMES-2044 SimpleMessageSearchIndex should support searches on sent date

Posted by bt...@apache.org.
JAMES-2044 SimpleMessageSearchIndex should support searches on sent date


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5aae15d8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5aae15d8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5aae15d8

Branch: refs/heads/master
Commit: 5aae15d8faef6a00af42adbebc2d0ae7f6500e54
Parents: d256b27
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 11:30:45 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../search/SimpleMessageSearchIndexTest.java    | 14 ----
 .../mailbox/store/search/MessageSearches.java   | 69 +++++++++++++-------
 2 files changed, 47 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5aae15d8/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
index 7b0ba58..533ac00 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
@@ -251,18 +251,4 @@ public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest
     public void searchWithFullTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() throws Exception {
     }
 
-    @Ignore
-    @Override
-    public void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
-    }
-
-    @Ignore
-    @Override
-    public void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
-    }
-
-    @Ignore
-    @Override
-    public void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5aae15d8/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 9516717..a58e925 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -201,6 +201,8 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
             result = matches((SearchQuery.AttachmentCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             result = matches((SearchQuery.ModSeqCriterion) criterion, message);
+        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
+            result = matches((SearchQuery.SentDateCriterion) criterion, message);
         } else {
             throw new UnsupportedSearchException();
         }
@@ -586,16 +588,16 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     private boolean matchesInternalDate(SearchQuery.DateOperator operator, MailboxMessage message)
             throws UnsupportedSearchException {
         Date date = operator.getDate();
-        DateResolution res = operator.getDateResultion();
+        DateResolution dateResultion = operator.getDateResultion();
         Date internalDate = message.getInternalDate();
         SearchQuery.DateComparator type = operator.getType();
         switch (type) {
         case ON:
-            return on(internalDate, date, res);
+            return on(internalDate, date, dateResultion);
         case BEFORE:
-            return before(internalDate, date, res);
+            return before(internalDate, date, dateResultion);
         case AFTER:
-            return after(internalDate, date, res);
+            return after(internalDate, date, dateResultion);
         default:
             throw new UnsupportedSearchException();
         }
@@ -622,37 +624,60 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     }
 
     private String createDateString(Date date, DateResolution res) {
-        SimpleDateFormat format;
+        SimpleDateFormat format = createFormat(res);
+        format.setCalendar(getGMT());
+        return format.format(date);
+    }
+
+    private SimpleDateFormat createFormat(DateResolution res) {
         switch (res) {
         case Year:
-            format = new SimpleDateFormat("yyyy");
-            break;
+            return new SimpleDateFormat("yyyy");
         case Month:
-            format = new SimpleDateFormat("yyyyMM");
-            break;
+            return new SimpleDateFormat("yyyyMM");
         case Day:
-            format = new SimpleDateFormat("yyyyMMdd");
-            break;
+            return new SimpleDateFormat("yyyyMMdd");
         case Hour:
-            format = new SimpleDateFormat("yyyyMMddhh");
-            break;
+            return new SimpleDateFormat("yyyyMMddhh");
         case Minute:
-            format = new SimpleDateFormat("yyyyMMddhhmm");
-            break;
+            return new SimpleDateFormat("yyyyMMddhhmm");
         case Second:
-            format = new SimpleDateFormat("yyyyMMddhhmmss");
-            break;
+            return new SimpleDateFormat("yyyyMMddhhmmss");
         default:
-            format = new SimpleDateFormat("yyyyMMddhhmmssSSS");
-
-            break;
+            return new SimpleDateFormat("yyyyMMddhhmmssSSS");
         }
-        format.setCalendar(getGMT());
-        return format.format(date);
     }
 
     private Calendar getGMT() {
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
     }
 
+    private boolean matches(SearchQuery.SentDateCriterion criterion, MailboxMessage message) throws MailboxException {
+        SearchQuery.DateOperator operator = criterion.getOperator();
+        try {
+            return matchesSentDate(operator, message);
+        } catch (IOException e) {
+            throw new MailboxException("Can not read header Date", e);
+        } catch (ParseException e) {
+            throw new MailboxException("Can not parse header Date", e);
+        }
+    }
+
+    private boolean matchesSentDate(SearchQuery.DateOperator operator, MailboxMessage message) throws MailboxException, IOException, ParseException {
+        Date date = operator.getDate();
+        DateResolution dateResolution = operator.getDateResultion();
+        Date sentDate = toISODate(headerValue("Date", message));
+        SearchQuery.DateComparator type = operator.getType();
+        switch (type) {
+            case ON:
+                return on(sentDate, date, dateResolution);
+            case BEFORE:
+                return before(sentDate, date, dateResolution);
+            case AFTER:
+                return after(sentDate, date, dateResolution);
+            default:
+                throw new UnsupportedSearchException();
+        }
+    }
+
 }


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


[21/21] james-project git commit: JAMES-2049 Improve image display in preview

Posted by bt...@apache.org.
JAMES-2049 Improve image display in preview


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4ae9c8e9
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4ae9c8e9
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4ae9c8e9

Branch: refs/heads/master
Commit: 4ae9c8e9f5d3b573849d9a6e9e1793dc37708fcf
Parents: 048f95d
Author: benwa <bt...@linagora.com>
Authored: Wed Jun 7 11:55:05 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:40:31 2017 +0700

----------------------------------------------------------------------
 .../jmap/utils/JsoupHtmlTextExtractor.java      | 10 ++++-
 .../jmap/utils/JsoupHtmlTextExtractorTest.java  | 42 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4ae9c8e9/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
index d5b359e..4381086 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
@@ -83,12 +83,20 @@ public class JsoupHtmlTextExtractor implements HtmlTextExtractor {
                 return "\n\n";
             }
             if (element.tagName().equals(IMG_TAG)) {
-                return "[" + element.attributes().get(ALT_TAG) + "]";
+                return generateImageAlternativeText(element);
             }
         }
         return "";
     }
 
+    private String generateImageAlternativeText(Element element) {
+        return Optional.ofNullable(element.attributes().get(ALT_TAG))
+            .map(StringUtils::normalizeSpace)
+            .filter(s -> !s.isEmpty())
+            .map(s -> "[" + s + "]")
+            .orElse("");
+    }
+
     private String convertListElement(int nestedLevel) {
         if (nestedLevel == 0) {
             return "\n\n";

http://git-wip-us.apache.org/repos/asf/james-project/blob/4ae9c8e9/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
index 30e858a..c1830c6 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
@@ -155,6 +155,48 @@ public class JsoupHtmlTextExtractorTest {
     }
 
     @Test
+    public void imgShouldBeWellInsertedInText() {
+        String html = "Text <img src=\"whitePoney.png\" alt=\"My wonderfull white poney picture\"/> text";
+        String expectedPlainText = "Text [My wonderfull white poney picture] text";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
+    public void imgShouldNotBeDisplayedOnEmptyAlt() {
+        String html = "Text <img src=\"whitePoney.png\" alt=\"\"/> text";
+        String expectedPlainText = "Text  text";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
+    public void imgShouldNotBeDisplayedOnWhiteSpaceAlt() {
+        String html = "Text <img src=\"whitePoney.png\" alt=\" \"/> text";
+        String expectedPlainText = "Text  text";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
+    public void imgShouldNotBeDisplayedOnTabSpaceAlt() {
+        String html = "Text <img src=\"whitePoney.png\" alt=\"\t\"/> text";
+        String expectedPlainText = "Text  text";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
+    public void imgShouldNotBeDisplayedOnLineBreakSpaceAlt() {
+        String html = "Text <img src=\"whitePoney.png\" alt=\"\n\"/> text";
+        String expectedPlainText = "Text  text";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
+    public void imgShouldNotBeDisplayedOnMissingAlt() {
+        String html = "Text <img src=\"whitePoney.png\"/> text";
+        String expectedPlainText = "Text  text";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
     public void nestedListsShouldBeWellHandled() {
         String html = " <ul>" +
             "  <li>Coffee</li>" +


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


[04/21] james-project git commit: JAMES-2044 Improve MessageSearchIndex tests

Posted by bt...@apache.org.
JAMES-2044 Improve MessageSearchIndex tests

 - Criteria parameters to SearchQuery constructor
 - More imports
 - ImmutableList every where
 - Blank lines before assertions


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d256b275
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d256b275
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d256b275

Branch: refs/heads/master
Commit: d256b2750ae1139cbd44d84ab9be40ece331fc35
Parents: 4a01620
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 11:12:40 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:19 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java |  19 +-
 ...icSearchListeningMessageSearchIndexTest.java |   7 +-
 .../elasticsearch/query/SearchQueryTest.java    |  77 ++++
 .../search/AbstractMessageSearchIndexTest.java  | 377 ++++++++++---------
 4 files changed, 286 insertions(+), 194 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d256b275/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 7c22750..5a28541 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -35,6 +35,8 @@ import org.apache.james.mailbox.MessageUid;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
 
 /**
  * <p>
@@ -732,6 +734,18 @@ public class SearchQuery implements Serializable {
         return new CustomFlagCriterion(flag, BooleanOperator.unset());
     }
 
+    public SearchQuery() {
+        this(new ArrayList<Criterion>());
+    }
+
+    public SearchQuery(Criterion... criteria) {
+        this(ImmutableList.copyOf(criteria));
+    }
+
+    public SearchQuery(List<Criterion> criterias) {
+        this.criterias = criterias;
+    }
+
     /**
      * Creates a filter matching all messages.
      * 
@@ -743,7 +757,7 @@ public class SearchQuery implements Serializable {
 
     private final Set<MessageUid> recentMessageUids = new HashSet<MessageUid>();
 
-    private final List<Criterion> criterias = new ArrayList<Criterion>();
+    private final List<Criterion> criterias;
 
     private List<Sort> sorts = Collections.singletonList(new Sort(Sort.SortClause.Uid, false));
 
@@ -1854,7 +1868,8 @@ public class SearchQuery implements Serializable {
         private final DateResolution dateResolution;
 
         public DateOperator(DateComparator type, Date date, DateResolution dateResolution) {
-            super();
+            Preconditions.checkNotNull(date);
+            Preconditions.checkNotNull(dateResolution);
             this.type = type;
             this.date = date;
             this.dateResolution = dateResolution;

http://git-wip-us.apache.org/repos/asf/james-project/blob/d256b275/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index 91611bd..c8fb778 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -71,7 +71,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
     private MessageToElasticSearchJson messageToElasticSearchJson;
     private ElasticSearchListeningMessageSearchIndex testee;
     private MailboxSession session;
-    private User user;
+    private List<User> users;
     
     @Before
     public void setup() throws JsonProcessingException {
@@ -84,7 +84,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
         
         testee = new ElasticSearchListeningMessageSearchIndex(mapperFactory, indexer, elasticSearchSearcher, messageToElasticSearchJson);
         session = new MockMailboxSession(USERNAME);
-        user = session.getUser();
+        users = ImmutableList.of(session.getUser());
     }
     
     @Test
@@ -94,7 +94,6 @@ public class ElasticSearchListeningMessageSearchIndexTest {
         when(mailbox.getMailboxId())
             .thenReturn(MAILBOX_ID);
         MailboxMessage message = mockedMessage(MESSAGE_UID);
-        List<User> users = ImmutableList.of(user);
         
         when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
             .thenReturn(EXPECTED_JSON_CONTENT);
@@ -115,7 +114,6 @@ public class ElasticSearchListeningMessageSearchIndexTest {
             .thenReturn(MAILBOX_ID);
         
         MailboxMessage message = mockedMessage(MESSAGE_UID);
-        List<User> users = ImmutableList.of(user);
         
         when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
             .thenThrow(JsonProcessingException.class);
@@ -145,7 +143,6 @@ public class ElasticSearchListeningMessageSearchIndexTest {
         when(mailbox.getMailboxId())
             .thenReturn(MAILBOX_ID);
         MailboxMessage message = mockedMessage(MESSAGE_UID);
-        List<User> users = ImmutableList.of(user);
         
         when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
             .thenThrow(JsonProcessingException.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/d256b275/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/SearchQueryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/SearchQueryTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/SearchQueryTest.java
new file mode 100644
index 0000000..5d64c0c
--- /dev/null
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/SearchQueryTest.java
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.elasticsearch.query;
+
+import java.util.Date;
+
+import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.DateResolution;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class SearchQueryTest {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void sentDateOnShouldThrowOnNullDate() {
+        expectedException.expect(NullPointerException.class);
+
+        SearchQuery.sentDateOn(null, DateResolution.Day);
+    }
+
+    @Test
+    public void sentDateOnShouldThrowOnNullResolution() {
+        expectedException.expect(NullPointerException.class);
+
+        SearchQuery.sentDateOn(new Date(), null);
+    }
+
+    @Test
+    public void sentDateAfterShouldThrowOnNullDate() {
+        expectedException.expect(NullPointerException.class);
+
+        SearchQuery.sentDateAfter(null, DateResolution.Day);
+    }
+
+    @Test
+    public void sentDateAfterShouldThrowOnNullResolution() {
+        expectedException.expect(NullPointerException.class);
+
+        SearchQuery.sentDateAfter(new Date(), null);
+    }
+
+    @Test
+    public void sentDateBeforeShouldThrowOnNullDate() {
+        expectedException.expect(NullPointerException.class);
+
+        SearchQuery.sentDateBefore(null, DateResolution.Day);
+    }
+
+    @Test
+    public void sentDateBeforeShouldThrowOnNullResolution() {
+        expectedException.expect(NullPointerException.class);
+
+        SearchQuery.sentDateOn(new Date(), null);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d256b275/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 080345c..6d622ee 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -37,6 +37,9 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
+import org.apache.james.mailbox.model.SearchQuery.DateResolution;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -47,7 +50,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
 
 public abstract class AbstractMessageSearchIndexTest {
 
@@ -59,6 +61,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public static final long LIMIT = 100L;
     public static final boolean RECENT = true;
     public static final boolean NOT_RECENT = false;
+    public static final boolean REVERSE = true;
 
     protected MessageSearchIndex messageSearchIndex;
     protected StoreMailboxManager storeMailboxManager;
@@ -342,71 +345,67 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void allShouldReturnAllUids() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.all());
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void bodyContainsShouldReturnUidOfMessageContainingTheGivenText() throws MailboxException {
-        /*
-        Only mail4.eml contains word MAILET-94
-         */
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.bodyContains("MAILET-94"));
+        /* Only mail4.eml contains word MAILET-94 */
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.bodyContains("MAILET-94"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
     }
 
     @Test
     public void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() throws MailboxException {
-        /*
-        mail1.eml contains words created AND summary
-        mail.eml contains created and thus matches the query with a low score
-         */
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.bodyContains("created summary"));
+        /* mail1.eml contains words created AND summary
+           mail.eml contains created and thus matches the query with a low score */
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.bodyContains("created summary"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid(), m8.getUid());
     }
 
     @Test
     public void hasAttachmentShouldOnlyReturnMessageThatHasAttachmentWhichAreNotInline() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.hasAttachment());
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.hasAttachment());
+
         assertThat(messageSearchIndex.search(session, mailbox2, searchQuery))
             .containsOnly(mailWithAttachment.getUid());
     }
 
     @Test
     public void hasNoAttachmenShouldOnlyReturnMessageThatHasNoAttachmentWhichAreNotInline() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.hasNoAttachment());
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.hasNoAttachment());
+
         assertThat(messageSearchIndex.search(session, mailbox2, searchQuery))
             .containsOnly(mOther.getUid(), mailWithInlinedAttachment.getUid());
     }
 
     @Test
     public void flagIsSetShouldReturnUidOfMessageMarkedAsDeletedWhenUsedWithFlagDeleted() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.DELETED));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.DELETED));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid());
     }
 
     @Test
     public void flagIsSetShouldReturnUidOfMessageMarkedAsAnsweredWhenUsedWithFlagAnswered() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.ANSWERED));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.ANSWERED));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid());
     }
 
     @Test
     public void flagIsSetShouldReturnUidOfMessageMarkedAsDraftWhenUsedWithFlagDraft() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid());
     }
@@ -414,16 +413,16 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void flagIsSetShouldReturnUidOfMessageMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
         // Only message 7 is not marked as RECENT
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.RECENT));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.RECENT));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void flagIsSetShouldReturnUidOfMessageMarkedAsFlaggedWhenUsedWithFlagFlagged() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.FLAGGED));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.FLAGGED));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
     }
@@ -431,16 +430,15 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void flagIsSetShouldReturnUidOfMessageMarkedAsSeenWhenUsedWithFlagSeen() throws MailboxException {
         // Only message 6 is marked as read.
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m6.getUid());
     }
     
     @Test
     public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
 
         List<MessageId> actual = messageSearchIndex.search(session, MultimailboxesSearchQuery.from(searchQuery).build(), LIMIT);
 
@@ -449,8 +447,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInOneMailbox() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
         MultimailboxesSearchQuery query = 
                 MultimailboxesSearchQuery
                     .from(searchQuery)
@@ -464,8 +461,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void multimailboxSearchShouldReturnUidOfMessageWithExpectedFromInTwoMailboxes() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.address(AddressType.From, "murari"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.From, "murari"));
         MultimailboxesSearchQuery query = 
                 MultimailboxesSearchQuery
                     .from(searchQuery)
@@ -478,8 +474,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void multimailboxSearchShouldReturnUidOfMessageWithExpectedFromInAllMailboxes() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.address(AddressType.From, "murari"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.From, "murari"));
         MultimailboxesSearchQuery query = 
                 MultimailboxesSearchQuery
                     .from(searchQuery)
@@ -492,8 +487,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInTwoMailboxes() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
         MultimailboxesSearchQuery query = 
                 MultimailboxesSearchQuery
                     .from(searchQuery)
@@ -507,8 +501,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void multimailboxSearchShouldLimitTheSize() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
         MultimailboxesSearchQuery query =
             MultimailboxesSearchQuery
                 .from(searchQuery)
@@ -525,40 +518,40 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void flagIsSetShouldReturnUidsOfMessageContainingAGivenUserFlag() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet("Hello"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet("Hello"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m8.getUid());
     }
 
     @Test
     public void userFlagsShouldBeMatchedExactly() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsSet("Hello bonjour"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet("Hello bonjour"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .isEmpty();
     }
 
     @Test
     public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsDeletedWhenUsedWithFlagDeleted() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.DELETED));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.DELETED));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsAnsweredWhenUsedWithFlagAnswered() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.ANSWERED));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.ANSWERED));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsDraftWhenUsedWithFlagDraft() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.DRAFT));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.DRAFT));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
@@ -566,16 +559,16 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
         // Only message 7 is not marked as RECENT
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.RECENT));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.RECENT));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m7.getUid());
     }
 
     @Test
     public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsFlaggedWhenUsedWithFlagFlagged() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.FLAGGED));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.FLAGGED));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
@@ -583,97 +576,109 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsSeendWhenUsedWithFlagSeen() throws MailboxException {
         // Only message 6 is marked as read.
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.SEEN));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.SEEN));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void flagIsUnSetShouldReturnUidsOfMessageNotContainingAGivenUserFlag() throws MailboxException {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.flagIsUnSet("Hello"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet("Hello"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(),  m9.getUid());
     }
 
     @Test
     public void internalDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.internalDateAfter(
+            new Date(1404252000000L),
+            DateResolution.Day));
         // Date : 2014/07/02 00:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.internalDateAfter(new Date(1404252000000L), SearchQuery.DateResolution.Day));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.internalDateBefore(
+            new Date(1391295600000L),
+            DateResolution.Day));
         // Date : 2014/02/02 00:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.internalDateBefore(new Date(1391295600000L), SearchQuery.DateResolution.Day));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid());
     }
 
     @Test
     public void internalDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.internalDateOn(
+            new Date(1393714800000L),
+            DateResolution.Day));
         // Date : 2014/03/02 00:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.internalDateOn(new Date(1393714800000L), SearchQuery.DateResolution.Day));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid());
     }
 
     @Test
     public void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.sentDateAfter(
+            new Date(1433408400000L),
+            DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.sentDateAfter(new Date(1433408400000L), SearchQuery.DateResolution.Second));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid(), m2.getUid());
     }
 
     @Test
     public void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.sentDateBefore(
+            new Date(1433109600000L),
+            DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.sentDateBefore(new Date(1433109600000L), SearchQuery.DateResolution.Day));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
     }
 
     @Test
     public void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.sentDateOn(
+            new Date(1433224800000L),
+            DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.sentDateOn(new Date(1433224800000L), SearchQuery.DateResolution.Day));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m4.getUid(), m9.getUid());
     }
 
     @Test
     public void modSeqEqualsShouldReturnUidsOfMessageHavingAGivenModSeq() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.modSeqEquals(2L));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.modSeqEquals(2L));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid());
     }
 
     @Test
     public void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.modSeqGreaterThan(7L));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.modSeqGreaterThan(7L));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.modSeqLessThan(3L));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.modSeqLessThan(3L));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid());
     }
@@ -681,8 +686,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sizeGreaterThanShouldReturnUidsOfMessageExceedingTheSpecifiedSize() throws Exception {
         // Only message 6 is over 6.8 KB
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.sizeGreaterThan(6800L));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.sizeGreaterThan(6800L));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m6.getUid());
     }
@@ -690,74 +695,73 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sizeLessThanShouldReturnUidsOfMessageNotExceedingTheSpecifiedSize() throws Exception {
         // Only message 2 3 4 5 7 9 are under 5 KB
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.sizeLessThan(5000L));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.sizeLessThan(5000L));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m7.getUid(), m9.getUid());
     }
 
     @Test
     public void headerContainsShouldReturnUidsOfMessageHavingThisHeaderWithTheSpecifiedValue() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.headerContains("Precedence", "list"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.headerContains("Precedence", "list"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m6.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void headerExistsShouldReturnUidsOfMessageHavingThisHeader() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.headerExists("Precedence"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.headerExists("Precedence"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.From, "murari.ksr@gmail.com"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.From, "murari.ksr@gmail.com"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m8.getUid());
     }
 
     @Test
     public void addressShouldReturnUidHavingRightRecipientWhenToIsSpecified() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.To, "root@listes.minet.net"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.To, "root@listes.minet.net"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid());
     }
 
     @Test
     public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecified() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.Cc, "any@any.com"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.Cc, "any@any.com"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
     }
 
     @Test
     public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecified() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.Bcc, "no@no.com"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.Bcc, "no@no.com"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m9.getUid());
     }
 
     @Test
     public void uidShouldreturnExistingUidsOnTheGivenRanges() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m4.getUid()), new SearchQuery.UidRange(m6.getUid(), m7.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid(), m3.getUid(), m4.getUid(), m6.getUid(), m7.getUid());
     }
 
     @Test
     public void uidShouldreturnEveryThing() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
@@ -767,17 +771,17 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.headerExists("Precedence"));
         searchQuery.andCriteria(SearchQuery.modSeqGreaterThan(6L));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m6.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void andShouldReturnResultsMatchingBothRequests() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(
-            SearchQuery.and(
-                SearchQuery.headerExists("Precedence"),
-                SearchQuery.modSeqGreaterThan(6L)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.and(
+            SearchQuery.headerExists("Precedence"),
+            SearchQuery.modSeqGreaterThan(6L)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m6.getUid(), m8.getUid(), m9.getUid());
     }
@@ -785,86 +789,88 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void orShouldReturnResultsMatchinganyRequests() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m4.getUid())};
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(
-            SearchQuery.or(
-                SearchQuery.uid(numericRanges),
-                SearchQuery.modSeqGreaterThan(6L)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.or(
+            SearchQuery.uid(numericRanges),
+            SearchQuery.modSeqGreaterThan(6L)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m2.getUid(), m3.getUid(), m4.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void notShouldReturnResultsThatDoNotMatchAQuery() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(
+        SearchQuery searchQuery = new SearchQuery(
             SearchQuery.not(SearchQuery.headerExists("Precedence")));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m7.getUid());
     }
 
     @Test
     public void sortShouldOrderMessages() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.all());
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m1.getUid(), m2.getUid(), m3.getUid(), m5.getUid(), m4.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
     public void revertSortingShouldReturnElementsInAReversedOrder() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.all());
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m9.getUid(), m8.getUid(), m7.getUid(), m6.getUid(), m4.getUid(), m5.getUid(), m3.getUid(), m2.getUid(), m1.getUid());
     }
 
     @Test
     public void headerDateAfterShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(
+            SearchQuery.headerDateAfter("sentDate", new Date(1433408400000L), DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.headerDateAfter("sentDate", new Date(1433408400000L), SearchQuery.DateResolution.Second));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid(), m2.getUid());
     }
 
     @Test
     public void headerDateBeforeShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(
+            SearchQuery.headerDateBefore("sentDate", new Date(1433109600000L), DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.headerDateBefore("sentDate", new Date(1433109600000L), SearchQuery.DateResolution.Day));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
     }
 
     @Test
     public void headerDateOnShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(
+            SearchQuery.headerDateOn("sentDate", new Date(1433224800000L), DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
-        searchQuery.andCriteria(SearchQuery.headerDateOn("sentDate", new Date(1433224800000L), SearchQuery.DateResolution.Day));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m4.getUid(), m9.getUid());
     }
 
     @Test
     public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.mailContains("root mailing list"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.mailContains("root mailing list"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m6.getUid());
     }
 
     @Test
     public void sortOnCcShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxCc)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxCc)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid(), m5.getUid(), m4.getUid(), m2.getUid());
         // 2 : No cc
@@ -875,10 +881,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnFromShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxFrom)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxFrom)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid(), m2.getUid(), m4.getUid(), m5.getUid());
         // 2 : jira2@apache.org
@@ -889,10 +895,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnToShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid(), m2.getUid(), m3.getUid(), m4.getUid());
         // 2 : server-dev@james.apache.org
@@ -903,10 +909,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnSubjectShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m4.getUid(), m3.getUid(), m2.getUid(), m5.getUid());
         // 2 : [jira] [Created] (MAILBOX-234) Convert Message into JSON
@@ -917,10 +923,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnSizeShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid(), m5.getUid(), m4.getUid());
         // 2 : 3210 o
@@ -931,10 +937,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnDisplayFromShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m4.getUid(), m3.getUid(), m5.getUid(), m2.getUid());
         // 2 : Tellier Benoit (JIRA)
@@ -945,10 +951,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnDisplayToShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid(), m2.getUid(), m4.getUid(), m5.getUid());
         // 2 : abc
@@ -959,10 +965,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnSentDateShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid(), m4.getUid(), m2.getUid(), m3.getUid());
         // 2 : 4 Jun 2015 09:23:37
@@ -973,10 +979,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void sortOnIdShouldWork() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
-        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid)));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
+        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid)));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid());
     }
@@ -984,8 +990,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnNoMailWhenNotMatching() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("unmatching"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("unmatching"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .isEmpty();
     }
@@ -993,8 +999,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenFromMatches() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("spam.minet.net"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("spam.minet.net"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m1.getUid());
     }
@@ -1002,8 +1008,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenToMatches() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("listes.minet.net"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("listes.minet.net"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m1.getUid());
     }
@@ -1011,8 +1017,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenCcMatches() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("abc.org"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("abc.org"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid());
     }
@@ -1020,8 +1026,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenBccMatches() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("any.com"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("any.com"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid());
     }
@@ -1029,8 +1035,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenTextBodyMatches() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("reviewing work"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("reviewing work"));
+
         // text/plain contains: "We are reviewing work I did for this feature."
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid());
@@ -1039,10 +1045,10 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenTextBodyMatchesAndNonContinuousWords() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("reviewing feature"));
         // 2: text/plain contains: "Issue Type: New Feature"
         // 3: text/plain contains: "We are reviewing work I did for this feature."
-        searchQuery.andCriteria(SearchQuery.textContains("reviewing feature"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid());
     }
@@ -1050,9 +1056,9 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenTextBodyMatchesInsensitiveWords() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("reVieWing"));
         // text/plain contains: "We are reviewing work I did for this feature."
-        searchQuery.andCriteria(SearchQuery.textContains("reVieWing"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid());
     }
@@ -1060,9 +1066,9 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenTextBodyWithExtraUnindexedWords() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("a reviewing of the work"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("a reviewing of the work"));
         // text/plain contains: "We are reviewing work I did for this feature."
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid());
     }
@@ -1070,9 +1076,9 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenHtmlBodyMatches() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("contains a banana"));
         // text/html contains: "This is a mail with beautifull html content which contains a banana."
-        searchQuery.andCriteria(SearchQuery.textContains("contains a banana"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m7.getUid());
     }
@@ -1080,8 +1086,8 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("contain banana"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("contain banana"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m7.getUid());
     }
@@ -1089,16 +1095,15 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void searchWithFullTextShouldReturnMailsWhenHtmlBodyMatchesAndNonContinuousWords() throws Exception {
         Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(SearchQuery.textContains("beautifull banana"));
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("beautifull banana"));
+
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m7.getUid());
     }
 
     @Test
     public void sortShouldNotDiscardResultWhenSearchingFieldIsIdentical() throws Exception {
-        SearchQuery searchQuery = new SearchQuery();
-        searchQuery.andCriteria(new SearchQuery.AllCriterion());
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
         searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival)));
 
         List<MessageId> actual = messageSearchIndex.search(session, MultimailboxesSearchQuery.from(searchQuery).build(), LIMIT);
@@ -1109,8 +1114,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void searchInMultiMailboxShouldReturnMessagesBelongingToUserSession() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
+        SearchQuery query = new SearchQuery(SearchQuery.all());
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery.from(query).build();
 
@@ -1121,8 +1125,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
     @Test
     public void searchInMultiMailboxShouldNotReturnMessagesBelongingToAnotherUserSession() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
+        SearchQuery query = new SearchQuery(SearchQuery.all());
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery.from(query).build();
 


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


[13/21] james-project git commit: JAMES-2048 Enhance log information when indexing

Posted by bt...@apache.org.
JAMES-2048 Enhance log information when indexing


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d4246a01
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d4246a01
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d4246a01

Branch: refs/heads/master
Commit: d4246a01cdf95323192aeaaef529db71286531bd
Parents: 86e0703
Author: quynhn <qn...@linagora.com>
Authored: Fri Jun 2 10:13:01 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:35:43 2017 +0700

----------------------------------------------------------------------
 .../ElasticSearchListeningMessageSearchIndex.java | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d4246a01/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index 55d3f2e..bfd8c1f 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -109,13 +109,27 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
     @Override
     public void add(MailboxSession session, Mailbox mailbox, MailboxMessage message) throws MailboxException {
         try {
+            LOGGER.info("Indexing mailbox {}-{} of user {} on message {}",
+                    mailbox.getName(),
+                    mailbox.getMailboxId(),
+                    session.getUser().getUserName(),
+                    message.getUid());
             indexer.indexMessage(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJson(message, ImmutableList.of(session.getUser())));
         } catch (Exception e) {
             try {
-                LOGGER.warn("indexing message {} without attachments ", message.getUid());
+                LOGGER.warn("Indexing mailbox {}-{} of user {} on message {} without attachments ",
+                        mailbox.getName(),
+                        mailbox.getMailboxId(),
+                        session.getUser().getUserName(),
+                        message.getUid());
                 indexer.indexMessage(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJsonWithoutAttachment(message, ImmutableList.of(session.getUser())));
             } catch (JsonProcessingException e1) {
-                LOGGER.error("Error when indexing message " + message.getUid() + " without its attachment", e1);
+                LOGGER.error("Error when indexing mailbox {}-{} of user {} on message {} without its attachment",
+                        mailbox.getName(),
+                        mailbox.getMailboxId(),
+                        session.getUser().getUserName(),
+                        message.getUid(),
+                        e1);
             }
         }
     }


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


[06/21] james-project git commit: JAMES-2044 SentDateCriterion is redundant

Posted by bt...@apache.org.
JAMES-2044 SentDateCriterion is redundant


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/81ef4293
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/81ef4293
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/81ef4293

Branch: refs/heads/master
Commit: 81ef4293dd6913133e0ffa1f4d3bf4bbc3fd0776
Parents: fc089b9
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 12:02:40 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java | 50 ++------------------
 .../elasticsearch/query/CriterionConverter.java |  3 --
 .../lucene/search/LuceneMessageSearchIndex.java |  3 --
 .../mailbox/store/search/MessageSearches.java   | 30 ------------
 4 files changed, 4 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 1ae0042..9888f15 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -52,6 +52,7 @@ import com.google.common.collect.ImmutableList;
  */
 public class SearchQuery implements Serializable {
     private static final long serialVersionUID = 1L;
+    private static final String DATE_HEADER_NAME = "Date";
 
     /**
      * The Resolution which should get used for {@link Date} searches
@@ -344,7 +345,7 @@ public class SearchQuery implements Serializable {
      * @return <code>Criterion</code>, not null
      */
     public static Criterion sentDateAfter(Date date, DateResolution dateResolution) {
-        return new SentDateCriterion(new DateOperator(DateComparator.AFTER, date, dateResolution));
+        return headerDateAfter(DATE_HEADER_NAME, date, dateResolution);
     }
 
     /**
@@ -360,7 +361,7 @@ public class SearchQuery implements Serializable {
      * @return <code>Criterion</code>, not null
      */
     public static Criterion sentDateOn(Date date, DateResolution dateResolution) {
-        return new SentDateCriterion(new DateOperator(DateComparator.ON, date, dateResolution));
+        return headerDateOn(DATE_HEADER_NAME, date, dateResolution);
     }
 
     /**
@@ -377,7 +378,7 @@ public class SearchQuery implements Serializable {
      * @return <code>Criterion</code>, not null
      */
     public static Criterion sentDateBefore(Date date, DateResolution dateResolution) {
-        return new SentDateCriterion(new DateOperator(DateComparator.BEFORE, date, dateResolution));
+        return headerDateBefore(DATE_HEADER_NAME, date, dateResolution);
     }
 
     /**
@@ -1254,49 +1255,6 @@ public class SearchQuery implements Serializable {
     }
 
     /**
-     * Filters on the sent date.
-     */
-    public static class SentDateCriterion extends Criterion {
-        private static final long serialVersionUID = 1L;
-
-        private final DateOperator operator;
-
-        public SentDateCriterion(DateOperator operator) {
-            this.operator = operator;
-        }
-
-        public DateOperator getOperator() {
-            return operator;
-        }
-
-        public HeaderCriterion toHeaderCriterion() {
-            return new HeaderCriterion("Date", operator);
-        }
-
-        @Override
-        public int hashCode() {
-            return Objects.hashCode(operator);
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj instanceof SentDateCriterion) {
-                SentDateCriterion that = (SentDateCriterion) obj;
-
-                return Objects.equal(this.operator, that.operator);
-            }
-            return false;
-        }
-
-        @Override
-        public String toString() {
-            return MoreObjects.toStringHelper(this)
-                .add("operator", operator)
-                .toString();
-        }
-    }
-
-    /**
      * Filters on the mod-sequence of the messages.
      */
     public static class ModSeqCriterion extends Criterion {

http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 600c335..9e06c87 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -80,9 +80,6 @@ public class CriterionConverter {
         registerCriterionConverter(SearchQuery.InternalDateCriterion.class,
             criterion -> dateRangeFilter(JsonMessageConstants.DATE, criterion.getOperator()));
 
-        registerCriterionConverter(SearchQuery.SentDateCriterion.class,
-            criterion -> dateRangeFilter(JsonMessageConstants.SENT_DATE, criterion.getOperator()));
-
         registerCriterionConverter(SearchQuery.AttachmentCriterion.class, this::convertAttachmentCriterion);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 8326cf1..91b39a6 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -1267,9 +1267,6 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
             return createConjunctionQuery(crit, inMailboxes, recentUids);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             return createModSeqQuery((SearchQuery.ModSeqCriterion) criterion);
-        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
-            SearchQuery.SentDateCriterion sentDateCriterion = (SearchQuery.SentDateCriterion) criterion;
-            return createHeaderQuery(sentDateCriterion.toHeaderCriterion());
         }
         throw new UnsupportedSearchException();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index a58e925..6cee0d4 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -201,8 +201,6 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
             result = matches((SearchQuery.AttachmentCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             result = matches((SearchQuery.ModSeqCriterion) criterion, message);
-        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
-            result = matches((SearchQuery.SentDateCriterion) criterion, message);
         } else {
             throw new UnsupportedSearchException();
         }
@@ -652,32 +650,4 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
     }
 
-    private boolean matches(SearchQuery.SentDateCriterion criterion, MailboxMessage message) throws MailboxException {
-        SearchQuery.DateOperator operator = criterion.getOperator();
-        try {
-            return matchesSentDate(operator, message);
-        } catch (IOException e) {
-            throw new MailboxException("Can not read header Date", e);
-        } catch (ParseException e) {
-            throw new MailboxException("Can not parse header Date", e);
-        }
-    }
-
-    private boolean matchesSentDate(SearchQuery.DateOperator operator, MailboxMessage message) throws MailboxException, IOException, ParseException {
-        Date date = operator.getDate();
-        DateResolution dateResolution = operator.getDateResultion();
-        Date sentDate = toISODate(headerValue("Date", message));
-        SearchQuery.DateComparator type = operator.getType();
-        switch (type) {
-            case ON:
-                return on(sentDate, date, dateResolution);
-            case BEFORE:
-                return before(sentDate, date, dateResolution);
-            case AFTER:
-                return after(sentDate, date, dateResolution);
-            default:
-                throw new UnsupportedSearchException();
-        }
-    }
-
 }


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


[18/21] james-project git commit: JAMES-2047 Add error management to ConcurrentTestRunner

Posted by bt...@apache.org.
JAMES-2047 Add error management to ConcurrentTestRunner


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/04566013
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/04566013
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/04566013

Branch: refs/heads/master
Commit: 045660137ff53a360f8d91fe9b155332342dac8d
Parents: 2e1d41d
Author: benwa <bt...@linagora.com>
Authored: Tue Jun 6 11:19:32 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:39:06 2017 +0700

----------------------------------------------------------------------
 .../util/concurrency/ConcurrentTestRunner.java  | 22 ++++-
 .../concurrency/ConcurrentTestRunnerTest.java   | 98 ++++++++++++++++++++
 2 files changed, 119 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/04566013/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java b/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
index 0a4fa40..cc06686 100644
--- a/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
+++ b/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
@@ -19,15 +19,20 @@
 
 package org.apache.james.util.concurrency;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
 
 public class ConcurrentTestRunner {
 
@@ -40,6 +45,7 @@ public class ConcurrentTestRunner {
     private class ConcurrentRunnableTask implements Runnable {
         private final int threadNumber;
         private final BiConsumer biConsumer;
+        private Exception exception;
 
         public ConcurrentRunnableTask(int threadNumber, BiConsumer biConsumer) {
             this.threadNumber = threadNumber;
@@ -48,14 +54,19 @@ public class ConcurrentTestRunner {
 
         @Override
         public void run() {
+            exception = null;
             countDownLatch.countDown();
             for (int i = 0; i < operationCount; i++) {
                 try {
                     biConsumer.consume(threadNumber, i);
                 } catch (Exception e) {
                     LOGGER.error("Error caught during concurrent testing", e);
+                    exception = e;
                 }
             }
+            if (exception != null) {
+                throw Throwables.propagate(exception);
+            }
         }
     }
 
@@ -64,6 +75,7 @@ public class ConcurrentTestRunner {
     private final CountDownLatch countDownLatch;
     private final BiConsumer biConsumer;
     private final ExecutorService executorService;
+    private final List<Future> futures;
 
     public ConcurrentTestRunner(int threadCount, int operationCount, BiConsumer biConsumer) {
         Preconditions.checkArgument(threadCount > 0, "Thread count should be strictly positive");
@@ -74,11 +86,19 @@ public class ConcurrentTestRunner {
         this.countDownLatch = new CountDownLatch(threadCount);
         this.biConsumer = biConsumer;
         this.executorService = Executors.newFixedThreadPool(threadCount);
+        this.futures = new ArrayList<Future>();
     }
 
     public ConcurrentTestRunner run() {
         for (int i = 0; i < threadCount; i++) {
-            executorService.submit(new ConcurrentRunnableTask(i, biConsumer));
+            futures.add(executorService.submit(new ConcurrentRunnableTask(i, biConsumer)));
+        }
+        return this;
+    }
+
+    public ConcurrentTestRunner assertNoException() throws ExecutionException, InterruptedException {
+        for (Future future: futures) {
+            future.get();
         }
         return this;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/04566013/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java b/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
index 98bde34..89396e0 100644
--- a/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
+++ b/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
@@ -22,6 +22,7 @@ package org.apache.james.util.concurrency;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Rule;
@@ -132,4 +133,101 @@ public class ConcurrentTestRunnerTest {
         assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
         assertThat(queue).containsOnly("0:0", "0:1", "1:0", "1:1");
     }
+
+    @Test
+    public void runShouldNotThrowOnExceptions() throws Exception {
+        int operationCount = 2;
+        int threadCount = 2;
+
+        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
+            new ConcurrentTestRunner.BiConsumer() {
+                @Override
+                public void consume(int threadNumber, int step) throws Exception {
+                    throw new RuntimeException();
+                }
+            })
+            .run();
+
+        assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
+    }
+
+    @Test
+    public void noExceptionsShouldNotThrowWhenNoExceptionGenerated() throws Exception {
+        int operationCount = 2;
+        int threadCount = 2;
+
+        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
+            new ConcurrentTestRunner.BiConsumer() {
+                @Override
+                public void consume(int threadNumber, int step) throws Exception {
+
+                }
+            })
+            .run();
+
+        concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS);
+
+        concurrentTestRunner.assertNoException();
+    }
+
+    @Test
+    public void assertNoExceptionShouldThrowOnExceptions() throws Exception {
+        int operationCount = 2;
+        int threadCount = 2;
+
+        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
+            new ConcurrentTestRunner.BiConsumer() {
+                @Override
+                public void consume(int threadNumber, int step) throws Exception {
+                    throw new RuntimeException();
+                }
+            })
+            .run();
+        concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS);
+
+        expectedException.expect(ExecutionException.class);
+        concurrentTestRunner.assertNoException();
+    }
+
+    @Test
+    public void runShouldPerformAllOperationsEvenOnExceptions() throws Exception {
+        int operationCount = 2;
+        int threadCount = 2;
+        final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();
+
+        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
+            new ConcurrentTestRunner.BiConsumer() {
+                @Override
+                public void consume(int threadNumber, int step) throws Exception {
+                    queue.add(threadNumber + ":" + step);
+                    throw new RuntimeException();
+                }
+            })
+            .run();
+
+        assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
+        assertThat(queue).containsOnly("0:0", "0:1", "1:0", "1:1");
+    }
+
+    @Test
+    public void runShouldPerformAllOperationsEvenOnOccasionalExceptions() throws Exception {
+        int operationCount = 2;
+        int threadCount = 2;
+        final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();
+
+        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
+            new ConcurrentTestRunner.BiConsumer() {
+                @Override
+                public void consume(int threadNumber, int step) throws Exception {
+                    queue.add(threadNumber + ":" + step);
+                    if ((threadNumber + step) % 2 == 0) {
+                        throw new RuntimeException();
+                    }
+                }
+            })
+            .run();
+
+        assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
+        assertThat(queue).containsOnly("0:0", "0:1", "1:0", "1:1");
+    }
 }


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


[03/21] james-project git commit: JAMES-2044 Improve naming for DateResolution in SearchQuery SearchQuery

Posted by bt...@apache.org.
JAMES-2044 Improve naming for DateResolution in SearchQuery SearchQuery


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/691b72a0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/691b72a0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/691b72a0

Branch: refs/heads/master
Commit: 691b72a07331803a3bd4832c9c61f47c7684924f
Parents: a54f1ee
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 10:29:03 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:32:51 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java | 68 ++++++++++----------
 1 file changed, 34 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/691b72a0/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index deb3535..39e91bc 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -284,15 +284,15 @@ public class SearchQuery implements Serializable {
      * 
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion internalDateAfter(Date date, DateResolution res) {
-        return new InternalDateCriterion(new DateOperator(DateComparator.AFTER, date, res));
+    public static Criterion internalDateAfter(Date date, DateResolution dateResolution) {
+        return new InternalDateCriterion(new DateOperator(DateComparator.AFTER, date, dateResolution));
     }
 
     /**
@@ -300,15 +300,15 @@ public class SearchQuery implements Serializable {
      * 
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion internalDateOn(Date date, DateResolution res) {
-        return new InternalDateCriterion(new DateOperator(DateComparator.ON, date, res));
+    public static Criterion internalDateOn(Date date, DateResolution dateResolution) {
+        return new InternalDateCriterion(new DateOperator(DateComparator.ON, date, dateResolution));
     }
 
     /**
@@ -317,15 +317,15 @@ public class SearchQuery implements Serializable {
      * 
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion internalDateBefore(Date date, DateResolution res) {
-        return new InternalDateCriterion(new DateOperator(DateComparator.BEFORE, date, res));
+    public static Criterion internalDateBefore(Date date, DateResolution dateResolution) {
+        return new InternalDateCriterion(new DateOperator(DateComparator.BEFORE, date, dateResolution));
     }
 
     /**
@@ -334,15 +334,15 @@ public class SearchQuery implements Serializable {
      * 
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion sentDateAfter(Date date, DateResolution res) {
-        return new SentDateCriterion(new DateOperator(DateComparator.AFTER, date, res));
+    public static Criterion sentDateAfter(Date date, DateResolution dateResolution) {
+        return new SentDateCriterion(new DateOperator(DateComparator.AFTER, date, dateResolution));
     }
 
     /**
@@ -350,15 +350,15 @@ public class SearchQuery implements Serializable {
      * 
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion sentDateOn(Date date, DateResolution res) {
-        return new SentDateCriterion(new DateOperator(DateComparator.ON, date, res));
+    public static Criterion sentDateOn(Date date, DateResolution dateResolution) {
+        return new SentDateCriterion(new DateOperator(DateComparator.ON, date, dateResolution));
     }
 
     /**
@@ -367,15 +367,15 @@ public class SearchQuery implements Serializable {
      * 
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion sentDateBefore(Date date, DateResolution res) {
-        return new SentDateCriterion(new DateOperator(DateComparator.BEFORE, date, res));
+    public static Criterion sentDateBefore(Date date, DateResolution dateResolution) {
+        return new SentDateCriterion(new DateOperator(DateComparator.BEFORE, date, dateResolution));
     }
 
     /**
@@ -387,15 +387,15 @@ public class SearchQuery implements Serializable {
      *            name of the header whose value will be compared, not null
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion headerDateAfter(String headerName, Date date, DateResolution res) {
-        return new HeaderCriterion(headerName, new DateOperator(DateComparator.AFTER, date, res));
+    public static Criterion headerDateAfter(String headerName, Date date, DateResolution dateResolution) {
+        return new HeaderCriterion(headerName, new DateOperator(DateComparator.AFTER, date, dateResolution));
     }
 
     /**
@@ -407,15 +407,15 @@ public class SearchQuery implements Serializable {
      *            name of the header whose value will be compared, not null
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion headerDateOn(String headerName, Date date, DateResolution res) {
-        return new HeaderCriterion(headerName, new DateOperator(DateComparator.ON, date, res));
+    public static Criterion headerDateOn(String headerName, Date date, DateResolution dateResolution) {
+        return new HeaderCriterion(headerName, new DateOperator(DateComparator.ON, date, dateResolution));
     }
 
     /**
@@ -427,15 +427,15 @@ public class SearchQuery implements Serializable {
      *            name of the header whose value will be compared, not null
      * @param date
      *            given date
-     * @param res
+     * @param dateResolution
      *            the date resolution, either {@link DateResolution#Year},
      *            {@link DateResolution#Month}, {@link DateResolution#Day},
      *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
      *            {@link DateResolution#Second}
      * @return <code>Criterion</code>, not null
      */
-    public static Criterion headerDateBefore(String headerName, Date date, DateResolution res) {
-        return new HeaderCriterion(headerName, new DateOperator(DateComparator.BEFORE, date, res));
+    public static Criterion headerDateBefore(String headerName, Date date, DateResolution dateResolution) {
+        return new HeaderCriterion(headerName, new DateOperator(DateComparator.BEFORE, date, dateResolution));
     }
 
     /**
@@ -1852,13 +1852,13 @@ public class SearchQuery implements Serializable {
 
         private final Date date;
 
-        private final DateResolution res;
+        private final DateResolution dateResolution;
 
-        public DateOperator(DateComparator type, Date date, DateResolution res) {
+        public DateOperator(DateComparator type, Date date, DateResolution dateResolution) {
             super();
             this.type = type;
             this.date = date;
-            this.res = res;
+            this.dateResolution = dateResolution;
         }
 
         public Date getDate() {
@@ -1866,7 +1866,7 @@ public class SearchQuery implements Serializable {
         }
 
         public DateResolution getDateResultion() {
-            return res;
+            return dateResolution;
         }
 
         /**
@@ -1881,7 +1881,7 @@ public class SearchQuery implements Serializable {
 
         @Override
         public int hashCode() {
-            return Objects.hashCode(res, type);
+            return Objects.hashCode(dateResolution, type);
         }
 
 
@@ -1890,7 +1890,7 @@ public class SearchQuery implements Serializable {
             if (obj instanceof DateOperator) {
                 DateOperator that = (DateOperator) obj;
 
-                return Objects.equal(this.res, that.res)
+                return Objects.equal(this.dateResolution, that.dateResolution)
                     && Objects.equal(this.type, that.type);
             }
             return false;
@@ -1900,7 +1900,7 @@ public class SearchQuery implements Serializable {
         public String toString() {
             return MoreObjects.toStringHelper(this)
                 .add("date", date)
-                .add("res", res)
+                .add("dateResolution", dateResolution)
                 .add("type", type)
                 .toString();
         }


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


[20/21] james-project git commit: JAMES-2047 Concurrency issues when saving mailboxes

Posted by bt...@apache.org.
JAMES-2047 Concurrency issues when saving mailboxes


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/048f95da
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/048f95da
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/048f95da

Branch: refs/heads/master
Commit: 048f95da0efdf6f2828b4a2e66c931dbfa86d25d
Parents: 8357286
Author: benwa <bt...@linagora.com>
Authored: Tue Jun 6 15:52:46 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:40:04 2017 +0700

----------------------------------------------------------------------
 .../inmemory/mail/InMemoryMailboxMapper.java    | 59 +++++++++-----------
 1 file changed, 25 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/048f95da/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
index 8f42eed..b85cdef 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
@@ -20,7 +20,6 @@ package org.apache.james.mailbox.inmemory.mail;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -36,55 +35,49 @@ import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 
 import com.google.common.base.Objects;
+import com.google.common.base.Optional;
 
 public class InMemoryMailboxMapper implements MailboxMapper {
     
     private static final int INITIAL_SIZE = 128;
-    private final Map<InMemoryId, Mailbox> mailboxesById;
+    private final ConcurrentHashMap<MailboxPath, Mailbox> mailboxesByPath;
     private final AtomicLong mailboxIdGenerator = new AtomicLong();
 
     public InMemoryMailboxMapper() {
-        mailboxesById = new ConcurrentHashMap<InMemoryId, Mailbox>(INITIAL_SIZE);
+        mailboxesByPath = new ConcurrentHashMap<MailboxPath, Mailbox>(INITIAL_SIZE);
     }
 
     /**
      * @see org.apache.james.mailbox.store.mail.MailboxMapper#delete(org.apache.james.mailbox.store.mail.model.Mailbox)
      */
     public void delete(Mailbox mailbox) throws MailboxException {
-        mailboxesById.remove(mailbox.getMailboxId());
+        mailboxesByPath.remove(mailbox.generateAssociatedPath());
     }
 
     public void deleteAll() throws MailboxException {
-        mailboxesById.clear();
+        mailboxesByPath.clear();
     }
 
     /**
      * @see org.apache.james.mailbox.store.mail.MailboxMapper#findMailboxByPath(org.apache.james.mailbox.model.MailboxPath)
      */
     public synchronized Mailbox findMailboxByPath(MailboxPath path) throws MailboxException {
-        Mailbox result = null;
-        for (Mailbox mailbox:mailboxesById.values()) {
-            MailboxPath mp = new MailboxPath(mailbox.getNamespace(), mailbox.getUser(), mailbox.getName());
-            if (mp.equals(path)) {
-                result = mailbox;
-                break;
-            }
-        }
+        Mailbox result = mailboxesByPath.get(path);
         if (result == null) {
             throw new MailboxNotFoundException(path);
         } else {
-            return result;
+            return new SimpleMailbox(result);
         }
     }
 
     public synchronized Mailbox findMailboxById(MailboxId id) throws MailboxException {
         InMemoryId mailboxId = (InMemoryId)id;
-        Mailbox result = mailboxesById.get(mailboxId);
-        if (result == null) {
-            throw new MailboxNotFoundException(mailboxId.serialize());
-        } else {
-            return result;
+        for (Mailbox mailbox: mailboxesByPath.values()) {
+            if (mailbox.getMailboxId().equals(mailboxId)) {
+                return new SimpleMailbox(mailbox);
+            }
         }
+        throw new MailboxNotFoundException(mailboxId.serialize());
     }
 
     /**
@@ -93,9 +86,9 @@ public class InMemoryMailboxMapper implements MailboxMapper {
     public List<Mailbox> findMailboxWithPathLike(MailboxPath path) throws MailboxException {
         final String regex = path.getName().replace("%", ".*");
         List<Mailbox> results = new ArrayList<Mailbox>();
-        for (Mailbox mailbox:mailboxesById.values()) {
+        for (Mailbox mailbox: mailboxesByPath.values()) {
             if (mailboxMatchesRegex(mailbox, path, regex)) {
-                results.add(mailbox);
+                results.add(new SimpleMailbox(mailbox));
             }
         }
         return results;
@@ -115,23 +108,21 @@ public class InMemoryMailboxMapper implements MailboxMapper {
         if (id == null) {
             id = InMemoryId.of(mailboxIdGenerator.incrementAndGet());
             ((SimpleMailbox) mailbox).setMailboxId(id);
+        } else {
+            try {
+                Mailbox mailboxWithPreviousName = findMailboxById(id);
+                mailboxesByPath.remove(mailboxWithPreviousName.generateAssociatedPath());
+            } catch (MailboxNotFoundException e) {
+                // No need to remove the previous mailbox
+            }
         }
-        if (isPathAlreadyUsedByAnotherMailbox(mailbox)) {
+        Mailbox previousMailbox = mailboxesByPath.putIfAbsent(mailbox.generateAssociatedPath(), mailbox);
+        if (previousMailbox != null) {
             throw new MailboxExistsException(mailbox.getName());
         }
-        mailboxesById.put(id, mailbox);
         return mailbox.getMailboxId();
     }
 
-    private boolean isPathAlreadyUsedByAnotherMailbox(Mailbox mailbox) throws MailboxException {
-        try {
-            Mailbox storedMailbox = findMailboxByPath(mailbox.generateAssociatedPath());
-            return !Objects.equal(storedMailbox.getMailboxId(), mailbox.getMailboxId());
-        } catch (MailboxNotFoundException e) {
-            return false;
-        }
-    }
-
     /**
      * Do nothing
      */
@@ -144,7 +135,7 @@ public class InMemoryMailboxMapper implements MailboxMapper {
      */
     public boolean hasChildren(Mailbox mailbox, char delimiter) throws MailboxException {
         String mailboxName = mailbox.getName() + delimiter;
-        for (Mailbox box:mailboxesById.values()) {
+        for (Mailbox box: mailboxesByPath.values()) {
             if (belongsToSameUser(mailbox, box) && box.getName().startsWith(mailboxName)) {
                 return true;
             }
@@ -161,7 +152,7 @@ public class InMemoryMailboxMapper implements MailboxMapper {
      * @see org.apache.james.mailbox.store.mail.MailboxMapper#list()
      */
     public List<Mailbox> list() throws MailboxException {
-        return new ArrayList<Mailbox>(mailboxesById.values());
+        return new ArrayList<Mailbox>(mailboxesByPath.values());
     }
 
     public <T> T execute(Transaction<T> transaction) throws MailboxException {


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


[16/21] james-project git commit: JAMES-2048 Parser message in case of empty or blank CID and its tests

Posted by bt...@apache.org.
JAMES-2048 Parser message in case of empty or blank CID and its tests


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/730f44ff
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/730f44ff
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/730f44ff

Branch: refs/heads/master
Commit: 730f44ff5fac3dd4736e6c0a20b31b03f2e7fca6
Parents: d8c7063
Author: quynhn <qn...@linagora.com>
Authored: Tue Jun 6 13:47:08 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:35:51 2017 +0700

----------------------------------------------------------------------
 .../store/mail/model/impl/MessageParser.java    | 34 +++++----
 .../mail/model/impl/MessageParserTest.java      | 18 ++++-
 ...AttachmentsWithOneWrongInlinedAttachment.eml | 73 --------------------
 .../eml/oneInlinedAttachmentWithBlankCid.eml    | 62 +++++++++++++++++
 .../eml/oneInlinedAttachmentWithEmptyCid.eml    | 62 +++++++++++++++++
 .../eml/oneInlinedAttachmentWithNoCid.eml       | 61 ++++++++++++++++
 6 files changed, 222 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index 8692375..3e7e42e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -69,6 +69,25 @@ public class MessageParser {
             ContentDispositionField.DISPOSITION_TYPE_ATTACHMENT.toLowerCase(Locale.US),
             ContentDispositionField.DISPOSITION_TYPE_INLINE.toLowerCase(Locale.US));
     private static final Logger LOGGER = LoggerFactory.getLogger(MessageParser.class);
+    private static final Function<String, Optional<Cid>> STRING_TO_CID_FUNCTION = new Function<String, Optional<Cid>>() {
+        @Override
+        public Optional<Cid> apply(String cid) {
+            try {
+                return Optional.of(Cid.from(cid));
+            } catch (IllegalArgumentException e) {
+                return Optional.absent();
+            }
+        }
+    };
+
+    private static final Function<ContentIdField, Optional<Cid>> CONTENT_ID_FIELD_TO_OPTIONAL_CID_FUNCTION = new Function<ContentIdField, Optional<Cid>>() {
+        @Override
+        public Optional<Cid> apply(ContentIdField field) {
+            return Optional.fromNullable(field.getId())
+                    .transform(STRING_TO_CID_FUNCTION)
+                    .or(Optional.<Cid>absent());
+        }
+    };
 
     public List<MessageAttachment> retrieveAttachments(InputStream fullContent) throws MimeException, IOException {
         DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder();
@@ -178,19 +197,8 @@ public class MessageParser {
     }
 
     private Optional<Cid> cid(Optional<ContentIdField> contentIdField) {
-        return contentIdField.transform(new Function<ContentIdField, Optional<Cid>>() {
-            @Override
-            public Optional<Cid> apply(ContentIdField field) {
-                return Optional.fromNullable(field.getId())
-                        .transform(new Function<String, Cid>() {
-
-                            @Override
-                            public Cid apply(String cid) {
-                                return Cid.from(cid);
-                            }
-                        });
-            }
-        }).or(Optional.<Cid> absent());
+        return contentIdField.transform(CONTENT_ID_FIELD_TO_OPTIONAL_CID_FUNCTION)
+                .or(Optional.<Cid>absent());
     }
 
     private boolean isMultipart(Entity entity) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index 4fc4979..ceb3df9 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -201,9 +201,23 @@ public class MessageParserTest {
 
     @Test
     public void getAttachmentsShouldRetrieveAttachmentsWhenNoCidForInlined() throws Exception {
-        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/multiAttachmentsWithOneWrongInlinedAttachment.eml"));
+        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithNoCid.eml"));
 
-        assertThat(attachments).hasSize(2);
+        assertThat(attachments).hasSize(1);
+    }
+
+    @Test
+    public void getAttachmentsShouldRetrieveAttachmentsWhenEmptyCidForInlined() throws Exception {
+        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithEmptyCid.eml"));
+
+        assertThat(attachments).hasSize(1);
+    }
+
+    @Test
+    public void getAttachmentsShouldRetrieveAttachmentsWhenBlankCidForInlined() throws Exception {
+        List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithBlankCid.eml"));
+
+        assertThat(attachments).hasSize(1);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml b/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
deleted file mode 100644
index c7cd548..0000000
--- a/mailbox/store/src/test/resources/eml/multiAttachmentsWithOneWrongInlinedAttachment.eml
+++ /dev/null
@@ -1,73 +0,0 @@
-Return-Path: <fr...@linagora.com>
-Received: from alderaan.linagora.com (smtp.linagora.dc1 [172.16.18.53])
-	 by imap (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA;
-	 Mon, 27 Feb 2017 05:24:55 +0100
-X-Sieve: CMU Sieve 2.2
-Received: from [192.168.12.138] (unknown [1.55.245.4])
-	(using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
-	(No client certificate requested)
-	by alderaan.linagora.com (Postfix) with ESMTPSA id 688BF7A9
-	for <fr...@linagora.com>; Mon, 27 Feb 2017 05:24:54 +0100 (CET)
-To: to@linagora.com
-From: Lina <fr...@linagora.com>
-Subject: MultiAttachment
-Message-ID: <13...@linagora.com>
-Date: Mon, 27 Feb 2017 11:24:48 +0700
-User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
- Thunderbird/45.2.0
-MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------64D8D789FC30153D6ED18258"
-
-This is a multi-part message in MIME format.
---------------64D8D789FC30153D6ED18258
-Content-Type: text/plain; charset=utf-8; format=flowed
-Content-Transfer-Encoding: 7bit
-
-Send
-
-
---------------64D8D789FC30153D6ED18258
-Content-Type: text/plain; charset=UTF-8;
- name="text1"
-Content-Transfer-Encoding: base64
-Content-Disposition: wrongDisposition;
- filename="text1"
-
-LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb2dJQkFBS0NBUUVBeDdQRzAr
-RS8vRU1wbTdJZ0k1UTlUTURTRnlhLzFoRSt2dlRKcmswaUdGbGxQZUhMCkE1L1ZsVE0wWVdn
-RzZYNTBxaU1mRTNWTGF6ZjJjMTlpWHJUMG1xLzIxUFoxd0Zub2d2NHp4VU5haWgrQm5nNjIK
-RjBTeXJ1RS9PL05qcXhoL0NjcTZLL2UwNVRWNFQ2NDNVU3hBZUcwS3BwbVlXOXg4SEEvR3ZW
-ODMyYXBadXhrVgppNk5Wa0RCcmZ6YVVDd3U0ekgrSHdPdi9wSTg3RTdLY2NIWUMrK0JpYWoz
-Cg==
---------------64D8D789FC30153D6ED18258
-Content-Type: application/vnd.ms-publisher;
- name="text2"
-Content-Transfer-Encoding: base64
-Content-Disposition: inline;
- filename="text2"
-
-c3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFCQVFESHM4YlQ0VC84UXltYnNp
-QWpsRDFNd05JWEpyL1dFVDYrOU1tdVRTSVlXV1U5NGNzRG45V1ZNelJoYUFicGZuU3FJeDhU
-ZFV0ck4vWnpYMkpldFBTYXIvYlU5blhBV2VpQy9qUEZRMXFLSDRHZURyWVhSTEt1NFQ4Nzgy
-T3JHSDhKeXJvcjk3VGxOWGhQcmpkUkxFQjRiUXFtbVpoYjNId2NEOGE5WHpmWnFsbTdHUldM
-bzFXUU1HdC9OcFFMQzdqTWY0ZkE2LytranpzVHNweHdkZ0w3NEdKcVBmT1hPaXdnTEhYOENa
-Ni81UnlUcWhUNnBEM01rdFNOV2F6L3pJSFBORXFmNUJZOUNCTTFURlI1dys2TURIbzBnbWlJ
-c1hGRUpUUG5maEJ2SERoU2pCMVJJMEt4VUNseVlySjRmQmxVVmVLZm5hd29WY3U3WXZDcUY0
-RjUgcXV5bmhubkBsaW5hZ29yYQo=
---------------64D8D789FC30153D6ED18258
-Content-Type: text/plain; charset=UTF-8;
- name="text3"
-Content-Transfer-Encoding: base64
-Content-Disposition: attachment;
- filename="text3"
-
-fDF8b1M3NU9nTDN2RjJHZGw5OUNKRGJFcGFKM3lFPXxJTkdxbGpDVzFYTWY0Z2dPUW0yNi9C
-Tm5LR2M9IHNzaC1yc2EgQUFBQUIzTnphQzF5YzJFQUFBQUJJd0FBQVFFQXEyQTdoUkdtZG5t
-OXRVRGJPOUlEU3dCSzZUYlFhK1BYWVBDUHk2cmJUclR0dzdQSGtjY0tycHAweVZocDVIZEVJ
-Y0tyNnBMbFZEQmZPTFg5UVVzeUNPVjB3emZqSUpObEdFWXNkbExKaXpIaGJuMm1VanZTQUhR
-cVpFVFlQODFlRnpMUU5uUEh0NEVWVlVoN1ZmREVTVTg0S2V6bUQ1UWxXcFhMbXZVMzEveU1m
-K1NlOHhoSFR2S1NDWklGSW1Xd29HNm1iVW9XZjluenBJb2FTakIrd2VxcVVVbXBhYWFzWFZh
-bDcySitVWDJCKzJSUFczUmNUMGVPelFncWxKTDNSS3JUSnZkc2pFM0pFQXZHcTNsR0hTWlh5
-TjZtNVU0aHBwaDl1T3Y1NGFIYzRYcjhqaEFhL1NYNU1KCg==
---------------64D8D789FC30153D6ED18258--

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml
new file mode 100644
index 0000000..6b2ec2e
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithBlankCid.eml
@@ -0,0 +1,62 @@
+Return-Path: <te...@local.com>
+Received: from localhost;
+	 Tue, 05 Jul 2016 11:47:47 +0200
+X-Sieve: CMU Sieve 2.2
+To: Test <te...@local.com>
+From: Test <te...@local.com>
+Subject: Inline attachment
+Message-ID: <26...@linagora.com>
+Date: Tue, 5 Jul 2016 11:47:46 +0200
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.1.1
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------FC06E08B3CDF05E9A3E28077"
+
+This is a multi-part message in MIME format.
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is an inline attachment:
+Cheers!
+
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: multipart/related;
+ boundary="------------47107B0D40019CDFED2C4263"
+
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    This is an inline attachment:<br>
+    <br>
+    <img alt="" src="cid:part1.37A15C92.A7C3488D@linagora.com"
+      height="73" width="73"><br>
+    <br>
+    <br>
+    Cheers!<br>
+  </body>
+</html>
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: image/png;
+ name="james-logo-square.png"
+Content-Transfer-Encoding: base64
+Content-ID: <  >
+Content-Disposition: inline;
+ filename="james-logo-square.png"
+
+iVBORw0KGgoAAAANSUhEUgAAAEkAAABJCAYAAABxcwvcAAAABGdBTUEAALGPC/xhBQAAAAFz
+UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+AAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAASQAAAEkA
+cHRoLXdyaXR0ZW4ACKfELPIAAAAASUVORK5CYII=
+--------------47107B0D40019CDFED2C4263--
+
+--------------FC06E08B3CDF05E9A3E28077--

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml
new file mode 100644
index 0000000..9316235
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithEmptyCid.eml
@@ -0,0 +1,62 @@
+Return-Path: <te...@local.com>
+Received: from localhost;
+	 Tue, 05 Jul 2016 11:47:47 +0200
+X-Sieve: CMU Sieve 2.2
+To: Test <te...@local.com>
+From: Test <te...@local.com>
+Subject: Inline attachment
+Message-ID: <26...@linagora.com>
+Date: Tue, 5 Jul 2016 11:47:46 +0200
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.1.1
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------FC06E08B3CDF05E9A3E28077"
+
+This is a multi-part message in MIME format.
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is an inline attachment:
+Cheers!
+
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: multipart/related;
+ boundary="------------47107B0D40019CDFED2C4263"
+
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    This is an inline attachment:<br>
+    <br>
+    <img alt="" src="cid:part1.37A15C92.A7C3488D@linagora.com"
+      height="73" width="73"><br>
+    <br>
+    <br>
+    Cheers!<br>
+  </body>
+</html>
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: image/png;
+ name="james-logo-square.png"
+Content-Transfer-Encoding: base64
+Content-ID:
+Content-Disposition: inline;
+ filename="james-logo-square.png"
+
+iVBORw0KGgoAAAANSUhEUgAAAEkAAABJCAYAAABxcwvcAAAABGdBTUEAALGPC/xhBQAAAAFz
+UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+AAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAASQAAAEkA
+cHRoLXdyaXR0ZW4ACKfELPIAAAAASUVORK5CYII=
+--------------47107B0D40019CDFED2C4263--
+
+--------------FC06E08B3CDF05E9A3E28077--

http://git-wip-us.apache.org/repos/asf/james-project/blob/730f44ff/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml
new file mode 100644
index 0000000..16573b5
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/oneInlinedAttachmentWithNoCid.eml
@@ -0,0 +1,61 @@
+Return-Path: <te...@local.com>
+Received: from localhost;
+	 Tue, 05 Jul 2016 11:47:47 +0200
+X-Sieve: CMU Sieve 2.2
+To: Test <te...@local.com>
+From: Test <te...@local.com>
+Subject: Inline attachment
+Message-ID: <26...@linagora.com>
+Date: Tue, 5 Jul 2016 11:47:46 +0200
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.1.1
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------FC06E08B3CDF05E9A3E28077"
+
+This is a multi-part message in MIME format.
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is an inline attachment:
+Cheers!
+
+--------------FC06E08B3CDF05E9A3E28077
+Content-Type: multipart/related;
+ boundary="------------47107B0D40019CDFED2C4263"
+
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 7bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    This is an inline attachment:<br>
+    <br>
+    <img alt="" src="cid:part1.37A15C92.A7C3488D@linagora.com"
+      height="73" width="73"><br>
+    <br>
+    <br>
+    Cheers!<br>
+  </body>
+</html>
+
+--------------47107B0D40019CDFED2C4263
+Content-Type: image/png;
+ name="james-logo-square.png"
+Content-Transfer-Encoding: base64
+Content-Disposition: inline;
+ filename="james-logo-square.png"
+
+iVBORw0KGgoAAAANSUhEUgAAAEkAAABJCAYAAABxcwvcAAAABGdBTUEAALGPC/xhBQAAAAFz
+UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+AAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAl2cEFnAAAASQAAAEkA
+cHRoLXdyaXR0ZW4ACKfELPIAAAAASUVORK5CYII=
+--------------47107B0D40019CDFED2C4263--
+
+--------------FC06E08B3CDF05E9A3E28077--


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


[05/21] james-project git commit: JAMES-2044 Removing useless else blocks in LuceneMessageSearchIndex

Posted by bt...@apache.org.
JAMES-2044 Removing useless else blocks in LuceneMessageSearchIndex


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/10260702
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/10260702
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/10260702

Branch: refs/heads/master
Commit: 10260702d71366b6df357abcd24137b058fa4561
Parents: 81ef429
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 16:22:17 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../lucene/search/LuceneMessageSearchIndex.java | 30 +++++++-------------
 1 file changed, 10 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/10260702/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 91b39a6..61a32e1 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -1068,63 +1068,53 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
             case Arrival:
                 if (reverse) {
                     return ARRIVAL_MAILBOX_SORT_REVERSE;
-                } else {
-                    return ARRIVAL_MAILBOX_SORT;
                 }
+                return ARRIVAL_MAILBOX_SORT;
             case SentDate:
                 if (reverse) {
                     return SENT_DATE_SORT_REVERSE;
-                } else {
-                    return SENT_DATE_SORT;
                 }
+                return SENT_DATE_SORT;
             case MailboxCc:
                 if (reverse) {
                     return FIRST_CC_MAILBOX_SORT_REVERSE;
-                } else {
-                    return FIRST_CC_MAILBOX_SORT;
                 }
+                return FIRST_CC_MAILBOX_SORT;
             case MailboxFrom:
                 if (reverse) {
                     return FIRST_FROM_MAILBOX_SORT_REVERSE;
-                } else {
-                    return FIRST_FROM_MAILBOX_SORT;
                 }
+                return FIRST_FROM_MAILBOX_SORT;
             case Size:
                 if (reverse) {
                     return SIZE_SORT_REVERSE;
-                } else {
-                    return SIZE_SORT;
                 }
+                return SIZE_SORT;
             case BaseSubject:
                 if (reverse) {
                     return BASE_SUBJECT_SORT_REVERSE;
-                } else {
-                    return BASE_SUBJECT_SORT;
                 }
+                return BASE_SUBJECT_SORT;
             case MailboxTo:
                 if (reverse) {
                     return FIRST_TO_MAILBOX_SORT_REVERSE;
-                } else {
-                    return FIRST_TO_MAILBOX_SORT;
                 }
+                return FIRST_TO_MAILBOX_SORT;
             case Uid:
                 if (reverse) {
                     return UID_SORT_REVERSE;
-                } else {
-                    return UID_SORT;
                 }
+                return UID_SORT;
             case DisplayFrom:
                 if (reverse) {
                     return FIRST_FROM_MAILBOX_DISPLAY_SORT_REVERSE;
-                } else {
-                    return FIRST_FROM_MAILBOX_DISPLAY_SORT;
                 }
+                return FIRST_FROM_MAILBOX_DISPLAY_SORT;
             case DisplayTo:
                 if (reverse) {
                     return FIRST_TO_MAILBOX_DISPLAY_SORT_REVERSE;
-                } else {
-                    return FIRST_TO_MAILBOX_DISPLAY_SORT;
                 }
+                return FIRST_TO_MAILBOX_DISPLAY_SORT;
             default:
                 return null;
         }


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


[09/21] james-project git commit: JAMES-2044 Improve Lucene messageSearchIndex switch clauses

Posted by bt...@apache.org.
JAMES-2044 Improve Lucene messageSearchIndex switch clauses


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7a7a0a61
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7a7a0a61
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7a7a0a61

Branch: refs/heads/master
Commit: 7a7a0a61769b6408d413ff334becb9c86f716b11
Parents: 5aae15d
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 11:42:37 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../lucene/search/LuceneMessageSearchIndex.java | 237 ++++++++-----------
 1 file changed, 104 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7a7a0a61/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index e243052..91b39a6 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -773,65 +773,45 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
     }
 
     private String toSentDateField(DateResolution res) {
-        String field;
         switch (res) {
-        case Year:
-            field = SENT_DATE_FIELD_YEAR_RESOLUTION;
-            break;
-        case Month:
-            field = SENT_DATE_FIELD_MONTH_RESOLUTION;
-            break;
-        case Day:
-            field = SENT_DATE_FIELD_DAY_RESOLUTION;
-            break;
-        case Hour:
-            field = SENT_DATE_FIELD_HOUR_RESOLUTION;
-            break;
-        case Minute:
-            field = SENT_DATE_FIELD_MINUTE_RESOLUTION;
-            break;
-        case Second:
-            field = SENT_DATE_FIELD_SECOND_RESOLUTION;
-            break;
-        default:
-            field = SENT_DATE_FIELD_MILLISECOND_RESOLUTION;
-            break;
+            case Year:
+                return SENT_DATE_FIELD_YEAR_RESOLUTION;
+            case Month:
+                return SENT_DATE_FIELD_MONTH_RESOLUTION;
+            case Day:
+                return SENT_DATE_FIELD_DAY_RESOLUTION;
+            case Hour:
+                return SENT_DATE_FIELD_HOUR_RESOLUTION;
+            case Minute:
+                return SENT_DATE_FIELD_MINUTE_RESOLUTION;
+            case Second:
+                return SENT_DATE_FIELD_SECOND_RESOLUTION;
+            default:
+                return SENT_DATE_FIELD_MILLISECOND_RESOLUTION;
         }
-        return field;
     }
 
-
     private static Calendar getGMT() {
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
     }
 
-    
     private String toInteralDateField(DateResolution res) {
-        String field;
         switch (res) {
-        case Year:
-            field = INTERNAL_DATE_FIELD_YEAR_RESOLUTION;
-            break;
-        case Month:
-            field = INTERNAL_DATE_FIELD_MONTH_RESOLUTION;
-            break;
-        case Day:
-            field = INTERNAL_DATE_FIELD_DAY_RESOLUTION;
-            break;
-        case Hour:
-            field = INTERNAL_DATE_FIELD_HOUR_RESOLUTION;
-            break;
-        case Minute:
-            field = INTERNAL_DATE_FIELD_MINUTE_RESOLUTION;
-            break;
-        case Second:
-            field = INTERNAL_DATE_FIELD_SECOND_RESOLUTION;
-            break;
-        default:
-            field = INTERNAL_DATE_FIELD_MILLISECOND_RESOLUTION;
-            break;
+            case Year:
+                return INTERNAL_DATE_FIELD_YEAR_RESOLUTION;
+            case Month:
+                return INTERNAL_DATE_FIELD_MONTH_RESOLUTION;
+            case Day:
+                return INTERNAL_DATE_FIELD_DAY_RESOLUTION;
+            case Hour:
+                return INTERNAL_DATE_FIELD_HOUR_RESOLUTION;
+            case Minute:
+                return INTERNAL_DATE_FIELD_MINUTE_RESOLUTION;
+            case Second:
+                return INTERNAL_DATE_FIELD_SECOND_RESOLUTION;
+            default:
+                return INTERNAL_DATE_FIELD_MILLISECOND_RESOLUTION;
         }
-        return field;
     }
     
     /**
@@ -1059,106 +1039,97 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
     }
     
     private Sort createSort(List<SearchQuery.Sort> sorts) {
-        Sort sort = new Sort();
         List<SortField> fields = new ArrayList<SortField>();
 
-        for (SearchQuery.Sort s : sorts) {
-            boolean reverse = s.isReverse();
-            SortField sf = null;
-
-            switch (s.getSortClause()) {
-                case Arrival:
-                    if (reverse) {
-                        sf = ARRIVAL_MAILBOX_SORT_REVERSE;
-                    } else {
-                        sf = ARRIVAL_MAILBOX_SORT;
-                    }
-                    break;
-                case SentDate:
-                    if (reverse) {
-                        sf = SENT_DATE_SORT_REVERSE;
-                    } else {
-                        sf = SENT_DATE_SORT;
-                    }
-                    break;
-                case MailboxCc:
-                    if (reverse) {
-                        sf = FIRST_CC_MAILBOX_SORT_REVERSE;
-                    } else {
-                        sf = FIRST_CC_MAILBOX_SORT;
-                    }
-                    break;
-                case MailboxFrom:
-                    if (reverse) {
-                        sf = FIRST_FROM_MAILBOX_SORT_REVERSE;
-                    } else {
-                        sf = FIRST_FROM_MAILBOX_SORT;
-                    }
-                    break;
-                case Size:
-                    if (reverse) {
-                        sf = SIZE_SORT_REVERSE;
-                    } else {
-                        sf = SIZE_SORT;
-                    }
-                    break;
-                case BaseSubject:
-                    if (reverse) {
-                        sf = BASE_SUBJECT_SORT_REVERSE;
-                    } else {
-                        sf = BASE_SUBJECT_SORT;
-                    }
-                    break;
-                case MailboxTo:
-                    if (reverse) {
-                        sf = FIRST_TO_MAILBOX_SORT_REVERSE;
-                    } else {
-                        sf = FIRST_TO_MAILBOX_SORT;
-                    }
-                    break;
-
-                case Uid:
-                    if (reverse) {
-                        sf = UID_SORT_REVERSE;
-                    } else {
-                        sf = UID_SORT;
-                    }
-                    break;
-                case DisplayFrom:
-                    if (reverse) {
-                        sf = FIRST_FROM_MAILBOX_DISPLAY_SORT_REVERSE;
-                    } else {
-                        sf = FIRST_FROM_MAILBOX_DISPLAY_SORT;
-                    }
-                    break;
-                case DisplayTo:
-                    if (reverse) {
-                        sf = FIRST_TO_MAILBOX_DISPLAY_SORT_REVERSE;
-                    } else {
-                        sf = FIRST_TO_MAILBOX_DISPLAY_SORT;
-                    }
-                    break;
-                default:
-                    break;
-            }
-            if (sf != null) {
+        for (SearchQuery.Sort sort : sorts) {
+            boolean reverse = sort.isReverse();
+            SortField sortField = createSortField(sort, reverse);
+            if (sortField != null) {
 
-                fields.add(sf);
+                fields.add(sortField);
 
                 // Add the uid sort as tie-breaker
-                if (sf == SENT_DATE_SORT) {
+                if (sortField == SENT_DATE_SORT) {
                     fields.add(UID_SORT);
-                } else if (sf == SENT_DATE_SORT_REVERSE) {
+                } else if (sortField == SENT_DATE_SORT_REVERSE) {
                     fields.add(UID_SORT_REVERSE);
                 }
             }
         }
         // add the uid sorting as last so if no other sorting was able todo the job it will get sorted by the uid
         fields.add(UID_SORT);
+        Sort sort = new Sort();
         sort.setSort(fields.toArray(new SortField[0]));
         return sort;
     }
-    
+
+    private SortField createSortField(SearchQuery.Sort s, boolean reverse) {
+        switch (s.getSortClause()) {
+            case Arrival:
+                if (reverse) {
+                    return ARRIVAL_MAILBOX_SORT_REVERSE;
+                } else {
+                    return ARRIVAL_MAILBOX_SORT;
+                }
+            case SentDate:
+                if (reverse) {
+                    return SENT_DATE_SORT_REVERSE;
+                } else {
+                    return SENT_DATE_SORT;
+                }
+            case MailboxCc:
+                if (reverse) {
+                    return FIRST_CC_MAILBOX_SORT_REVERSE;
+                } else {
+                    return FIRST_CC_MAILBOX_SORT;
+                }
+            case MailboxFrom:
+                if (reverse) {
+                    return FIRST_FROM_MAILBOX_SORT_REVERSE;
+                } else {
+                    return FIRST_FROM_MAILBOX_SORT;
+                }
+            case Size:
+                if (reverse) {
+                    return SIZE_SORT_REVERSE;
+                } else {
+                    return SIZE_SORT;
+                }
+            case BaseSubject:
+                if (reverse) {
+                    return BASE_SUBJECT_SORT_REVERSE;
+                } else {
+                    return BASE_SUBJECT_SORT;
+                }
+            case MailboxTo:
+                if (reverse) {
+                    return FIRST_TO_MAILBOX_SORT_REVERSE;
+                } else {
+                    return FIRST_TO_MAILBOX_SORT;
+                }
+            case Uid:
+                if (reverse) {
+                    return UID_SORT_REVERSE;
+                } else {
+                    return UID_SORT;
+                }
+            case DisplayFrom:
+                if (reverse) {
+                    return FIRST_FROM_MAILBOX_DISPLAY_SORT_REVERSE;
+                } else {
+                    return FIRST_FROM_MAILBOX_DISPLAY_SORT;
+                }
+            case DisplayTo:
+                if (reverse) {
+                    return FIRST_TO_MAILBOX_DISPLAY_SORT_REVERSE;
+                } else {
+                    return FIRST_TO_MAILBOX_DISPLAY_SORT;
+                }
+            default:
+                return null;
+        }
+    }
+
     /**
      * Convert the given {@link Flag} to a String
      * 


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


[15/21] james-project git commit: JAMES-2048 Add UT on CasssandraMessageDAO for the cases of attachement with or without CID

Posted by bt...@apache.org.
JAMES-2048 Add UT on CasssandraMessageDAO for the cases of attachement with or without CID


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d8c7063f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d8c7063f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d8c7063f

Branch: refs/heads/master
Commit: d8c7063f76bbbbef5655e005c8a1fef5a2b7fb37
Parents: c69c7ef
Author: quynhn <qn...@linagora.com>
Authored: Tue Jun 6 13:43:51 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:35:50 2017 +0700

----------------------------------------------------------------------
 .../cassandra/mail/CassandraMessageDAOTest.java | 144 +++++++++++++++++++
 1 file changed, 144 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d8c7063f/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
new file mode 100644
index 0000000..7535768
--- /dev/null
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
@@ -0,0 +1,144 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.cassandra.mail;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.cassandra.CassandraId;
+import org.apache.james.mailbox.cassandra.CassandraMessageId;
+import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
+import org.apache.james.mailbox.model.MessageAttachment;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableList;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CassandraMessageDAOTest {
+    private static final int BODY_START = 16;
+    private static final CassandraId MAILBOX_ID = CassandraId.timeBased();
+    private static final String CONTENT = "Subject: Test7 \n\nBody7\n.\n";
+    private static final MessageUid messageUid = MessageUid.of(1);
+
+    private CassandraCluster cassandra;
+
+    private CassandraMessageDAO testee;
+    private CassandraMessageId.Factory messageIdFactory;
+
+    private SimpleMailboxMessage messageWith1Attachment;
+    private CassandraMessageId messageId;
+    private Attachment attachment;
+    private ComposedMessageId composedMessageId;
+    private List<ComposedMessageIdWithMetaData> messageIds;
+
+    @Before
+    public void setUp() {
+        cassandra = CassandraCluster.create(new CassandraMessageModule());
+        cassandra.ensureAllTables();
+
+        messageIdFactory = new CassandraMessageId.Factory();
+        messageId = messageIdFactory.generate();
+        testee = new CassandraMessageDAO(cassandra.getConf(), cassandra.getTypesProvider());
+
+        attachment = Attachment.builder()
+                .attachmentId(AttachmentId.from("123"))
+                .bytes("attachment".getBytes())
+                .type("content")
+                .build();
+
+        composedMessageId = new ComposedMessageId(MAILBOX_ID, messageId, messageUid);
+
+        messageIds = ImmutableList.of(ComposedMessageIdWithMetaData.builder()
+                .composedMessageId(composedMessageId)
+                .flags(new Flags())
+                .modSeq(1)
+                .build());
+    }
+
+    @After
+    public void tearDown() {
+        cassandra.clearAllTables();
+    }
+
+    @Test
+    public void saveShouldStoreMessageWithAttachmentAndCid() throws Exception {
+        messageWith1Attachment = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(),
+                ImmutableList.of(MessageAttachment.builder()
+                        .attachment(attachment)
+                        .cid(Cid.from("<cid>"))
+                        .isInline(true)
+                        .build()));
+
+        testee.save(messageWith1Attachment);
+
+        List<Optional<CassandraMessageDAO.MessageAttachmentRepresentation>> attachmentRepresentation = testee.retrieveMessages(messageIds, MessageMapper.FetchType.Body, Optional.empty())
+                .get()
+                .map(pair -> pair.getRight())
+                .map(streamAttachemnt -> streamAttachemnt.findFirst())
+                .collect(Guavate.toImmutableList());
+
+        Cid expectedCid = Cid.from("cid");
+
+        assertThat(attachmentRepresentation).hasSize(1);
+        assertThat(attachmentRepresentation.get(0).get().getCid().get()).isEqualTo(expectedCid);
+    }
+
+    @Test
+    public void saveShouldStoreMessageWithAttachmentButNoCid() throws Exception {
+        messageWith1Attachment = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(),
+                ImmutableList.of(MessageAttachment.builder()
+                        .attachment(attachment)
+                        .isInline(true)
+                        .build()));
+
+        testee.save(messageWith1Attachment);
+
+        List<Optional<CassandraMessageDAO.MessageAttachmentRepresentation>> attachmentRepresentation = testee.retrieveMessages(messageIds, MessageMapper.FetchType.Body, Optional.empty())
+                .get()
+                .map(pair -> pair.getRight())
+                .map(streamAttachemnt -> streamAttachemnt.findFirst())
+                .collect(Guavate.toImmutableList());
+
+        assertThat(attachmentRepresentation).hasSize(1);
+        assertThat(attachmentRepresentation.get(0).get().getCid().isPresent()).isFalse();
+    }
+
+    private SimpleMailboxMessage createMessage(MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder, List<MessageAttachment> attachments) {
+        return new SimpleMailboxMessage(messageId, new Date(), content.length(), bodyStart, new SharedByteArrayInputStream(content.getBytes()), new Flags(), propertyBuilder, MAILBOX_ID, attachments);
+    }
+
+}
\ No newline at end of file


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


[07/21] james-project git commit: JAMES-2044 Adding SentDate support to Lucene message search index

Posted by bt...@apache.org.
JAMES-2044 Adding SentDate support to Lucene message search index


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/fc089b96
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/fc089b96
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/fc089b96

Branch: refs/heads/master
Commit: fc089b96b3ef81f2abded92b477cc30ab7b1c9e6
Parents: 7a7a0a6
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 11:48:28 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/mailbox/model/SearchQuery.java   |  4 ++++
 .../lucene/search/LuceneMessageSearchIndex.java       |  3 +++
 .../lucene/search/LuceneMessageSearchIndexTest.java   | 14 --------------
 3 files changed, 7 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fc089b96/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 5a28541..1ae0042 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -1269,6 +1269,10 @@ public class SearchQuery implements Serializable {
             return operator;
         }
 
+        public HeaderCriterion toHeaderCriterion() {
+            return new HeaderCriterion("Date", operator);
+        }
+
         @Override
         public int hashCode() {
             return Objects.hashCode(operator);

http://git-wip-us.apache.org/repos/asf/james-project/blob/fc089b96/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 91b39a6..8326cf1 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -1267,6 +1267,9 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
             return createConjunctionQuery(crit, inMailboxes, recentUids);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             return createModSeqQuery((SearchQuery.ModSeqCriterion) criterion);
+        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
+            SearchQuery.SentDateCriterion sentDateCriterion = (SearchQuery.SentDateCriterion) criterion;
+            return createHeaderQuery(sentDateCriterion.toHeaderCriterion());
         }
         throw new UnsupportedSearchException();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/fc089b96/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
index 8e05fca..dc03f7f 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
@@ -150,18 +150,4 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
     public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws MailboxException {
     }
 
-    @Ignore
-    @Override
-    public void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
-    }
-
-    @Ignore
-    @Override
-    public void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
-    }
-
-    @Ignore
-    @Override
-    public void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
-    }
 }


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


[02/21] james-project git commit: JAMES-2044 Remove useless super call for SentDateCriterion

Posted by bt...@apache.org.
JAMES-2044 Remove useless super call for SentDateCriterion


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1d306c89
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1d306c89
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1d306c89

Branch: refs/heads/master
Commit: 1d306c89dfd29fccde57a325c191dada41dfafd8
Parents: 691b72a
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 10:30:08 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:32:51 2017 +0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/james/mailbox/model/SearchQuery.java   | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1d306c89/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 39e91bc..7c22750 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -1248,7 +1248,6 @@ public class SearchQuery implements Serializable {
         private final DateOperator operator;
 
         public SentDateCriterion(DateOperator operator) {
-            super();
             this.operator = operator;
         }
 


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


[19/21] james-project git commit: JAMES-2047 Ensure JMAP mailbox provisioning do not fail on concurrent runs

Posted by bt...@apache.org.
JAMES-2047 Ensure JMAP mailbox provisioning do not fail on concurrent runs


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/83572862
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/83572862
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/83572862

Branch: refs/heads/master
Commit: 8357286255bf921bf49b6b78295e24e1d0b9d6ad
Parents: 0456601
Author: benwa <bt...@linagora.com>
Authored: Tue Jun 6 11:20:32 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:40:00 2017 +0700

----------------------------------------------------------------------
 .../DefaultMailboxesProvisioningFilter.java     |  3 +
 .../DefaultMailboxesProvisioningFilterTest.java | 84 ++++++++++++++++++++
 2 files changed, 87 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/83572862/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
index 0089ff2..e405604 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.metrics.api.TimeMetric;
@@ -102,6 +103,8 @@ public class DefaultMailboxesProvisioningFilter implements Filter {
     private void createMailbox(MailboxPath mailboxPath, MailboxSession session) {
         try {
             mailboxManager.createMailbox(mailboxPath, session);
+        } catch (MailboxExistsException e) {
+            LOGGER.info("Mailbox {} have been created concurrently", mailboxPath);
         } catch (MailboxException e) {
             throw Throwables.propagate(e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/83572862/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
new file mode 100644
index 0000000..e706d27
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.jmap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.util.concurrency.ConcurrentTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.steveash.guavate.Guavate;
+
+public class DefaultMailboxesProvisioningFilterTest {
+
+    public static final String USERNAME = "username";
+    private DefaultMailboxesProvisioningFilter testee;
+    private MailboxSession session;
+    private MailboxManager mailboxManager;
+
+    @Before
+    public void before() throws Exception {
+        session = new MockMailboxSession(USERNAME);
+
+        InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources();
+        mailboxManager = inMemoryIntegrationResources.createMailboxManager(new SimpleGroupMembershipResolver());
+        testee = new DefaultMailboxesProvisioningFilter(mailboxManager, new NoopMetricFactory());
+    }
+
+    @Test
+    public void createMailboxesIfNeededShouldCreateSystemMailboxes() throws Exception {
+        testee.createMailboxesIfNeeded(session);
+
+        assertThat(mailboxManager.list(session))
+            .containsOnlyElementsOf(DefaultMailboxes.DEFAULT_MAILBOXES
+                .stream()
+                .map(mailboxName -> new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME, mailboxName))
+                .collect(Guavate.toImmutableList()));
+    }
+
+    @Test
+    public void createMailboxesIfNeededShouldNotGenerateExceptionsInConcurrentEnvironment() throws Exception {
+        int threadCount = 10;
+        int operationCount = 1;
+        new ConcurrentTestRunner(threadCount, operationCount,
+            (threadNumber, step) -> testee.createMailboxesIfNeeded(session))
+            .run()
+            .assertNoException()
+            .awaitTermination(10, TimeUnit.SECONDS);
+
+        assertThat(mailboxManager.list(session))
+            .containsOnlyElementsOf(DefaultMailboxes.DEFAULT_MAILBOXES
+                .stream()
+                .map(mailboxName -> new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME, mailboxName))
+                .collect(Guavate.toImmutableList()));
+    }
+
+}
+


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


[08/21] james-project git commit: JAMES-2044 Sort order should be an enum

Posted by bt...@apache.org.
JAMES-2044 Sort order should be an enum


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4f1ff45d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4f1ff45d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4f1ff45d

Branch: refs/heads/master
Commit: 4f1ff45de005081980bfa3eb0cd4680049c78d3b
Parents: 1026070
Author: benwa <bt...@linagora.com>
Authored: Tue Jun 6 16:44:17 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java |  23 ++--
 .../LuceneMailboxMessageSearchIndexTest.java    | 120 ++++++++++---------
 .../search/AbstractMessageSearchIndexTest.java  |  32 ++---
 .../store/search/CombinedComparatorTest.java    |  28 +++--
 .../apache/james/jmap/utils/SortConverter.java  |  23 ++--
 .../james/jmap/utils/SortConverterTest.java     |  18 +--
 6 files changed, 129 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 9888f15..d81b74d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -71,6 +71,11 @@ public class SearchQuery implements Serializable {
     public static class Sort implements Serializable {
         private static final long serialVersionUID = 1L;
 
+        public enum Order {
+            REVERSE,
+            NATURAL
+        }
+
         /**
          * Specify on what to sort
          */
@@ -158,21 +163,21 @@ public class SearchQuery implements Serializable {
             Id
         }
 
-        private final boolean reverse;
+        private final Order order;
         private final SortClause sortClause;
 
-        public Sort(SortClause sortClause, boolean reverse) {
-            this.reverse = reverse;
+        public Sort(SortClause sortClause, Order order) {
+            this.order = order;
             this.sortClause = sortClause;
         }
 
         /**
-         * Create a new {@link Sort} which is NOT {@link #reverse}
+         * Create a new {@link Sort} which is NOT {@link #order}
          * 
          * @param sortClause
          */
         public Sort(SortClause sortClause) {
-            this(sortClause, false);
+            this(sortClause, Order.NATURAL);
         }
 
         /**
@@ -181,7 +186,7 @@ public class SearchQuery implements Serializable {
          * @return reverse
          */
         public boolean isReverse() {
-            return reverse;
+            return order == Order.REVERSE;
         }
 
         /**
@@ -198,14 +203,14 @@ public class SearchQuery implements Serializable {
             if (o instanceof Sort) {
                 Sort that = (Sort) o;
                 return Objects.equal(this.sortClause, that.sortClause)
-                    && Objects.equal(this.reverse, that.reverse);
+                    && Objects.equal(this.order, that.order);
             }
             return false;
         }
 
         @Override
         public int hashCode() {
-            return Objects.hashCode(sortClause, reverse);
+            return Objects.hashCode(sortClause, order);
         }
     }
 
@@ -760,7 +765,7 @@ public class SearchQuery implements Serializable {
 
     private final List<Criterion> criterias;
 
-    private List<Sort> sorts = Collections.singletonList(new Sort(Sort.SortClause.Uid, false));
+    private List<Sort> sorts = Collections.singletonList(new Sort(Sort.SortClause.Uid, Sort.Order.NATURAL));
 
     public void andCriteria(Criterion crit) {
         criterias.add(crit);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
index 413e4fb..15a9edb 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.lucene.search;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.nio.charset.Charset;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
@@ -44,7 +43,9 @@ import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
 import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
 import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.TestMessageId;
@@ -55,6 +56,8 @@ import org.apache.lucene.store.RAMDirectory;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public class LuceneMailboxMessageSearchIndexTest {
 
     public static final long LIMIT = 100L;
@@ -457,171 +460,171 @@ public class LuceneMailboxMessageSearchIndexTest {
     
     @Test
     public void uidReverseSortShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Uid, true)));
-        query.andCriteria(SearchQuery.all());
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Uid, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid3, uid1);
     }
     
     @Test
     public void sortOnSentDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.SentDate, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.SentDate, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnSentDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.SentDate, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.SentDate, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid4, uid3);
     }
 
     @Test
     public void sortOnSubjectShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.BaseSubject, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void reverseSortOnSubjectShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.BaseSubject, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void sortOnMailboxFromShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxFrom, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxFrom, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnMailboxFromShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxFrom, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxFrom, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid4, uid3);
     }
     
     @Test
     public void sortOnMailboxCCShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxCc, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxCc, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid3, uid4);
     }
     
     @Test
     public void reverseSortOnMailboxCCShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxCc, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxCc, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void sortOnMailboxToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxTo, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void reverseSortOnMailboxToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxTo, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void sortOnDisplayToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayTo, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void reverseSortOnDisplayToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayTo, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void sortOnDisplayFromShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayFrom, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnDisplayFromShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayFrom, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid4, uid3);
     }
     
     @Test
     public void sortOnArrivalDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Arrival, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void reverseSortOnArrivalDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Arrival, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void sortOnSizeShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Size, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Size, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnSizeShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Size, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Size, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid3, uid4);
     }
@@ -630,6 +633,7 @@ public class LuceneMailboxMessageSearchIndexTest {
     public void notOperatorShouldReverseMatching() throws Exception {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.not(SearchQuery.uid(new SearchQuery.UidRange[] { new SearchQuery.UidRange(uid1)})));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 6d622ee..c489d80 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -39,6 +39,7 @@ import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
 import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
 import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
@@ -61,7 +62,6 @@ public abstract class AbstractMessageSearchIndexTest {
     public static final long LIMIT = 100L;
     public static final boolean RECENT = true;
     public static final boolean NOT_RECENT = false;
-    public static final boolean REVERSE = true;
 
     protected MessageSearchIndex messageSearchIndex;
     protected StoreMailboxManager storeMailboxManager;
@@ -629,7 +629,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Date(1433408400000L),
             DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid(), m2.getUid());
@@ -641,7 +641,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Date(1433109600000L),
             DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
@@ -653,7 +653,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Date(1433224800000L),
             DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m4.getUid(), m9.getUid());
@@ -818,7 +818,7 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void revertSortingShouldReturnElementsInAReversedOrder() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m9.getUid(), m8.getUid(), m7.getUid(), m6.getUid(), m4.getUid(), m5.getUid(), m3.getUid(), m2.getUid(), m1.getUid());
@@ -829,7 +829,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateAfter("sentDate", new Date(1433408400000L), DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid(), m2.getUid());
@@ -840,7 +840,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateBefore("sentDate", new Date(1433109600000L), DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
@@ -851,7 +851,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateOn("sentDate", new Date(1433224800000L), DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m4.getUid(), m9.getUid());
@@ -897,7 +897,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnToShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid(), m2.getUid(), m3.getUid(), m4.getUid());
@@ -911,7 +911,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnSubjectShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m4.getUid(), m3.getUid(), m2.getUid(), m5.getUid());
@@ -925,7 +925,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnSizeShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Size)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid(), m5.getUid(), m4.getUid());
@@ -939,7 +939,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnDisplayFromShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m4.getUid(), m3.getUid(), m5.getUid(), m2.getUid());
@@ -953,7 +953,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnDisplayToShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid(), m2.getUid(), m4.getUid(), m5.getUid());
@@ -967,7 +967,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnSentDateShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.SentDate)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid(), m4.getUid(), m2.getUid(), m3.getUid());
@@ -981,7 +981,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnIdShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Uid)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid());
@@ -1104,7 +1104,7 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortShouldNotDiscardResultWhenSearchingFieldIsIdentical() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival)));
 
         List<MessageId> actual = messageSearchIndex.search(session, MultimailboxesSearchQuery.from(searchQuery).build(), LIMIT);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
index fc2ceee..8376687 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java
@@ -22,6 +22,9 @@ package org.apache.james.mailbox.store.search;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.apache.james.mailbox.store.search.comparator.BaseSubjectComparator;
 import org.apache.james.mailbox.store.search.comparator.CombinedComparator;
 import org.apache.james.mailbox.store.search.comparator.HeaderDisplayComparator;
@@ -40,7 +43,6 @@ import com.google.common.collect.ImmutableList;
 
 public class CombinedComparatorTest {
 
-    public static final boolean REVERSE = true;
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
@@ -61,84 +63,84 @@ public class CombinedComparatorTest {
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertInternalDate() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Arrival))).getComparators())
             .containsOnly(InternalDateComparator.INTERNALDATE);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertCc() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxCc))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxCc))).getComparators())
             .containsOnly(HeaderMailboxComparator.CC_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertFrom() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxFrom))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxFrom))).getComparators())
             .containsOnly(HeaderMailboxComparator.FROM_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertTo() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxTo))).getComparators())
             .containsOnly(HeaderMailboxComparator.TO_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertSize() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Size))).getComparators())
             .containsOnly(SizeComparator.SIZE);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertBaseSubject() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.BaseSubject))).getComparators())
             .containsOnly(BaseSubjectComparator.BASESUBJECT);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertUid() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Uid))).getComparators())
             .containsOnly(UidComparator.UID);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertSentDate() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.SentDate))).getComparators())
             .containsOnly(SentDateComparator.SENTDATE);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertDisplayTo() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayTo))).getComparators())
             .containsOnly(HeaderDisplayComparator.TO_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertDisplayFrom() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayFrom))).getComparators())
             .containsOnly(HeaderDisplayComparator.FROM_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertId() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Id))).getComparators())
             .containsOnly(MessageIdComparator.MESSAGE_ID_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldReverse() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom, REVERSE))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayFrom, Order.REVERSE))).getComparators())
             .containsOnly(new ReverseComparator(HeaderDisplayComparator.FROM_COMPARATOR));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
index 2a97f46..5d5daac 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
@@ -23,6 +23,9 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
@@ -35,19 +38,19 @@ public class SortConverter {
     private static final String DESC_ORDERING = "desc";
     private static final String ASC_ORDERING = "asc";
 
-    private static final Map<String, SearchQuery.Sort.SortClause> SORT_CLAUSE_MAP = ImmutableMap.of(
-        "date", SearchQuery.Sort.SortClause.SentDate,
-        "id", SearchQuery.Sort.SortClause.Id);
+    private static final Map<String, SortClause> SORT_CLAUSE_MAP = ImmutableMap.of(
+        "date", SortClause.SentDate,
+        "id", SortClause.Id);
 
 
-    public static List<SearchQuery.Sort> convertToSorts(List<String> jmapSorts) {
+    public static List<Sort> convertToSorts(List<String> jmapSorts) {
         Preconditions.checkNotNull(jmapSorts);
         return jmapSorts.stream()
             .map(SortConverter::toSort)
             .collect(Guavate.toImmutableList());
     }
 
-    private static SearchQuery.Sort toSort(String jmapSort) {
+    private static Sort toSort(String jmapSort) {
         Preconditions.checkNotNull(jmapSort);
         List<String> splitToList = Splitter.on(SEPARATOR).splitToList(jmapSort);
         checkField(splitToList);
@@ -55,23 +58,23 @@ public class SortConverter {
             isReverse(splitToList));
     }
 
-    private static SearchQuery.Sort.SortClause getSortClause(String field) {
+    private static SortClause getSortClause(String field) {
         if (! SORT_CLAUSE_MAP.containsKey(field)) {
             throw new IllegalArgumentException("Unknown sorting field: " + field + " should be one of " + SORT_CLAUSE_MAP.keySet());
         }
         return SORT_CLAUSE_MAP.get(field);
     }
 
-    private static boolean isReverse(List<String> splitList) {
+    private static Order isReverse(List<String> splitList) {
         if (splitList.size() == 1) {
-            return true;
+            return Order.REVERSE;
         }
         String order = splitList.get(1);
         switch (order) {
             case DESC_ORDERING:
-                return true;
+                return Order.REVERSE;
             case ASC_ORDERING:
-                return false;
+                return Order.NATURAL;
         }
         throw new IllegalArgumentException("Unknown sorting order: " + order + " should be one of [asc, desc]");
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
index b30aeb2..af0686c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
@@ -23,7 +23,9 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.List;
 
-import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -33,8 +35,6 @@ import com.google.common.collect.Lists;
 
 public class SortConverterTest {
 
-    public static final boolean REVERSE = true;
-    public static final boolean NOT_REVERSE = !REVERSE;
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
@@ -72,19 +72,19 @@ public class SortConverterTest {
     @Test
     public void convertToSortsShouldSupportDate() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date desc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.REVERSE));
     }
 
     @Test
     public void convertToSortsShouldSupportId() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("id desc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id, REVERSE));
+            .containsExactly(new Sort(SortClause.Id, Order.REVERSE));
     }
 
     @Test
     public void convertToSortsShouldBeDescWhenNoOrderClause() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.REVERSE));
     }
 
     @Test
@@ -96,7 +96,7 @@ public class SortConverterTest {
     @Test
     public void convertToSortsShouldSupportAscOrder() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date asc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, NOT_REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.NATURAL));
     }
 
     @Test
@@ -108,7 +108,7 @@ public class SortConverterTest {
     @Test
     public void convertToSortsShouldSupportMultipleSorts() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date asc", "id desc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, NOT_REVERSE),
-                new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id, REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.NATURAL),
+                new Sort(SortClause.Id, Order.REVERSE));
     }
 }


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


[11/21] james-project git commit: JAMES-2044 Rename some non explicit variable in MessageSearches

Posted by bt...@apache.org.
JAMES-2044 Rename some non explicit variable in MessageSearches


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/86e07036
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/86e07036
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/86e07036

Branch: refs/heads/master
Commit: 86e070366de5a17e91dd6d9b0c654a64853d2f57
Parents: c78db73
Author: benwa <bt...@linagora.com>
Authored: Wed Jun 7 09:21:19 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:33 2017 +0700

----------------------------------------------------------------------
 .../mailbox/store/search/MessageSearches.java   | 26 ++++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/86e07036/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 414abf9..ae5690e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -578,34 +578,34 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         }
     }
 
-    private boolean on(Date date1, Date date2, DateResolution res) {
-        String d1 = createDateString(date1, res);
-        String d2 = createDateString(date2, res);
+    private boolean on(Date date1, Date date2, DateResolution dateResolution) {
+        String d1 = createDateString(date1, dateResolution);
+        String d2 = createDateString(date2, dateResolution);
         return d1.compareTo(d2) == 0;
     }
 
-    private boolean before(Date date1, Date date2, DateResolution res) {
-        String d1 = createDateString(date1, res);
-        String d2 = createDateString(date2, res);
+    private boolean before(Date date1, Date date2, DateResolution dateResolution) {
+        String d1 = createDateString(date1, dateResolution);
+        String d2 = createDateString(date2, dateResolution);
 
         return d1.compareTo(d2) < 0;
     }
 
-    private boolean after(Date date1, Date date2, DateResolution res) {
-        String d1 = createDateString(date1, res);
-        String d2 = createDateString(date2, res);
+    private boolean after(Date date1, Date date2, DateResolution dateResolution) {
+        String d1 = createDateString(date1, dateResolution);
+        String d2 = createDateString(date2, dateResolution);
 
         return d1.compareTo(d2) > 0;
     }
 
-    private String createDateString(Date date, DateResolution res) {
-        SimpleDateFormat format = createFormat(res);
+    private String createDateString(Date date, DateResolution dateResolution) {
+        SimpleDateFormat format = createFormat(dateResolution);
         format.setCalendar(getGMT());
         return format.format(date);
     }
 
-    private SimpleDateFormat createFormat(DateResolution res) {
-        switch (res) {
+    private SimpleDateFormat createFormat(DateResolution dateResolution) {
+        switch (dateResolution) {
         case Year:
             return new SimpleDateFormat("yyyy");
         case Month:


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


[17/21] james-project git commit: JAMES-2048 Add IT testing for attachment with blank CID

Posted by bt...@apache.org.
JAMES-2048 Add IT testing for attachment with blank CID


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2e1d41da
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2e1d41da
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2e1d41da

Branch: refs/heads/master
Commit: 2e1d41da91331e343ae1d99b6396f1281f35d1a1
Parents: 730f44f
Author: quynhn <qn...@linagora.com>
Authored: Tue Jun 6 13:48:36 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:35:54 2017 +0700

----------------------------------------------------------------------
 .../cucumber/GetMessagesMethodStepdefs.java     |  5 ++
 .../test/resources/cucumber/GetMessages.feature | 13 ++++
 .../mailWithInlinedAttachmentAndBlankCid.eml    | 74 ++++++++++++++++++++
 3 files changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2e1d41da/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index 107eaf3..97dbc64 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -221,6 +221,11 @@ public class GetMessagesMethodStepdefs {
         appendMessage(messageName, "eml/mailWithInlinedAttachmentButNoCid.eml");
     }
 
+    @Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" mailbox with inline attachment and blank CID$")
+    public void appendMessageWithInlineAttachmentAndBlankCid(String messageName, String mailbox) throws Throwable {
+        appendMessage(messageName, "eml/mailWithInlinedAttachmentAndBlankCid.eml");
+    }
+
     @Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" mailbox with HTML body with many empty tags$")
     public void appendMessageWithNoPreview(String messageName, String mailbox) throws Exception {
         appendMessage(messageName, "eml/htmlBodyWithManyEmptyTags.eml");

http://git-wip-us.apache.org/repos/asf/james-project/blob/2e1d41da/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index a0c4104..9f0255f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -262,6 +262,19 @@ Feature: GetMessages method
       |cid      |null                                       |
       |isInline |true                                      |
 
+  Scenario: Retrieving message with inline attachment and blank CID should convert that inlined attachment to normal attachment
+    Given the user has a message "m1" in "INBOX" mailbox with inline attachment and blank CID
+    When the user ask for messages "m1"
+    Then no error is returned
+    And the list should contain 1 message
+    And the hasAttachment of the message is "true"
+    And the list of attachments of the message contains 1 attachments
+    And the first attachment is:
+        |key      | value            |
+        |type     |"application/pdf" |
+        |cid      |null              |
+        |isInline |true              |
+
   Scenario: Preview should be computed even when HTML body contains many tags without content
     Given the user has a message "m1" in "INBOX" mailbox with HTML body with many empty tags
     When the user ask for messages "m1"

http://git-wip-us.apache.org/repos/asf/james-project/blob/2e1d41da/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/mailWithInlinedAttachmentAndBlankCid.eml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/mailWithInlinedAttachmentAndBlankCid.eml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/mailWithInlinedAttachmentAndBlankCid.eml
new file mode 100644
index 0000000..39facf2
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/mailWithInlinedAttachmentAndBlankCid.eml
@@ -0,0 +1,74 @@
+Return-Path: <se...@gmail.com>
+MIME-Version: 1.0
+Delivered-To: test@localhost
+Received: from localhost
+X-Virus-Scanned: Debian
+X-Spam-Flag: NO
+X-Spam-Score: -1.78
+X-Spam-Level:
+X-Spam-Status: No, score=-1.78 tagged_above=-99 required=2
+	tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001,
+	RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_DKIM_INVALID=0.01,
+	T_FREEMAIL_DOC_PDF=0.01] autolearn=no
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
+        d=gmail.com; s=20161025;
+        h=from:mime-version:subject:message-id:date:cc:to;
+        bh=lgK1xUjmh9FzAPFKLN2lvhSSlfI6ujj8K57kqImKrA8=;
+        b=tw7ave7egTqm3ZcXDe0NeuPSli3nkOBuqjOWLaK0MivSzO8FTQEWzCMEAlyhG4PMcP
+         jkxmhKAAjNPshiFnAYzPB4LNQV6GKPNUQ5igA9HDzh4dfbdT/6GiTEvUyWKZ6VpGVASR
+         x9Ioyiwxrdf4phsMYSHT7/Y+94/SvmAQj5gZZXfQ8JvmIAlxN9F4mvMnk2JQM4wcGv8Z
+         15zNoTxcUPODEybnawotJUewQu2sCKL7S46vFfKiuYEiKPC/XhGPFsjvwBAvcMBfRgbm
+         jJSAPk0TlXERVjhd3CSCHC1ukQ1nICb3yTZacuOK0gUgJ7rKY25zQoq2QvYgX97SuThz
+         BpHw==
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
+        d=1e100.net; s=20161025;
+        h=x-gm-message-state:from:mime-version:subject:message-id:date:cc:to;
+        bh=lgK1xUjmh9FzAPFKLN2lvhSSlfI6ujj8K57kqImKrA8=;
+        b=VmTt7K8LRHq/MdOYtIhRnA/Lkbx41VnZh6+SYior8s5kLaKgrJWi+N/ql7SU6lCR2m
+         JFTyvIfUqsNFiHy0wPMlI4RauXHNVQWe9C+UQ5hc5BT+Z67O/5dxe+KDhtchRqh7JWC5
+         aWDjuvROFqhEEqphuEtGLqEqnHPbmweMZBIouasP2Z0TiHTSASSJq60HUcwf7UcVbmbw
+         m5O35XykCkecEX+H9fGAqgzlvFvtfy4PDENWfz8Yhzv730FsAmDutRjww0HYriyLwgpN
+         OjrT1o6p6DrWs5JlcgRh7F5qauiR/WTq+srbWbe/tLD7Lx8WRKyeXuzjKyTKJ5TjV6c5
+         AHKA==
+X-Gm-Message-State: AFeK/H1blcvejtSjL0KgKvb81Bc5uVOYQpq8wm/HouMZgtBr1kw+d9+VOes+FQrObRJdbQ==
+X-Received: by 10.28.133.84 with SMTP id h81mr8649035wmd.23.1489999897292;
+        Mon, 20 Mar 2017 01:51:37 -0700 (PDT)
+From: <fr...@localhost>
+Content-Type: multipart/mixed;
+ boundary="Apple-Mail=_DF3869A6-784C-445C-8AA0-EBEFE28034A4"
+Subject: mail with attachment from apple mail
+Message-Id: <15...@gmail.com>
+Date: Mon, 20 Mar 2017 09:51:28 +0100
+To: <to...@localhost>
+X-Mailer: Apple Mail (2.3259)
+
+
+--Apple-Mail=_DF3869A6-784C-445C-8AA0-EBEFE28034A4
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/plain;
+	charset=utf-8
+
+Voil=C3=A0
+
+--=20
+Voila=
+
+--Apple-Mail=_DF3869A6-784C-445C-8AA0-EBEFE28034A4
+Content-Disposition: inline;
+	filename=deromaCollection-628.pdf
+Content-ID:
+Content-Type: application/pdf;
+	x-unix-mode=0644;
+	name="deromaCollection-628.pdf"
+Content-ID: <   >
+Content-Transfer-Encoding: base64
+
+JVBERi0xLjQKJeLjz9MKMSAwIG9iaiAKPDwvVHlwZSAvQ2F0YWxvZyAvVmVyc2lvbiAvMS40IC9Q
+YWdlcyAyIDAgUiAvTmFtZXMgNiAwIFIgPj4KZW5kb2JqCjIgMCBvYmogCjw8L1R5cGUgL1BhZ2Vz
+IC9LaWRzIFsxMCAwIFIgMTIgMCBSIDE5IDAgUiBdIC9Db3VudCAzID4+CmVuZG9iagozIDAgb2Jq
+IAo8PC9UaXRsZSAo/v8AVADpAG4A6QByAOkpIC9BdXRob3IgKERlcm9tYSBTcGEpIC9TdWJqZWN0
+ICj+/wBDAG8AbABsAGUAYwB0AGkAbwBuACAAVADpAG4A6QByAOkpIC9LZXl3b3JkcyAo/v8ARABl
+AHMALABwAGkA6ABjAGUAcwAsAHUAbgBpAHEAdQBlAHMALAAsAGMAcgDpAOkAZQBzACwAcABhAHIA
+LABkAGUALAB0AGEAbABlAG4AdAB1AGUAdQB4ACwAYQByAHQAaQBzAGEAbgBzACwAcABvAHQAaQBl
+bmZvIDMgMCBSID4+CnN0YXJ0eHJlZgoyOTQ0MDcKJSVFT0YK
+--Apple-Mail=_DF3869A6-784C-445C-8AA0-EBEFE28034A4--


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


[12/21] james-project git commit: JAMES-2044 Improve a bit flow in MessageSearches

Posted by bt...@apache.org.
JAMES-2044 Improve a bit flow in MessageSearches


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c78db735
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c78db735
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c78db735

Branch: refs/heads/master
Commit: c78db735d15aa35f8d8bf6422f4675b0dd2c5b55
Parents: 4f1ff45
Author: benwa <bt...@linagora.com>
Authored: Wed Jun 7 09:20:23 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 7 17:34:33 2017 +0700

----------------------------------------------------------------------
 .../mailbox/store/search/MessageSearches.java   | 109 ++++++++-----------
 1 file changed, 43 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c78db735/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 6cee0d4..414abf9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -147,16 +147,14 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     private boolean isMatch(MailboxMessage message) throws MailboxException {
         final List<SearchQuery.Criterion> criteria = query.getCriterias();
         final Collection<MessageUid> recentMessageUids = query.getRecentMessageUids();
-        boolean result = true;
         if (criteria != null) {
             for (SearchQuery.Criterion criterion : criteria) {
                 if (!isMatch(criterion, message, recentMessageUids)) {
-                    result = false;
-                    break;
+                    return false;
                 }
             }
         }
-        return result;
+        return true;
     }
 
     /**
@@ -174,37 +172,35 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
      */
     public boolean isMatch(SearchQuery.Criterion criterion, MailboxMessage message,
             final Collection<MessageUid> recentMessageUids) throws MailboxException {
-        final boolean result;
         if (criterion instanceof SearchQuery.InternalDateCriterion) {
-            result = matches((SearchQuery.InternalDateCriterion) criterion, message);
+            return matches((SearchQuery.InternalDateCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.SizeCriterion) {
-            result = matches((SearchQuery.SizeCriterion) criterion, message);
+            return matches((SearchQuery.SizeCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.HeaderCriterion) {
             try {
-                result = matches((SearchQuery.HeaderCriterion) criterion, message);
+                return matches((SearchQuery.HeaderCriterion) criterion, message);
             } catch (IOException e) {
                 throw new MailboxException("Unable to search header", e);
             }
         } else if (criterion instanceof SearchQuery.UidCriterion) {
-            result = matches((SearchQuery.UidCriterion) criterion, message);
+            return matches((SearchQuery.UidCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.FlagCriterion) {
-            result = matches((SearchQuery.FlagCriterion) criterion, message, recentMessageUids);
+            return matches((SearchQuery.FlagCriterion) criterion, message, recentMessageUids);
         } else if (criterion instanceof SearchQuery.CustomFlagCriterion) {
-            result = matches((SearchQuery.CustomFlagCriterion) criterion, message, recentMessageUids);
+            return matches((SearchQuery.CustomFlagCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.TextCriterion) {
-            result = matches((SearchQuery.TextCriterion) criterion, message);
+            return matches((SearchQuery.TextCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.AllCriterion) {
-            result = true;
+            return true;
         } else if (criterion instanceof SearchQuery.ConjunctionCriterion) {
-            result = matches((SearchQuery.ConjunctionCriterion) criterion, message, recentMessageUids);
+            return matches((SearchQuery.ConjunctionCriterion) criterion, message, recentMessageUids);
         } else if (criterion instanceof SearchQuery.AttachmentCriterion) {
-            result = matches((SearchQuery.AttachmentCriterion) criterion, message);
+            return matches((SearchQuery.AttachmentCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
-            result = matches((SearchQuery.ModSeqCriterion) criterion, message);
+            return matches((SearchQuery.ModSeqCriterion) criterion, message);
         } else {
             throw new UnsupportedSearchException();
         }
-        return result;
     }
 
     private boolean matches(SearchQuery.TextCriterion criterion, MailboxMessage message)
@@ -302,71 +298,62 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     }
 
     private boolean and(List<SearchQuery.Criterion> criteria, MailboxMessage message,
-            final Collection<MessageUid> recentMessageUids) throws MailboxException {
-        boolean result = true;
+                        Collection<MessageUid> recentMessageUids) throws MailboxException {
         for (SearchQuery.Criterion criterion : criteria) {
             boolean matches = isMatch(criterion, message, recentMessageUids);
             if (!matches) {
-                result = false;
-                break;
+                return false;
             }
         }
-        return result;
+        return true;
     }
 
     private boolean or(List<SearchQuery.Criterion> criteria, MailboxMessage message,
-            final Collection<MessageUid> recentMessageUids) throws MailboxException {
-        boolean result = false;
+                       Collection<MessageUid> recentMessageUids) throws MailboxException {
         for (SearchQuery.Criterion criterion : criteria) {
             boolean matches = isMatch(criterion, message, recentMessageUids);
             if (matches) {
-                result = true;
-                break;
+                return true;
             }
         }
-        return result;
+        return false;
     }
 
     private boolean nor(List<SearchQuery.Criterion> criteria, MailboxMessage message,
-            final Collection<MessageUid> recentMessageUids) throws MailboxException {
-        boolean result = true;
+                        Collection<MessageUid> recentMessageUids) throws MailboxException {
         for (SearchQuery.Criterion criterion : criteria) {
             boolean matches = isMatch(criterion, message, recentMessageUids);
             if (matches) {
-                result = false;
-                break;
+                return false;
             }
         }
-        return result;
+        return true;
     }
 
     private boolean matches(SearchQuery.FlagCriterion criterion, MailboxMessage message,
-            Collection<MessageUid> recentMessageUids) {
+                            Collection<MessageUid> recentMessageUids) {
         SearchQuery.BooleanOperator operator = criterion.getOperator();
         boolean isSet = operator.isSet();
         Flags.Flag flag = criterion.getFlag();
-        boolean result;
         if (flag == Flags.Flag.ANSWERED) {
-            result = isSet == message.isAnswered();
+            return isSet == message.isAnswered();
         } else if (flag == Flags.Flag.SEEN) {
-            result = isSet == message.isSeen();
+            return isSet == message.isSeen();
         } else if (flag == Flags.Flag.DRAFT) {
-            result = isSet == message.isDraft();
+            return isSet == message.isDraft();
         } else if (flag == Flags.Flag.FLAGGED) {
-            result = isSet == message.isFlagged();
+            return isSet == message.isFlagged();
         } else if (flag == Flags.Flag.RECENT) {
             final MessageUid uid = message.getUid();
-            result = isSet == recentMessageUids.contains(uid);
+            return isSet == recentMessageUids.contains(uid);
         } else if (flag == Flags.Flag.DELETED) {
-            result = isSet == message.isDeleted();
+            return isSet == message.isDeleted();
         } else {
-            result = false;
+            return false;
         }
-        return result;
     }
 
-    private boolean matches(SearchQuery.CustomFlagCriterion criterion, MailboxMessage message,
-            Collection<MessageUid> recentMessageUids) {
+    private boolean matches(SearchQuery.CustomFlagCriterion criterion, MailboxMessage message) {
         SearchQuery.BooleanOperator operator = criterion.getOperator();
         boolean isSet = operator.isSet();
         String flag = criterion.getFlag();
@@ -377,33 +364,29 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         SearchQuery.UidInOperator operator = criterion.getOperator();
         UidRange[] ranges = operator.getRange();
         MessageUid uid = message.getUid();
-        boolean result = false;
         for (UidRange numericRange : ranges) {
             if (numericRange.isIn(uid)) {
-                result = true;
-                break;
+                return true;
             }
         }
-        return result;
+        return false;
     }
 
     private boolean matches(SearchQuery.HeaderCriterion criterion, MailboxMessage message)
             throws MailboxException, IOException {
         SearchQuery.HeaderOperator operator = criterion.getOperator();
         String headerName = criterion.getHeaderName();
-        boolean result;
         if (operator instanceof SearchQuery.DateOperator) {
-            result = matches((SearchQuery.DateOperator) operator, headerName, message);
+            return matches((SearchQuery.DateOperator) operator, headerName, message);
         } else if (operator instanceof SearchQuery.ContainsOperator) {
-            result = matches((SearchQuery.ContainsOperator) operator, headerName, message);
+            return matches((SearchQuery.ContainsOperator) operator, headerName, message);
         } else if (operator instanceof SearchQuery.ExistsOperator) {
-            result = exists(headerName, message);
+            return exists(headerName, message);
         } else if (operator instanceof SearchQuery.AddressOperator) {
-            result = matchesAddress((SearchQuery.AddressOperator) operator, headerName, message);
+            return matchesAddress((SearchQuery.AddressOperator) operator, headerName, message);
         } else {
             throw new UnsupportedSearchException();
         }
-        return result;
     }
 
     /**
@@ -450,23 +433,20 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     }
 
     private boolean exists(String headerName, MailboxMessage message) throws MailboxException, IOException {
-        boolean result = false;
         List<Header> headers = ResultUtils.createHeaders(message);
 
         for (Header header : headers) {
             String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
-                result = true;
-                break;
+                return true;
             }
         }
-        return result;
+        return false;
     }
 
     private boolean matches(SearchQuery.ContainsOperator operator, String headerName,
             MailboxMessage message) throws MailboxException, IOException {
         String text = operator.getValue().toUpperCase(Locale.US);
-        boolean result = false;
         List<Header> headers = ResultUtils.createHeaders(message);
         for (Header header : headers) {
             String name = header.getName();
@@ -474,13 +454,12 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
                 String value = MimeUtil.unscrambleHeaderValue(header.getValue());
                 if (value != null) {
                     if (value.toUpperCase(Locale.US).contains(text)) {
-                        result = true;
-                        break;
+                        return true;
                     }
                 }
             }
         }
-        return result;
+        return false;
     }
 
     private boolean matches(SearchQuery.DateOperator operator, String headerName, MailboxMessage message)
@@ -517,15 +496,13 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
 
     private String headerValue(String headerName, MailboxMessage message) throws MailboxException, IOException {
         List<Header> headers = ResultUtils.createHeaders(message);
-        String value = null;
         for (Header header : headers) {
             String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
-                value = MimeUtil.unscrambleHeaderValue(header.getValue());
-                break;
+                return MimeUtil.unscrambleHeaderValue(header.getValue());
             }
         }
-        return value;
+        return null;
     }
 
     private Date toISODate(String value) throws ParseException {


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