diff --git a/.gitignore b/.gitignore index 8321ce1fa..9bbaeaca7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ nbproject/private/ .m2/ webrev mbox/.ccls-cache/ +/bin/ +.classpath +.project +.settings/ diff --git a/mail/src/main/java/jakarta/mail/internet/MimeBodyPart.java b/mail/src/main/java/jakarta/mail/internet/MimeBodyPart.java index 1dc4e0f2e..f5fb40c6c 100644 --- a/mail/src/main/java/jakarta/mail/internet/MimeBodyPart.java +++ b/mail/src/main/java/jakarta/mail/internet/MimeBodyPart.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,16 +16,42 @@ package jakarta.mail.internet; -import jakarta.mail.*; -import jakarta.activation.*; -import java.io.*; -import java.util.*; -import com.sun.mail.util.PropUtil; +import jakarta.activation.DataHandler; +import jakarta.activation.DataSource; +import jakarta.activation.FileDataSource; +import jakarta.mail.BodyPart; +import jakarta.mail.EncodingAware; +import jakarta.mail.FolderClosedException; +import jakarta.mail.Header; +import jakarta.mail.IllegalWriteException; +import jakarta.mail.Message; +import jakarta.mail.MessageContext; +import jakarta.mail.MessageRemovedException; +import jakarta.mail.MessagingException; +import jakarta.mail.Multipart; +import jakarta.mail.Part; +import jakarta.mail.Session; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Properties; + import com.sun.mail.util.ASCIIUtility; -import com.sun.mail.util.MimeUtil; -import com.sun.mail.util.MessageRemovedIOException; import com.sun.mail.util.FolderClosedIOException; import com.sun.mail.util.LineOutputStream; +import com.sun.mail.util.MessageRemovedIOException; +import com.sun.mail.util.MimeUtil; +import com.sun.mail.util.PropUtil; /** * This class represents a MIME body part. It implements the @@ -63,29 +89,30 @@ public class MimeBodyPart extends BodyPart implements MimePart { // Paranoia: // allow this last minute change to be disabled if it causes problems - private static final boolean setDefaultTextCharset = - PropUtil.getBooleanSystemProperty( - "mail.mime.setdefaulttextcharset", true); - - private static final boolean setContentTypeFileName = - PropUtil.getBooleanSystemProperty( - "mail.mime.setcontenttypefilename", true); - - private static final boolean encodeFileName = - PropUtil.getBooleanSystemProperty("mail.mime.encodefilename", false); - private static final boolean decodeFileName = - PropUtil.getBooleanSystemProperty("mail.mime.decodefilename", false); - private static final boolean ignoreMultipartEncoding = - PropUtil.getBooleanSystemProperty( - "mail.mime.ignoremultipartencoding", true); - private static final boolean allowutf8 = - PropUtil.getBooleanSystemProperty("mail.mime.allowutf8", true); - + static final boolean SET_DEFAULT_TEXT_CHARSET = + PropUtil.getBooleanSystemProperty("mail.mime.setdefaulttextcharset", true); + static final boolean SET_CONTENT_TYPE_FILE_NAME = + PropUtil.getBooleanSystemProperty("mail.mime.setcontenttypefilename", true); + static final boolean ENCODE_FILE_NAME = + PropUtil.getBooleanSystemProperty("mail.mime.encodefilename", false); + static final boolean DECODE_FILE_NAME = + PropUtil.getBooleanSystemProperty("mail.mime.decodefilename", false); + static final boolean IGNORE_MULTIPART_ENCODING = + PropUtil.getBooleanSystemProperty("mail.mime.ignoremultipartencoding", true); + static final boolean ALLOW_UTF8 = + PropUtil.getBooleanSystemProperty("mail.mime.allowutf8", true); // Paranoia: // allow this last minute change to be disabled if it causes problems - static final boolean cacheMultipart = // accessed by MimeMessage - PropUtil.getBooleanSystemProperty("mail.mime.cachemultipart", true); + static final boolean CACHE_MULTIPART = // accessed by MimeMessage + PropUtil.getBooleanSystemProperty("mail.mime.cachemultipart", true); + protected boolean setDefaultTextCharset = SET_DEFAULT_TEXT_CHARSET; + protected boolean setContentTypeFileName = SET_CONTENT_TYPE_FILE_NAME; + protected boolean encodeFileName = ENCODE_FILE_NAME; + protected boolean decodeFileName = DECODE_FILE_NAME; + protected boolean ignoreMultipartEncoding = IGNORE_MULTIPART_ENCODING; + protected boolean allowutf8 = ALLOW_UTF8; + protected boolean cacheMultipart = CACHE_MULTIPART; /** * The DataHandler object representing this Part's content. @@ -192,6 +219,34 @@ public MimeBodyPart(InternetHeaders headers, byte[] content) this.content = content; } + /** + * Initializes MimeBodyPart from the InputStream is and it overwrites + * properties from session. + * + * @param session Session object for this message + * @param is the message input stream + * @exception MessagingException for failures + */ + public MimeBodyPart(Session session, InputStream is) throws MessagingException { + this(is); + initializeProperties(session); + } + + /** + * Set the values from session properties if exist, otherwise it keeps the previous value. + * @param session the not null session + */ + private void initializeProperties(Session session) { + Properties props = session.getProperties(); + setDefaultTextCharset = PropUtil.getBooleanProperty(props, "mail.mime.setdefaulttextcharset", setDefaultTextCharset); + setContentTypeFileName = PropUtil.getBooleanProperty(props, "mail.mime.setcontenttypefilename", setContentTypeFileName); + encodeFileName = PropUtil.getBooleanProperty(props, "mail.mime.encodefilename", encodeFileName); + decodeFileName = PropUtil.getBooleanProperty(props, "mail.mime.decodefilename", decodeFileName); + ignoreMultipartEncoding = PropUtil.getBooleanProperty(props, "mail.mime.ignoremultipartencoding", ignoreMultipartEncoding); + allowutf8 = PropUtil.getBooleanProperty(props, "mail.mime.allowutf8", allowutf8); + cacheMultipart = PropUtil.getBooleanProperty(props, "mail.mime.cachemultipart", cacheMultipart); + } + /** * Return the size of the content of this body part in bytes. * Return -1 if the size cannot be determined.

@@ -522,7 +577,7 @@ public void setDescription(String description, String charset) */ @Override public String getFileName() throws MessagingException { - return getFileName(this); + return getFileName(this, decodeFileName); } /** @@ -550,7 +605,7 @@ public String getFileName() throws MessagingException { */ @Override public void setFileName(String filename) throws MessagingException { - setFileName(this, filename); + setFileName(this, filename, encodeFileName, setContentTypeFileName); } /** @@ -969,7 +1024,7 @@ public void saveFile(String file) throws IOException, MessagingException { @Override public void writeTo(OutputStream os) throws IOException, MessagingException { - writeTo(this, os, null); + writeTo(this, os, null, allowutf8, ignoreMultipartEncoding); } /** @@ -1145,7 +1200,7 @@ public Enumeration getNonMatchingHeaderLines(String[] names) * @exception MessagingException for failures */ protected void updateHeaders() throws MessagingException { - updateHeaders(this); + updateHeaders(this, setDefaultTextCharset, setContentTypeFileName, encodeFileName); /* * If we've cached a Multipart or Message object then * we're now committed to using this instance of the @@ -1261,7 +1316,7 @@ static String getDescription(MimePart part) } } - static String getFileName(MimePart part) throws MessagingException { + static String getFileName(MimePart part, boolean decodeFileName) throws MessagingException { String filename = null; String s = part.getHeader("Content-Disposition", null); @@ -1291,7 +1346,8 @@ static String getFileName(MimePart part) throws MessagingException { return filename; } - static void setFileName(MimePart part, String name) + static void setFileName(MimePart part, String name, boolean encodeFileName, + boolean setContentTypeFileName) throws MessagingException { if (encodeFileName && name != null) { try { @@ -1440,7 +1496,7 @@ static void setEncoding(MimePart part, String encoding) * Content-Type of the specified MimePart. Returns * either the original encoding or null. */ - static String restrictEncoding(MimePart part, String encoding) + static String restrictEncoding(MimePart part, String encoding, boolean ignoreMultipartEncoding) throws MessagingException { if (!ignoreMultipartEncoding || encoding == null) return encoding; @@ -1473,7 +1529,8 @@ static String restrictEncoding(MimePart part, String encoding) return encoding; } - static void updateHeaders(MimePart part) throws MessagingException { + static void updateHeaders(MimePart part, boolean setDefaultTextCharset, boolean setContentTypeFileName, + boolean encodeFileName) throws MessagingException { DataHandler dh = part.getDataHandler(); if (dh == null) // Huh ? return; @@ -1620,8 +1677,8 @@ static void invalidateContentHeaders(MimePart part) part.removeHeader("Content-Transfer-Encoding"); } - static void writeTo(MimePart part, OutputStream os, String[] ignoreList) - throws IOException, MessagingException { + static void writeTo(MimePart part, OutputStream os, String[] ignoreList, boolean allowutf8, + boolean ignoreMultipartEncoding) throws IOException, MessagingException { // see if we already have a LOS LineOutputStream los = null; @@ -1666,7 +1723,7 @@ static void writeTo(MimePart part, OutputStream os, String[] ignoreList) os.write(buf, 0, len); } else { os = MimeUtility.encode(os, - restrictEncoding(part, part.getEncoding())); + restrictEncoding(part, part.getEncoding(), ignoreMultipartEncoding)); part.getDataHandler().writeTo(os); } } finally { diff --git a/mail/src/main/java/jakarta/mail/internet/MimeMessage.java b/mail/src/main/java/jakarta/mail/internet/MimeMessage.java index f987ec1e1..f534faa7a 100644 --- a/mail/src/main/java/jakarta/mail/internet/MimeMessage.java +++ b/mail/src/main/java/jakarta/mail/internet/MimeMessage.java @@ -16,19 +16,49 @@ package jakarta.mail.internet; -import jakarta.mail.*; -import jakarta.activation.*; -import java.lang.*; -import java.io.*; -import java.util.*; +import static jakarta.mail.internet.MimeBodyPart.ALLOW_UTF8; +import static jakarta.mail.internet.MimeBodyPart.CACHE_MULTIPART; +import static jakarta.mail.internet.MimeBodyPart.DECODE_FILE_NAME; +import static jakarta.mail.internet.MimeBodyPart.ENCODE_FILE_NAME; +import static jakarta.mail.internet.MimeBodyPart.IGNORE_MULTIPART_ENCODING; +import static jakarta.mail.internet.MimeBodyPart.SET_CONTENT_TYPE_FILE_NAME; +import static jakarta.mail.internet.MimeBodyPart.SET_DEFAULT_TEXT_CHARSET; + +import jakarta.activation.DataHandler; +import jakarta.mail.Address; +import jakarta.mail.Flags; +import jakarta.mail.Folder; +import jakarta.mail.FolderClosedException; +import jakarta.mail.Header; +import jakarta.mail.IllegalWriteException; +import jakarta.mail.Message; +import jakarta.mail.MessageRemovedException; +import jakarta.mail.MessagingException; +import jakarta.mail.Multipart; +import jakarta.mail.Session; +import jakarta.mail.util.SharedByteArrayInputStream; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; import java.text.ParseException; -import com.sun.mail.util.PropUtil; +import java.util.ArrayList; +import java.util.Date; +import java.util.Enumeration; +import java.util.List; +import java.util.Properties; + import com.sun.mail.util.ASCIIUtility; -import com.sun.mail.util.MimeUtil; -import com.sun.mail.util.MessageRemovedIOException; import com.sun.mail.util.FolderClosedIOException; import com.sun.mail.util.LineOutputStream; -import jakarta.mail.util.SharedByteArrayInputStream; +import com.sun.mail.util.MessageRemovedIOException; +import com.sun.mail.util.MimeUtil; +import com.sun.mail.util.PropUtil; /** * This class represents a MIME style email message. It implements @@ -159,8 +189,20 @@ public class MimeMessage extends Message implements MimePart { // Should addresses in headers be parsed in "strict" mode? private boolean strict = true; + + protected boolean setDefaultTextCharset = SET_DEFAULT_TEXT_CHARSET; + protected boolean setContentTypeFileName = SET_CONTENT_TYPE_FILE_NAME; + protected boolean encodeFileName = ENCODE_FILE_NAME; + protected boolean decodeFileName = DECODE_FILE_NAME; + protected boolean ignoreMultipartEncoding = IGNORE_MULTIPART_ENCODING; + /* + * This is not a duplicate of allowutf8Headers. When mail.mime.allowutf8 + * is not defined, this value is 'true'. Meanwhile allowutf8Headers is 'false' + */ + protected boolean allowutf8 = ALLOW_UTF8; + protected boolean cacheMultipart = CACHE_MULTIPART; // Is UTF-8 allowed in headers? - private boolean allowutf8 = false; + private boolean allowutf8Headers = false; /** * Default constructor. An empty message object is created. @@ -296,16 +338,21 @@ protected MimeMessage(Folder folder, InternetHeaders headers, } /** - * Set the strict flag based on property. + * Set the properties from session if exists, otherwise it keeps the previous value. */ private void initStrict() { - if (session != null) { - Properties props = session.getProperties(); - strict = PropUtil.getBooleanProperty(props, - "mail.mime.address.strict", true); - allowutf8 = PropUtil.getBooleanProperty(props, - "mail.mime.allowutf8", false); - } + if (session != null) { + Properties props = session.getProperties(); + strict = PropUtil.getBooleanProperty(props, "mail.mime.address.strict", true); + allowutf8Headers = PropUtil.getBooleanProperty(props, "mail.mime.allowutf8", false); + setDefaultTextCharset = PropUtil.getBooleanProperty(props, "mail.mime.setdefaulttextcharset", setDefaultTextCharset); + setContentTypeFileName = PropUtil.getBooleanProperty(props, "mail.mime.setcontenttypefilename", setContentTypeFileName); + encodeFileName = PropUtil.getBooleanProperty(props, "mail.mime.encodefilename", encodeFileName); + decodeFileName = PropUtil.getBooleanProperty(props, "mail.mime.decodefilename", decodeFileName); + ignoreMultipartEncoding = PropUtil.getBooleanProperty(props, "mail.mime.ignoremultipartencoding", ignoreMultipartEncoding); + allowutf8 = PropUtil.getBooleanProperty(props, "mail.mime.allowutf8", allowutf8); + cacheMultipart = PropUtil.getBooleanProperty(props, "mail.mime.cachemultipart", cacheMultipart); + } } /** @@ -736,7 +783,7 @@ private Address[] getAddressHeader(String name) private void setAddressHeader(String name, Address[] addresses) throws MessagingException { String s; - if (allowutf8) + if (allowutf8Headers) s = InternetAddress.toUnicodeString(addresses, name.length() + 2); else s = InternetAddress.toString(addresses, name.length() + 2); @@ -760,7 +807,7 @@ private void addAddressHeader(String name, Address[] addresses) System.arraycopy(addresses, 0, anew, a.length, addresses.length); } String s; - if (allowutf8) + if (allowutf8Headers) s = InternetAddress.toUnicodeString(anew, name.length() + 2); else s = InternetAddress.toString(anew, name.length() + 2); @@ -1304,7 +1351,7 @@ public String getMessageID() throws MessagingException { */ @Override public String getFileName() throws MessagingException { - return MimeBodyPart.getFileName(this); + return MimeBodyPart.getFileName(this, decodeFileName); } /** @@ -1329,7 +1376,7 @@ public String getFileName() throws MessagingException { */ @Override public void setFileName(String filename) throws MessagingException { - MimeBodyPart.setFileName(this, filename); + MimeBodyPart.setFileName(this, filename, encodeFileName, setContentTypeFileName); } private String getHeaderName(Message.RecipientType type) @@ -1487,7 +1534,7 @@ public Object getContent() throws IOException, MessagingException { } catch (MessageRemovedIOException mex) { throw new MessageRemovedException(mex.getMessage()); } - if (MimeBodyPart.cacheMultipart && + if (cacheMultipart && (c instanceof Multipart || c instanceof Message) && (content != null || contentStream != null)) { cachedContent = c; @@ -1885,14 +1932,14 @@ public void writeTo(OutputStream os, String[] ignoreList) saveChanges(); if (modified) { - MimeBodyPart.writeTo(this, os, ignoreList); + MimeBodyPart.writeTo(this, os, ignoreList, allowutf8, ignoreMultipartEncoding); return; } // Else, the content is untouched, so we can just output it // First, write out the header Enumeration hdrLines = getNonMatchingHeaderLines(ignoreList); - LineOutputStream los = new LineOutputStream(os, allowutf8); + LineOutputStream los = new LineOutputStream(os, allowutf8Headers); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); @@ -2243,7 +2290,7 @@ protected void updateMessageID() throws MessagingException { * @exception MessagingException for other failures */ protected synchronized void updateHeaders() throws MessagingException { - MimeBodyPart.updateHeaders(this); + MimeBodyPart.updateHeaders(this, setDefaultTextCharset, setContentTypeFileName, encodeFileName); setHeader("MIME-Version", "1.0"); if (getHeader("Date") == null) setSentDate(new Date()); @@ -2276,7 +2323,7 @@ protected synchronized void updateHeaders() throws MessagingException { */ protected InternetHeaders createInternetHeaders(InputStream is) throws MessagingException { - return new InternetHeaders(is, allowutf8); + return new InternetHeaders(is, allowutf8Headers); } /** diff --git a/mail/src/main/java/jakarta/mail/internet/MimeMultipart.java b/mail/src/main/java/jakarta/mail/internet/MimeMultipart.java index 4f6f39ede..01b66e875 100644 --- a/mail/src/main/java/jakarta/mail/internet/MimeMultipart.java +++ b/mail/src/main/java/jakarta/mail/internet/MimeMultipart.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -991,7 +991,13 @@ protected MimeBodyPart createMimeBodyPart(InternetHeaders headers, */ protected MimeBodyPart createMimeBodyPart(InputStream is) throws MessagingException { - return new MimeBodyPart(is); + if (ds != null && ds instanceof MimePartDataSource) { + Session session = ((MimePartDataSource)ds).getMessageContext().getSession(); + if (session != null) { + return new MimeBodyPart(session, is); + } + } + return new MimeBodyPart(is); } private MimeBodyPart createMimeBodyPartIs(InputStream is) diff --git a/mail/src/main/java/jakarta/mail/internet/MimePartDataSource.java b/mail/src/main/java/jakarta/mail/internet/MimePartDataSource.java index 91fe4cdea..072205342 100644 --- a/mail/src/main/java/jakarta/mail/internet/MimePartDataSource.java +++ b/mail/src/main/java/jakarta/mail/internet/MimePartDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,12 +16,22 @@ package jakarta.mail.internet; -import jakarta.mail.*; -import jakarta.activation.*; -import java.io.*; +import static jakarta.mail.internet.MimeBodyPart.IGNORE_MULTIPART_ENCODING; + +import jakarta.activation.DataSource; +import jakarta.mail.FolderClosedException; +import jakarta.mail.MessageAware; +import jakarta.mail.MessageContext; +import jakarta.mail.MessagingException; +import jakarta.mail.Session; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.UnknownServiceException; -import com.sun.mail.util.PropUtil; + import com.sun.mail.util.FolderClosedIOException; +import com.sun.mail.util.PropUtil; /** * A utility class that implements a DataSource out of @@ -33,6 +43,8 @@ */ public class MimePartDataSource implements DataSource, MessageAware { + + protected boolean ignoreMultipartEncoding = IGNORE_MULTIPART_ENCODING; /** * The MimePart that provides the data for this DataSource. * @@ -48,7 +60,13 @@ public class MimePartDataSource implements DataSource, MessageAware { * @param part the MimePart */ public MimePartDataSource(MimePart part) { - this.part = part; + this.part = part; + this.context = new MessageContext(part); + Session session = context.getSession(); + if (session != null) { + this.ignoreMultipartEncoding = PropUtil.getBooleanProperty(session.getProperties(), + "mail.mime.ignoremultipartencoding", ignoreMultipartEncoding); + } } /** @@ -80,7 +98,7 @@ else if (part instanceof MimeMessage) throw new MessagingException("Unknown part"); String encoding = - MimeBodyPart.restrictEncoding(part, part.getEncoding()); + MimeBodyPart.restrictEncoding(part, part.getEncoding(), ignoreMultipartEncoding); if (encoding != null) return MimeUtility.decode(is, encoding); else @@ -145,9 +163,7 @@ public String getName() { * @since JavaMail 1.1 */ @Override - public synchronized MessageContext getMessageContext() { - if (context == null) - context = new MessageContext(part); - return context; + public MessageContext getMessageContext() { + return context; } } diff --git a/mail/src/test/java/jakarta/mail/internet/MimeBodyPartTest.java b/mail/src/test/java/jakarta/mail/internet/MimeBodyPartTest.java index aada2280d..be57ffabd 100644 --- a/mail/src/test/java/jakarta/mail/internet/MimeBodyPartTest.java +++ b/mail/src/test/java/jakarta/mail/internet/MimeBodyPartTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -177,6 +177,63 @@ public void testEmptyContentTransferEncoding() throws Exception { assertEquals("empty C-T-E data", "test\n", mbp.getContent()); } + @Test + public void sessionProperties() throws MessagingException, IOException { + Properties prop = new Properties(); + MimeMessage orig = buildFromProperties(prop); + MimeMultipart omp = (MimeMultipart)orig.getContent(); + MimeBodyPart obp = (MimeBodyPart)omp.getBodyPart(0); + // No properties added, so default will be checked + // MimeMessage + assertTrue(orig.setDefaultTextCharset); + assertTrue(orig.setContentTypeFileName); + assertFalse(orig.encodeFileName); + assertFalse(orig.decodeFileName); + assertTrue(orig.ignoreMultipartEncoding); + assertTrue(orig.allowutf8); + assertTrue(orig.cacheMultipart); + // MimeBodyPart + assertTrue(obp.setDefaultTextCharset); + assertTrue(obp.setContentTypeFileName); + assertFalse(obp.encodeFileName); + assertFalse(obp.decodeFileName); + assertTrue(obp.ignoreMultipartEncoding); + assertTrue(obp.allowutf8); + assertTrue(obp.cacheMultipart); + // Change the properties in opposite way + prop.put("mail.mime.setdefaulttextcharset", Boolean.FALSE); + prop.put("mail.mime.setcontenttypefilename", Boolean.FALSE); + prop.put("mail.mime.encodefilename", Boolean.TRUE); + prop.put("mail.mime.decodefilename", Boolean.TRUE); + prop.put("mail.mime.ignoremultipartencoding", Boolean.FALSE); + prop.put("mail.mime.allowutf8", Boolean.FALSE); + prop.put("mail.mime.cachemultipart", Boolean.FALSE); + orig = buildFromProperties(prop); + omp = (MimeMultipart)orig.getContent(); + obp = (MimeBodyPart)omp.getBodyPart(0); + // MimeMessage + assertFalse(orig.setDefaultTextCharset); + assertFalse(orig.setContentTypeFileName); + assertTrue(orig.encodeFileName); + assertTrue(orig.decodeFileName); + assertFalse(orig.ignoreMultipartEncoding); + assertFalse(orig.allowutf8); + assertFalse(orig.cacheMultipart); + // MimeBodyPart + assertFalse(obp.setDefaultTextCharset); + assertFalse(obp.setContentTypeFileName); + assertTrue(obp.encodeFileName); + assertTrue(obp.decodeFileName); + assertFalse(obp.ignoreMultipartEncoding); + assertFalse(obp.allowutf8); + assertFalse(obp.cacheMultipart); + } + + private MimeMessage buildFromProperties(Properties prop) throws MessagingException, IOException { + Session s = Session.getInstance(prop); + MimeMessage orig = createMessage(s); + return orig; + } private static MimeMessage createMessage(Session s) throws MessagingException { diff --git a/mail/src/test/java/jakarta/mail/internet/NonAsciiFileNames.java b/mail/src/test/java/jakarta/mail/internet/NonAsciiFileNames.java index 03b9f8743..869664b1c 100644 --- a/mail/src/test/java/jakarta/mail/internet/NonAsciiFileNames.java +++ b/mail/src/test/java/jakarta/mail/internet/NonAsciiFileNames.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -42,7 +42,7 @@ public void testNonAsciiFileName() throws Exception { MimeBodyPart mbp = new MimeBodyPart(); mbp.setText("test\n"); mbp.setFileName("test\u00a1\u00a2\u00a3"); - MimeBodyPart.updateHeaders(mbp); + MimeBodyPart.updateHeaders(mbp, true, true, false); String s = mbp.getHeader("Content-Disposition", null); assertTrue("Content-Disposition filename", s.indexOf("filename*") >= 0); @@ -60,7 +60,7 @@ public void testNonAsciiFileNameWithContentType() throws Exception { mbp.setText("test\n"); mbp.setHeader("Content-Type", "text/x-test"); mbp.setFileName("test\u00a1\u00a2\u00a3"); - MimeBodyPart.updateHeaders(mbp); + MimeBodyPart.updateHeaders(mbp, true, true, false); String s = mbp.getHeader("Content-Disposition", null); assertTrue("Content-Disposition filename", s.indexOf("filename*") >= 0);