Index: src/java/org/apache/james/imapserver/commands/FetchCommand.java
===================================================================
--- src/java/org/apache/james/imapserver/commands/FetchCommand.java	(revision 465801)
+++ src/java/org/apache/james/imapserver/commands/FetchCommand.java	(working copy)
@@ -372,32 +372,41 @@
             FetchRequest fetch = new FetchRequest();
 
             char next = nextNonSpaceChar( request );
-            consumeChar( request, '(' );
-
-            next = nextNonSpaceChar( request );
-            while ( next != ')' ) {
+            if (request.nextChar() == '(') {
+                consumeChar( request, '(' );
+    
+                next = nextNonSpaceChar( request );
+                while ( next != ')' ) {
+                    addNextElement( request, fetch );
+                    next = nextNonSpaceChar( request );
+                }
+                consumeChar(request, ')');
+            } else {
                 addNextElement( request, fetch );
-                next = nextNonSpaceChar( request );
+                
             }
 
-            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,9 @@
                 else {
                     consumeChar( command, '[' );
 
-                    StringBuffer sectionIdentifier = new StringBuffer();
-                    next = nextCharInLine( command );
-                    while ( next != ']' ) {
-                        sectionIdentifier.append( next );
-                        command.consume();
-                        next = nextCharInLine(command);
-                    }
-                    consumeChar( command, ']' );
+                    
+                    String parameter = readWord(command, "]");
 
-                    String parameter = sectionIdentifier.toString();
-
                     if ( "BODY".equalsIgnoreCase( name ) ) {
                         fetch.add(new BodyFetchElement("BODY[" + parameter + "]", parameter), false);
                     } else if ( "BODY.PEEK".equalsIgnoreCase( name ) ) {
@@ -461,6 +462,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
         {
