You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2008/03/29 23:10:11 UTC

svn commit: r642626 - in /james/server/trunk: experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/ imap-api/src/main/java/...

Author: rdonkin
Date: Sat Mar 29 15:10:09 2008
New Revision: 642626

URL: http://svn.apache.org/viewvc?rev=642626&view=rev
Log:
Partial FETCH fixes and tests. Also RECENT fixes.

Added:
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestPartialFetch.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/ExperimentalPartialFetchTest.java
Modified:
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/FileProtocolSessionBuilder.java
    james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/AppendSelectInbox.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/BodyPartialFetch.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchBodyNoSection.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFields.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFieldsNot.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartAlternative.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixed.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixedComplex.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchPeek.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822Text.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchText.test
    james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/Store.test
    james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
    james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElement.java
    james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElementTest.java

Added: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestPartialFetch.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestPartialFetch.java?rev=642626&view=auto
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestPartialFetch.java (added)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestPartialFetch.java Sat Mar 29 15:10:09 2008
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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.test.functional.imap;
+
+import java.util.Locale;
+
+public abstract class AbstractTestPartialFetch extends BaseTestSelectedState {
+
+    public AbstractTestPartialFetch(HostSystem system) {
+        super(system);
+    }
+    
+    public void testBodyPartialFetchUS() throws Exception {
+        scriptTest("BodyPartialFetch", Locale.US);
+    }
+}

Modified: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/FileProtocolSessionBuilder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/FileProtocolSessionBuilder.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/FileProtocolSessionBuilder.java (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/FileProtocolSessionBuilder.java Sat Mar 29 15:10:09 2008
@@ -90,6 +90,7 @@
         BufferedReader reader = new BufferedReader( new InputStreamReader( is ) );
         String next;
         int lineNumber = -1;
+        String lastClientMsg = "";
         while ( ( next = reader.readLine() ) != null ) {
             String location = fileName + ":" + lineNumber;
             if (SERVER_CONTINUATION_TAG.equals(next)) {
@@ -100,13 +101,14 @@
                     clientMsg = next.substring( 3 );
                 }
                 session.CL( sessionNumber, clientMsg );
+                lastClientMsg = clientMsg;
             }
             else if ( next.startsWith( SERVER_TAG ) ) {
                 String serverMsg = "";
                 if ( next.length() > 3 ) {
                     serverMsg = next.substring( 3 );
                 }
-                session.SL( sessionNumber, serverMsg, location );
+                session.SL( sessionNumber, serverMsg, location, lastClientMsg );
             }
             else if ( next.startsWith( OPEN_UNORDERED_BLOCK_TAG ) ) {
                 List unorderedLines = new ArrayList( 5 );
@@ -122,7 +124,7 @@
                     lineNumber++;
                 }
 
-                session.SUB( sessionNumber, unorderedLines, location );
+                session.SUB( sessionNumber, unorderedLines, location, lastClientMsg );
             }
             else if ( next.startsWith( COMMENT_TAG )
                     || next.trim().length() == 0 ) {

Modified: james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/ProtocolSession.java Sat Mar 29 15:10:09 2008
@@ -159,19 +159,19 @@
     /**
      * adds a new Server Response line to the test elements, with the specified location.
      */
-    public void SL( int sessionNumber, String serverLine, String location )
+    public void SL( int sessionNumber, String serverLine, String location, String lastClientMessage )
     {
         this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
-        testElements.add( new ServerResponse( sessionNumber, serverLine, location ) );
+        testElements.add( new ServerResponse( sessionNumber, serverLine, location, lastClientMessage ) );
     }
 
     /**
      * adds a new Server Unordered Block to the test elements.
      */
-    public void SUB( int sessionNumber, List serverLines, String location )
+    public void SUB( int sessionNumber, List serverLines, String location, String lastClientMessage )
     {
         this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
-        testElements.add( new ServerUnorderedBlockResponse( sessionNumber, serverLines, location ) );
+        testElements.add( new ServerUnorderedBlockResponse( sessionNumber, serverLines, location, lastClientMessage ) );
     }
 
     /**
@@ -236,6 +236,7 @@
      */
     private class ServerResponse implements ProtocolElement
     {
+        private String lastClientMessage;
         private int sessionNumber;
         private String expectedLine;
         protected String location;
@@ -248,7 +249,7 @@
          */
         public ServerResponse( String expectedPattern, String location )
         {
-            this(-1, expectedPattern, location);
+            this(-1, expectedPattern, location, null);
         }
 
         /**
@@ -258,11 +259,12 @@
          *                        the line recieved.
          * @param location A descriptive value to use in error messages.
          */
-        public ServerResponse( int sessionNumber, String expectedPattern, String location )
+        public ServerResponse( int sessionNumber, String expectedPattern, String location, String lastClientMessage )
         {
             this.sessionNumber = sessionNumber;
             this.expectedLine = expectedPattern;
             this.location = location;
+            this.lastClientMessage = lastClientMessage;
         }
 
         /**
@@ -293,6 +295,7 @@
             String testLine = readLine(session);
             if ( ! match( expectedLine, testLine ) ) {
                 String errMsg = "\nLocation: " + location +
+                        "\nLastClientMsg: " + lastClientMessage +
                         "\nExpected: '" + expectedLine +
                         "'\nActual   : '" + testLine + "'";
                 if (continueAfterFailure) {
@@ -355,7 +358,7 @@
          */
         public ServerUnorderedBlockResponse( List expectedLines, String location )
         {
-            this(-1, expectedLines, location);
+            this(-1, expectedLines, location, null);
         }
 
         /**
@@ -367,9 +370,9 @@
          * @param location A descriptive location string for error messages.
          */
         public ServerUnorderedBlockResponse( int sessionNumber,
-                                             List expectedLines, String location )
+                                             List expectedLines, String location, String lastClientMessage)
         {
-            super( sessionNumber, "<Unordered Block>", location );
+            super( sessionNumber, "<Unordered Block>", location, lastClientMessage);
             this.expectedLines = expectedLines;
         }
 

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/AppendSelectInbox.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/AppendSelectInbox.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/AppendSelectInbox.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/AppendSelectInbox.test Sat Mar 29 15:10:09 2008
@@ -56,7 +56,7 @@
 C: abcd SELECT "INBOX"
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 2 EXISTS
-S: \* 0 RECENT
+S: \* 2 RECENT
 S: \* OK \[UIDVALIDITY \d+\]
 S: (\* OK \[UNSEEN 1\] Message 1 is the first unseen)|(\* OK No messages unseen)
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\]

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/BodyPartialFetch.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/BodyPartialFetch.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/BodyPartialFetch.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/BodyPartialFetch.test Sat Mar 29 15:10:09 2008
@@ -1,16 +1,31 @@
-S: \* OK Dovecot ready\.
-C: A1 LOGIN imapuser password
-S: A1 OK Logged in\.
+################################################################
+# 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.                                           #
+################################################################
 C: A2 CREATE testmailbox
-S: A2 OK Create completed\.
+S: A2 OK CREATE completed\.
 C: A3 SELECT testmailbox
-S: \* FLAGS \(\\Answered \\Flagged \\Deleted \\Seen \\Draft\)
-S: \* OK \[PERMANENTFLAGS \(\\Answered \\Flagged \\Deleted \\Seen \\Draft \\\*\)\] Flags permitted\.
+S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 0 EXISTS
 S: \* 0 RECENT
-S: \* OK \[UIDVALIDITY 1206782202\] UIDs valid
-S: \* OK \[UIDNEXT 1\] Predicted next UID
-S: A3 OK \[READ-WRITE\] Select completed\.
+S: \* OK \[UIDVALIDITY (.)*\]
+S: \* OK No messages unseen
+S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\]
+S: A3 OK \[READ-WRITE\] SELECT completed\.
 C: A4 APPEND testmailbox {765+}
 C: From: Timothy Tayler <ti...@example.org>
 C: To: Samual Smith <sa...@example.org>
@@ -48,26 +63,25 @@
 C: 
 S: \* 1 EXISTS
 S: \* 1 RECENT
-S: A4 OK Append completed\.
+S: A4 OK APPEND completed\.
 C: A5 SELECT testmailbox
-S: \* FLAGS \(\\Answered \\Flagged \\Deleted \\Seen \\Draft\)
-S: \* OK \[PERMANENTFLAGS \(\\Answered \\Flagged \\Deleted \\Seen \\Draft \\\*\)\] Flags permitted\.
+S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
 S: \* 1 RECENT
-S: \* OK \[UNSEEN 1\] First unseen\.
-S: \* OK \[UIDVALIDITY 1206782202\] UIDs valid
-S: \* OK \[UIDNEXT 2\] Predicted next UID
-S: A5 OK \[READ-WRITE\] Select completed\.
+S: \* OK \[UIDVALIDITY (.)*\]
+S: \* OK \[UNSEEN 1\](.)*
+S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\]
+S: A5 OK \[READ-WRITE\] SELECT completed\.
 C: A6 FETCH 1 (BODY[]<0.10>)
-S: \* 1 FETCH \(FLAGS \(\\Seen \\Recent\) BODY\[\]<0> \{10\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) BODY\[\]<0> \{10\}
 S: From: Timo\)
-S: A6 OK Fetch completed\.
+S: A6 OK FETCH completed\.
 C: A7 FETCH 1 (BODY[]<0.100>)
 S: \* 1 FETCH \(BODY\[\]<0> \{100\}
 S: From: Timothy Tayler <timothy@example\.org>
 S: To: Samual Smith <samual@example\.org>
 S: Date: Thu, 14 Feb\)
-S: A7 OK Fetch completed\.
+S: A7 OK FETCH completed\.
 C: A8 FETCH 1 (BODY[]<0.1000>)
 S: \* 1 FETCH \(BODY\[\]<0> \{765\}
 S: From: Timothy Tayler <timothy@example\.org>
@@ -104,7 +118,7 @@
 S: 
 S: --1729--
 S: \)
-S: A8 OK Fetch completed\.
+S: A8 OK FETCH completed\.
 C: A9 FETCH 1 (BODY[]<0.10000>)
 S: \* 1 FETCH \(BODY\[\]<0> \{765\}
 S: From: Timothy Tayler <timothy@example\.org>
@@ -141,7 +155,7 @@
 S: 
 S: --1729--
 S: \)
-S: A9 OK Fetch completed\.
+S: A9 OK FETCH completed\.
 C: A10 FETCH 1 (BODY[]<0.100000>)
 S: \* 1 FETCH \(BODY\[\]<0> \{765\}
 S: From: Timothy Tayler <timothy@example\.org>
@@ -178,18 +192,17 @@
 S: 
 S: --1729--
 S: \)
-S: A10 OK Fetch completed\.
+S: A10 OK FETCH completed\.
 C: A11 FETCH 1 (BODY[]<100.10>)
 S: \* 1 FETCH \(BODY\[\]<100> \{10\}
 S:  2008 12:0\)
-S: A11 OK Fetch completed\.
+S: A11 OK FETCH completed\.
 C: A12 FETCH 1 (BODY[]<100.100>)
 S: \* 1 FETCH \(BODY\[\]<100> \{100\}
 S:  2008 12:00:00 \+0000 \(GMT\)
 S: Subject: A Multipart Email
-S: Content-Type: multipart/mixed;boundary=1729
-\)
-S: A12 OK Fetch completed\.
+S: Content-Type: multipart/mixed;boundary=1729\r\)
+S: A12 OK FETCH completed\.
 C: A13 FETCH 1 (BODY[]<100.1000>)
 S: \* 1 FETCH \(BODY\[\]<100> \{665\}
 S:  2008 12:00:00 \+0000 \(GMT\)
@@ -224,7 +237,7 @@
 S: 
 S: --1729--
 S: \)
-S: A13 OK Fetch completed\.
+S: A13 OK FETCH completed\.
 C: A14 FETCH 1 (BODY[]<100.10000>)
 S: \* 1 FETCH \(BODY\[\]<100> \{665\}
 S:  2008 12:00:00 \+0000 \(GMT\)
@@ -259,7 +272,7 @@
 S: 
 S: --1729--
 S: \)
-S: A14 OK Fetch completed\.
+S: A14 OK FETCH completed\.
 C: A15 FETCH 1 (BODY[]<100.100000>)
 S: \* 1 FETCH \(BODY\[\]<100> \{665\}
 S:  2008 12:00:00 \+0000 \(GMT\)
@@ -294,29 +307,27 @@
 S: 
 S: --1729--
 S: \)
-S: A15 OK Fetch completed\.
+S: A15 OK FETCH completed\.
 C: A16 FETCH 1 (BODY[]<10000.10>)
 S: \* 1 FETCH \(BODY\[\]<10000> \{0\}
 S: \)
-S: A16 OK Fetch completed\.
+S: A16 OK FETCH completed\.
 C: A17 FETCH 1 (BODY[]<10000.100>)
 S: \* 1 FETCH \(BODY\[\]<10000> \{0\}
 S: \)
-S: A17 OK Fetch completed\.
+S: A17 OK FETCH completed\.
 C: A18 FETCH 1 (BODY[]<10000.1000>)
 S: \* 1 FETCH \(BODY\[\]<10000> \{0\}
 S: \)
-S: A18 OK Fetch completed\.
+S: A18 OK FETCH completed\.
 C: A19 FETCH 1 (BODY[]<10000.10000>)
 S: \* 1 FETCH \(BODY\[\]<10000> \{0\}
 S: \)
-S: A19 OK Fetch completed\.
+S: A19 OK FETCH completed\.
 C: A20 FETCH 1 (BODY[]<10000.100000>)
 S: \* 1 FETCH \(BODY\[\]<10000> \{0\}
 S: \)
-S: A20 OK Fetch completed\.
+S: A20 OK FETCH completed\.
 C: A21 DELETE testmailbox
-S: A21 OK Delete completed\.
-C: A22 LOGOUT
-S: \* BYE Logging out
-S: A22 OK Logout completed\.
+S: A21 OK DELETE completed\.
+

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchBodyNoSection.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchBodyNoSection.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchBodyNoSection.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchBodyNoSection.test Sat Mar 29 15:10:09 2008
@@ -19,7 +19,7 @@
 # BODY[]
 # Not PEEK, so the Seen flag is implicitly set.
 C: f1 FETCH 1 (BODY[])
-S: \* 1 FETCH \(FLAGS \(\\Seen\) BODY\[\] \{254\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) BODY\[\] \{254\}
 S: Date: Mon, 7 Feb 1994 21:52:25 -0800 \(PST\)
 S: From: Fred Foobar <foobar@Blurdybloop\.COM>
 S: Subject: Test 01

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFields.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFields.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFields.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFields.test Sat Mar 29 15:10:09 2008
@@ -275,7 +275,7 @@
 C: A13 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 9 EXISTS
-S: \* 0 RECENT
+S: \* 9 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\] Message 1 is the first unseen
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*
@@ -579,7 +579,7 @@
 C: A16 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 9 EXISTS
-S: \* 0 RECENT
+S: \* 9 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\] (.)*
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFieldsNot.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFieldsNot.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFieldsNot.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchHeaderFieldsNot.test Sat Mar 29 15:10:09 2008
@@ -275,9 +275,7 @@
 C: A13 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 9 EXISTS
-# TODO: FIX RECENT
-#S: \* 1 RECENT
-S: \* 0 RECENT
+S: \* 9 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\] (.)*
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*
@@ -558,7 +556,7 @@
 C: A16 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 9 EXISTS
-S: \* 0 RECENT
+S: \* 9 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\] (.)*
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartAlternative.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartAlternative.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartAlternative.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartAlternative.test Sat Mar 29 15:10:09 2008
@@ -61,15 +61,13 @@
 C: A5 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
-# TODO: fix recent flag
-S: \* 0 RECENT
+S: \* 1 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\](.)*
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*
 S: A5 OK \[READ-WRITE\] SELECT completed\.
 C: A6 FETCH 1 (BODY[])
-# TODO: fix recent flag
-S: \* 1 FETCH \(FLAGS \(\\Seen\) BODY\[\] \{666\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) BODY\[\] \{666\}
 S: From: Timothy Tayler <timothy@example\.org>
 S: To: Samual Smith <samual@example\.org>
 S: Date: Thu, 14 Feb 2008 12:00:00 \+0000 \(GMT\)
@@ -152,7 +150,7 @@
 C: A12 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
-S: \* 0 RECENT
+S: \* 1 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK No messages unseen
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixed.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixed.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixed.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixed.test Sat Mar 29 15:10:09 2008
@@ -68,15 +68,13 @@
 C: A5 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
-# TODO FIX RECENT
-S: \* 0 RECENT
+S: \* 1 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\] Message 1 is the first unseen
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*
 S: A5 OK \[READ-WRITE\] SELECT completed\.
 C: A6 FETCH 1 (BODY[])
-# TODO FIX RECENT
-S: \* 1 FETCH \(FLAGS \(\\Seen\) BODY\[\] \{765\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) BODY\[\] \{765\}
 S: From: Timothy Tayler <timothy@example\.org>
 S: To: Samual Smith <samual@example\.org>
 S: Date: Thu, 14 Feb 2008 12:00:00 \+0000 \(GMT\)
@@ -179,7 +177,7 @@
 C: A13 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
-S: \* 0 RECENT
+S: \* 1 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK No messages unseen
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixedComplex.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixedComplex.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixedComplex.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchMultipartMixedComplex.test Sat Mar 29 15:10:09 2008
@@ -125,15 +125,13 @@
 C: A5 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
-# TODO: FIX RECENT
-S: \* 0 RECENT
+S: \* 1 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK \[UNSEEN 1\] Message 1 is the first unseen
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*
 S: A5 OK \[READ-WRITE\] SELECT completed\.
 C: A6 FETCH 1 (BODY[])
-# TODO: FIX RECENT
-S: \* 1 FETCH \(FLAGS \(\\Seen\) BODY\[\] \{1767\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) BODY\[\] \{1767\}
 S: From: Timothy Tayler <timothy@example\.org>
 S: To: Samual Smith <samual@example\.org>
 S: Date: Thu, 14 Feb 2008 12:00:00 \+0000 \(GMT\)
@@ -564,7 +562,7 @@
 C: A26 SELECT testmailbox
 S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
 S: \* 1 EXISTS
-S: \* 0 RECENT
+S: \* 1 RECENT
 S: \* OK \[UIDVALIDITY (.)*
 S: \* OK No messages unseen
 S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)\](.)*

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchPeek.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchPeek.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchPeek.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchPeek.test Sat Mar 29 15:10:09 2008
@@ -22,7 +22,7 @@
 
 # Check that the initial flags are correct
 C: f1 FETCH 2 (FLAGS)
-S: \* 2 FETCH \(FLAGS \(\\Flagged\)\)
+S: \* 2 FETCH \(FLAGS \(\\Flagged \\Recent\)\)
 S: f1 OK FETCH completed.
 
 # BODY.PEEK[]
@@ -87,6 +87,6 @@
 
 # Check that the flags are still correct
 C: f1 FETCH 2 (FLAGS)
-S: \* 2 FETCH \(FLAGS \(\\Flagged\)\)
+S: \* 2 FETCH \(FLAGS \(\\Flagged \\Recent\)\)
 S: f1 OK FETCH completed.
 

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822.test Sat Mar 29 15:10:09 2008
@@ -19,7 +19,7 @@
 # RFC822
 # Not PEEK, so the Seen flag is implicitly set.
 C: f1 FETCH 1 (RFC822)
-S: \* 1 FETCH \(FLAGS \(\\Seen\) RFC822 \{254\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) RFC822 \{254\}
 S: Date: Mon, 7 Feb 1994 21:52:25 -0800 \(PST\)
 S: From: Fred Foobar <foobar@Blurdybloop\.COM>
 S: Subject: Test 01

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822Text.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822Text.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822Text.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchRFC822Text.test Sat Mar 29 15:10:09 2008
@@ -18,7 +18,7 @@
 ################################################################
 # RFC822.TEXT
 C: f1 FETCH 1 (RFC822.TEXT)
-S: \* 1 FETCH \(FLAGS \(\\Seen\) RFC822.TEXT \{9\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) RFC822.TEXT \{9\}
 S: Test 01
 S: \)
 S: f1 OK FETCH completed.

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchText.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchText.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchText.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchText.test Sat Mar 29 15:10:09 2008
@@ -18,7 +18,7 @@
 ################################################################
 # BODY[TEXT]
 C: f1 FETCH 1 (BODY[TEXT])
-S: \* 1 FETCH \(FLAGS \(\\Seen\) BODY\[TEXT\] \{9\}
+S: \* 1 FETCH \(FLAGS \(\\Recent \\Seen\) BODY\[TEXT\] \{9\}
 S: Test 01
 S: \)
 S: f1 OK FETCH completed.

Modified: james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/Store.test
URL: http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/Store.test?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/Store.test (original)
+++ james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/Store.test Sat Mar 29 15:10:09 2008
@@ -18,10 +18,10 @@
 ################################################################
 # FLAGS
 C: f1 FETCH 1:4 (FLAGS)
-S: \* 1 FETCH \(FLAGS \(\)\)
-S: \* 2 FETCH \(FLAGS \(\)\)
-S: \* 3 FETCH \(FLAGS \(\)\)
-S: \* 4 FETCH \(FLAGS \(\)\)
+S: \* 1 FETCH \(FLAGS \(\\Recent\)\)
+S: \* 2 FETCH \(FLAGS \(\\Recent\)\)
+S: \* 3 FETCH \(FLAGS \(\\Recent\)\)
+S: \* 4 FETCH \(FLAGS \(\\Recent\)\)
 S: f1 OK FETCH completed.
 
 #Simple store
@@ -30,7 +30,7 @@
 S: f2 OK STORE completed.
 
 C: f3 FETCH 1 (FLAGS)
-S: \* 1 FETCH \(FLAGS \(\\Deleted\)\)
+S: \* 1 FETCH \(FLAGS \(\\Deleted \\Recent\)\)
 S: f3 OK FETCH completed.
 
 #Override previous value (silent)
@@ -38,7 +38,7 @@
 S: f2 OK STORE completed.
 
 C: f1 FETCH 1 (FLAGS)
-S: \* 1 FETCH \(FLAGS \(\\Draft \\Flagged\)\)
+S: \* 1 FETCH \(FLAGS \(\\Draft \\Flagged \\Recent\)\)
 S: f1 OK FETCH completed.
 
 #Add to existing flags
@@ -47,7 +47,7 @@
 S: f2 OK STORE completed.
 
 C: f1 FETCH 1 (FLAGS)
-S: \* 1 FETCH \(FLAGS \(\\Deleted \\Draft \\Flagged\)\)
+S: \* 1 FETCH \(FLAGS \(\\Deleted \\Draft \\Flagged \\Recent\)\)
 S: f1 OK FETCH completed.
 
 #Remove from existing flags (silent)
@@ -55,7 +55,7 @@
 S: f2 OK STORE completed.
 
 C: f1 FETCH 1 (FLAGS)
-S: \* 1 FETCH \(FLAGS \(\\Deleted \\Flagged\)\)
+S: \* 1 FETCH \(FLAGS \(\\Deleted \\Flagged \\Recent\)\)
 S: f1 OK FETCH completed.
 
 C: f4 STORE 3:4 FLAGS (\Flagged)
@@ -64,8 +64,8 @@
 S: f4 OK STORE completed.
 
 C: f1 FETCH 1:4 (FLAGS)
-S: \* 1 FETCH \(FLAGS \(\\Deleted \\Flagged\)\)
-S: \* 2 FETCH \(FLAGS \(\)\)
-S: \* 3 FETCH \(FLAGS \(\\Flagged\)\)
-S: \* 4 FETCH \(FLAGS \(\\Flagged\)\)
+S: \* 1 FETCH \(FLAGS \(\\Deleted \\Flagged \\Recent\)\)
+S: \* 2 FETCH \(FLAGS \(\\Recent\)\)
+S: \* 3 FETCH \(FLAGS \(\\Flagged \\Recent\)\)
+S: \* 4 FETCH \(FLAGS \(\\Flagged \\Recent\)\)
 S: f1 OK FETCH completed.

Modified: james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java (original)
+++ james/server/trunk/imap-api/src/main/java/org/apache/james/api/imap/process/SelectedImapMailbox.java Sat Mar 29 15:10:09 2008
@@ -41,4 +41,6 @@
     public int recentCount();
     
     public String getName();
+
+    public boolean isRecent(long uid);
 }

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/base/SelectedMailboxSessionImpl.java Sat Mar 29 15:10:09 2008
@@ -20,7 +20,6 @@
 package org.apache.james.imapserver.processor.base;
 
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -229,5 +228,17 @@
             final Long uid = (Long) it.next();
             recentUids.remove(uid);
         }
+    }
+
+    public boolean isRecent(long uid) {
+        boolean result = false;
+        for (Iterator ir = recentUids.iterator(); ir.hasNext();) {
+            Long recentUid = (Long) ir.next();
+            if (recentUid.longValue() == uid) {
+                result = true;
+                break;
+            }
+        }
+        return result;
     }
 }

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java Sat Mar 29 15:10:09 2008
@@ -67,7 +67,6 @@
             ImapCommand command) throws MailboxException,
             AuthorizationException, ProtocolException {
         ImapResponseMessage result;
-        session.deselect();
         try {
             String fullMailboxName = buildFullName(session, mailboxName);
             selectMailbox(fullMailboxName, session, isExamine);
@@ -110,6 +109,21 @@
         final MailboxManager mailboxManager = getMailboxManager(session);
         final ImapMailbox mailbox = mailboxManager.getImapMailbox(mailboxName, false);
         final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+
+        final SelectedImapMailbox sessionMailbox;
+        final SelectedImapMailbox currentMailbox = session.getSelected();
+        if (currentMailbox == null || !currentMailbox.getName().equals(mailboxName)) {
+            sessionMailbox = createNewSelectedMailbox(mailbox, mailboxSession, session);            
+        } else {
+            sessionMailbox = currentMailbox;
+        }
+        addRecent(readOnly, mailbox, mailboxSession, sessionMailbox);
+        return readOnly;
+    }
+
+    private SelectedImapMailbox createNewSelectedMailbox(final ImapMailbox mailbox, final MailboxSession mailboxSession,
+            ImapSession session) throws MailboxManagerException {
+        final SelectedImapMailbox sessionMailbox;
         final Iterator it = mailbox.getMessages(GeneralMessageSetImpl
                 .all(), FetchGroupImpl.MINIMAL, mailboxSession);
         final List uids = new ArrayList();
@@ -117,14 +131,12 @@
             final MessageResult result = (MessageResult) it.next();
             uids.add(new Long(result.getUid()));
         }
-        SelectedImapMailbox sessionMailbox = new SelectedMailboxSessionImpl(mailbox, uids, mailboxSession);
-        
-        addRecent(readOnly, mailbox, mailboxSession, sessionMailbox);
+        sessionMailbox = new SelectedMailboxSessionImpl(mailbox, uids, mailboxSession);
         session.selected(sessionMailbox);
         session.setAttribute(
                 ImapSessionUtils.SELECTED_MAILBOX_ATTRIBUTE_SESSION_KEY,
                 mailbox);
-        return readOnly;
+        return sessionMailbox;
     }
 
     private void addRecent(boolean readOnly, final ImapMailbox mailbox, final MailboxSession mailboxSession, SelectedImapMailbox sessionMailbox) throws MailboxManagerException {

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java Sat Mar 29 15:10:09 2008
@@ -45,6 +45,7 @@
 import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
 import org.apache.james.api.imap.process.ImapProcessor;
 import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.api.imap.process.SelectedImapMailbox;
 import org.apache.james.imap.message.request.imap4rev1.FetchRequest;
 import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
 import org.apache.james.imap.message.response.imap4rev1.FetchResponse.BodyElement;
@@ -238,7 +239,10 @@
                 ImapSession session, boolean useUids)
                 throws MailboxException, ProtocolException {
             ImapMailbox mailbox = ImapSessionUtils.getMailbox(session);
-            setMsn(session.getSelected().msn(result.getUid()));
+            final SelectedImapMailbox selected = session.getSelected();
+            final long resultUid = result.getUid();
+            final int resultMsn = selected.msn(resultUid);
+            setMsn(resultMsn);
             
             // Check if this fetch will cause the "SEEN" flag to be set on this
             // message
@@ -247,17 +251,21 @@
             try {
                 final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
                 boolean ensureFlagsResponse = false;
+                final Flags resultFlags = result.getFlags();
                 if (fetch.isSetSeen()
-                        && !result.getFlags().contains(Flags.Flag.SEEN)) {
+                        && !resultFlags.contains(Flags.Flag.SEEN)) {
                     mailbox.setFlags(new Flags(Flags.Flag.SEEN), true, false,
-                            GeneralMessageSetImpl.oneUid(result.getUid()), FetchGroupImpl.MINIMAL, mailboxSession);
-                    result.getFlags().add(Flags.Flag.SEEN);
+                            GeneralMessageSetImpl.oneUid(resultUid), FetchGroupImpl.MINIMAL, mailboxSession);
+                    resultFlags.add(Flags.Flag.SEEN);
                     ensureFlagsResponse = true;
                 }
                 
                 // FLAGS response
                 if (fetch.isFlags() || ensureFlagsResponse) {
-                    setFlags(result.getFlags());
+                    if (selected.isRecent(resultUid)) {
+                        resultFlags.add(Flags.Flag.RECENT);
+                    }
+                    setFlags(resultFlags);
                 }
 
                 // INTERNALDATE response
@@ -296,7 +304,7 @@
                 }
                 // UID response
                 if (fetch.isUid()) {
-                    setUid(result.getUid());
+                    setUid(resultUid);
                 }
 
                 // BODY part responses.
@@ -440,6 +448,7 @@
                 addresses.add(address);
             }
             final FetchResponse.Envelope.Address end = endGroup();
+            addresses.add(end);
         }
         
         private FetchResponse.Envelope.Address startGroup(String groupName) {

Modified: james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElement.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElement.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElement.java Sat Mar 29 15:10:09 2008
@@ -13,6 +13,7 @@
     private final BodyElement delegate;
     private final long firstOctet;
     private final long numberOfOctets;
+    private final String name;
     
     public PartialFetchBodyElement(final BodyElement delegate, final long firstOctet, 
             final long numberOfOctets) {
@@ -20,21 +21,24 @@
         this.delegate = delegate;
         this.firstOctet = firstOctet;
         this.numberOfOctets = numberOfOctets;
+        name = delegate.getName() + "<" + firstOctet + ">";
     }
 
     public String getName() {
-        return delegate.getName();
+        return name;
     }
 
     public long size() {
         final long size = delegate.size();
-        final long numberOfOctets;
-        if (size > this.numberOfOctets) {
-            numberOfOctets = this.numberOfOctets;
+        final long lastOctet = this.numberOfOctets + firstOctet;
+        final long result;
+        if (firstOctet > size) {
+            result = 0;
+        } else if (size > lastOctet) {
+            result = numberOfOctets;
         } else {
-            numberOfOctets = size;
+            result = size - firstOctet;
         }
-        final long result = numberOfOctets - firstOctet;
         return result;
     }
 

Modified: james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElementTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElementTest.java?rev=642626&r1=642625&r2=642626&view=diff
==============================================================================
--- james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElementTest.java (original)
+++ james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/PartialFetchBodyElementTest.java Sat Mar 29 15:10:09 2008
@@ -32,6 +32,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         mockBodyElement = mock(BodyElement.class);
+        mockBodyElement.expects(once()).method("getName").will(returnValue("Name"));
     }
 
     protected void tearDown() throws Exception {
@@ -63,10 +64,26 @@
     }
     
     public void testWhenStartPlusNumberOfOctetsIsLessThanSizeSizeShouldBeNumberOfOctetsMinusStart() throws Exception {
-        long size = 600;
+        long size = 100;
         PartialFetchBodyElement element = new PartialFetchBodyElement((BodyElement) mockBodyElement.proxy(), 
                 10, NUMBER_OF_OCTETS);
         mockBodyElement.expects(once()).method("size").will(returnValue(new Long(size)));
         assertEquals("Size is less than number of octets so should be size", 90, element.size());
+    }
+    
+    public void testSizeShouldBeZeroWhenStartIsMoreThanSize() throws Exception {
+        long size = 100;
+        PartialFetchBodyElement element = new PartialFetchBodyElement((BodyElement) mockBodyElement.proxy(), 
+                1000, NUMBER_OF_OCTETS);
+        mockBodyElement.expects(once()).method("size").will(returnValue(new Long(size)));
+        assertEquals("Size is less than number of octets so should be size", 0, element.size());
+    }
+    
+    public void testSizeShouldBeNumberOfOctetsWhenStartMoreThanOctets() throws Exception {
+        long size = 2000;
+        PartialFetchBodyElement element = new PartialFetchBodyElement((BodyElement) mockBodyElement.proxy(), 
+                1000, NUMBER_OF_OCTETS);
+        mockBodyElement.expects(once()).method("size").will(returnValue(new Long(size)));
+        assertEquals("Content size is less than start. Size should be zero.", NUMBER_OF_OCTETS, element.size());
     }
 }

Added: james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/ExperimentalPartialFetchTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/ExperimentalPartialFetchTest.java?rev=642626&view=auto
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/ExperimentalPartialFetchTest.java (added)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/ExperimentalPartialFetchTest.java Sat Mar 29 15:10:09 2008
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.experimental.imapserver;
+
+import org.apache.james.test.functional.imap.AbstractTestPartialFetch;
+
+public class ExperimentalPartialFetchTest extends AbstractTestPartialFetch {
+
+    public ExperimentalPartialFetchTest() throws Exception {
+        super(HostSystemFactory.createStandardImap());
+    }
+
+}



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