james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r773263 - in /james/imap/trunk: mailbox/src/main/java/org/apache/james/imap/mailbox/ processor/src/main/java/org/apache/james/imap/processor/ store/src/main/java/org/apache/james/imap/store/ torque/src/main/java/org/apache/james/mailboxmana...
Date Sat, 09 May 2009 19:21:06 GMT
Author: rdonkin
Date: Sat May  9 19:21:05 2009
New Revision: 773263

URL: http://svn.apache.org/viewvc?rev=773263&view=rev
Log:
Consolidate unseen into a single MetaData for the Mailbox. Differences between STATUS and
SELECT/EXAMINE mean that a FetchGroup needed to be created. IMAP-79 https://issues.apache.org/jira/browse/IMAP-79

Modified:
    james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MailboxMetaData.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MailboxMetaData.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java

Modified: james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java (original)
+++ james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java Sat
May  9 19:21:05 2009
@@ -47,17 +47,6 @@
      */
     Iterator<Long> search(SearchQuery searchQuery, MailboxSession mailboxSession) throws
MailboxException;
 
-    int getUnseenCount(MailboxSession mailboxSession) throws MailboxException;
-
-    /**
-     * Gets the UID of the first unseen message.
-     * @param mailboxSession not null
-     * @return uid of the first unseen message,
-     * or null when there are no unseen messages
-     * @throws MailboxException 
-     */
-    Long getFirstUnseen(MailboxSession mailboxSession) throws MailboxException;
-
     /**
      * Expunges messages in the given range from this mailbox.
      * @param set not null
@@ -106,7 +95,8 @@
      * @return MessageResult with the fields defined by FetchGroup
      * @throws MailboxException
      */
-    Iterator<MessageResult> getMessages(MessageRange set, FetchGroup fetchGroup, MailboxSession
mailboxSession) throws MailboxException;
+    Iterator<MessageResult> getMessages(MessageRange set, FetchGroup fetchGroup, 
+            MailboxSession mailboxSession) throws MailboxException;
     
     /**
      * Gets current meta data for the mailbox.
@@ -116,10 +106,11 @@
      * @param resetRecent true when recent flags should be reset,
      * false otherwise
      * @param mailboxSession context, not null
+     * @param fetchGroup describes which optional data should be returned
      * @return meta data, not null
      * @throws MailboxException
      */
-    MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession) throws MailboxException;
+    MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession, Mailbox.MetaData.FetchGroup
fetchGroup) throws MailboxException;
     
     /**
      * Meta data about the current state of the mailbox.
@@ -127,6 +118,13 @@
     public interface MetaData {
         
         /**
+         * Describes the optional data types.
+         */
+        public enum FetchGroup {
+            NO_UNSEEN, UNSEEN_COUNT, FIRST_UNSEEN
+        };
+        
+        /**
          * Gets the UIDs of recent messages. 
          * @return the uids flagged RECENT in this mailbox, 
          * or null when there are no recent uids
@@ -156,7 +154,6 @@
          * Gets the next UID predicted.
          * @param mailboxSession not null
          * @return the uid that will be assigned to the next appended message
-         * @throws MailboxException
          */
         long getUidNext();
         
@@ -165,5 +162,23 @@
          * @return number of messages contained
          */
         int getMessageCount();
+        
+        /**
+         * Gets the number of unseen messages contained in this mailbox.
+         * This is an optional property.
+         * @return number of unseen messages contained 
+         * or zero when this optional data has not been requested
+         * @see FetchGroup#UNSEEN_COUNT
+         */
+        int getUnseenCount();
+        
+        /**
+         * Gets the UID of the first unseen message.
+         * This is an optional property.
+         * @return uid of the first unseen message,
+         * or null when there are no unseen messages
+         * @see FetchGroup#FIRST_UNSEEN
+         */
+        Long getFirstUnseen();
     }
 }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
Sat May  9 19:21:05 2009
@@ -94,17 +94,13 @@
             final Mailbox.MetaData metaData, Responder responder) throws MailboxException
{
 
         Mailbox mailbox = getSelectedMailbox(session);
-        final MailboxSession mailboxSession = ImapSessionUtils
-                .getMailboxSession(session);
         final SelectedMailbox selected = session.getSelected();
-
-        // TODO: compact this into a single API call for meta-data about the
-        // repository
+        
         flags(responder);
         exists(responder, metaData);
         recent(responder, selected);
         uidValidity(responder, metaData);
-        unseen(responder, mailbox, mailboxSession, selected);
+        unseen(responder, metaData, selected);
         permanentFlags(responder, metaData);
         uidNext(responder, metaData);
         taggedOk(responder, tag, command, mailbox);
@@ -144,10 +140,9 @@
         responder.respond(untaggedOk);
     }
 
-    private void unseen(Responder responder, Mailbox mailbox,
-            final MailboxSession mailboxSession,
+    private void unseen(Responder responder, Mailbox.MetaData metaData,
             final SelectedMailbox selected) throws MailboxException {
-        final Long firstUnseen = mailbox.getFirstUnseen(mailboxSession);
+        final Long firstUnseen = metaData.getFirstUnseen();
         if (firstUnseen != null) {
             final long unseenUid = firstUnseen;
             int msn = selected.msn(unseenUid);
@@ -193,7 +188,7 @@
         } else {
             sessionMailbox = currentMailbox;
         }
-        final Mailbox.MetaData metaData = mailbox.getMetaData(!openReadOnly, mailboxSession);
+        final Mailbox.MetaData metaData = mailbox.getMetaData(!openReadOnly, mailboxSession,
Mailbox.MetaData.FetchGroup.FIRST_UNSEEN);
         addRecent(metaData, sessionMailbox);
         return metaData;
     }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
Sat May  9 19:21:05 2009
@@ -67,13 +67,19 @@
 
             final MailboxManager mailboxManager = getMailboxManager();
             final Mailbox mailbox = mailboxManager.getMailbox(fullMailboxName, ImapSessionUtils.getMailboxSession(session));
-            final Mailbox.MetaData metaData = mailbox.getMetaData(false, mailboxSession);
+            final Mailbox.MetaData.FetchGroup fetchGroup;
+            if (statusDataItems.isUnseen()) {
+                fetchGroup = Mailbox.MetaData.FetchGroup.UNSEEN_COUNT;
+            } else {
+                fetchGroup = Mailbox.MetaData.FetchGroup.NO_UNSEEN;
+            }
+            final Mailbox.MetaData metaData = mailbox.getMetaData(false, mailboxSession,
fetchGroup);
             
             final Long messages = messages(statusDataItems, metaData);
             final Long recent = recent(statusDataItems, metaData);
             final Long uidNext = uidNext(statusDataItems, metaData);
             final Long uidValidity = uidValidity(statusDataItems, metaData);
-            final Long unseen = unseen(statusDataItems, mailboxSession, mailbox);
+            final Long unseen = unseen(statusDataItems, metaData);
 
             final MailboxStatusResponse response = new MailboxStatusResponse(messages,
                     recent, uidNext, uidValidity, unseen, mailboxName);
@@ -87,11 +93,11 @@
     }
 
     private Long unseen(final StatusDataItems statusDataItems,
-            final MailboxSession mailboxSession, final Mailbox mailbox)
+            final Mailbox.MetaData metaData)
             throws MailboxException {
         final Long unseen;
         if (statusDataItems.isUnseen()) {
-            final int unseenCountValue = mailbox.getUnseenCount(mailboxSession);
+            final int unseenCountValue = metaData.getUnseenCount();
             unseen = new Long(unseenCountValue);
         } else {
             unseen = null;

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MailboxMetaData.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MailboxMetaData.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MailboxMetaData.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MailboxMetaData.java
Sat May  9 19:21:05 2009
@@ -35,9 +35,11 @@
     private final long uidValidity;
     private final long nextUid;
     private final int messageCount;
+    private final int unseenCount;
+    private final Long firstUnseen;
     
     public MailboxMetaData(final long[] recent, final Flags premanentFlags, final long uidValidity,
final long nextUid,
-            final int messageCount) {
+            final int messageCount, final int unseenCount, final Long firstUnseen) {
         super();
         if (recent == null) {
             recentCount = 0;
@@ -49,6 +51,8 @@
         this.uidValidity = uidValidity;
         this.nextUid = nextUid;
         this.messageCount = messageCount;
+        this.unseenCount = unseenCount;
+        this.firstUnseen = firstUnseen;
     }
 
     /**
@@ -86,7 +90,21 @@
         return nextUid;
     }
 
+    /**
+     * @see {@link Mailbox.MetaData#getMessageCount()}
+     */
     public int getMessageCount() {
         return messageCount;
     }
+
+    /**
+     * @see {@link Mailbox.MetaData#getUnseenCount()}
+     */
+    public int getUnseenCount() {
+        return unseenCount;
+    }
+
+    public Long getFirstUnseen() {
+        return firstUnseen;
+    }
 }

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java Sat
May  9 19:21:05 2009
@@ -471,14 +471,32 @@
     }
     
     /**
-     * @see {@link Mailbox#getMetaData(boolean, MailboxSession)}
+     * @see {@link Mailbox#getMetaData(boolean, MailboxSession, FetchGroup)}
      */
-    public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession) throws
MailboxException {
+    public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession, 
+            org.apache.james.imap.mailbox.Mailbox.MetaData.FetchGroup fetchGroup) throws
MailboxException {
         final long[] recent = recent(resetRecent, mailboxSession);
         final Flags permanentFlags = getPermanentFlags();
         final long uidValidity = getUidValidity(mailboxSession);
         final long uidNext = getUidNext(mailboxSession);
         final int messageCount = getMessageCount(mailboxSession);
-        return new MailboxMetaData(recent, permanentFlags, uidValidity, uidNext, messageCount);
+        final int unseenCount;
+        final Long firstUnseen;
+        switch (fetchGroup) {
+            case UNSEEN_COUNT:
+                unseenCount = getUnseenCount(mailboxSession);
+                firstUnseen = null;
+                break;
+            case FIRST_UNSEEN:
+                firstUnseen = getFirstUnseen(mailboxSession);
+                unseenCount = 0;
+                break;
+            default:
+                firstUnseen = null;
+                unseenCount = 0;
+                break;
+        }
+            
+        return new MailboxMetaData(recent, permanentFlags, uidValidity, uidNext, messageCount,
unseenCount, firstUnseen);
     }
 }

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MailboxMetaData.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MailboxMetaData.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MailboxMetaData.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MailboxMetaData.java
Sat May  9 19:21:05 2009
@@ -23,7 +23,6 @@
 
 import org.apache.james.imap.mailbox.Mailbox;
 
-
 /**
  * Describes the current state of a mailbox.
  */
@@ -35,9 +34,11 @@
     private final long uidValidity;
     private final long nextUid;
     private final int messageCount;
+    private final int unseenCount;
+    private final Long firstUnseen;
     
     public MailboxMetaData(final long[] recent, final Flags premanentFlags, final long uidValidity,
final long nextUid,
-            final int messageCount) {
+            final int messageCount, final int unseenCount, final Long firstUnseen) {
         super();
         if (recent == null) {
             recentCount = 0;
@@ -49,6 +50,8 @@
         this.uidValidity = uidValidity;
         this.nextUid = nextUid;
         this.messageCount = messageCount;
+        this.unseenCount = unseenCount;
+        this.firstUnseen = firstUnseen;
     }
 
     /**
@@ -86,7 +89,21 @@
         return nextUid;
     }
 
+    /**
+     * @see {@link Mailbox.MetaData#getMessageCount()}
+     */
     public int getMessageCount() {
         return messageCount;
     }
+
+    /**
+     * @see {@link Mailbox.MetaData#getUnseenCount()}
+     */
+    public int getUnseenCount() {
+        return unseenCount;
+    }
+
+    public Long getFirstUnseen() {
+        return firstUnseen;
+    }
 }

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=773263&r1=773262&r2=773263&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
Sat May  9 19:21:05 2009
@@ -809,14 +809,31 @@
     }
 
     /**
-     * @see {@link Mailbox#getMetaData(boolean, MailboxSession)}
+     * @see {@link Mailbox#getMetaData(boolean, MailboxSession, FetchGroup)}
      */
-    public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession) throws
MailboxException {
+    public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession, Mailbox.MetaData.FetchGroup
fetchGroup) throws MailboxException {
         final long[] recent = recent(resetRecent, mailboxSession);
         final Flags permanentFlags = getPermanentFlags();
         final long uidValidity = getUidValidity(mailboxSession);
         final long uidNext = getUidNext(mailboxSession);
         final int messageCount = getMessageCount(mailboxSession);
-        return new MailboxMetaData(recent, permanentFlags, uidValidity, uidNext, messageCount);
+        final int unseenCount;
+        final Long firstUnseen;
+        switch (fetchGroup) {
+            case UNSEEN_COUNT:
+                unseenCount = getUnseenCount(mailboxSession);
+                firstUnseen = null;
+                break;
+            case FIRST_UNSEEN:
+                firstUnseen = getFirstUnseen(mailboxSession);
+                unseenCount = 0;
+                break;
+            default:
+                firstUnseen = null;
+                unseenCount = 0;
+                break;
+        }
+            
+        return new MailboxMetaData(recent, permanentFlags, uidValidity, uidNext, messageCount,
unseenCount, firstUnseen);
     }
 }



---------------------------------------------------------------------
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