Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 3546 invoked from network); 31 Mar 2006 22:37:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Mar 2006 22:37:00 -0000 Received: (qmail 36271 invoked by uid 500); 31 Mar 2006 22:36:59 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 36122 invoked by uid 500); 31 Mar 2006 22:36:58 -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 36111 invoked by uid 99); 31 Mar 2006 22:36:58 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Mar 2006 14:36:58 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 31 Mar 2006 14:36:58 -0800 Received: (qmail 3455 invoked by uid 65534); 31 Mar 2006 22:36:37 -0000 Message-ID: <20060331223637.3452.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: jlaskowski@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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