You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bugfix: Fixed MessageID not preserved when signing/encrypting with S/MIME and/or DKIM #461
Here, the messageId is changed by calling message.saveChanges().
In any case, the messageId inside the email object should not be changed if it already exists.
There are two possible solutions
Restore the messageId inside the message object to its original value after calling message.saveChanges().
If the messageId already exists, do not call message.saveChanges().
(There is no need to unnecessarily call saveChanges on the mimeMessage created by convertMimeMessage.)
Thank you for your report. Can you please provide evidence that this is not working? fixingMessageId is specifically made for this kind of situation and has been a core feature for many years. When message.saveChanges() is called, the following override is triggered:
I see the confusion you're having now.
I think I may have caused confusion due to my inadequate explanation
Please take a look at the code a bit further down.
When returning through ModuleLoader, MimeMessage is overridden again. This means that when using features such as Smime or Dkim, MimeMessage is overridden again. code
if (email.getPkcs12ConfigForSmimeSigning() != null) {
message = ModuleLoader.loadSmimeModule().signMessageWithSmime(session, message, email.getPkcs12ConfigForSmimeSigning());
}
if (email.getX509CertificateForSmimeEncryption() != null) {
message = ModuleLoader.loadSmimeModule().encryptMessageWithSmime(session, message, email.getX509CertificateForSmimeEncryption());
}
if (email.getDkimConfig() != null) {
message = ModuleLoader.loadDKIMModule().signMessageWithDKIM(message, email.getDkimConfig(), checkNonEmptyArgument(email.getFromRecipient(), "fromRecipient"));
}
if (email.getBounceToRecipient() != null) {
// display name not applicable: https://tools.ietf.org/html/rfc5321#section-4.1.2message = newImmutableDelegatingSMTPMessage(message, email.getBounceToRecipient().getAddress());
}
In other words, if use the Dkim feature, the overriding of the updateMessageID method above becomes useless.
publicclassDkimMessageextendsSMTPMessage {
privatestaticbyte[] NL = { (byte) '\r', (byte) '\n' };
privateDkimSignersigner;
privateStringencodedBody;
/** * Created a new {@code DkimMessage} from the given {@link MimeMessage} and * {@link DkimSigner}. * * @param message * The {@link MimeMessage} to be signed. * @param signer * The {@link DkimSigner} to sign the message with. * @throws MessagingException * If constructing this {@code DkimMessage} failed. */publicDkimMessage(MimeMessagemessage, DkimSignersigner) throwsMessagingException {
super(message);
this.signer = signer;
}
...
DkimMessage is the result of extending Jakarta MimeMessage.
There is no updated version of 'updateMessageId(..)' that you have redefined here.
It simply creates a new messageId unconditionally.
Oh wauw, that's a nice find! I'll see about reproducing this in my tests so that's covered. I'll fix this, but I'm not sure how fast. Might be a week or two.
changed the title [-]the messageId is lost when applying DKIM through signWithDomainKey(...)[/-][+]Bugfix: Fixed MessageID not preserved when signing/encrypting with S/MIME and/or DKIM[/+]on Jun 7, 2023
Just if someone else experience a java.lang.ClassNotFoundException: org.simplejavamail.internal.dkimsupport.DkimMessageIdFixingMimeMessage. Up to now, I used nothing from the dkim-module dependency and therefore haven't listed it in my pom. But with this update the dkim-module is required for the runtime otherwise the above exception is thrown when sending signed emails with S/MIME. Error does not occur on compile time.
Yikes, you're right! I already know why it happens, but a quick work around is indeed to have both dkim and s/mime moduled on the classpath. I'll send out a fix ASAP.
Thank you so much for bringing this to our attention.
Just if someone else experience a java.lang.ClassNotFoundException: org.simplejavamail.internal.dkimsupport.DkimMessageIdFixingMimeMessage. Up to now, I used nothing from the dkim-module dependency and therefore haven't listed it in my pom. But with this update the dkim-module is required for the runtime otherwise the above exception is thrown when sending signed emails with S/MIME. Error does not occur on compile time.
Activity
bbottema commentedon May 9, 2023
Thank you for your report. Can you please provide evidence that this is not working? fixingMessageId is specifically made for this kind of situation and has been a core feature for many years. When
message.saveChanges()is called, the following override is triggered:This is also extensively automatically tested using a real (but for testing) SMTP server (in MailerLiveTest.java).
However, it's possibly a regression bug, but then I would expect the tests to fail on this feature.
honorhs commentedon May 9, 2023
I see the confusion you're having now.
I think I may have caused confusion due to my inadequate explanation
Please take a look at the code a bit further down.
When returning through ModuleLoader, MimeMessage is overridden again. This means that when using features such as Smime or Dkim, MimeMessage is overridden again. code
In other words, if use the Dkim feature, the overriding of the updateMessageID method above becomes useless.
honorhs commentedon May 9, 2023
DKIMSigner. signMessageWithDKIM(...)
DkimMessage (in utils-mail-dkim-3.0.0.jar)
DkimMessage is the result of extending Jakarta MimeMessage.
There is no updated version of 'updateMessageId(..)' that you have redefined here.
It simply creates a new messageId unconditionally.
bbottema commentedon May 9, 2023
Oh wauw, that's a nice find! I'll see about reproducing this in my tests so that's covered. I'll fix this, but I'm not sure how fast. Might be a week or two.
Thank you for bringing this to my attention.
honorhs commentedon May 10, 2023
Thank you for taking the time to fix the bug.
I hope to see the issue resolved quickly. 👍
honorhs commentedon May 30, 2023
@bbottema
Are there any updates?
#461: Preserve fixed MessageID for DKIM and S/MIME sgned/encrypted me…
[-]the messageId is lost when applying DKIM through signWithDomainKey(...)[/-][+]Bugfix: Fixed MessageID not preserved when signing/encrypting with S/MIME and/or DKIM[/+]bbottema commentedon Jun 7, 2023
Fix released in v8.1.1. Can you please verify?
kkrupka commentedon Jun 23, 2023
Just if someone else experience a
java.lang.ClassNotFoundException: org.simplejavamail.internal.dkimsupport.DkimMessageIdFixingMimeMessage. Up to now, I used nothing from the dkim-module dependency and therefore haven't listed it in my pom. But with this update the dkim-module is required for the runtime otherwise the above exception is thrown when sending signed emails with S/MIME. Error does not occur on compile time.bbottema commentedon Jun 23, 2023
Yikes, you're right! I already know why it happens, but a quick work around is indeed to have both dkim and s/mime moduled on the classpath. I'll send out a fix ASAP.
Thank you so much for bringing this to our attention.
bbottema commentedon Jun 23, 2023
Fixed in v8.1.2!
kkrupka commentedon Jun 23, 2023
You are great. Super quick fix! I can confirm, it works as before (without dkim-module dep).