From c65924880e4e532014f9c0be4ce6c551e840a668 Mon Sep 17 00:00:00 2001 From: jmehrens Date: Thu, 15 Feb 2024 22:32:26 -0600 Subject: [PATCH 1/3] Cannot parse messages without a session #710 Signed-off-by: jmehrens jason_mehrens@hotmail.com --- .../jakarta/mail/internet/MimeMessage.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/jakarta/mail/internet/MimeMessage.java b/api/src/main/java/jakarta/mail/internet/MimeMessage.java index c1a71934..67000ded 100644 --- a/api/src/main/java/jakarta/mail/internet/MimeMessage.java +++ b/api/src/main/java/jakarta/mail/internet/MimeMessage.java @@ -29,6 +29,7 @@ import jakarta.mail.Multipart; import jakarta.mail.Session; import jakarta.mail.util.LineOutputStream; +import jakarta.mail.util.StreamProvider; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -44,6 +45,7 @@ import java.util.Enumeration; import java.util.List; import java.util.Properties; +import java.util.ServiceConfigurationError; /** @@ -243,9 +245,9 @@ public MimeMessage(MimeMessage source) throws MessagingException { strict = source.strict; source.writeTo(bos); bos.close(); - InputStream bis = session.getStreamProvider().inputSharedByteArray(bos.toByteArray()); - parse(bis); - bis.close(); + try (InputStream bis = provider().inputSharedByteArray(bos.toByteArray())) { + parse(bis); + } saved = true; } catch (IOException ex) { // should never happen, but just in case... @@ -1408,7 +1410,7 @@ protected InputStream getContentStream() throws MessagingException { if (contentStream != null) return ((SharedInputStream) contentStream).newStream(0, -1); if (content != null) { - return session.getStreamProvider().inputSharedByteArray(content); + return provider().inputSharedByteArray(content); } throw new MessagingException("No MimeMessage content"); } @@ -1915,7 +1917,7 @@ public void writeTo(OutputStream os, String[] ignoreList) // Else, the content is untouched, so we can just output it // First, write out the header Enumeration hdrLines = getNonMatchingHeaderLines(ignoreList); - LineOutputStream los = session.getStreamProvider().outputLineStream(os, allowutf8); + LineOutputStream los = provider().outputLineStream(os, allowutf8); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); @@ -2320,4 +2322,23 @@ protected MimeMessage createMimeMessage(Session session) throws MessagingException { return new MimeMessage(session); } + + private StreamProvider provider() throws MessagingException { + try { + try { + final Session s = this.session; + if (s != null) { + return s.getStreamProvider(); + } else { + return Session.getDefaultInstance(System.getProperties(), + null).getStreamProvider(); + } + } catch (ServiceConfigurationError sce) { + throw new IllegalStateException(sce); + } + } catch (RuntimeException re) { + throw new MessagingException("Unable to get " + + StreamProvider.class.getName(), re); + } + } } From 78ed1dac0b5b74cafd31795f6637888bab33ec4d Mon Sep 17 00:00:00 2001 From: jmehrens Date: Thu, 15 Feb 2024 22:49:53 -0600 Subject: [PATCH 2/3] Cannot parse messages without a session #710 Signed-off-by: jmehrens jason_mehrens@hotmail.com --- doc/release/CHANGES.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/release/CHANGES.txt b/doc/release/CHANGES.txt index 8d1675ee..efaf7d43 100644 --- a/doc/release/CHANGES.txt +++ b/doc/release/CHANGES.txt @@ -24,6 +24,7 @@ longer available. E 631 Session.getService does not use proper classloader in OSGI environment E 665 Jakarta Mail erroneously assumes that classes can be loaded from Thread#getContextClassLoader E 695 SharedFileInputStream should comply with spec +E 710 Cannot parse messages without a session CHANGES IN THE 2.1.2 RELEASE @@ -141,7 +142,7 @@ GH 334 gimap set labels error with some non english characters The following bugs have been fixed in the 1.6.1 release. GH 262 Some IMAP servers send EXPUNGE responses for unknown messages -GH 278 BODYSTRUCTURE Parser fails on specific IMAP Server response +GH 278 BODYSTRUCTURE Parser fails on specific IMAP Server response GH 283 clean up connections when closing IMAPStore GH 287 Allow relaxed Content-Disposition parsing GH 289 use a different IMAP tag prefix for each connection @@ -862,7 +863,7 @@ The following bugs have been fixed in the 1.1.2 release. fix bug in SMTP output that sometimes duplicated "." close SMTP transport on I/O error 4230541 don't send SMTP NOOP unnecessarily -4216666 IMAP provider INTERNALDATE formatter error, causing +4216666 IMAP provider INTERNALDATE formatter error, causing problems during appendMessages() 4227888 IMAP provider does not honor the UID item in its FetchProfile From 905edd1ee5aed426b19ded4cc13661324853964f Mon Sep 17 00:00:00 2001 From: jmehrens Date: Thu, 15 Feb 2024 22:51:13 -0600 Subject: [PATCH 3/3] Cannot parse messages without a session #710 Signed-off-by: jmehrens jason_mehrens@hotmail.com --- api/src/main/java/jakarta/mail/internet/MimeMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/jakarta/mail/internet/MimeMessage.java b/api/src/main/java/jakarta/mail/internet/MimeMessage.java index 67000ded..e832b097 100644 --- a/api/src/main/java/jakarta/mail/internet/MimeMessage.java +++ b/api/src/main/java/jakarta/mail/internet/MimeMessage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024 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