Skip to content

Commit abe990f

Browse files
jbescoslukasj
authored andcommitted
Reviews changes
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent a10a173 commit abe990f

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

api/src/main/java/jakarta/mail/internet/MimeMessage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,4 +2318,13 @@ protected MimeMessage createMimeMessage(Session session)
23182318
throws MessagingException {
23192319
return new MimeMessage(session);
23202320
}
2321+
2322+
boolean isStrict() {
2323+
return strict;
2324+
}
2325+
2326+
boolean isAllowutf8() {
2327+
return allowutf8;
2328+
}
2329+
23212330
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package jakarta.mail.internet;
18+
19+
20+
import static org.junit.Assert.assertEquals;
21+
22+
import java.util.Properties;
23+
import jakarta.mail.Session;
24+
import org.junit.Test;
25+
26+
/**
27+
* Test the properties that control strict address parsing and UTF-8 support
28+
*/
29+
public class MimeMessageTest {
30+
31+
@Test
32+
public void testDefaultProperties() throws Exception {
33+
Session session = Session.getInstance(new Properties());
34+
MimeMessage message = new MimeMessage(session);
35+
assertEquals(true, message.isStrict());
36+
assertEquals(false, message.isAllowutf8());
37+
}
38+
39+
@Test
40+
public void testSystemAndSession() throws Exception {
41+
try {
42+
System.setProperty("mail.mime.address.strict", Boolean.TRUE.toString());
43+
System.setProperty("mail.mime.allowutf8", Boolean.FALSE.toString());
44+
Properties properties = new Properties();
45+
properties.setProperty("mail.mime.address.strict", Boolean.FALSE.toString());
46+
properties.setProperty("mail.mime.allowutf8", Boolean.TRUE.toString());
47+
Session session = Session.getInstance(properties);
48+
MimeMessage message = new MimeMessage(session);
49+
assertEquals(false, message.isStrict());
50+
assertEquals(true, message.isAllowutf8());
51+
} finally {
52+
System.clearProperty("mail.mime.address.strict");
53+
System.clearProperty("mail.mime.allowutf8");
54+
}
55+
}
56+
57+
@Test
58+
public void testSystemPropertiesNoSession() throws Exception {
59+
try {
60+
System.setProperty("mail.mime.address.strict", Boolean.FALSE.toString());
61+
System.setProperty("mail.mime.allowutf8", Boolean.TRUE.toString());
62+
MimeMessage message = new MimeMessage((Session) null);
63+
assertEquals(false, message.isStrict());
64+
assertEquals(true, message.isAllowutf8());
65+
} finally {
66+
System.clearProperty("mail.mime.address.strict");
67+
System.clearProperty("mail.mime.allowutf8");
68+
}
69+
}
70+
71+
@Test
72+
public void testSystemPropertiesAndSessionWithNoProperties() throws Exception {
73+
try {
74+
System.setProperty("mail.mime.address.strict", Boolean.FALSE.toString());
75+
System.setProperty("mail.mime.allowutf8", Boolean.TRUE.toString());
76+
Session session = Session.getInstance(new Properties());
77+
MimeMessage message = new MimeMessage(session);
78+
// System properties are ignored when Session is present (even if empty)
79+
assertEquals(true, message.isStrict());
80+
assertEquals(false, message.isAllowutf8());
81+
} finally {
82+
System.clearProperty("mail.mime.address.strict");
83+
System.clearProperty("mail.mime.allowutf8");
84+
}
85+
}
86+
}

doc/release/CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ longer available.
2222
CHANGES IN THE 2.1.5 RELEASE
2323
----------------------------
2424
E 752 Inconsistent MailMessage contentId property
25+
E 758 Improve MimeMessage UTF8 handling
2526
E 789 Only one META-INF/javamail.providers resource file is processed
2627

2728
CHANGES IN THE 2.1.4 RELEASE

0 commit comments

Comments
 (0)