Author: norman
Date: Fri Jan 14 17:08:45 2011
New Revision: 1059074

URL: http://svn.apache.org/viewvc?rev=1059074&view=rev
Log:
More work on push model for imap

Modified:
    
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
    
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
    
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
    
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
    
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
    
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
    
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java

Modified: 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
 Fri Jan 14 17:08:45 2011
@@ -48,6 +48,10 @@ public class ImapRequestLineReader {
         this.data = data;
     }
     
+    
+    public boolean isConsumed() {
+        return data.length == pos;
+    }
 
     /**
      * Reads the next character in the current line. This method will continue
@@ -64,7 +68,7 @@ public class ImapRequestLineReader {
         if (!nextSeen) {
             int next = -1;
 
-            if (pos == data.length) {
+            if (isConsumed()) {
                 throw new 
DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, 
                         "Unexpected end of stream.");
             } 
@@ -113,6 +117,8 @@ public class ImapRequestLineReader {
      *             end-of-file is reached.
      */
     public void eol() throws DecodingException {
+        if (isConsumed()) return;
+        
         char next = nextChar();
 
         // Ignore trailing spaces.
@@ -120,15 +126,10 @@ public class ImapRequestLineReader {
             consume();
             next = nextChar();
         }
-
-        // handle DOS and unix end-of-lines
-        if (next == '\r') {
-            consume();
-            next = nextChar();
-        }
+        consume();
 
         // Check if we found extra characters.
-        if (next != '\n') {
+        if (isConsumed() == false) {
             throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, 
                     "Expected end-of-line, found '" + (char) next + "'.");
         }

Modified: 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
 Fri Jan 14 17:08:45 2011
@@ -286,6 +286,7 @@ public abstract class AbstractImapComman
             } else {
                 throw new 
DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Invalid character: '" + 
next + "'");
             }
+            if (request.isConsumed()) break;
             next = request.nextChar();
         }
         return atom.toString();

Modified: 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
 Fri Jan 14 17:08:45 2011
@@ -905,10 +905,10 @@ public class SearchCommandParser extends
         request.nextWordChar();
         final SearchKey firstKey = searchKey(request, null, true);
         final SearchKey result;
-        if (request.nextChar() == ' ') {
+        if (request.isConsumed() == false && request.nextChar() == ' ') {
             List<SearchKey> keys = new ArrayList<SearchKey>();
             keys.add(firstKey);
-            while (request.nextChar() == ' ') {
+            while (request.isConsumed() == false && request.nextChar() == ' ') 
{
                 request.nextWordChar();
                 final SearchKey key = searchKey(request, null, false);
                 keys.add(key);

Modified: 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
 Fri Jan 14 17:08:45 2011
@@ -63,7 +63,7 @@ public class FetchCommandParserPartialFe
         FetchData data = new FetchData();
         data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null,
                 null, new Long(0), new Long(100)), false);
-        check("1 (BODY[]<0.100>)\r\n", ranges, false, data, "A01");
+        check("1 (BODY[]<0.100>)", ranges, false, data, "A01");
     }
 
     @Test
@@ -72,7 +72,7 @@ public class FetchCommandParserPartialFe
         FetchData data = new FetchData();
         data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null,
                 null, new Long(20), new Long(12342348)), false);
-        check("1 (BODY[]<20.12342348>)\r\n", ranges, false, data, "A01");
+        check("1 (BODY[]<20.12342348>)", ranges, false, data, "A01");
     }
 
     @Test

Modified: 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
 Fri Jan 14 17:08:45 2011
@@ -189,7 +189,7 @@ public class SearchCommandParserAndParen
 
     private void check(Input in) throws UnsupportedEncodingException,
             DecodingException {
-        String input = in.input + "\r\n";
+        String input = in.input;
         ImapRequestLineReader reader = new 
ImapRequestLineReader(input.getBytes("US-ASCII"),
                 new MockImapResponseComposer());
 

Modified: 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
 Fri Jan 14 17:08:45 2011
@@ -190,7 +190,7 @@ public class SearchCommandParserTopLevel
 
     private void check(List<SearchKey> keys, StringBuffer buffer)
             throws UnsupportedEncodingException, DecodingException {
-        buffer.append("\r\n");
+        //buffer.append("\r\n");
         String input = buffer.toString();
         SearchKey key = SearchKey.buildAnd(keys);
         ImapRequestLineReader reader = new ImapRequestLineReader(

Modified: 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
URL: 
http://svn.apache.org/viewvc/james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java?rev=1059074&r1=1059073&r2=1059074&view=diff
==============================================================================
--- 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
 (original)
+++ 
james/imap/branches/nio-refactoring/message/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
 Fri Jan 14 17:08:45 2011
@@ -67,7 +67,7 @@ public class StoreCommandParserTest {
         Flags flags = new Flags();
         flags.add(Flags.Flag.DRAFT);
         flags.add(Flags.Flag.FLAGGED);
-        check("1 FLAGS.SILENT (\\Draft \\Flagged)\r\n", ranges, true, null,
+        check("1 FLAGS.SILENT (\\Draft \\Flagged)", ranges, true, null,
                 flags, false, "A01");
     }
 



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

Reply via email to