Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 32109 invoked from network); 8 Jun 2006 10:53:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Jun 2006 10:53:12 -0000 Received: (qmail 32144 invoked by uid 500); 8 Jun 2006 10:53:11 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 32111 invoked by uid 500); 8 Jun 2006 10:53:11 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 32100 invoked by uid 99); 8 Jun 2006 10:53:11 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jun 2006 03:53:11 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jun 2006 03:53:10 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 383131A983A; Thu, 8 Jun 2006 03:52:50 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: rickmcguire@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060608105250.383131A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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()); + } }