Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions api/src/main/java/jakarta/mail/internet/InternetHeaders.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026 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
Expand Down Expand Up @@ -660,8 +660,10 @@ public void addHeaderLine(String line) {
try {
char c = line.charAt(0);
if (c == ' ' || c == '\t') {
InternetHeader h = headers.get(headers.size() - 1);
h.line += "\r\n" + line;
if (!headers.isEmpty()) {
InternetHeader h = headers.get(headers.size() - 1);
h.line += "\r\n" + line;
}
} else
headers.add(new InternetHeader(line));
} catch (StringIndexOutOfBoundsException e) {
Expand Down
13 changes: 12 additions & 1 deletion api/src/test/java/jakarta/mail/internet/MimeMessageTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026 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
Expand All @@ -19,6 +19,8 @@

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.util.Base64;
import java.util.Properties;
import jakarta.mail.Session;
import org.junit.Test;
Expand Down Expand Up @@ -83,4 +85,13 @@ public void testSystemPropertiesAndSessionWithNoProperties() throws Exception {
System.clearProperty("mail.mime.allowutf8");
}
}

@Test
public void testEmptyHeaders() throws Exception {
String base64Input = "ICAgIAogICAKCg==";
byte[] input = Base64.getDecoder().decode(base64Input);
Session session = Session.getDefaultInstance(new Properties());
ByteArrayInputStream is = new ByteArrayInputStream(input);
new MimeMessage(session, is);
}
}
1 change: 1 addition & 0 deletions doc/release/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ longer available.

CHANGES IN THE 2.2.0 RELEASE
----------------------------
E 827 Exception in Internet-headers when parsing malformed MIME headers
E 714 Support minimum JDK of 11+ and minimum of Android API 33+
E 720 finalize() in java.lang.Object has been deprecated
E 744 Remove SecurityManager reference from API
Expand Down