Skip to content

Commit

Permalink
Moved S/MIME signing / encryption of the actual MimeMessage to the Me…
Browse files Browse the repository at this point in the history
…ssageProducer class, where things like DKIM signing was already being done
  • Loading branch information
bbottema committed May 26, 2019
1 parent 5bfeba3 commit 471f713
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.simplejavamail.converter.internal.mimemessage;

import org.simplejavamail.api.email.Email;
import org.simplejavamail.internal.modules.ModuleLoader;

import javax.annotation.Nonnull;
import javax.mail.MessagingException;
Expand Down Expand Up @@ -43,7 +44,7 @@ final MimeMessage populateMimeMessage(@Nonnull final Email email, @Nonnull Sessi
checkArgumentNotEmpty(email, "email is missing");
checkArgumentNotEmpty(session, "session is needed, it cannot be attached later");

final MimeMessage message = new MimeMessage(session) {
MimeMessage message = new MimeMessage(session) {
@Override
protected void updateMessageID() throws MessagingException {
if (valueNullOrEmpty(email.getId())) {
Expand Down Expand Up @@ -75,9 +76,13 @@ public String toString() {
message.setSentDate(new Date());

if (!valueNullOrEmpty(email.getDkimSigningDomain())) {
return signMessageWithDKIM(message, email);
message = signMessageWithDKIM(message, email);
}


if (ModuleLoader.smimeModuleAvailable()) {
message = ModuleLoader.loadSmimeModule().signAndOrEncryptEmail(session, message, email);
}

return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ private MimeMessageProducerHelper() {
public static MimeMessage produceMimeMessage(@Nonnull Email email, @Nonnull Session session) throws UnsupportedEncodingException, MessagingException {
for (MimeMessageProducer mimeMessageProducer : mimeMessageProducers) {
if (mimeMessageProducer.compatibleWithEmail(email)) {
final MimeMessage mimeMessage = mimeMessageProducer.populateMimeMessage(email, session);
return ModuleLoader.smimeModuleAvailable()
? ModuleLoader.loadSmimeModule().signAndOrEncryptEmail(session, mimeMessage, email)
: mimeMessage;
return mimeMessageProducer.populateMimeMessage(email, session);
}
}
throw new AssertionError("no compatible MimeMessageProducer found for email");
Expand Down

0 comments on commit 471f713

Please # to comment.