JAMES-1874 GetMailboxes should not rely at all on the entire list of recent UIDs
Message manager should offer a way to get only the part of the Metadata we want. My work implied de-deprecating a method. I checked it was not called. I believe it was deprecated to force IMAP implementation to use IMAP business object. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/82c934e3 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/82c934e3 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/82c934e3 Branch: refs/heads/master Commit: 82c934e3c12c00e4fda1235fcc81bfca596bd391 Parents: 0054b41 Author: Benoit Tellier <btell...@linagora.com> Authored: Fri Feb 3 10:14:42 2017 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Tue Feb 7 08:57:45 2017 +0700 ---------------------------------------------------------------------- .../java/org/apache/james/mailbox/MessageManager.java | 14 ++++++++++---- .../james/mailbox/store/StoreMessageManager.java | 6 ++++++ .../imap/processor/base/MailboxEventAnalyserTest.java | 6 +++++- .../org/apache/james/jmap/model/MailboxFactory.java | 10 ++-------- 4 files changed, 23 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/82c934e3/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java index 1dc4c33..572c438 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java @@ -53,18 +53,24 @@ public interface MessageManager { } /** - * Return the count + * Return the count of messages in the mailbox * * @param mailboxSession * @return count * @throws MailboxException - * @deprecated use - * {@link #getMetaData(boolean, MailboxSession, org.apache.james.mailbox.MessageManager.MetaData.FetchGroup)} */ - @Deprecated long getMessageCount(MailboxSession mailboxSession) throws MailboxException; /** + * Return the count of unseen messages in the mailbox + * + * @param mailboxSession + * @return count + * @throws MailboxException + */ + long getUnseenMessageCount(MailboxSession mailboxSession) throws MailboxException; + + /** * Return if the Mailbox is writable * * @param session http://git-wip-us.apache.org/repos/asf/james-project/blob/82c934e3/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java index 4a394d3..a7febbe 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java @@ -230,6 +230,12 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana return new Flags(MINIMAL_PERMANET_FLAGS); } + @Override + public long getUnseenMessageCount(MailboxSession mailboxSession) throws MailboxException { + return mapperFactory.createMessageMapper(mailboxSession) + .countUnseenMessagesInMailbox(mailbox); + } + /** * Returns the flags which are shared for the current mailbox, i.e. the * flags set up so that changes to those flags are visible to another user. http://git-wip-us.apache.org/repos/asf/james-project/blob/82c934e3/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java index f68f9dd..abc895a 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java @@ -173,7 +173,11 @@ public class MailboxEventAnalyserTest { public MessageManager getMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException { return new MessageManager() { - + @Override + public long getUnseenMessageCount(MailboxSession mailboxSession) throws MailboxException { + return 0; + } + public long getMessageCount(MailboxSession mailboxSession) throws MailboxException { return 1; } http://git-wip-us.apache.org/repos/asf/james-project/blob/82c934e3/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java index 7ac9e42..352eafc 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java @@ -39,7 +39,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Splitter; public class MailboxFactory { - private static final boolean DONT_RESET_RECENT = false; private static final Logger LOGGER = LoggerFactory.getLogger(MailboxFactory.class); private final MailboxManager mailboxManager; @@ -71,22 +70,17 @@ public class MailboxFactory { private Optional<Mailbox> fromMessageManager(MessageManager messageManager, MailboxSession mailboxSession) throws MailboxException { MailboxPath mailboxPath = messageManager.getMailboxPath(); Optional<Role> role = Role.from(mailboxPath.getName()); - MessageManager.MetaData mailboxMetaData = getMailboxMetaData(messageManager, mailboxSession); return Optional.ofNullable(Mailbox.builder() .id(messageManager.getId()) .name(getName(mailboxPath, mailboxSession)) .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).orElse(null)) .role(role) - .unreadMessages(mailboxMetaData.getUnseenCount()) - .totalMessages(mailboxMetaData.getMessageCount()) + .unreadMessages(messageManager.getUnseenMessageCount(mailboxSession)) + .totalMessages(messageManager.getMessageCount(mailboxSession)) .sortOrder(SortOrder.getSortOrder(role)) .build()); } - private MessageManager.MetaData getMailboxMetaData(MessageManager messageManager, MailboxSession mailboxSession) throws MailboxException { - return messageManager.getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT); - } - @VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession) { String name = mailboxPath.getName(); if (name.contains(String.valueOf(mailboxSession.getPathDelimiter()))) { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org