Skip to content

Bugfix: Fixed MessageID not preserved when signing/encrypting with S/MIME and/or DKIM #461

@honorhs

Description

@honorhs

hi.
I've found a serious bug in the DKIM authentication process.

This is the typical flow for sending mail

  1. An internal messageId is generated and applied via fixingMessageId()
currentEmailBuilder.fixingMessageId("<123@456>");
  1. DKIM configuration is performed for security enhancement
currentEmailBuilder.signWithDomainKey(
    DkimConfig.builder()
        .dkimPrivateKeyData(byte[] / File / InputStream)
        .dkimSigningDomain("your_domain.org")
        .dkimSelector("your_selector")
        .build()
);
  1. The email is sent
mailer.sendMail(email);

However, after step 3, the messageId value inside the email object is changed, even though the messageId was fixed in step 1.

The cause of the issue is the following line of code
message.saveChanges()

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

  1. Restore the messageId inside the message object to its original value after calling message.saveChanges().
  2. If the messageId already exists, do not call message.saveChanges().
    (There is no need to unnecessarily call saveChanges on the mimeMessage created by convertMimeMessage.)

The second solution seems to be the best

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions