geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r412720 - in /geronimo/specs/trunk/geronimo-spec-javamail/src: main/java/javax/mail/internet/MimeBodyPart.java test/java/javax/mail/internet/MimeBodyPartTest.java
Date Thu, 08 Jun 2006 10:52:49 GMT
Author: rickmcguire
Date: Thu Jun  8 03:52:48 2006
New Revision: 412720

URL: http://svn.apache.org/viewvc?rev=412720&view=rev
Log:
GERONIMO-2091  MimeBodyPart.getFileName() not retrieving name from the Content-Disposition
header


Modified:
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
    geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java?rev=412720&r1=412719&r2=412720&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
Thu Jun  8 03:52:48 2006
@@ -42,7 +42,9 @@
 public class MimeBodyPart extends BodyPart implements MimePart {
 	 // constants for accessed properties
     private static final String MIME_DECODEFILENAME = "mail.mime.decodefilename";
+    private static final String MIME_ENCODEFILENAME = "mail.mime.encodefilename";
     private static final String MIME_SETDEFAULTTEXTCHARSET = "mail.mime.setdefaulttextcharset";
+    private static final String MIME_SETCONTENTTYPEFILENAME = "mail.mime.setcontenttypefilename";
 
 
     /**
@@ -287,7 +289,7 @@
 
     public String getFileName() throws MessagingException {
         // see if there is a disposition.  If there is, parse off the filename parameter.
-        String disposition = getDisposition();
+        String disposition = getSingleHeader("Content-Disposition");
         String filename = null;
 
         if (disposition != null) {
@@ -297,7 +299,7 @@
         // if there's no filename on the disposition, there might be a name parameter on
a
         // Content-Type header.
         if (filename == null) {
-            String type = getContentType();
+            String type = getSingleHeader("Content-Type");
             if (type != null) {
                 try {
                     filename = new ContentType(type).getParameter("name");
@@ -321,7 +323,7 @@
     public void setFileName(String name) throws MessagingException {
         // there's an optional session property that requests file name encoding...we need
to process this before
         // setting the value.
-        if (name == null) {
+        if (name != null && SessionUtil.getBooleanProperty(MIME_ENCODEFILENAME, false))
{
             try {
                 name = MimeUtility.encodeText(name);
             } catch (UnsupportedEncodingException e) {
@@ -335,12 +337,22 @@
         if (disposition == null) {
             disposition = Part.ATTACHMENT;
         }
+
         // now create a disposition object and set the parameter.
         ContentDisposition contentDisposition = new ContentDisposition(disposition);
         contentDisposition.setParameter("filename", name);
 
         // serialize this back out and reset.
         setDisposition(contentDisposition.toString());
+        setHeader("Content-Disposition", contentDisposition.toString());
+
+        // The Sun implementation appears to update the Content-type name parameter too,
based on
+        // another system property
+        if (SessionUtil.getBooleanProperty(MIME_SETCONTENTTYPEFILENAME, true)) {
+            ContentType type = new ContentType(getContentType());
+            type.setParameter("name", name);
+            setHeader("Content-Type", type.toString());
+        }
     }
 
     public InputStream getInputStream() throws MessagingException, IOException {
@@ -385,7 +397,13 @@
     }
 
     public void setContent(Object content, String type) throws MessagingException {
-        setDataHandler(new DataHandler(content, type));
+        // Multipart content needs to be handled separately.
+        if (content instanceof Multipart) {
+            setContent((Multipart)content);
+        }
+        else {
+            setDataHandler(new DataHandler(content, type));
+        }
     }
 
     public void setText(String text) throws MessagingException {

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java?rev=412720&r1=412719&r2=412720&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeBodyPartTest.java
Thu Jun  8 03:52:48 2006
@@ -97,5 +97,27 @@
         part.setDescription(null);
         assertNull(part.getDescription());
     }
+
+    public void testSetFileName() throws Exception {
+        MimeBodyPart part = new MimeBodyPart();
+        part.setFileName("test.dat");
+
+        assertEquals("test.dat", part.getFileName());
+
+        ContentDisposition disp = new ContentDisposition(part.getHeader("Content-Disposition",
null));
+        assertEquals("test.dat", disp.getParameter("filename"));
+
+        ContentType type = new ContentType(part.getHeader("Content-Type", null));
+        assertEquals("test.dat", type.getParameter("name"));
+
+        MimeBodyPart part2 = new MimeBodyPart();
+
+        part2.setHeader("Content-Type", type.toString());
+
+        assertEquals("test.dat", part2.getFileName());
+        part2.setHeader("Content-Type", null);
+        part2.setHeader("Content-Disposition", disp.toString());
+        assertEquals("test.dat", part2.getFileName());
+    }
 }
 



Mime
View raw message