james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [04/11] james-project git commit: JAMES-1825 use a MessageUid strong type instead of long in the whole code base
Date Mon, 10 Oct 2016 10:34:22 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/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 c9c3fe2..8b36a1c 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
@@ -29,6 +29,7 @@ import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -56,6 +57,16 @@ public abstract class AbstractMessageSearchIndexTest {
     private Mailbox mailbox2;
     private MailboxSession session;
 
+    private MessageUid m1;
+    private MessageUid m2;
+    private MessageUid m3;
+    private MessageUid m4;
+    private MessageUid m5;
+    private MessageUid m6;
+    private MessageUid m7;
+    private MessageUid m8;
+    private MessageUid m9;
+
     @Before
     public void setUp() throws Exception {
         initializeMailboxManager();
@@ -71,9 +82,7 @@ public abstract class AbstractMessageSearchIndexTest {
         mailbox = inboxMessageManager.getMailboxEntity();
         mailbox2 = myFolderMessageManager.getMailboxEntity();
 
-        // sentDate: Wed, 3 Jun 2015 09:05:46 +0000
-        // Internal date : 2014/01/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m1 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"),
             new Date(1388617200000L),
             session,
@@ -81,7 +90,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.DELETED));
         // sentDate: Thu, 4 Jun 2015 09:23:37 +0000
         // Internal date : 2014/02/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m2 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/mail1.eml"),
             new Date(1391295600000L),
             session,
@@ -89,7 +98,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.ANSWERED));
         // sentDate: Thu, 4 Jun 2015 09:27:37 +0000
         // Internal date : 2014/03/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m3 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/mail2.eml"),
             new Date(1393714800000L),
             session,
@@ -97,7 +106,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.DRAFT));
         // sentDate: Tue, 2 Jun 2015 08:16:19 +0000
         // Internal date : 2014/05/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m4 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/mail3.eml"),
             new Date(1398981600000L),
             session,
@@ -105,7 +114,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.RECENT));
         // sentDate: Fri, 15 May 2015 06:35:59 +0000
         // Internal date : 2014/04/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m5 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/mail4.eml"),
             new Date(1396389600000L),
             session,
@@ -113,7 +122,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.FLAGGED));
         // sentDate: Wed, 03 Jun 2015 19:14:32 +0000
         // Internal date : 2014/06/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m6 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"),
             new Date(1401660000000L),
             session,
@@ -121,7 +130,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.SEEN));
         // sentDate: Thu, 04 Jun 2015 07:36:08 +0000
         // Internal date : 2014/07/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m7 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/htmlMail.eml"),
             new Date(1404252000000L),
             session,
@@ -129,7 +138,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags());
         // sentDate: Thu, 4 Jun 2015 06:08:41 +0200
         // Internal date : 2014/08/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m8 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/mail.eml"),
             new Date(1406930400000L),
             session,
@@ -145,7 +154,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Flags(Flags.Flag.SEEN));
         // sentDate: Tue, 2 Jun 2015 12:00:55 +0200
         // Internal date : 2014/09/02 00:00:00.000
-        inboxMessageManager.appendMessage(
+        m9 = inboxMessageManager.appendMessage(
             ClassLoader.getSystemResourceAsStream("eml/frnog.eml"),
             new Date(1409608800000L),
             session,
@@ -178,7 +187,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void emptySearchQueryShouldReturnAllUids() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m5, m6, m7, m8, m9);
     }
 
     @Test
@@ -186,7 +195,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.all());
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m5, m6, m7, m8, m9);
     }
 
     @Test
@@ -197,7 +206,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.bodyContains("MAILET-94"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(5L);
+            .containsOnly(m5);
     }
 
     @Test
@@ -209,7 +218,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.bodyContains("created summary"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L, 8L);
+            .containsOnly(m2, m8);
     }
 
     @Test
@@ -217,7 +226,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.DELETED));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L);
+            .containsOnly(m1);
     }
 
     @Test
@@ -225,7 +234,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.ANSWERED));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L);
+            .containsOnly(m2);
     }
 
     @Test
@@ -233,7 +242,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(3L);
+            .containsOnly(m3);
     }
 
     @Test
@@ -242,7 +251,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.RECENT));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m5, m6, m8, m9);
     }
 
     @Test
@@ -250,7 +259,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.FLAGGED));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(5L);
+            .containsOnly(m5);
     }
 
     @Test
@@ -259,17 +268,17 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(6L);
+            .containsOnly(m6);
     }
     
     @Test
     public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet(Flags.Flag.SEEN));
-        Map<MailboxId, Collection<Long>> actual = messageSearchIndex.search(session, MultimailboxesSearchQuery.from(searchQuery).build());
+        Map<MailboxId, Collection<MessageUid>> actual = messageSearchIndex.search(session, MultimailboxesSearchQuery.from(searchQuery).build());
         assertThat(actual.entrySet()).hasSize(2);
-        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(6L);
-        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(1L);
+        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(m6);
+        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(m1);
     }
 
     @Test
@@ -281,9 +290,9 @@ public abstract class AbstractMessageSearchIndexTest {
                     .from(searchQuery)
                     .inMailboxes(mailbox.getMailboxId())
                     .build();
-        Map<MailboxId, Collection<Long>> actual = messageSearchIndex.search(session, query);
+        Map<MailboxId, Collection<MessageUid>> actual = messageSearchIndex.search(session, query);
         assertThat(actual.entrySet()).hasSize(1);
-        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(6L);
+        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(m6);
     }
 
     @Test
@@ -295,10 +304,10 @@ public abstract class AbstractMessageSearchIndexTest {
                     .from(searchQuery)
                     .inMailboxes(mailbox.getMailboxId(), mailbox2.getMailboxId())
                     .build();
-        Map<MailboxId, Collection<Long>> actual = messageSearchIndex.search(session, query);
+        Map<MailboxId, Collection<MessageUid>> actual = messageSearchIndex.search(session, query);
         assertThat(actual.entrySet()).hasSize(2);
-        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(8L);
-        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(1L);
+        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(m8);
+        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(m1);
     }
 
     @Test
@@ -309,10 +318,10 @@ public abstract class AbstractMessageSearchIndexTest {
                 MultimailboxesSearchQuery
                     .from(searchQuery)
                     .build();
-        Map<MailboxId, Collection<Long>> actual = messageSearchIndex.search(session, query);
+        Map<MailboxId, Collection<MessageUid>> actual = messageSearchIndex.search(session, query);
         assertThat(actual.entrySet()).hasSize(2);
-        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(8L);
-        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(1L);
+        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(m8);
+        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(m1);
     }
 
     @Test
@@ -324,10 +333,10 @@ public abstract class AbstractMessageSearchIndexTest {
                     .from(searchQuery)
                     .inMailboxes(mailbox.getMailboxId(), mailbox2.getMailboxId())
                     .build();
-        Map<MailboxId, Collection<Long>> actual = messageSearchIndex.search(session, query);
+        Map<MailboxId, Collection<MessageUid>> actual = messageSearchIndex.search(session, query);
         assertThat(actual.entrySet()).hasSize(2);
-        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(6L);
-        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(1L);
+        assertThat(actual.get(mailbox.getMailboxId())).containsExactly(m6);
+        assertThat(actual.get(mailbox2.getMailboxId())).containsExactly(m1);
     }
     
     @Test
@@ -335,7 +344,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet("Hello"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(8L);
+            .containsOnly(m8);
     }
 
     @Test
@@ -351,7 +360,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.DELETED));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+            .containsOnly(m2, m3, m4, m5, m6, m7, m8, m9);
     }
 
     @Test
@@ -359,7 +368,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.ANSWERED));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+            .containsOnly(m1, m3, m4, m5, m6, m7, m8, m9);
     }
 
     @Test
@@ -367,7 +376,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.DRAFT));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L);
+            .containsOnly(m1, m2, m4, m5, m6, m7, m8, m9);
     }
 
     @Test
@@ -376,7 +385,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.RECENT));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(7L);
+            .containsOnly(m7);
     }
 
     @Test
@@ -384,7 +393,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.FLAGGED));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 6L, 7L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m6, m7, m8, m9);
     }
 
     @Test
@@ -393,7 +402,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flags.Flag.SEEN));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m5, m7, m8, m9);
     }
 
     @Test
@@ -401,7 +410,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet("Hello"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L,  9L);
+            .containsOnly(m1, m2, m3, m4, m5, m6, m7,  m9);
     }
 
     @Test
@@ -410,7 +419,7 @@ public abstract class AbstractMessageSearchIndexTest {
         // 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(7L, 8L, 9L);
+            .containsOnly(m7, m8, m9);
     }
 
     @Test
@@ -419,7 +428,7 @@ public abstract class AbstractMessageSearchIndexTest {
         // 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(1L, 2L);
+            .containsOnly(m1, m2);
     }
 
     @Test
@@ -428,7 +437,7 @@ public abstract class AbstractMessageSearchIndexTest {
         // 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(3L);
+            .containsOnly(m3);
     }
 
     @Test
@@ -436,7 +445,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.modSeqEquals(2L));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L);
+            .containsOnly(m2);
     }
 
     @Test
@@ -444,7 +453,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.modSeqGreaterThan(7L));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(7L, 8L, 9L);
+            .containsOnly(m7, m8, m9);
     }
 
     @Test
@@ -452,7 +461,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.modSeqLessThan(3L));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L);
+            .containsOnly(m1, m2, m3);
     }
 
     @Test
@@ -461,7 +470,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.sizeGreaterThan(6800L));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(6L);
+            .containsOnly(m6);
     }
 
     @Test
@@ -470,7 +479,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.sizeLessThan(5000L));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L, 3L, 4L, 5L, 7l, 9L);
+            .containsOnly(m2, m3, m4, m5, m7, m9);
     }
 
     @Test
@@ -478,7 +487,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.headerContains("Precedence", "list"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 6L, 8L, 9L);
+            .containsOnly(m1, m6, m8, m9);
     }
 
     @Test
@@ -486,7 +495,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.headerExists("Precedence"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m5, m6, m8, m9);
     }
 
     @Test
@@ -494,7 +503,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.From, "murari.ksr@gmail.com"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(8L);
+            .containsOnly(m8);
     }
 
     @Test
@@ -502,7 +511,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.To, "root@listes.minet.net"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L);
+            .containsOnly(m1);
     }
 
     @Test
@@ -510,7 +519,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.Cc, "any@any.com"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(5L);
+            .containsOnly(m5);
     }
 
     @Test
@@ -518,25 +527,25 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.Bcc, "no@no.com"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(9L);
+            .containsOnly(m9);
     }
 
     @Test
     public void uidShouldreturnExistingUidsOnTheGivenRanges() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 4L), new SearchQuery.NumericRange(6L, 7L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m4), new SearchQuery.UidRange(m6, m7)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L, 3L, 4L, 6L, 7L);
+            .containsOnly(m2, m3, m4, m6, m7);
     }
 
     @Test
     public void uidShouldreturnEveryThing() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {};
+        SearchQuery.UidRange[] numericRanges = {};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+            .containsOnly(m1, m2, m3, m4, m5, m6, m7, m8, m9);
     }
 
     @Test
@@ -545,7 +554,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.headerExists("Precedence"));
         searchQuery.andCriteria(SearchQuery.modSeqGreaterThan(6L));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(6L, 8L, 9L);
+            .containsOnly(m6, m8, m9);
     }
 
     @Test
@@ -556,19 +565,19 @@ public abstract class AbstractMessageSearchIndexTest {
                 SearchQuery.headerExists("Precedence"),
                 SearchQuery.modSeqGreaterThan(6L)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(6L, 8L, 9L);
+            .containsOnly(m6, m8, m9);
     }
 
     @Test
     public void orShouldReturnResultsMatchinganyRequests() throws Exception {
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 4L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m4)};
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(
             SearchQuery.or(
                 SearchQuery.uid(numericRanges),
                 SearchQuery.modSeqGreaterThan(6L)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(2L, 3L, 4L, 6L, 7L, 8L, 9L);
+            .containsOnly(m2, m3, m4, m6, m7, m8, m9);
     }
 
     @Test
@@ -577,7 +586,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(
             SearchQuery.not(SearchQuery.headerExists("Precedence")));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(7L);
+            .containsOnly(m7);
     }
 
     @Test
@@ -586,7 +595,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.all());
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(1L, 2L, 3L, 5L, 4L, 6L, 7L, 8L, 9L);
+            .containsExactly(m1, m2, m3, m5, m4, m6, m7, m8, m9);
     }
 
     @Test
@@ -595,7 +604,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.all());
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(9L, 8L, 7L, 6L, 4L, 5L, 3L, 2L, 1L);
+            .containsExactly(m9, m8, m7, m6, m4, m5, m3, m2, m1);
     }
 
     @Test
@@ -605,7 +614,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.headerDateAfter("sentDate", new Date(1433408400000L), SearchQuery.DateResolution.Second));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(3L, 2L);
+            .containsOnly(m3, m2);
     }
 
     @Test
@@ -615,7 +624,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.headerDateBefore("sentDate", new Date(1433109600000L), SearchQuery.DateResolution.Day));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(5L);
+            .containsOnly(m5);
     }
 
     @Test
@@ -625,7 +634,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.headerDateOn("sentDate", new Date(1433224800000L), SearchQuery.DateResolution.Day));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival, true)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(4L, 9L);
+            .containsOnly(m4, m9);
     }
 
     @Test
@@ -633,17 +642,17 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.mailContains("root mailing list"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(1L, 6L);
+            .containsOnly(m1, m6);
     }
 
     @Test
     public void sortOnCcShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxCc)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(3L, 5L, 4L, 2L);
+            .containsExactly(m3, m5, m4, m2);
         // 2 : No cc
         // 3 : Cc : abc@abc.org
         // 4 : zzz@bcd.org
@@ -653,11 +662,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnFromShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxFrom)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(3L, 2L, 4L, 5L);
+            .containsExactly(m3, m2, m4, m5);
         // 2 : jira2@apache.org
         // 3 : jira1@apache.org
         // 4 : jira@apache.org
@@ -667,11 +676,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnToShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(5L, 2L, 3L, 4L);
+            .containsExactly(m5, m2, m3, m4);
         // 2 : server-dev@james.apache.org
         // 3 : server-dev@james.apache.org
         // 4 : server-dev@james.apache.org
@@ -681,11 +690,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnSubjectShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(4L, 3L, 2L, 5L);
+            .containsExactly(m4, m3, m2, m5);
         // 2 : [jira] [Created] (MAILBOX-234) Convert Message into JSON
         // 3 : [jira] [Closed] (MAILBOX-217) We should index attachment in elastic search
         // 4 : [jira] [Closed] (MAILBOX-11) MailboxQuery ignore namespace
@@ -695,11 +704,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnSizeShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(2L, 3L, 5L, 4L);
+            .containsExactly(m2, m3, m5, m4);
         // 2 : 3210 o
         // 3 : 3647 o
         // 4 : 4360 o
@@ -709,11 +718,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnDisplayFromShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(4L, 3L, 5L, 2L);
+            .containsExactly(m4, m3, m5, m2);
         // 2 : Tellier Benoit (JIRA)
         // 3 : efij
         // 4 : abcd
@@ -723,11 +732,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnDisplayToShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(3L, 2L, 4L, 5L);
+            .containsExactly(m3, m2, m4, m5);
         // 2 : abc
         // 3 : aaa
         // 4 : server
@@ -737,11 +746,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnSentDateShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(5L, 4L, 2L, 3L);
+            .containsExactly(m5, m4, m2, m3);
         // 2 : 4 Jun 2015 09:23:37
         // 3 : 4 Jun 2015 09:27:37
         // 4 : 2 Jun 2015 08:16:19
@@ -751,11 +760,11 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortOnIdShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
-        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 5L)};
+        SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2, m5)};
         searchQuery.andCriteria(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid)));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(2L, 3L, 4L, 5L);
+            .containsExactly(m2, m3, m4, m5);
     }
 
     @Test
@@ -773,7 +782,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.textContains("spam.minet.net"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(1l);
+            .containsExactly(m1);
     }
 
     @Test
@@ -782,7 +791,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.textContains("listes.minet.net"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(1l);
+            .containsExactly(m1);
     }
 
     @Test
@@ -791,7 +800,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.textContains("abc.org"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(3l);
+            .containsExactly(m3);
     }
 
     @Test
@@ -800,7 +809,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.textContains("any.com"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(5l);
+            .containsExactly(m5);
     }
 
     @Test
@@ -810,7 +819,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(SearchQuery.textContains("reviewing work"));
         // text/plain contains: "We are reviewing work I did for this feature."
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(3l);
+            .containsExactly(m3);
     }
 
     @Test
@@ -821,7 +830,7 @@ public abstract class AbstractMessageSearchIndexTest {
         // 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(2l, 3l);
+            .containsExactly(m2, m3);
     }
 
     @Test
@@ -831,7 +840,7 @@ public abstract class AbstractMessageSearchIndexTest {
         // text/plain contains: "We are reviewing work I did for this feature."
         searchQuery.andCriteria(SearchQuery.textContains("reVieWing"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(3l);
+            .containsExactly(m3);
     }
 
     @Test
@@ -841,7 +850,7 @@ public abstract class AbstractMessageSearchIndexTest {
         searchQuery.andCriteria(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(3l);
+            .containsExactly(m3);
     }
 
     @Test
@@ -851,7 +860,7 @@ public abstract class AbstractMessageSearchIndexTest {
         // 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(7l);
+            .containsExactly(m7);
     }
 
     @Test
@@ -860,7 +869,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.textContains("contain banana"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(7l);
+            .containsExactly(m7);
     }
 
     @Test
@@ -869,6 +878,6 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.textContains("beautifull banana"));
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .containsExactly(7l);
+            .containsExactly(m7);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/resources/eml/nonTextual.json
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/nonTextual.json b/mailbox/store/src/test/resources/eml/nonTextual.json
index fff32e6..0cdffc0 100644
--- a/mailbox/store/src/test/resources/eml/nonTextual.json
+++ b/mailbox/store/src/test/resources/eml/nonTextual.json
@@ -1,5 +1,5 @@
 {
-  "id":0,
+  "id": 25,
   "mailboxId":"18",
   "modSeq":42,
   "size":25,

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/resources/eml/spamMail.json
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/spamMail.json b/mailbox/store/src/test/resources/eml/spamMail.json
index aa86788..6e150b0 100644
--- a/mailbox/store/src/test/resources/eml/spamMail.json
+++ b/mailbox/store/src/test/resources/eml/spamMail.json
@@ -1,5 +1,5 @@
 {
-  "id": 0,
+  "id": 25,
   "mailboxId": "18",
   "modSeq": 42,
   "size": 25,

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
index 4a37684..ba8dd30 100644
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
+++ b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
@@ -20,6 +20,8 @@
 package org.apache.james.mailbox.indexer.events;
 
 import com.google.common.base.Objects;
+
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
 
 import javax.mail.Flags;
@@ -27,17 +29,17 @@ import javax.mail.Flags;
 public class FlagsMessageEvent implements ImpactingMessageEvent {
 
     private final MailboxPath mailboxPath;
-    private final long uid;
+    private final MessageUid uid;
     private final Flags flags;
 
-    public FlagsMessageEvent(MailboxPath mailboxPath, long uid, Flags flags) {
+    public FlagsMessageEvent(MailboxPath mailboxPath, MessageUid uid, Flags flags) {
         this.mailboxPath = mailboxPath;
         this.uid = uid;
         this.flags = flags;
     }
 
     @Override
-    public long getUid() {
+    public MessageUid getUid() {
         return uid;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
index 5f7a2f6..9e3b985 100644
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
+++ b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
@@ -19,8 +19,10 @@
 
 package org.apache.james.mailbox.indexer.events;
 
+import org.apache.james.mailbox.MessageUid;
+
 public interface ImpactingMessageEvent extends ImpactingEvent {
 
-    long getUid();
+    MessageUid getUid();
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
index ae4cf5f..7fac6f6 100644
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
+++ b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
@@ -20,20 +20,22 @@
 package org.apache.james.mailbox.indexer.events;
 
 import com.google.common.base.Objects;
+
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
 
 public class MessageDeletedEvent implements ImpactingMessageEvent {
 
     private final MailboxPath mailboxPath;
-    private final long uid;
+    private final MessageUid uid;
 
-    public MessageDeletedEvent(MailboxPath mailboxPath, long uid) {
+    public MessageDeletedEvent(MailboxPath mailboxPath, MessageUid uid) {
         this.mailboxPath = mailboxPath;
         this.uid = uid;
     }
 
     @Override
-    public long getUid() {
+    public MessageUid getUid() {
         return uid;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
index 36417dd..6213afb 100644
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
+++ b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.indexer.registrations;
 import java.util.List;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.indexer.events.FlagsMessageEvent;
 import org.apache.james.mailbox.indexer.events.ImpactingMessageEvent;
 import org.apache.james.mailbox.indexer.events.MessageDeletedEvent;
@@ -35,11 +36,11 @@ import com.google.common.collect.Multimaps;
 
 public class MailboxRegistration implements MailboxListener {
 
-    private final Multimap<Long, ImpactingMessageEvent> impactingMessageEvents;
+    private final Multimap<MessageUid, ImpactingMessageEvent> impactingMessageEvents;
     private final MailboxPath mailboxPath;
 
     public MailboxRegistration(MailboxPath mailboxPath) {
-        this.impactingMessageEvents = Multimaps.synchronizedMultimap(ArrayListMultimap.<Long, ImpactingMessageEvent>create());
+        this.impactingMessageEvents = Multimaps.synchronizedMultimap(ArrayListMultimap.<MessageUid, ImpactingMessageEvent>create());
         this.mailboxPath = mailboxPath;
     }
 
@@ -53,7 +54,7 @@ public class MailboxRegistration implements MailboxListener {
         return ExecutionMode.SYNCHRONOUS;
     }
 
-    public List<ImpactingMessageEvent> getImpactingEvents(long uid) {
+    public List<ImpactingMessageEvent> getImpactingEvents(MessageUid uid) {
         return ImmutableList.copyOf(impactingMessageEvents.get(uid));
     }
 
@@ -64,7 +65,7 @@ public class MailboxRegistration implements MailboxListener {
                 impactingMessageEvents.put(updatedFlags.getUid(), new FlagsMessageEvent(mailboxPath, updatedFlags.getUid(), updatedFlags.getNewFlags()));
             }
         } else if (event instanceof Expunged) {
-            for (Long uid: ((Expunged) event).getUids()) {
+            for (MessageUid uid: ((Expunged) event).getUids()) {
                 impactingMessageEvents.put(uid, new MessageDeletedEvent(mailboxPath, uid));
             }
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
index dfa3b48..495e4bf 100644
--- a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
+++ b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
@@ -31,6 +31,7 @@ import java.util.Iterator;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -148,7 +149,7 @@ public class ReIndexerImplTest {
         when(user1MessageMapper.findInMailbox(user1Mailbox, MessageRange.all(), MessageMapper.FetchType.Full, ReIndexerImpl.NO_LIMIT))
             .thenReturn(ImmutableList.of(user1MailboxMessage).iterator());
         when(user1MailboxMessage.getUid())
-            .thenReturn(1l);
+            .thenReturn(MessageUid.of(1));
 
         when(mailboxManager.list(systemMailboxSession))
             .thenReturn(ImmutableList.of(user1MailboxPath));

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
index 0a84886..19f165c 100644
--- a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
+++ b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
@@ -27,6 +27,7 @@ import java.util.TreeMap;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.indexer.events.FlagsMessageEvent;
 import org.apache.james.mailbox.indexer.events.MessageDeletedEvent;
 import org.apache.james.mailbox.mock.MockMailboxSession;
@@ -44,7 +45,7 @@ import com.google.common.collect.Lists;
 public class MailboxRegistrationTest {
 
     public static final MailboxPath INBOX = new MailboxPath("#private", "btellier@apache.org", "INBOX");
-    public static final Long UID = 18L;
+    public static final MessageUid UID = MessageUid.of(18);
     public static final int UID_VALIDITY = 45;
     public static final SimpleMailbox MAILBOX = new SimpleMailbox(INBOX, UID_VALIDITY);
     public static final MockMailboxSession SESSION = new MockMailboxSession("test");
@@ -68,7 +69,7 @@ public class MailboxRegistrationTest {
 
     @Test
     public void AddedEventsShouldNotBeReported() {
-        TreeMap<Long, MessageMetaData> treeMap = new TreeMap<Long, MessageMetaData>();
+        TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<MessageUid, MessageMetaData>();
         treeMap.put(UID, new SimpleMessageMetaData(UID, MOD_SEQ, new Flags(), SIZE, new Date()));
         MailboxListener.Event event = eventFactory.added(SESSION, treeMap, MAILBOX);
         mailboxRegistration.event(event);
@@ -77,7 +78,7 @@ public class MailboxRegistrationTest {
 
     @Test
     public void ExpungedEventsShouldBeReported() {
-        TreeMap<Long, MessageMetaData> treeMap = new TreeMap<Long, MessageMetaData>();
+        TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<MessageUid, MessageMetaData>();
         treeMap.put(UID, new SimpleMessageMetaData(UID, MOD_SEQ, new Flags(), SIZE, new Date()));
         MailboxListener.Event event = eventFactory.expunged(SESSION, treeMap, MAILBOX);
         mailboxRegistration.event(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java b/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java
index 2720ae3..955b5c5 100644
--- a/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java
+++ b/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java
@@ -19,10 +19,12 @@
 package org.apache.james.mailbox.store.mail;
 
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.netflix.curator.RetryPolicy;
 import com.netflix.curator.framework.CuratorFramework;
@@ -53,14 +55,14 @@ public class ZooUidProvider implements UidProvider {
     }
 
     @Override
-    public long nextUid(MailboxSession session, Mailbox mailbox) throws MailboxException {
+    public MessageUid nextUid(MailboxSession session, Mailbox mailbox) throws MailboxException {
         if (client.getState() == CuratorFrameworkState.STARTED) {
             DistributedAtomicLong uid = new DistributedAtomicLong(client, pathForMailbox(mailbox), retryPolicy);
             try {
                 uid.increment();
                 AtomicValue<Long> value = uid.get();
                 if (value.succeeded()) {
-                    return value.postValue();
+                    return MessageUid.of(value.postValue());
                 }
             } catch (Exception e) {
                 throw new MailboxException("Exception incrementing UID for session " + session, e);
@@ -70,13 +72,17 @@ public class ZooUidProvider implements UidProvider {
     }
 
     @Override
-    public long lastUid(MailboxSession session, Mailbox mailbox) throws MailboxException {
+    public Optional<MessageUid> lastUid(MailboxSession session, Mailbox mailbox) throws MailboxException {
         if (client.getState() == CuratorFrameworkState.STARTED) {
             DistributedAtomicLong uid = new DistributedAtomicLong(client, pathForMailbox(mailbox), retryPolicy);
             try {
                 AtomicValue<Long> value = uid.get();
                 if (value.succeeded()) {
-                    return value.postValue();
+                    Long postValue = value.postValue();
+                    if (postValue == 0) {
+                        return Optional.absent();
+                    }
+                    return Optional.of(MessageUid.of(value.postValue()));
                 }
             } catch (Exception e) {
                 throw new MailboxException("Exception getting last UID for session " + session, e);

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java
----------------------------------------------------------------------
diff --git a/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java b/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java
index 2671c6a..26028b5 100644
--- a/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java
+++ b/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.UUID;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -29,6 +30,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.base.Optional;
 import com.netflix.curator.RetryPolicy;
 import com.netflix.curator.framework.CuratorFramework;
 import com.netflix.curator.framework.CuratorFrameworkFactory;
@@ -163,10 +165,10 @@ public class ZooUidProviderTest {
 	    @Test
 	    public void testNextUid() throws Exception {
 	        System.out.println("Testing nextUid");
-	        long result = uuidProvider.nextUid(null, mailboxUUID);
-	        assertEquals("Next UID is 1", 1, result);
+	        MessageUid result = uuidProvider.nextUid(null, mailboxUUID);
+	        assertEquals("Next UID is 1", 1, result.asLong());
 	        result = longProvider.nextUid(null, mailboxLong);
-	        assertEquals("Next UID is 1", 1, result);
+	        assertEquals("Next UID is 1", 1, result.asLong());
 	    }
 	
 	    /**
@@ -175,10 +177,10 @@ public class ZooUidProviderTest {
 	    @Test
 	    public void testLastUid() throws Exception {
 	        System.out.println("Testing lastUid");
-	        long result = uuidProvider.lastUid(null, mailboxUUID);
-	        assertEquals("Next UID is 0", 0, result);
-	        result = uuidProvider.nextUid(null, mailboxUUID);
-	        assertEquals("Next UID is 1", 1, result);
+	        Optional<MessageUid> result = uuidProvider.lastUid(null, mailboxUUID);
+	        assertEquals("Next UID is empty", Optional.absent(), result);
+	        MessageUid nextResult = uuidProvider.nextUid(null, mailboxUUID);
+	        assertEquals("Next UID is 1", 1, nextResult.asLong());
 	    }
 	
 	    /**
@@ -187,9 +189,9 @@ public class ZooUidProviderTest {
 	    @Test
 	    public void testLongLastUid() throws Exception {
 	        System.out.println("Testing long lastUid");
-	        long result = longProvider.lastUid(null, mailboxLong);
-	        assertEquals("Next UID is 0", 0, result);
-	        result = longProvider.nextUid(null, mailboxLong);
-	        assertEquals("Next UID is 1", 1, result);
+	        Optional<MessageUid> result = longProvider.lastUid(null, mailboxLong);
+	        assertEquals("Next UID is empty", Optional.absent(), result);
+	        MessageUid nextResult = longProvider.nextUid(null, mailboxLong);
+	        assertEquals("Next UID is 1", 1, nextResult.asLong());
 	    }
 	}

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/protocols/imap/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/imap/pom.xml b/protocols/imap/pom.xml
index 804ebda..91e7ac5 100644
--- a/protocols/imap/pom.xml
+++ b/protocols/imap/pom.xml
@@ -104,6 +104,12 @@
         <dependency>
             <groupId>org.jmock</groupId>
             <artifactId>jmock-junit4</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>junit</groupId>
+                    <artifactId>junit-dep</artifactId>
+                </exclusion>
+            </exclusions>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -122,6 +128,11 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>nl.jqno.equalsverifier</groupId>
+            <artifactId>equalsverifier</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
new file mode 100644
index 0000000..cf1455e
--- /dev/null
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
@@ -0,0 +1,148 @@
+/****************************************************************
+ * 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.imap.api.message;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MessageRange;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.TreeRangeSet;
+
+public final class UidRange implements Iterable<MessageUid> {
+
+    public static List<UidRange> mergeRanges(List<UidRange> ranges) {
+        if (ranges.isEmpty()) {
+            return ranges;
+        }
+
+        RangeSet<MessageUid> rangeSet = createSortedRangeSet(ranges);
+        List<Range<MessageUid>> mergedRanges = mergeContiguousRanges(rangeSet);
+        return toUidRanges(mergedRanges);
+    }
+
+    private static RangeSet<MessageUid> createSortedRangeSet(List<UidRange> ranges) {
+        RangeSet<MessageUid> rangeSet = TreeRangeSet.create();
+        for (UidRange range: ranges) {
+            rangeSet.add(Range.closed(range.getLowVal(), range.getHighVal()));
+        }
+        return rangeSet;
+    }
+
+    private static LinkedList<Range<MessageUid>> mergeContiguousRanges(RangeSet<MessageUid> rangeSet) {
+        LinkedList<Range<MessageUid>> mergedRanges = new LinkedList<Range<MessageUid>>();
+        
+        for (Range<MessageUid> range: rangeSet.asRanges()) {
+            Range<MessageUid> previous = mergedRanges.peekLast();
+            if (rangesShouldBeMerged(range, previous)) {
+                replaceLastRange(mergedRanges, mergeRanges(range, previous));
+            } else {
+                mergedRanges.add(range);
+            }
+        }
+        return mergedRanges;
+    }
+
+    private static boolean rangesShouldBeMerged(Range<MessageUid> range, Range<MessageUid> previous) {
+        return previous != null && previous.upperEndpoint().distance(range.lowerEndpoint()) <= 1;
+    }
+
+    private static void replaceLastRange(LinkedList<Range<MessageUid>> mergedRanges, Range<MessageUid> newRange) {
+        mergedRanges.removeLast();
+        mergedRanges.add(newRange);
+    }
+
+    private static Range<MessageUid> mergeRanges(Range<MessageUid> range, Range<MessageUid> previous) {
+        return Range.closed(previous.lowerEndpoint(), range.upperEndpoint());
+    }
+
+
+    private static LinkedList<UidRange> toUidRanges(List<Range<MessageUid>> mergedRanges) {
+        LinkedList<UidRange> result = new LinkedList<UidRange>();
+        for (Range<MessageUid> range: mergedRanges) {
+            result.add(new UidRange(range.lowerEndpoint(), range.upperEndpoint()));
+        }
+        return result;
+    }
+    
+    private final MessageRange range;
+
+    public UidRange(MessageUid singleVal) {
+        this.range = singleVal.toRange();
+    }
+
+    public UidRange(MessageUid minValue, MessageUid messageUid) {
+        if (minValue.compareTo(messageUid) > 0) {
+            throw new IllegalArgumentException("LowVal must be <= HighVal");
+        }
+        this.range = MessageRange.range(minValue, messageUid);
+    }
+
+    public MessageUid getLowVal() {
+        return range.getUidFrom();
+    }
+
+    public MessageUid getHighVal() {
+        return range.getUidTo();
+    }
+
+    public boolean includes(MessageUid value) {
+        return range.includes(value);
+    }
+
+    public int hashCode() {
+        return Objects.hashCode(range);
+    }
+
+    public boolean equals(Object obj) {
+        if (obj instanceof UidRange) {
+            UidRange other = (UidRange) obj;
+            return Objects.equal(this.range, other.range);
+        }
+        return false;
+    }
+
+    public String toString() {
+        return "IdRange : " + range.toString();
+    }
+
+    public String getFormattedString() {
+        if (range.getUidFrom().equals(range.getUidTo())) {
+            return String.valueOf(range.getUidFrom().asLong());
+        } else {
+            return String.format("%d:%d", range.getUidFrom().asLong(), range.getUidTo().asLong());
+        }
+    }
+
+    @Override
+    public Iterator<MessageUid> iterator() {
+        return range.iterator();
+    }
+
+    public MessageRange toMessageRange() {
+        return range;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
index d288a89..67fc626 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.api.message.UidRange;
 
 /**
  * Atom key used by a search. Build instances by factory methods.
@@ -31,8 +32,8 @@ import org.apache.james.imap.api.message.IdRange;
 public final class SearchKey {
 
     // NUMBERS
-    public static final int TYPE_SEQUENCE_SET = 1;
 
+    public static final int TYPE_SEQUENCE_SET = 1;
     public static final int TYPE_UID = 2;
 
     // NO PARAMETERS
@@ -118,41 +119,41 @@ public final class SearchKey {
 
     public static final int TYPE_MODSEQ = 40;
 
-    private static final SearchKey UNSEEN = new SearchKey(TYPE_UNSEEN, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey UNSEEN = new SearchKey(TYPE_UNSEEN, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey UNFLAGGED = new SearchKey(TYPE_UNFLAGGED, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey UNFLAGGED = new SearchKey(TYPE_UNFLAGGED, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey UNDRAFT = new SearchKey(TYPE_UNDRAFT, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey UNDRAFT = new SearchKey(TYPE_UNDRAFT, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey UNDELETED = new SearchKey(TYPE_UNDELETED, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey UNDELETED = new SearchKey(TYPE_UNDELETED, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey UNANSWERED = new SearchKey(TYPE_UNANSWERED, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey UNANSWERED = new SearchKey(TYPE_UNANSWERED, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey SEEN = new SearchKey(TYPE_SEEN, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey SEEN = new SearchKey(TYPE_SEEN, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey RECENT = new SearchKey(TYPE_RECENT, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey RECENT = new SearchKey(TYPE_RECENT, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey OLD = new SearchKey(TYPE_OLD, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey OLD = new SearchKey(TYPE_OLD, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey NEW = new SearchKey(TYPE_NEW, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey NEW = new SearchKey(TYPE_NEW, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey FLAGGED = new SearchKey(TYPE_FLAGGED, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey FLAGGED = new SearchKey(TYPE_FLAGGED, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey DRAFT = new SearchKey(TYPE_DRAFT, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey DRAFT = new SearchKey(TYPE_DRAFT, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey DELETED = new SearchKey(TYPE_DELETED, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey DELETED = new SearchKey(TYPE_DELETED, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey ANSWERED = new SearchKey(TYPE_ANSWERED, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey ANSWERED = new SearchKey(TYPE_ANSWERED, null, null, 0, null, null, null, null, -1, -1);
 
-    private static final SearchKey ALL = new SearchKey(TYPE_ALL, null, null, 0, null, null, null, -1, -1);
+    private static final SearchKey ALL = new SearchKey(TYPE_ALL, null, null, 0, null, null, null, null, -1, -1);
 
     // NUMBERS
     public static SearchKey buildSequenceSet(IdRange[] ids) {
-        return new SearchKey(TYPE_SEQUENCE_SET, null, null, 0, null, null, ids, -1, -1);
+        return new SearchKey(TYPE_SEQUENCE_SET, null, null, 0, null, null, null, ids, -1, -1);
     }
 
-    public static SearchKey buildUidSet(IdRange[] ids) {
-        return new SearchKey(TYPE_UID, null, null, 0, null, null, ids, -1, -1);
+    public static SearchKey buildUidSet(UidRange[] ids) {
+        return new SearchKey(TYPE_UID, null, null, 0, null, null, ids, null, -1, -1);
     }
 
     // NO PARAMETERS
@@ -214,94 +215,94 @@ public final class SearchKey {
 
     // ONE VALUE
     public static SearchKey buildBcc(String value) {
-        return new SearchKey(TYPE_BCC, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_BCC, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildBody(String value) {
-        return new SearchKey(TYPE_BODY, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_BODY, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildCc(String value) {
-        return new SearchKey(TYPE_CC, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_CC, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildFrom(String value) {
-        return new SearchKey(TYPE_FROM, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_FROM, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildKeyword(String value) {
-        return new SearchKey(TYPE_KEYWORD, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_KEYWORD, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildSubject(String value) {
-        return new SearchKey(TYPE_SUBJECT, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_SUBJECT, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildText(String value) {
-        return new SearchKey(TYPE_TEXT, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_TEXT, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildTo(String value) {
-        return new SearchKey(TYPE_TO, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_TO, null, null, 0, null, value, null, null, -1, -1);
     }
 
     public static SearchKey buildUnkeyword(String value) {
-        return new SearchKey(TYPE_UNKEYWORD, null, null, 0, null, value, null, -1, -1);
+        return new SearchKey(TYPE_UNKEYWORD, null, null, 0, null, value, null, null, -1, -1);
     }
     // ONE DATE
     public static SearchKey buildYounger(long seconds) {
-        return new SearchKey(TYPE_YOUNGER, null, null, 0, null, null, null, seconds, -1);
+        return new SearchKey(TYPE_YOUNGER, null, null, 0, null, null, null, null, seconds, -1);
     }
 
     public static SearchKey buildOlder(long seconds) {
-        return new SearchKey(TYPE_OLDER, null, null, 0, null, null, null, seconds, -1);
+        return new SearchKey(TYPE_OLDER, null, null, 0, null, null, null, null, seconds, -1);
     }
 
     
     // ONE DATE
     public static SearchKey buildBefore(DayMonthYear date) {
-        return new SearchKey(TYPE_BEFORE, date, null, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_BEFORE, date, null, 0, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildOn(DayMonthYear date) {
-        return new SearchKey(TYPE_ON, date, null, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_ON, date, null, 0, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildSentBefore(DayMonthYear date) {
-        return new SearchKey(TYPE_SENTBEFORE, date, null, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_SENTBEFORE, date, null, 0, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildSentOn(DayMonthYear date) {
-        return new SearchKey(TYPE_SENTON, date, null, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_SENTON, date, null, 0, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildSentSince(DayMonthYear date) {
-        return new SearchKey(TYPE_SENTSINCE, date, null, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_SENTSINCE, date, null, 0, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildSince(DayMonthYear date) {
-        return new SearchKey(TYPE_SINCE, date, null, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_SINCE, date, null, 0, null, null, null, null, -1, -1);
     }
 
     // FIELD VALUE
     public static SearchKey buildHeader(String name, String value) {
-        return new SearchKey(TYPE_HEADER, null, null, 0, name, value, null, -1, -1);
+        return new SearchKey(TYPE_HEADER, null, null, 0, name, value, null, null, -1, -1);
     }
 
     // ONE NUMBER
     public static SearchKey buildLarger(long size) {
-        return new SearchKey(TYPE_LARGER, null, null, size, null, null, null, -1, -1);
+        return new SearchKey(TYPE_LARGER, null, null, size, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildSmaller(long size) {
-        return new SearchKey(TYPE_SMALLER, null, null, size, null, null, null, -1, -1);
+        return new SearchKey(TYPE_SMALLER, null, null, size, null, null, null, null, -1, -1);
     }
 
     // NOT
     public static SearchKey buildNot(SearchKey key) {
         final List<SearchKey> keys = new ArrayList<SearchKey>();
         keys.add(key);
-        return new SearchKey(TYPE_NOT, null, keys, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_NOT, null, keys, 0, null, null, null, null, -1, -1);
     }
 
     // OR
@@ -309,7 +310,7 @@ public final class SearchKey {
         final List<SearchKey> keys = new ArrayList<SearchKey>();
         keys.add(keyOne);
         keys.add(keyTwo);
-        return new SearchKey(TYPE_OR, null, keys, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_OR, null, keys, 0, null, null, null, null, -1, -1);
     }
 
     /**
@@ -320,11 +321,11 @@ public final class SearchKey {
      * @return <code>SearchKey</code>, not null
      */
     public static SearchKey buildAnd(List<SearchKey> keys) {
-        return new SearchKey(TYPE_AND, null, keys, 0, null, null, null, -1, -1);
+        return new SearchKey(TYPE_AND, null, keys, 0, null, null, null, null, -1, -1);
     }
 
     public static SearchKey buildModSeq(long modSeq) {
-        return new SearchKey(TYPE_ANSWERED, null, null, 0, null, null, null, -1, modSeq);
+        return new SearchKey(TYPE_ANSWERED, null, null, 0, null, null, null, null, -1, modSeq);
     }
     private final int type;
 
@@ -339,24 +340,26 @@ public final class SearchKey {
     private final String value;
 
     private final IdRange[] sequence;
+    
+    private final UidRange[] uids;
 
     private final long seconds;
 
     private final long modSeq;
-
-    private SearchKey(int type, DayMonthYear date, List<SearchKey> keys, long number, String name, String value, IdRange[] sequence, long seconds, long modSeq) {
-        super();
+    
+    private SearchKey(int type, DayMonthYear date, List<SearchKey> keys, long number, String name, String value, UidRange[] uids, IdRange[] sequence, long seconds, long modSeq) {
         this.type = type;
         this.date = date;
         this.keys = keys;
         this.size = number;
         this.name = name;
         this.value = value;
-        this.sequence = sequence;
         this.seconds = seconds;
         this.modSeq = modSeq;
+        this.uids = uids;
+        this.sequence = sequence;
     }
-
+    
     /**
      * Gets a date value to be search upon.
      * 
@@ -387,6 +390,10 @@ public final class SearchKey {
         return sequence;
     }
 
+    public UidRange[] getUidRanges() {
+        return uids;
+    }
+    
     /**
      * Gets the field name.
      * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
index 6351cdb..2e5ee3b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
@@ -29,6 +29,8 @@ import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.MessageFlags;
+import org.apache.james.imap.api.message.UidRange;
+import org.apache.james.mailbox.MessageUid;
 
 /**
  * <p>
@@ -132,7 +134,7 @@ public interface StatusResponse extends ImapResponseMessage {
 
         
         /** RFC4315 <code>APPENDUID</code> response code */
-        public static ResponseCode appendUid(long uidValidity, IdRange[] uids) {
+        public static ResponseCode appendUid(long uidValidity, UidRange[] uids) {
             String uidParam = formatRanges(uids);
             return new ResponseCode("APPENDUID", Arrays.asList(uidParam), uidValidity, false);
         }
@@ -152,6 +154,13 @@ public interface StatusResponse extends ImapResponseMessage {
             return new ResponseCode("MODIFIED", Arrays.asList(new String[] { failed}), 0, false);
         }
         
+        /** RFC4551 <code>Conditional STORE</code> response code */
+        public static ResponseCode condStore(UidRange[] failedRanges) {
+            String failed = formatRanges(failedRanges);
+
+            return new ResponseCode("MODIFIED", Arrays.asList(new String[] { failed}), 0, false);
+        }
+        
         private static String formatRanges(IdRange[] ranges) {
             if (ranges == null || ranges.length == 0)
                 return "*";
@@ -165,6 +174,21 @@ public interface StatusResponse extends ImapResponseMessage {
             return rangeBuilder.toString();
         }
 
+        private static String formatRanges(UidRange[] ranges) {
+            if (ranges == null || ranges.length == 0) {
+                return "*";
+            }
+            StringBuilder rangeBuilder = new StringBuilder();
+            for (int i = 0; i < ranges.length; i++) {
+                rangeBuilder.append(ranges[i].getFormattedString());
+                if (i + 1 < ranges.length) {
+                    rangeBuilder.append(",");
+                }
+            }
+            return rangeBuilder.toString();
+        }
+
+        
         /**
          * Create a RFC5162 (QRESYNC) <code>CLOSED</code> response code
          * 
@@ -270,8 +294,8 @@ public interface StatusResponse extends ImapResponseMessage {
          *            positive non-zero integer
          * @return <code>ResponseCode</code>, not null
          */
-        public static ResponseCode uidNext(long uid) {
-            return new ResponseCode("UIDNEXT", uid);
+        public static ResponseCode uidNext(MessageUid uid) {
+            return new ResponseCode("UIDNEXT", uid.asLong());
         }
 
         

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
index ad1fdb3..9ff8261 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
@@ -23,8 +23,11 @@ import java.util.Collection;
 
 import javax.mail.Flags;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
 
+import com.google.common.base.Optional;
+
 /**
  * Interface which represent a selected Mailbox during the selected state
  */
@@ -40,43 +43,32 @@ public interface SelectedMailbox {
     /**
      * Return the msg index of the given uid or {@link #NO_SUCH_MESSAGE} if no
      * message with the given uid was found
-     * 
-     * @param uid
-     * @return index
      */
-    int msn(long uid);
+    int msn(MessageUid uid);
 
     /**
-     * Return the uid of the message for the given index or
-     * {@link #NO_SUCH_MESSAGE} if no message with the given index was found
-     * 
-     * @param index
-     * @return uid
+     * Return the uid of the message for the given index or empty if no message with the given index was found
      */
-    long uid(int index);
+    Optional<MessageUid> uid(int index);
 
     /**
      * Add a recent uid
      * 
-     * @param uid
      * @return true if it was successfully
      */
-    boolean addRecent(long uid);
+    boolean addRecent(MessageUid uid);
 
     /**
      * Remove a recent uid
      * 
-     * @param uid
      * @return true if it was successfully
      */
-    boolean removeRecent(long uid);
+    boolean removeRecent(MessageUid uid);
 
     /**
      * Return a Collection of all recent uids
-     * 
-     * @return recentUids
      */
-    Collection<Long> getRecent();
+    Collection<MessageUid> getRecent();
 
     /**
      * Return the count of all recent uids
@@ -102,10 +94,9 @@ public interface SelectedMailbox {
     /**
      * Is the given uid recent ?
      * 
-     * @param uid
      * @return true if the given uid is recent
      */
-    boolean isRecent(long uid);
+    boolean isRecent(MessageUid uid);
 
     /**
      * Is the mailbox deleted?
@@ -142,10 +133,8 @@ public interface SelectedMailbox {
 
     /**
      * Return a Collection which holds all uids which were expunged
-     * 
-     * @return expungedUids
      */
-    Collection<Long> expungedUids();
+    Collection<MessageUid> expungedUids();
 
     
     void resetExpungedUids();
@@ -159,31 +148,25 @@ public interface SelectedMailbox {
      *         {@link #NO_SUCH_MESSAGE} if no message with the given uid was
      *         found being expunged
      */
-    int remove(Long uid);
+    int remove(MessageUid uid);
 
     /**
      * Return a Collection which holds all uids reflecting the Messages which
      * flags were updated
-     * 
-     * @return flagsUids
      */
-    Collection<Long> flagUpdateUids();
+    Collection<MessageUid> flagUpdateUids();
 
     /**
-     * Return the uid of the first message in the mailbox or -1 if the mailbox
+     * Return the uid of the first message in the mailbox or empty if the mailbox
      * is empty
-     * 
-     * @return firstUid
      */
-    long getFirstUid();
+    Optional<MessageUid> getFirstUid();
 
     /**
-     * Return the uid of the last message in the mailbox or -1 if the mailbox is
+     * Return the uid of the last message in the mailbox or empty if the mailbox is
      * empty
-     * 
-     * @return lastUid
      */
-    long getLastUid();
+    Optional<MessageUid> getLastUid();
     
     /**
      * Return all applicable Flags for the selected mailbox


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


Mime
View raw message