Author: norman
Date: Tue Sep 14 05:39:31 2010
New Revision: 996760

URL: http://svn.apache.org/viewvc?rev=996760&view=rev
Log:
Handle unknown uid or msn ranges in Copy,Search,Store and Fetch commands, now 
it really acts like dovecot and respect MSN and UID (IMAP-209)

Modified:
    
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
    
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
    
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
    
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
    
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/UidToMsnConverter.java

Modified: 
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java?rev=996760&r1=996759&r2=996760&view=diff
==============================================================================
--- 
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
 (original)
+++ 
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
 Tue Sep 14 05:39:31 2010
@@ -151,4 +151,18 @@ public interface SelectedMailbox {
      * @return flagsUids
      */
     public Collection<Long> flagUpdateUids();
+    
+    /**
+     * Return the uid of the first message in the mailbox or -1 if the mailbox 
is empty
+     * 
+     * @return firstUid
+     */
+    public long getFirstUid();
+    
+    /**
+     * Return the uid of the last message in the mailbox or -1 if the mailbox 
is empty
+     * 
+     * @return lastUid
+     */
+    public long getLastUid();
 }
\ No newline at end of file

Modified: 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java?rev=996760&r1=996759&r2=996760&view=diff
==============================================================================
--- 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
 (original)
+++ 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
 Tue Sep 14 05:39:31 2010
@@ -373,6 +373,7 @@ abstract public class AbstractMailboxPro
     protected MessageRange messageRange(SelectedMailbox selected, IdRange 
range, boolean useUids) throws MessageRangeException {
         long lowVal = range.getLowVal();
         long highVal = range.getHighVal();
+      
         if (useUids == false) {
             if (lowVal != Long.MAX_VALUE) {
                 lowVal = selected.uid((int) lowVal);
@@ -384,6 +385,15 @@ abstract public class AbstractMailboxPro
                 if (highVal == SelectedMailbox.NO_SUCH_MESSAGE)
                     throw new MessageRangeException("No message found with msn 
" + highVal);
             }
+        } else {
+            
+               if (lowVal != Long.MAX_VALUE && lowVal < 
selected.getFirstUid()) {
+                throw new MessageRangeException("No message found with uid " + 
lowVal);
+               } 
+               
+               if (highVal != Long.MAX_VALUE && highVal > 
selected.getLastUid()) {
+                throw new MessageRangeException("No message found with uid " + 
highVal);
+               } 
         }
         MessageRange mRange = MessageRange.range(lowVal, highVal);
         return mRange;

Modified: 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SearchProcessor.java?rev=996760&r1=996759&r2=996760&view=diff
==============================================================================
--- 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
 (original)
+++ 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
 Tue Sep 14 05:39:31 2010
@@ -98,6 +98,7 @@ public class SearchProcessor extends Abs
     private Collection<Long> findIds(final boolean useUids,
             final ImapSession session, MessageManager mailbox, final 
SearchQuery query)
             throws MailboxException, MessageRangeException {
+       
         final Iterator<Long> it = mailbox.search(query, ImapSessionUtils
                 .getMailboxSession(session));
 
@@ -237,8 +238,9 @@ public class SearchProcessor extends Abs
             final long lowVal = range.getLowVal();
             final long lowUid;
             final long highUid;
+            final SelectedMailbox selected = session.getSelected();
+
             if (msn) {
-                final SelectedMailbox selected = session.getSelected();
                 if (highVal == Long.MAX_VALUE) {
                     highUid = Long.MAX_VALUE;
                 } else {
@@ -257,6 +259,15 @@ public class SearchProcessor extends Abs
             } else {
                 lowUid = lowVal;
                 highUid = highVal;
+                
+                
+               if (lowVal != Long.MAX_VALUE && lowVal < 
selected.getFirstUid()) {
+                    throw new MessageRangeException("No message found with uid 
" + lowVal);
+               } 
+               
+               if (highVal != Long.MAX_VALUE && highVal > 
selected.getLastUid()) {
+                    throw new MessageRangeException("No message found with uid 
" + highVal);
+               } 
             }
             ranges[i] = new SearchQuery.NumericRange(lowUid, highUid);
         }

Modified: 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java?rev=996760&r1=996759&r2=996760&view=diff
==============================================================================
--- 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
 (original)
+++ 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
 Tue Sep 14 05:39:31 2010
@@ -208,4 +208,20 @@ public class SelectedMailboxImpl impleme
     public Collection<Long> flagUpdateUids() {
         return events.flagUpdateUids();
     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.api.process.SelectedMailbox#getFirstUid()
+     */
+       public long getFirstUid() {
+               return converter.getFirstUid();
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.apache.james.imap.api.process.SelectedMailbox#getLastUid()
+        */
+       public long getLastUid() {
+               return converter.getLastUid();
+       }
 }

Modified: 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/UidToMsnConverter.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/UidToMsnConverter.java?rev=996760&r1=996759&r2=996760&view=diff
==============================================================================
--- 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/UidToMsnConverter.java
 (original)
+++ 
james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/UidToMsnConverter.java
 Tue Sep 14 05:39:31 2010
@@ -78,11 +78,7 @@ public class UidToMsnConverter implement
         if (uid != null) {
             return uid.longValue();
         } else {
-            if (msn > 0) {
-                return highestUid;
-            } else {
-                return 0;
-            }
+            return SelectedMailbox.NO_SUCH_MESSAGE;
         }
     }
 
@@ -156,6 +152,29 @@ public class UidToMsnConverter implement
         }
     }
 
+    
+    /**
+     * @see SelectedMailbox#getFirstUid()
+     */
+    public synchronized long getFirstUid() {
+       if (uidToMsn.isEmpty()) {
+               return -1;
+       } else {
+               return uidToMsn.firstKey();
+       }
+    }
+    
+    
+    /**
+     * @see SelectedMailbox#getLastUid()
+     */
+    public synchronized long getLastUid() {
+       if (uidToMsn.isEmpty()) {
+               return -1;
+       } else {
+               return uidToMsn.lastKey();
+       }
+    }
     /**
      * Close this {...@link MailboxListener}
      */



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to