geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r390527 - in /geronimo/specs/trunk/geronimo-spec-javamail: ./ src/main/java/javax/mail/internet/MimeBodyPart.java src/test/java/javax/mail/internet/MimeBodyPartTest.java
Date Fri, 31 Mar 2006 22:36:36 GMT
Author: jlaskowski
Date: Fri Mar 31 14:36:35 2006
New Revision: 390527

URL: http://svn.apache.org/viewcvs?rev=390527&view=rev
Log:
GERONIMO-1793 - MimeBodyPart setDescription()/getDescription() is not properly encoding header
description data
Submitted by: Rick McGuire

Added:
    geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
  (with props)
Modified:
    geronimo/specs/trunk/geronimo-spec-javamail/   (props changed)
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Mar 31 14:36:35 2006
@@ -1,5 +1,6 @@
 *.iml
 .project
+.settings
 .classpath
 maven.log
 junit*.properties

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java?rev=390527&r1=390526&r2=390527&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
Fri Mar 31 14:36:35 2006
@@ -253,7 +253,17 @@
     }
 
     public String getDescription() throws MessagingException {
-        return getSingleHeader("Content-Description");
+        String description = getSingleHeader("Content-Description");
+        if (description != null) {
+            try {
+                // this could be both folded and encoded.  Return this to usable form.
+                return MimeUtility.decodeText(ASCIIUtil.unfold(description));
+            } catch (UnsupportedEncodingException e) {
+                // ignore
+            }
+        }
+        // return the raw version for any errors.
+        return description;
     }
 
     public void setDescription(String description) throws MessagingException {

Added: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java?rev=390527&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
(added)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
Fri Mar 31 14:36:35 2006
@@ -0,0 +1,101 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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 javax.mail.internet;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.mail.MessagingException;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MimeBodyPartTest extends TestCase {
+
+    public void testGetSize() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertEquals(part.getSize(), -1);
+
+        part = new MimeBodyPart(new InternetHeaders(), new byte[] {'a', 'b', 'c'});
+        assertEquals(part.getSize(), 3);
+    }
+
+    public void testGetLineCount() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertEquals(part.getLineCount(), -1);
+
+        part = new MimeBodyPart(new InternetHeaders(), new byte[] {'a', 'b', 'c'});
+        assertEquals(part.getLineCount(), -1);
+    }
+
+
+    public void testGetContentType() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertEquals(part.getContentType(), "text/plain");
+
+        part.setHeader("Content-Type", "text/xml");
+        assertEquals(part.getContentType(), "text/xml");
+
+        part = new MimeBodyPart();
+        part.setText("abc");
+        assertEquals(part.getContentType(), "text/plain");
+    }
+
+
+    public void testIsMimeType() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertTrue(part.isMimeType("text/plain"));
+        assertTrue(part.isMimeType("text/*"));
+
+        part.setHeader("Content-Type", "text/xml");
+        assertTrue(part.isMimeType("text/xml"));
+        assertTrue(part.isMimeType("text/*"));
+    }
+
+
+    public void testGetDisposition() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertNull(part.getDisposition());
+
+        part.setDisposition("inline");
+        assertEquals(part.getDisposition(), "inline");
+    }
+
+
+    public void testSetDescription() throws MessagingException, UnsupportedEncodingException
{
+        MimeBodyPart part = new MimeBodyPart();
+
+        String simpleSubject = "Yada, yada";
+
+        String complexSubject = "Yada, yada\u0081";
+
+        String mungedSubject = "Yada, yada\u003F";
+
+        part.setDescription(simpleSubject);
+        assertEquals(part.getDescription(), simpleSubject);
+
+        part.setDescription(complexSubject, "UTF-8");
+        assertEquals(part.getDescription(), complexSubject);
+        assertEquals(part.getHeader("Content-Description", null), MimeUtility.encodeText(complexSubject,
"UTF-8", null));
+
+        part.setDescription(null);
+        assertNull(part.getDescription());
+    }
+}
+

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message