[enhancement+bug] Make EmailConverter API more consistent regarding Session parameter, don't use Session.getDefaultInstance
anymore and fix bug where emlToEmailBuilder
used emlToMimeMessage
#508
Labels
Milestone
Hi,
thanks for this lib, its really helpful.
However we have run into an issue:
In
org.simplejavamail.converter.EmailConverter
, some places need an instance ofjakarta.mail.Session
, so there is the methodcreateDummySession()
, which returnsSession.getDefaultInstance(new Properties())
. In our project setup, we have a mail session from another context, which cannot be used in this context.Session.getDefaultInstance(new Properties())
will always get the existing session, which leads to a race condition: ifcreateDummySession()
is called first, the session is created here, but then it wont work in the other context; if the session is created by our logic first, it is returned increateDummySession()
, which leads to errors.The most obvious fix would be to override
createDummySession()
to returnSession.getInstance(new Properties())
instead, since this always creates a new instance. However, we cannot do this, becauseEmailConverter
isfinal
.Another thing we noticed, is that in some places of the API, we can provide our own session. However this is not very consistent, and the API we are using does not allow handing over our own session (and internally calls
createDummySession()
nested after some delegations). Specifically we are usingemlToEmail(@NotNull InputStream emlInputStream, @Nullable Pkcs12Config pkcs12Config)
andoutlookMsgToEmail(@NotNull InputStream msgInputStream, @Nullable Pkcs12Config pkcs12Config)
.As a fix Would it be possible to make
EmailConverter
notfinal
so we can override the dummy session? Alternatively, couldcreateDummySession()
return a fresh session withSession.getInstance(new Properties())
, since (to our understanding) it's only used as a dummy? Thanks.The text was updated successfully, but these errors were encountered: