james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1722878 - in /james/project/trunk/server/protocols/jmap/src: main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
Date Mon, 04 Jan 2016 14:12:44 GMT
Author: matthieu
Date: Mon Jan  4 14:12:44 2016
New Revision: 1722878

URL: http://svn.apache.org/viewvc?rev=1722878&view=rev
Log:
JAMES-1650 Provide messages count (total and unread) in GetMailboxes response. Contributed
by Vignon <fvignon@linagora.com>

Modified:
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java?rev=1722878&r1=1722877&r2=1722878&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
Mon Jan  4 14:12:44 2016
@@ -30,9 +30,9 @@ import org.apache.james.jmap.model.mailb
 import org.apache.james.jmap.model.mailbox.SortOrder;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
@@ -98,11 +98,13 @@ public class GetMailboxesMethod<Id exten
     private Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession
mailboxSession) {
         try {
             Optional<Role> role = Role.from(mailboxPath.getName());
+            MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailboxPath, mailboxSession);
             return Optional.ofNullable(Mailbox.builder()
                     .id(getMailboxId(mailboxPath, mailboxSession))
                     .name(mailboxPath.getName())
                     .role(role)
-                    .unreadMessages(unreadMessages(mailboxPath, mailboxSession))
+                    .unreadMessages(mailboxMetaData.getUnseenCount())
+                    .totalMessages(mailboxMetaData.getMessageCount())
                     .sortOrder(SortOrder.getSortOrder(role))
                     .build());
         } catch (MailboxException e) {
@@ -111,17 +113,16 @@ public class GetMailboxesMethod<Id exten
         }
     }
 
-    private String getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws
MailboxException, MailboxNotFoundException {
+    private String getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws
MailboxException {
         return mailboxMapperFactory.getMailboxMapper(mailboxSession)
                 .findMailboxByPath(mailboxPath)
                 .getMailboxId()
                 .serialize();
     }
 
-    private long unreadMessages(MailboxPath mailboxPath, MailboxSession mailboxSession) throws
MailboxException {
+    private MessageManager.MetaData getMailboxMetaData(MailboxPath mailboxPath, MailboxSession
mailboxSession) throws MailboxException {
         return mailboxManager.getMailbox(mailboxPath, mailboxSession)
-                .getMetaData(DONT_RESET_RECENT, mailboxSession, FetchGroup.UNSEEN_COUNT)
-                .getUnseenCount();
+                .getMetaData(DONT_RESET_RECENT, mailboxSession, FetchGroup.UNSEEN_COUNT);
     }
 
 }

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java?rev=1722878&r1=1722877&r2=1722878&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
Mon Jan  4 14:12:44 2016
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.acl.Grou
 import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -167,4 +168,56 @@ public class GetMailboxesMethodTest {
                         Tuple.tuple("TEMPLATES", 80));
     }
 
-}
+    @Test
+    public void getMailboxesShouldReturnEmptyMailboxByDefault() throws MailboxException {
+        MailboxPath mailboxPath = new MailboxPath("#private", USERNAME, "name");
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+
+        GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
+                .build();
+
+        GetMailboxesResponse getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
mailboxSession);
+        assertThat(getMailboxesResponse.getList())
+                .extracting(Mailbox::getTotalMessages, Mailbox::getUnreadMessages)
+                .containsOnly(Tuple.tuple(0L, 0L));
+    }
+
+    @Test
+    public void getMailboxesShouldReturnCorrectTotalMessagesCount() throws MailboxException
{
+        MailboxPath mailboxPath = new MailboxPath("#private", USERNAME, "name");
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+        MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+        messageManager.appendMessage(new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+
+        GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
+                .build();
+
+        GetMailboxesResponse getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
mailboxSession);
+        assertThat(getMailboxesResponse.getList())
+                .extracting(Mailbox::getTotalMessages)
+                .containsExactly(2L);
+    }
+
+    @Test
+    public void getMailboxesShouldReturnCorrectUnreadMessagesCount() throws MailboxException
{
+        MailboxPath mailboxPath = new MailboxPath("#private", USERNAME, "name");
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+        MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+        Flags defaultUnseenFlag = new Flags();
+        Flags readMessageFlag = new Flags();
+        readMessageFlag.add(Flags.Flag.SEEN);
+        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, defaultUnseenFlag );
+        messageManager.appendMessage(new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, defaultUnseenFlag );
+        messageManager.appendMessage(new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, readMessageFlag);
+        GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
+                .build();
+        GetMailboxesResponse getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
mailboxSession);
+        assertThat(getMailboxesResponse.getList())
+                .extracting(Mailbox::getUnreadMessages)
+                .containsExactly(2L);
+    }
+}
\ 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


Mime
View raw message