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

Feature: Expand email builder API to support Content-Description on attachments #404

Closed
CrisVnait opened this issue Jul 13, 2022 · 12 comments

Comments

@CrisVnait
Copy link

CrisVnait commented Jul 13, 2022

Hello,

I want to send an email with an attachment. The attachment should contain as meta information a Content-Description. But my Content-Description header is ignored:

MimeMessage: Date: Wed, 13 Jul 2022 12:40:46 +0200 (CEST)
From: xxxx
Reply-To: xxxx
To: "xxxx"

Message-ID: 747447859.1.1657708846687@xxxxx
Subject: TEAU0_eb24af60-51f3-45e7-ac7b-2abcc7cdba10
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_1827369718.1657708846523"
X-KIM-Dienstkennung: eAU;Lieferung;V1.0
Disposition-Notification-To: xxxxxx
Return-Receipt-To: xxxxxx

------=_Part_0_1827369718.1657708846523
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

eAU
------=_Part_0_1827369718.1657708846523
Content-Type: application/octet-stream; filename=TEAU0_eb24af60-51f3-45e7-ac7b-2abcc7cdba10.p7s;
name=TEAU0_eb24af60-51f3-45e7-ac7b-2abcc7cdba10.p7s
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=TEAU0_eb24af60-51f3-45e7-ac7b-2abcc7cdba10.p7s
Content-ID: <TEAU0_eb24af60-51f3-45e7-ac7b-2abcc7cdba10.p7s>

Here at the end for 'eAU'-section the 'Content-Description'-element should be added.

My code:

List<AttachmentResource> attachmentResources = new ArrayList<>();

InternetHeaders headers = new InternetHeaders();
        headers.addHeader("Content-Description", storno ? "eAUStorno" : "eAU");
        headers.addHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM_VALUE);

MimeBodyPart mimeBodyPart = new MimeBodyPart(headers, xml, xml.length);

attachmentResources.add(new AttachmentResource(generateFilename(uuid, storno), mimeBodyPart.getDataHandler().getDataSource()));

Email email = EmailBuilder.startingBlank()
                    .withHeader(KimHeader.getDienstKennungHeaderName(), kimDienst.getEmailDienstKennungHeader())
                    .withReturnReceiptTo(from)
                    .withDispositionNotificationTo(from)
                    .withAttachments(attachmentResources)
                    .from(from)
                    .to(toName, toAdress)
                    .withSubject(subject)
                    .withPlainText(emailTextInhalt)
                    .buildEmail();

mailer.sendMail(email);

The 'Content-Type'-header is being processed, but the 'Content-Description' is ignored.
Version is 6.7.6

Any ideas how to solve my problem?
Thanks a lot for help!

@bbottema
Copy link
Owner

Why are you using a MimeBodyPart to add attachments??

@CrisVnait
Copy link
Author

CrisVnait commented Jul 13, 2022

Why are you using a MimeBodyPart to add attachments??

@bbottema
There is a setter provided to set description. But it has same behavior like setting with InternetHeader. So it's not required.
mimeBodyPart.setDescription("eAU");
What would you suggest to use instead?

@bbottema
Copy link
Owner

bbottema commented Jul 14, 2022

Simple Java Mail indeed does a conversion and only supports selected headers for attachments. Content-Description is not one of them (yet). I'm just wonder what you use this for, actually. I think this is the first time I see this header being used (on an attachment anyway). As far as I know it doesn't do anything, except for providing the given text in the resulting EML source, which is generally never inspected directly except for debugging purposes (and then still you have the attachment's name).

Is Content-Description value extracted and used somewhere in your process?

@CrisVnait
Copy link
Author

@bbottema Thanks for your detailed answer.
It is a global requirement from external to set Content-Description to a specific value. Otherwise the attachment is not accepted.
So unfortunately we have to switch the library, because I do not think we can expect a new version in the next days.
Thanks for your help!

@bbottema
Copy link
Owner

bbottema commented Jul 14, 2022

So unfortunately we have to switch the library, because I do not think we can expect a new version in the next days.

And you are basing this conclusion on what grounds exactly?

@CrisVnait
Copy link
Author

CrisVnait commented Jul 14, 2022

That we can not expect a new version? I'm not used to getting help so quickly.
So could we expect? :) It would save much effort for us.

@bbottema
Copy link
Owner

Well I wanted to look into it this morning, but then someone decided to drive into my car on the road so I had to deal with that. I hope I can take a look soon, though.

@CrisVnait
Copy link
Author

Oh, that's annoying. Thank you!

@bbottema
Copy link
Owner

bbottema commented Jul 14, 2022

Would this work for you?

String name = generateFilename(uuid, storno);
String description = storno ? "eAUStorno" : "eAU";

yourEmailBuilder
    (..)
    .withAttachment(name, new ByteArrayDataSource(xml, "text/plain"), description)
    // or
    .withAttachment(name, xml.getBytes(defaultCharset()), "text/plain", description)
    (..)
    .buildEmail();

@CrisVnait
Copy link
Author

CrisVnait commented Jul 14, 2022

Does it mean that AttachmentResource gets a field 'description', which could be initalized with constructor/setter?
This would be perfect yes!
The number of attachments could be differ in different use-cases, so we want to set attachments as list with

yourEmailBuilder
    (..)
    .withAttachments(attachmentResourceList)
    (..)
    .buildEmail();

Thanks for your effort!

@bbottema bbottema changed the title Attachment 'Content-Description' header is ignored Feature: Expand email builder API to support Content-Description on attachments Jul 15, 2022
@bbottema bbottema added this to the 7.3.0 milestone Jul 15, 2022
bbottema added a commit that referenced this issue Jul 15, 2022
@bbottema
Copy link
Owner

Released in 7.3.0! And yes, you can create AttachmentResources directly with descriptions too.

@CrisVnait
Copy link
Author

Thank you very much for the quick help and reactions!
Unfortunately it seems, that we can't migrate to version 7.3.0 with Jakarta 2.0.1, because we use Spring Boot 2.x.x (see https://stackoverflow.com/questions/68955884/update-jakarta-mail-1-6-5-to-2-0-1).
Would it be possible, that you also provide the 'content description'-feature in version 6.x.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants