james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r738066 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/codec/EncoderUtil.java main/java/org/apache/james/mime4j/field/Fields.java test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
Date Tue, 27 Jan 2009 12:16:34 GMT
Author: mwiederkehr
Date: Tue Jan 27 12:16:33 2009
New Revision: 738066

URL: http://svn.apache.org/viewvc?rev=738066&view=rev
Log:
change encodeContentTypeParameterValue in encodeHeaderParameter

Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/Fields.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java?rev=738066&r1=738065&r2=738066&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java Tue Jan
27 12:16:33 2009
@@ -138,20 +138,22 @@
     }
 
     /**
-     * Encodes the specified string as a value of a Content-Type parameter as
-     * described in RFC 2045 section 5.1. The specified string should not
+     * Encodes the specified strings into a header parameter as described in RFC
+     * 2045 section 5.1 and RFC 2183 section 2. The specified strings should not
      * contain any illegal (control or non-ASCII) characters.
      * 
+     * @param name
+     *            parameter name.
      * @param value
-     *            string to encode.
+     *            parameter value.
      * @return encoded result.
      */
-    public static String encodeContentTypeParameterValue(String value) {
+    public static String encodeHeaderParameter(String name, String value) {
         // value := token / quoted-string
         if (isToken(value)) {
-            return value;
+            return name + "=" + value;
         } else {
-            return quote(value);
+            return name + "=" + quote(value);
         }
     }
 

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/Fields.java?rev=738066&r1=738065&r2=738066&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/Fields.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/Fields.java Tue Jan 27
12:16:33 2009
@@ -53,10 +53,8 @@
             StringBuilder sb = new StringBuilder(mimeType);
             for (Map.Entry<String, String> entry : parameters.entrySet()) {
                 sb.append("; ");
-                sb.append(entry.getKey());
-                sb.append('=');
-                sb.append(EncoderUtil.encodeContentTypeParameterValue(entry
-                        .getValue()));
+                sb.append(EncoderUtil.encodeHeaderParameter(entry.getKey(),
+                        entry.getValue()));
             }
             String contentType = sb.toString();
             return contentType(contentType);

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java?rev=738066&r1=738065&r2=738066&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java Tue
Jan 27 12:16:33 2009
@@ -56,17 +56,16 @@
                 .encodeAddressLocalPart("clint eastwood"));
     }
 
-    public void testEncodeContentTypeParameterValue() throws Exception {
-        assertEquals("test", EncoderUtil
-                .encodeContentTypeParameterValue("test"));
-        assertEquals("\"test test\"", EncoderUtil
-                .encodeContentTypeParameterValue("test test"));
-        assertEquals("\"=test\"", EncoderUtil
-                .encodeContentTypeParameterValue("=test"));
-        assertEquals("\"\\\\test\"", EncoderUtil
-                .encodeContentTypeParameterValue("\\test"));
-        assertEquals("\"\\\"\\\\\\\"\"", EncoderUtil
-                .encodeContentTypeParameterValue("\"\\\""));
+    public void testEncodeHeaderParameter() throws Exception {
+        assertEquals("p=test", EncoderUtil.encodeHeaderParameter("p", "test"));
+        assertEquals("p=\"test test\"", EncoderUtil.encodeHeaderParameter("p",
+                "test test"));
+        assertEquals("p=\"=test\"", EncoderUtil.encodeHeaderParameter("p",
+                "=test"));
+        assertEquals("p=\"\\\\test\"", EncoderUtil.encodeHeaderParameter("p",
+                "\\test"));
+        assertEquals("p=\"\\\"\\\\\\\"\"", EncoderUtil.encodeHeaderParameter(
+                "p", "\"\\\""));
     }
 
     public void testHasToBeEncoded() throws Exception {



Mime
View raw message