Skip to content

Commit cb1f427

Browse files
committed
Adding setters for system properties
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent db4f348 commit cb1f427

File tree

5 files changed

+236
-58
lines changed

5 files changed

+236
-58
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ nbproject/private/
44
.m2/
55
webrev
66
mbox/.ccls-cache/
7+
/bin/
8+
.classpath
9+
.project
10+
.settings/

mail/src/main/java/jakarta/mail/internet/MimeBodyPart.java

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -63,29 +63,30 @@ public class MimeBodyPart extends BodyPart implements MimePart {
6363

6464
// Paranoia:
6565
// allow this last minute change to be disabled if it causes problems
66-
private static final boolean setDefaultTextCharset =
67-
PropUtil.getBooleanSystemProperty(
68-
"mail.mime.setdefaulttextcharset", true);
69-
70-
private static final boolean setContentTypeFileName =
71-
PropUtil.getBooleanSystemProperty(
72-
"mail.mime.setcontenttypefilename", true);
73-
74-
private static final boolean encodeFileName =
75-
PropUtil.getBooleanSystemProperty("mail.mime.encodefilename", false);
76-
private static final boolean decodeFileName =
77-
PropUtil.getBooleanSystemProperty("mail.mime.decodefilename", false);
78-
private static final boolean ignoreMultipartEncoding =
79-
PropUtil.getBooleanSystemProperty(
80-
"mail.mime.ignoremultipartencoding", true);
81-
private static final boolean allowutf8 =
82-
PropUtil.getBooleanSystemProperty("mail.mime.allowutf8", true);
83-
66+
static final boolean SET_DEFAULT_TEXT_CHARSET =
67+
PropUtil.getBooleanSystemProperty("mail.mime.setdefaulttextcharset", true);
68+
static final boolean SET_CONTENT_TYPE_FILE_NAME =
69+
PropUtil.getBooleanSystemProperty("mail.mime.setcontenttypefilename", true);
70+
static final boolean ENCODE_FILE_NAME =
71+
PropUtil.getBooleanSystemProperty("mail.mime.encodefilename", false);
72+
static final boolean DECODE_FILE_NAME =
73+
PropUtil.getBooleanSystemProperty("mail.mime.decodefilename", false);
74+
static final boolean IGNORE_MULTIPART_ENCODING =
75+
PropUtil.getBooleanSystemProperty("mail.mime.ignoremultipartencoding", true);
76+
static final boolean ALLOW_UTF8 =
77+
PropUtil.getBooleanSystemProperty("mail.mime.allowutf8", true);
8478
// Paranoia:
8579
// allow this last minute change to be disabled if it causes problems
86-
static final boolean cacheMultipart = // accessed by MimeMessage
87-
PropUtil.getBooleanSystemProperty("mail.mime.cachemultipart", true);
80+
static final boolean CACHE_MULTIPART = // accessed by MimeMessage
81+
PropUtil.getBooleanSystemProperty("mail.mime.cachemultipart", true);
8882

83+
private boolean setDefaultTextCharset = SET_DEFAULT_TEXT_CHARSET;
84+
private boolean setContentTypeFileName = SET_CONTENT_TYPE_FILE_NAME;
85+
private boolean encodeFileName = ENCODE_FILE_NAME;
86+
private boolean decodeFileName = DECODE_FILE_NAME;
87+
private boolean ignoreMultipartEncoding = IGNORE_MULTIPART_ENCODING;
88+
private boolean allowutf8 = ALLOW_UTF8;
89+
private boolean cacheMultipart = CACHE_MULTIPART;
8990

9091
/**
9192
* The DataHandler object representing this Part's content.
@@ -522,7 +523,7 @@ public void setDescription(String description, String charset)
522523
*/
523524
@Override
524525
public String getFileName() throws MessagingException {
525-
return getFileName(this);
526+
return getFileName(this, decodeFileName);
526527
}
527528

528529
/**
@@ -550,7 +551,7 @@ public String getFileName() throws MessagingException {
550551
*/
551552
@Override
552553
public void setFileName(String filename) throws MessagingException {
553-
setFileName(this, filename);
554+
setFileName(this, filename, encodeFileName, setContentTypeFileName);
554555
}
555556

556557
/**
@@ -969,7 +970,7 @@ public void saveFile(String file) throws IOException, MessagingException {
969970
@Override
970971
public void writeTo(OutputStream os)
971972
throws IOException, MessagingException {
972-
writeTo(this, os, null);
973+
writeTo(this, os, null, allowutf8, ignoreMultipartEncoding);
973974
}
974975

975976
/**
@@ -1145,7 +1146,7 @@ public Enumeration<String> getNonMatchingHeaderLines(String[] names)
11451146
* @exception MessagingException for failures
11461147
*/
11471148
protected void updateHeaders() throws MessagingException {
1148-
updateHeaders(this);
1149+
updateHeaders(this, setDefaultTextCharset, setContentTypeFileName, encodeFileName);
11491150
/*
11501151
* If we've cached a Multipart or Message object then
11511152
* we're now committed to using this instance of the
@@ -1261,7 +1262,7 @@ static String getDescription(MimePart part)
12611262
}
12621263
}
12631264

1264-
static String getFileName(MimePart part) throws MessagingException {
1265+
static String getFileName(MimePart part, boolean decodeFileName) throws MessagingException {
12651266
String filename = null;
12661267
String s = part.getHeader("Content-Disposition", null);
12671268

@@ -1291,7 +1292,8 @@ static String getFileName(MimePart part) throws MessagingException {
12911292
return filename;
12921293
}
12931294

1294-
static void setFileName(MimePart part, String name)
1295+
static void setFileName(MimePart part, String name, boolean encodeFileName,
1296+
boolean setContentTypeFileName)
12951297
throws MessagingException {
12961298
if (encodeFileName && name != null) {
12971299
try {
@@ -1440,7 +1442,7 @@ static void setEncoding(MimePart part, String encoding)
14401442
* Content-Type of the specified MimePart. Returns
14411443
* either the original encoding or null.
14421444
*/
1443-
static String restrictEncoding(MimePart part, String encoding)
1445+
static String restrictEncoding(MimePart part, String encoding, boolean ignoreMultipartEncoding)
14441446
throws MessagingException {
14451447
if (!ignoreMultipartEncoding || encoding == null)
14461448
return encoding;
@@ -1473,7 +1475,8 @@ static String restrictEncoding(MimePart part, String encoding)
14731475
return encoding;
14741476
}
14751477

1476-
static void updateHeaders(MimePart part) throws MessagingException {
1478+
static void updateHeaders(MimePart part, boolean setDefaultTextCharset, boolean setContentTypeFileName,
1479+
boolean encodeFileName) throws MessagingException {
14771480
DataHandler dh = part.getDataHandler();
14781481
if (dh == null) // Huh ?
14791482
return;
@@ -1620,8 +1623,8 @@ static void invalidateContentHeaders(MimePart part)
16201623
part.removeHeader("Content-Transfer-Encoding");
16211624
}
16221625

1623-
static void writeTo(MimePart part, OutputStream os, String[] ignoreList)
1624-
throws IOException, MessagingException {
1626+
static void writeTo(MimePart part, OutputStream os, String[] ignoreList, boolean allowutf8,
1627+
boolean ignoreMultipartEncoding) throws IOException, MessagingException {
16251628

16261629
// see if we already have a LOS
16271630
LineOutputStream los = null;
@@ -1666,7 +1669,7 @@ static void writeTo(MimePart part, OutputStream os, String[] ignoreList)
16661669
os.write(buf, 0, len);
16671670
} else {
16681671
os = MimeUtility.encode(os,
1669-
restrictEncoding(part, part.getEncoding()));
1672+
restrictEncoding(part, part.getEncoding(), ignoreMultipartEncoding));
16701673
part.getDataHandler().writeTo(os);
16711674
}
16721675
} finally {
@@ -1709,4 +1712,61 @@ MimePart getPart() {
17091712
return part;
17101713
}
17111714
}
1715+
1716+
/**
1717+
* Overrides the property of mail.mime.setdefaulttextcharset.
1718+
* @param setDefaultTextCharset Enable/disable setDefaultTextCharset
1719+
*/
1720+
public void setDefaultTextCharset(boolean setDefaultTextCharset) {
1721+
this.setDefaultTextCharset = setDefaultTextCharset;
1722+
}
1723+
1724+
/**
1725+
* Overrides the property of mail.mime.setContentTypeFileName.
1726+
* @param setContentTypeFileName Enable/disable setContentTypeFileName
1727+
*/
1728+
public void setContentTypeFileName(boolean setContentTypeFileName) {
1729+
this.setContentTypeFileName = setContentTypeFileName;
1730+
}
1731+
1732+
/**
1733+
* Overrides the property of mail.mime.encodeFileName.
1734+
* @param encodeFileName Enable/disable encodeFileName
1735+
*/
1736+
public void setEncodeFileName(boolean encodeFileName) {
1737+
this.encodeFileName = encodeFileName;
1738+
}
1739+
1740+
/**
1741+
* Overrides the property of mail.mime.decodeFileName.
1742+
* @param decodeFileName Enable/disable decodeFileName
1743+
*/
1744+
public void setDecodeFileName(boolean decodeFileName) {
1745+
this.decodeFileName = decodeFileName;
1746+
}
1747+
1748+
/**
1749+
* Overrides the property of mail.mime.ignoreMultipartEncoding.
1750+
* @param ignoreMultipartEncoding Enable/disable ignoreMultipartEncoding
1751+
*/
1752+
public void setIgnoreMultipartEncoding(boolean ignoreMultipartEncoding) {
1753+
this.ignoreMultipartEncoding = ignoreMultipartEncoding;
1754+
}
1755+
1756+
/**
1757+
* Overrides the property of mail.mime.cacheMultipart.
1758+
* @param cacheMultipart Enable/disable cacheMultipart
1759+
*/
1760+
public void setCacheMultipart(boolean cacheMultipart) {
1761+
this.cacheMultipart = cacheMultipart;
1762+
}
1763+
1764+
/**
1765+
* Overrides the property of mail.mime.cachedContent.
1766+
* @param cachedContent Enable/disable cachedContent
1767+
*/
1768+
public void setCachedContent(Object cachedContent) {
1769+
this.cachedContent = cachedContent;
1770+
}
1771+
17121772
}

0 commit comments

Comments
 (0)