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

Prevent Overwriting Custom Content-ID for Attachments #566

Open
0VP0 opened this issue Dec 15, 2024 · 0 comments
Open

Prevent Overwriting Custom Content-ID for Attachments #566

0VP0 opened this issue Dec 15, 2024 · 0 comments

Comments

@0VP0
Copy link

0VP0 commented Dec 15, 2024

Issue:
When I set a custom Content-ID for attachments, it gets overwritten after building the email using EmailBuilder.buildEmail() and send it .


Steps to Reproduce

  1. Create an email with an attachment using EmailBuilder.startingBlank().
  2. Convert the email to MimeMessage and set a custom Content-ID for the attachment.
  3. Convert it back to an Email using EmailConverter.mimeMessageToEmail(mimeMessage).
  4. Send the email.
  5. The Content-ID is changed after building the email and sending the email.

Expected Behavior

The custom Content-ID should stay the same after building the email and sending the email.


Actual Behavior

The Content-ID I set for the attachment gets overwritten after building the email and sending the email.


Example Code

Email email = EmailBuilder.startingBlank()
    .from("[email protected]")
    .to("[email protected]")
    .withSubject("Test Content-ID")
    .withAttachment("file.pdf", new FileDataSource("/path/to/file.pdf"))
    .buildEmail();

// Convert to MimeMessage
MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(email);
MimeMultipart multipart = (MimeMultipart) mimeMessage.getContent();

// Set the custom Content-ID
for (int i = 0; i < multipart.getCount(); i++) {
    BodyPart part = multipart.getBodyPart(i);
    if ("file.pdf".equals(part.getFileName())) {
        part.setHeader("Content-ID", "<custom-id-12345>");
    }
}

mimeMessage.setContent(multipart);
mimeMessage.saveChanges();

// Convert back to Email
Email updatedEmail = EmailConverter.mimeMessageToEmail(mimeMessage);

Request

  1. Prevent Overwriting: I need a way to keep the custom Content-ID I set for attachments. It should not be changed when build the email.
  2. Direct Option (Optional): If possible, I would like to set the Content-ID directly on the attachment without converting to MimeMessage, from the AttachmentResource resource directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant