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 2007/10/26 20:47:43 UTC

svn commit: r588742 - in /james/server/trunk/imap-codec-library/src: main/java/org/apache/james/imapserver/codec/decode/ main/java/org/apache/james/imapserver/codec/decode/base/ test/java/org/apache/james/imapserver/codec/decode/ test/java/org/apache/j...

Author: rdonkin
Date: Fri Oct 26 11:47:42 2007
New Revision: 588742

URL: http://svn.apache.org/viewvc?rev=588742&view=rev
Log:
Allow extension and custom flags as per RFC3501.

Added:
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/DecoderUtils.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/DecoderUtilsTest.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/base/
Modified:
    james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/base/AbstractImapCommandParser.java

Added: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/DecoderUtils.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/DecoderUtils.java?rev=588742&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/DecoderUtils.java (added)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/DecoderUtils.java Fri Oct 26 11:47:42 2007
@@ -0,0 +1,56 @@
+/****************************************************************
+ * 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.imapserver.codec.decode;
+
+import javax.mail.Flags;
+
+import org.apache.james.api.imap.message.MessageFlags;
+
+/**
+ * Utility procedures.
+ */
+public final class DecoderUtils {
+
+    public static void setFlag( final String flagString, final Flags flags )  {
+        if ( flagString.equalsIgnoreCase( MessageFlags.ANSWERED ) ) {
+            flags.add(Flags.Flag.ANSWERED);
+        }
+        else if ( flagString.equalsIgnoreCase( MessageFlags.DELETED ) ) {
+            flags.add(Flags.Flag.DELETED);
+        }
+        else if ( flagString.equalsIgnoreCase( MessageFlags.DRAFT ) ) {
+            flags.add(Flags.Flag.DRAFT);
+        }
+        else if ( flagString.equalsIgnoreCase( MessageFlags.FLAGGED ) ) {
+            flags.add(Flags.Flag.FLAGGED);
+        }
+        else if ( flagString.equalsIgnoreCase( MessageFlags.SEEN ) ) {
+            flags.add(Flags.Flag.SEEN);
+        } else {
+            if ( flagString.equalsIgnoreCase( MessageFlags.RECENT) ) {
+                // RFC3501 specifically excludes /Recent 
+                // The /Recent flag should be set automatically by the server
+            } else {
+                // RFC3501 allows novel flags
+                flags.add(flagString);
+            }
+        }
+    }
+}

Modified: james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/base/AbstractImapCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/base/AbstractImapCommandParser.java?rev=588742&r1=588741&r2=588742&view=diff
==============================================================================
--- james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/base/AbstractImapCommandParser.java (original)
+++ james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/decode/base/AbstractImapCommandParser.java Fri Oct 26 11:47:42 2007
@@ -34,10 +34,10 @@
 import org.apache.james.api.imap.ProtocolException;
 import org.apache.james.api.imap.imap4rev1.Imap4Rev1MessageFactory;
 import org.apache.james.api.imap.message.IdRange;
+import org.apache.james.imapserver.codec.decode.DecoderUtils;
 import org.apache.james.imapserver.codec.decode.ImapCommandParser;
 import org.apache.james.imapserver.codec.decode.ImapRequestLineReader;
 import org.apache.james.imapserver.codec.decode.MessagingImapCommandParser;
-import org.apache.james.api.imap.message.MessageFlags;
 
 /**
  * <p>
@@ -391,40 +391,18 @@
         CharacterValidator validator = new NoopCharValidator();
         String nextWord = consumeWord( request, validator );
         while ( ! nextWord.endsWith(")" ) ) {
-            setFlag( nextWord, flags );
+            DecoderUtils.setFlag( nextWord, flags );
             nextWord = consumeWord( request, validator );
         }
         // Got the closing ")", may be attached to a word.
         if ( nextWord.length() > 1 ) {
-            setFlag( nextWord.substring(0, nextWord.length() - 1 ), flags );
+            DecoderUtils.setFlag( nextWord.substring(0, nextWord.length() - 1 ), flags );
         }
 
         return flags;
         }
 
-    public void setFlag( String flagString, Flags flags ) throws ProtocolException
-    {
-        if ( flagString.equalsIgnoreCase( MessageFlags.ANSWERED ) ) {
-            flags.add(Flags.Flag.ANSWERED);
-        }
-        else if ( flagString.equalsIgnoreCase( MessageFlags.DELETED ) ) {
-            flags.add(Flags.Flag.DELETED);
-        }
-        else if ( flagString.equalsIgnoreCase( MessageFlags.DRAFT ) ) {
-            flags.add(Flags.Flag.DRAFT);
-        }
-        else if ( flagString.equalsIgnoreCase( MessageFlags.FLAGGED ) ) {
-            flags.add(Flags.Flag.FLAGGED);
-        }
-        else if ( flagString.equalsIgnoreCase( MessageFlags.SEEN ) ) {
-            flags.add(Flags.Flag.SEEN);
-        }
-        else {
-            throw new ProtocolException( "Invalid flag string." );
-        }
-    }
-
-     /**
+    /**
      * Reads an argument of type "number" from the request.
      */
     public long number( ImapRequestLineReader request ) throws ProtocolException

Added: james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/DecoderUtilsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/DecoderUtilsTest.java?rev=588742&view=auto
==============================================================================
--- james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/DecoderUtilsTest.java (added)
+++ james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/decode/DecoderUtilsTest.java Fri Oct 26 11:47:42 2007
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.imapserver.codec.decode;
+
+import javax.mail.Flags;
+
+import junit.framework.TestCase;
+
+public class DecoderUtilsTest extends TestCase {
+    
+    private static final String EXTENSION_FLAG = "\\Extension";
+    private static final String A_CUSTOM_FLAG = "Another";
+    private static final String FLAG_MESSAGE = "RFC3501 specifies that \\Recent flag cannot be set by the client but accept liberally for better compatibility.";
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testSetRecentFlag() throws Exception {
+        Flags flags = new Flags();
+        DecoderUtils.setFlag("\\Recent", flags);
+        assertFalse(FLAG_MESSAGE, flags.contains("\\Recent"));
+        assertFalse(FLAG_MESSAGE, flags.contains(Flags.Flag.RECENT));
+    }
+
+    public void testSetOtherFlag() throws Exception {
+        Flags flags = new Flags();
+        DecoderUtils.setFlag(A_CUSTOM_FLAG, flags);
+        assertTrue("Unknown flags should be added", flags.contains(A_CUSTOM_FLAG));
+    }
+    
+    public void testExtensionFlag() throws Exception {
+        Flags flags = new Flags();
+        DecoderUtils.setFlag(EXTENSION_FLAG, flags);
+        assertTrue("Extension flags should be added", flags.contains(EXTENSION_FLAG));
+    }
+}



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