(geronimo-mail) branch GERONIMO6884 updated: GERONIMO-6884 - Try to reproduce

[email protected] Thu, 06 Nov 2025 11:48:02 +0000
Newsgroups gmane.comp.java.geronimo.cvs
Message-ID <176242968276.3819541.9027582379361491204@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch GERONIMO6884
in repository https://gitbox.apache.org/repos/asf/geronimo-mail.git


The following commit(s) were added to refs/heads/GERONIMO6884 by this push:
     new d9ba84d  GERONIMO-6884 - Try to reproduce
d9ba84d is described below

commit d9ba84de3e8649f7b37390abb98f9e14880cd4c0
Author: Richard Zowalla <[email protected]>
AuthorDate: Thu Nov 6 12:47:55 2025 +0100

    GERONIMO-6884 - Try to reproduce
---
 .../geronimo/mail/issues/GERONIMO6884Test.java     |  60 ++++++++++++++++++++-
 .../src/test/resources/test-img.png                | Bin 22642 -> 619 bytes
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/issues/GERONIMO6884Test.java b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/issues/GERONIMO6884Test.java
index 645f4d2..f20e712 100644
--- a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/issues/GERONIMO6884Test.java
+++ b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/java/org/apache/geronimo/mail/issues/GERONIMO6884Test.java
@@ -32,6 +32,7 @@ import jakarta.mail.internet.MimeMultipart;
 import jakarta.mail.util.ByteArrayDataSource;
 import org.apache.geronimo.mail.testserver.AbstractProtocolTest;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.util.Properties;
@@ -39,7 +40,7 @@ import java.util.Properties;
 import static org.junit.Assert.assertArrayEquals;
 
 public class GERONIMO6884Test extends AbstractProtocolTest {
-    public void testGERONIMO6884() throws Exception {
+    public void testGERONIMO6884_0() throws Exception {
 
         final MimeBodyPart messageBodyPart = new MimeBodyPart();
         messageBodyPart.setText("Text body!");
@@ -75,6 +76,63 @@ public class GERONIMO6884Test extends AbstractProtocolTest {
         assertArrayEquals(bytes, attachmentBytes);
     }
 
+    public void testGERONIMO6884_1() throws Exception {
+
+        final MimeBodyPart messageBodyPart = new MimeBodyPart();
+        messageBodyPart.setText("Text body!");
+
+        // Use just 1 byte to trigger the "small buffer" case
+        byte[] bytes = new byte[] { 42 }; // any value works
+
+        final MimeBodyPart attachmentPart = new MimeBodyPart();
+        attachmentPart.setDataHandler(new DataHandler(new ByteArrayDataSource(bytes, "image/png")));
+        attachmentPart.setHeader("Content-Transfer-Encoding", "base64"); // crucial
+
+        final Multipart multipart = new MimeMultipart();
+        multipart.addBodyPart(messageBodyPart);
+        multipart.addBodyPart(attachmentPart);
+
+        final Message message = sendAndGetMessage(multipart);
+        final MimeMultipart content = (MimeMultipart) message.getContent();
+        final BodyPart attachment = content.getBodyPart(1);
+
+        final InputStream is = (InputStream) attachment.getContent();
+        byte[] attachmentBytes;
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            byte[] buffer = new byte[8192];
+            int bytesRead;
+            while ((bytesRead = is.read(buffer)) != -1) {
+                baos.write(buffer, 0, bytesRead);
+            }
+            attachmentBytes = baos.toByteArray();
+        }
+        assertArrayEquals(bytes, attachmentBytes);
+    }
+
+    public void testGERONIMO6884_2() throws Exception {
+
+        final MimeBodyPart messageBodyPart = new MimeBodyPart();
+        messageBodyPart.setText("Text body!");
+
+        // Use just 1 byte to trigger the "small buffer" case
+        byte[] bytes = new byte[]{42}; // any value works
+
+        final MimeBodyPart attachmentPart = new MimeBodyPart(new ByteArrayInputStream(bytes));
+
+        final Multipart multipart = new MimeMultipart();
+        multipart.addBodyPart(messageBodyPart);
+        multipart.addBodyPart(attachmentPart);
+
+        final Message message = sendAndGetMessage(multipart);
+
+        final MimeMultipart content = (MimeMultipart) message.getContent();
+        final BodyPart attachment = content.getBodyPart(1);
+
+        final Object o = attachment.getContent();
+        assertNotNull(o); //this will be an empty string
+    }
+
+
     private Message sendAndGetMessage(Multipart multipart) throws Exception {
 
         start();
diff --git a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/resources/test-img.png b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/resources/test-img.png
index 35ab855..ffd6294 100644
Binary files a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/resources/test-img.png and b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/test/resources/test-img.png differ