You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by rz...@apache.org on 2026/07/18 18:49:01 UTC
(geronimo-mail) 02/07: GERONIMO-6896 - getContentLanguage() throws NPE for IMAP messages whose BODYSTRUCTURE has no language field
This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/geronimo-mail.git
commit 51c2a9af39024002ea6da7a7ab17506c39d36608
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Sat Jul 18 20:48:28 2026 +0200
GERONIMO-6896 - getContentLanguage() throws NPE for IMAP messages whose BODYSTRUCTURE has no language field
---
.../geronimo/mail/store/imap/IMAPMessage.java | 3 +-
.../mail/store/imap/IMAPTckRegressionTest.java | 91 ++++++++++++++++++++++
geronimo-mail_2.1_tck/src/tck/geronimo.jtx | 1 -
3 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPMessage.java b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPMessage.java
index 7fa8f11..722bfb0 100644
--- a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPMessage.java
+++ b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPMessage.java
@@ -550,7 +550,8 @@ public class IMAPMessage extends MimeMessage {
public String[] getContentLanguage() throws MessagingException {
loadBodyStructure();
- if (!bodyStructure.languages.isEmpty()) {
+ // the BODYSTRUCTURE response may not have included any language information at all
+ if (bodyStructure.languages != null && !bodyStructure.languages.isEmpty()) {
return (String[])bodyStructure.languages.toArray(new String[bodyStructure.languages.size()]);
}
return null;
diff --git a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/store/imap/IMAPTckRegressionTest.java b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/store/imap/IMAPTckRegressionTest.java
new file mode 100644
index 0000000..667f94f
--- /dev/null
+++ b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/store/imap/IMAPTckRegressionTest.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.geronimo.mail.store.imap;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+import jakarta.mail.Folder;
+import jakarta.mail.Session;
+import jakarta.mail.Store;
+
+import org.apache.geronimo.mail.testserver.AbstractProtocolTest;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Regression tests for a set of IMAP provider defects surfaced by the
+ * Jakarta Mail TCK when run against Apache James.
+ */
+public class IMAPTckRegressionTest extends AbstractProtocolTest {
+
+ protected Store connect() throws Exception {
+ final Properties props = new Properties();
+ props.setProperty("mail.imap.port", String.valueOf(imapConf.getListenerPort()));
+ props.setProperty("mail.debug", "true");
+ final Session session = Session.getInstance(props);
+ final Store store = session.getStore("imap");
+ store.connect("127.0.0.1", "serveruser", "serverpass");
+ return store;
+ }
+
+ protected byte[] readMessageResource(final String name) throws Exception {
+ final ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ try (InputStream in = IMAPTckRegressionTest.class.getResourceAsStream(name)) {
+ final byte[] buf = new byte[4096];
+ int n;
+ while ((n = in.read(buf)) != -1) {
+ bout.write(buf, 0, n);
+ }
+ }
+ return bout.toByteArray();
+ }
+
+ protected void createMailboxWithMessage(final String name) throws Exception {
+ server.createUserMailbox(name);
+ server.appendToUserMailbox(name, readMessageResource("/messages/simple.msg"));
+ }
+
+ /**
+ * MimeMessage#getContentLanguage_Test: a message whose BODYSTRUCTURE
+ * carries no language information used to trigger a NullPointerException;
+ * the spec requires a null return instead.
+ */
+ @Test
+ public void testGetContentLanguageWithoutLanguagesReturnsNull() throws Exception {
+ start();
+ createMailboxWithMessage("test1");
+
+ final Store store = connect();
+ try {
+ final Folder folder = store.getDefaultFolder().getFolder("test1");
+ folder.open(Folder.READ_ONLY);
+ try {
+ final jakarta.mail.internet.MimeMessage msg =
+ (jakarta.mail.internet.MimeMessage) folder.getMessage(1);
+ assertNull(msg.getContentLanguage(),
+ "getContentLanguage must return null when the message has no Content-Language");
+ } finally {
+ folder.close(false);
+ }
+ } finally {
+ store.close();
+ }
+ }
+}
diff --git a/geronimo-mail_2.1_tck/src/tck/geronimo.jtx b/geronimo-mail_2.1_tck/src/tck/geronimo.jtx
index 844f991..0cbef10 100644
--- a/geronimo-mail_2.1_tck/src/tck/geronimo.jtx
+++ b/geronimo-mail_2.1_tck/src/tck/geronimo.jtx
@@ -54,7 +54,6 @@ javasoft/sqe/tests/jakarta/mail/internet/MimeBodyPart/testlist.html#attachFile_s
javasoft/sqe/tests/jakarta/mail/internet/MimeBodyPart/testlist.html#isMimeType_Test
javasoft/sqe/tests/jakarta/mail/internet/MimeBodyPart/testlist.html#setContentLanguage_Test
javasoft/sqe/tests/jakarta/mail/internet/MimeBodyPart/testlist.html#setFileNameEncoded_Test
-javasoft/sqe/tests/jakarta/mail/internet/MimeMessage/testlist.html#getContentLanguage_Test
javasoft/sqe/tests/jakarta/mail/internet/MimeMessage/testlist.html#setFileNameEncoded_Test
javasoft/sqe/tests/jakarta/mail/internet/MimeMessage/testlist.html#setSentDate_Test
javasoft/sqe/tests/jakarta/mail/internet/MimeMessage/testlist.html#unicode_Test