james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1133435 - in /james/imap/trunk: api/src/main/java/org/apache/james/imap/api/ api/src/main/java/org/apache/james/imap/api/display/ message/src/main/java/org/apache/james/imap/decode/parser/ processor/src/main/java/org/apache/james/imap/proc...
Date Wed, 08 Jun 2011 15:34:11 GMT
Author: norman
Date: Wed Jun  8 15:34:11 2011
New Revision: 1133435

URL: http://svn.apache.org/viewvc?rev=1133435&view=rev
Log:
Add support for I18NLEVEL-1. SEE IMAP-312

Added:
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
Modified:
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java?rev=1133435&r1=1133434&r2=1133435&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java (original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapConstants.java Wed Jun
 8 15:34:11 2011
@@ -85,6 +85,10 @@ public interface ImapConstants {
 
     public static final String SUPPORTS_RFC3348 = "CHILDREN";
 
+    public static final String UTF8 = "UTF-8";
+    
+    public static final String SUPPORTS_I18NLEVEL_1 = "I18NLEVEL=1";
+
     public static final String SUPPORTS_NAMESPACES = "NAMESPACE";
 
     public static final String SUPPORTS_STARTTLS = "STARTTLS";

Added: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java?rev=1133435&view=auto
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
(added)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
Wed Jun  8 15:34:11 2011
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.imap.api.display;
+
+import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Utility class which can be used to get a list of supported Charsets
+ * 
+ *
+ */
+public class CharsetUtil {
+
+    private static Set<String> charsetNames;
+    private static Set<Charset> charsets;
+
+
+    // build the sets which holds the charsets and names
+    static {
+        Set<String>cNames = new HashSet<String>();
+        Set<Charset> sets = new HashSet<Charset>();
+
+        for (final Iterator<Charset> it = Charset.availableCharsets().values().iterator();
it.hasNext();) {
+            final Charset charset = it.next();
+            final Set<String> aliases = charset.aliases();
+            cNames.addAll(aliases);
+            sets.add(charset);
+
+        }
+        charsetNames = Collections.unmodifiableSet(cNames);
+        charsets = Collections.unmodifiableSet(sets);
+    }
+
+    /**
+     * Return an unmodifiable {@link Set} which holds the names (and aliases) of all supported
Charsets
+     * 
+     * @return supportedCharsetNames
+     */
+    public final static Set<String> getAvailableCharsetNames() {
+        return charsetNames;
+    }
+    
+    /**
+     * Return an unmodifiable {@link Set} which holds all supported Charsets
+     * 
+     * @return supportedCharsets
+     */
+    public final static Set<Charset> getAvailableCharsets() {
+        return charsets;
+    }
+    
+}

Modified: james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java?rev=1133435&r1=1133434&r2=1133435&view=diff
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
(original)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
Wed Jun  8 15:34:11 2011
@@ -23,15 +23,12 @@ import java.nio.charset.IllegalCharsetNa
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.request.DayMonthYear;
@@ -51,9 +48,6 @@ import org.apache.james.imap.message.req
  */
 public class SearchCommandParser extends AbstractUidCommandParser {
 
-    /** Lazy loaded */
-    private Collection<String> charsetNames;
-
     public SearchCommandParser() {
         super(ImapCommand.selectedStateCommand(ImapConstants.SEARCH_COMMAND_NAME));
     }
@@ -885,24 +879,12 @@ public class SearchCommandParser extends
     }
 
     private ImapMessage unsupportedCharset(final String tag, final ImapCommand command) {
-        loadCharsetNames();
         final StatusResponseFactory factory = getStatusResponseFactory();
-        final ResponseCode badCharset = StatusResponse.ResponseCode.badCharset(charsetNames);
+        final ResponseCode badCharset = StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames());
         final StatusResponse result = factory.taggedNo(tag, command, HumanReadableText.BAD_CHARSET,
badCharset);
         return result;
     }
 
-    private synchronized void loadCharsetNames() {
-        if (charsetNames == null) {
-            charsetNames = new HashSet<String>();
-            for (final Iterator<Charset> it = Charset.availableCharsets().values().iterator();
it.hasNext();) {
-                final Charset charset = it.next();
-                final Set<String> aliases = charset.aliases();
-                charsetNames.addAll(aliases);
-            }
-        }
-    }
-
     /**
      * Parse the {@link SearchResultOption}'s which are used for ESEARCH
      */

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java?rev=1133435&r1=1133434&r2=1133435&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java
Wed Jun  8 15:34:11 2011
@@ -22,11 +22,14 @@ package org.apache.james.imap.processor;
 import static org.apache.james.imap.api.ImapConstants.SUPPORTS_LITERAL_PLUS;
 import static org.apache.james.imap.api.ImapConstants.SUPPORTS_RFC3348;
 import static org.apache.james.imap.api.ImapConstants.VERSION;
+import static org.apache.james.imap.api.ImapConstants.UTF8;
+import static org.apache.james.imap.api.ImapConstants.SUPPORTS_I18NLEVEL_1;
 
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -98,6 +101,11 @@ public class CapabilityProcessor extends
         capabilities.add(VERSION);
         capabilities.add(SUPPORTS_LITERAL_PLUS);
         capabilities.add(SUPPORTS_RFC3348);
+        
+        // UTF-8 is needed for I18NLEVEL_1
+        if (CharsetUtil.getAvailableCharsets().contains(UTF8)) {
+            capabilities.add(SUPPORTS_I18NLEVEL_1);
+        }
         return capabilities;
     }
 



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


Mime
View raw message