Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse messages without a session #121

Closed
OrangeDog opened this issue Jan 19, 2024 · 4 comments · Fixed by jakartaee/mail-api#711
Closed

Cannot parse messages without a session #121

OrangeDog opened this issue Jan 19, 2024 · 4 comments · Fixed by jakartaee/mail-api#711
Assignees
Labels
bug Something isn't working

Comments

@OrangeDog
Copy link

Describe the bug
It used to be the case that you could parse MimeMessages without any session, for an application that doesn't need to send or receive email itself.

This ability has been lost at some point in the migration from com.sun.mail to org.eclipse.angus.

To Reproduce
This code works if using com.sun.mail:mailapi:2.0.1:

String text = """
    From: user@example.com\r
    To: user@example.com\r
    Subject: Testing\r
    Date: Thu, 01 Jul 2021 12:11:25 +0000 (UTC)\r
    Content-Type: text/plain\r
    \r
    Best ever test content.\r
    """;
InputStream inputStream = new ByteArrayInputStream(text.getBytes())
MimeMessage mimeMessage = new MimeMessage(null, inputStream);
mimeMessage.getContent();

If using org.eclipse.angus:jakarta.mail:2.0.2 it throws:

jakarta.mail.MessagingException: No inputstream from datasource
;
  nested exception is:
	java.lang.NullPointerException: Cannot invoke "jakarta.mail.Session.getStreamProvider()" because "this.session" is null
	at jakarta.mail.internet.MimeMultipart.parse(MimeMultipart.java:586)
	at jakarta.mail.internet.MimeMessage.getContent(MimeMessage.java:1522)
	at com.example.Test.test(Test.java:28)

Expected behavior
A session only being necessary if connecting to a server of some kind. Code compatibility with older releases.

Additional information

  • org.eclipse.angus:jakarta.mail:1.0.0 throws the same exception
  • jakarta.mail:jakarta.mail-api:2.1.2 throws java.lang.IllegalStateException: Not provider of jakarta.mail.util.StreamProvider was found [sic]
  • jakarta.mail:jakarta.mail-api:2.0.1 throws java.lang.NoClassDefFoundError: com/sun/mail/util/FolderClosedIOException
  • com.sun.mail:jakarta.mail:2.0.1 works successfully
@OrangeDog
Copy link
Author

Using an "empty" session appears to work. It doesn't appear to try to connect to anything with the example above.

Session session = Session.getInstance(new Properties());

@jmehrens
Copy link
Contributor

For jakarta.mail:jakarta.mail-api:2.1.2 it looks like you are missing the Angus dependencies.

There are 4 jars that have to be added:
angus-activation-XXX.jar,
angus-mail-XXX.jar
jakarta.mail-api-XXX.jar
jakarta.activation-api-XXX.jar

The "java.lang.IllegalStateException: Not provider of jakarta.mail.util.StreamProvider" is usually missing dependencies.
The NullPointerException is a cascading failure. See: jakartaee/mail-api#550 (comment)

If you missing those dependencies in your test case then add them and retest.

@jmehrens jmehrens added the question Further information is requested label Jan 22, 2024
@jmehrens jmehrens added bug Something isn't working and removed question Further information is requested labels Jan 30, 2024
@jmehrens jmehrens self-assigned this Feb 16, 2024
@OrangeDog
Copy link
Author

OrangeDog commented Feb 16, 2024

you are missing the Angus dependencies

My point there is that in the previous version you did not need those dependencies. mailapi was sufficient to parse MIME messages.

@jmehrens
Copy link
Contributor

@OrangeDog Yes I was able to gather that when I dug deeper into the code. My initial understanding was incorrect. Because of that I fixed this. Thank you for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants