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 jo...@apache.org on 2006/11/03 14:43:12 UTC

svn commit: r470809 - in /james/server/trunk/src: java/org/apache/james/imapserver/commands/FetchCommand.java test/org/apache/james/imapserver/client/FetchCommand.java test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java

Author: joachim
Date: Fri Nov  3 05:43:12 2006
New Revision: 470809

URL: http://svn.apache.org/viewvc?view=rev&rev=470809
Log:
applied patches for JAMES-664
FETCH allows a single atom as fetch item
Thanks to Zsombor Gegesy for submitting the patch.

Modified:
    james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java
    james/server/trunk/src/test/org/apache/james/imapserver/client/FetchCommand.java
    james/server/trunk/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java

Modified: james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java?view=diff&rev=470809&r1=470808&r2=470809
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java Fri Nov  3 05:43:12 2006
@@ -372,32 +372,41 @@
             FetchRequest fetch = new FetchRequest();
 
             char next = nextNonSpaceChar( request );
-            consumeChar( request, '(' );
-
-            next = nextNonSpaceChar( request );
-            while ( next != ')' ) {
-                addNextElement( request, fetch );
+            if (request.nextChar() == '(') {
+                consumeChar( request, '(' );
+    
                 next = nextNonSpaceChar( request );
+                while ( next != ')' ) {
+                    addNextElement( request, fetch );
+                    next = nextNonSpaceChar( request );
+                }
+                consumeChar(request, ')');
+            } else {
+                addNextElement( request, fetch );
+                
             }
 
-            consumeChar(request, ')');
-
             return fetch;
         }
 
         private void addNextElement( ImapRequestLineReader command, FetchRequest fetch)
                 throws ProtocolException
         {
-            char next = nextCharInLine( command );
+            /*char next = nextCharInLine( command );
                 StringBuffer element = new StringBuffer();
-                while ( next != ' ' && next != '[' && next != ')' ) {
+                while ( next != ' ' && next != '[' && next != ')' && next!='\n' && next!='\r' ) {
                     element.append(next);
                     command.consume();
                     next = nextCharInLine( command );
-                }
-                String name = element.toString();
+                }*/
+             
+            
+                //String name = element.toString();
+                String name = readWord(command, " [)\r\n");
+                char next = command.nextChar();
                 // Simple elements with no '[]' parameters.
-                if ( next == ' ' || next == ')' ) {
+                //if ( next == ' ' || next == ')'  || next == '\n' || next == '\r') {
+                if (next != '[') {
                     if ( "FAST".equalsIgnoreCase( name ) ) {
                         fetch.flags = true;
                         fetch.internalDate = true;
@@ -440,17 +449,10 @@
                 else {
                     consumeChar( command, '[' );
 
-                    StringBuffer sectionIdentifier = new StringBuffer();
-                    next = nextCharInLine( command );
-                    while ( next != ']' ) {
-                        sectionIdentifier.append( next );
-                        command.consume();
-                        next = nextCharInLine(command);
-                    }
-                    consumeChar( command, ']' );
-
-                    String parameter = sectionIdentifier.toString();
+                    
+                    String parameter = readWord(command, "]");
 
+                    consumeChar( command, ']');
                     if ( "BODY".equalsIgnoreCase( name ) ) {
                         fetch.add(new BodyFetchElement("BODY[" + parameter + "]", parameter), false);
                     } else if ( "BODY.PEEK".equalsIgnoreCase( name ) ) {
@@ -461,6 +463,17 @@
                 }
             }
 
+        private String readWord(ImapRequestLineReader request, String terminator) throws ProtocolException {
+            StringBuffer buf = new StringBuffer();
+            char next = request.nextChar(); 
+            while(terminator.indexOf(next)==-1) {
+                buf.append(next);
+                request.consume();
+                next = request.nextChar();
+            }
+            return buf.toString();
+        }
+        
         private char nextCharInLine( ImapRequestLineReader request )
                 throws ProtocolException
         {

Modified: james/server/trunk/src/test/org/apache/james/imapserver/client/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/client/FetchCommand.java?view=diff&rev=470809&r1=470808&r2=470809
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/client/FetchCommand.java (original)
+++ james/server/trunk/src/test/org/apache/james/imapserver/client/FetchCommand.java Fri Nov  3 05:43:12 2006
@@ -30,6 +30,10 @@
     private boolean fetchRfc822Size;
     
     private FetchBody body;
+    
+    private boolean oneSwitchOnly = false;
+    
+    private boolean oneMessageOnly = false;
 
     public FetchCommand(MimeMessage[] msgs, long from, long to) {
         statusResponse = "OK FETCH completed.";
@@ -37,6 +41,18 @@
         this.from = from;
         this.to = to;
     }
+
+    public FetchCommand(MimeMessage[] msgs, long from) {
+        statusResponse = "OK FETCH completed.";
+        this.msgs = msgs;
+        this.from = from;
+        this.to = from;
+        this.oneMessageOnly = true;
+    }
+
+    public void setOneSwitchOnly(boolean oneSwitchOnly) {
+		this.oneSwitchOnly = oneSwitchOnly;
+	}
     
     public void setUids(long[] uids) {
         this.uids=uids;
@@ -48,33 +64,45 @@
         if (uid) {
             command += "UID ";
         }
-        command += "fetch " + from + ":";
-        if (to > 0) {
-            command += to;
+        command += "fetch " + from ;
+        if (!oneMessageOnly) {
+	        if (to > 0) {
+	            command += ":"+to;
+	        } else {
+	            command += ":*";
+	        }
+        }
+        if (oneSwitchOnly) {
+        	if (fetchFlags) {
+        		command += " FLAGS\n";
+        	} else if (fetchRfc822Size) {
+        		command += " RFC822.SIZE\n";
+        	} else if (body!=null) {
+        		command += " "+body.getCommand()+'\n';
+        	}
         } else {
-            command += "*";
-        }
-        command += " (";
-        String items="";
-        // FLAGS
-        if (fetchFlags) {
-            items += " FLAGS";  
-        }
-        // RFC822.SIZE
-        if (fetchRfc822Size) {
-            items += " RFC822.SIZE";
+	        command += " (";
+	        String items="";
+	        // FLAGS
+	        if (fetchFlags) {
+	            items += " FLAGS";  
+	        }
+	        // RFC822.SIZE
+	        if (fetchRfc822Size) {
+	            items += " RFC822.SIZE";
+	        }
+	        // BODY
+	        if (body!=null) {
+	            items += " "+body.getCommand();
+	        }
+	        
+	        
+	        if (items.length()>0) {
+	            items=items.substring(1);
+	        }
+	
+	        command += items+")\n";
         }
-        // BODY
-        if (body!=null) {
-            items += " "+body.getCommand();
-        }
-        
-        
-        if (items.length()>0) {
-            items=items.substring(1);
-        }
-
-        command += items+")\n";
         return command;
     }
 

Modified: james/server/trunk/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java?view=diff&rev=470809&r1=470808&r2=470809
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java Fri Nov  3 05:43:12 2006
@@ -117,4 +117,15 @@
         verifyCommandOrdered(fc);
     }        
 
+    public void testSimpleFetch() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
+        verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
+        verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
+        msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
+        
+        FetchCommand fc=new FetchCommand(msgs,1);
+        fc.setFetchBody(new FetchBody(true));
+        fc.setOneSwitchOnly(true);
+        verifyCommandOrdered(fc);
+    	
+    }
 }



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