Description
Hello,
I'm trying to use the library to achieve a rather simple workflow:
- I connect to a mailbox via JavaMail and retrieve all the MimeMessage in the inbox
- I create an
Email
entity from the MimeMessage (usingEmailBuilder.copying()
) - I modify some fields (recipient, from, reply to...) and I convert back to a
MimeMessage
in order to send the email to a specific recipient. I want the rest of the e-mail to be left untouched, or at least the HTML, text, attachments... should stay the same as much as possible.
The lib is working pretty well for that purpose and provides a much better experience than the JavaMail API. However, I'm facing an issue with some embedded images with e-mails sent from the Apple Mail App (don't know if it happens specifically with this client).
The original email has its Content-ID set like this:
--Apple-Mail=_99049156-A46B-4137-9A9A-DFF8F09A8EA7
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
charset=us-ascii
<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello<div class=""><img apple-inline="yes" id="71BD1091-7D82-4679-9C8F-7A0EEF348399" width="788" height="634" src="cid:E977B3EA-BC23-486B-A803-C23C9A849C51@home" class=""></div></body></html>
--Apple-Mail=_99049156-A46B-4137-9A9A-DFF8F09A8EA7
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename*=utf-8''Capture%20d%E2%80%99e%CC%81cran%202021%2D07%2D05%20a%CC%80%2009.57.31.png
Content-Type: image/png;
x-unix-mode=0644;
name="=?utf-8?B?Q2FwdHVyZSBk4oCZZcyBY3JhbiAyMDIxLTA3LTA1IGHMgCAwOS41Ny4zMS5w?=
=?utf-8?B?bmc=?="
Content-Id: <E977B3EA-BC23-486B-A803-C23C9A849C51@home>
There is no .png
at the end of Content-ID and the src:cid
img property is properly set.
Once I receive such an email and try to send it back, no matter if
- I do not clear embedded images from the
EmailBuilder
and keep the original list fromcopying()
- I clear the embedded images and call
withEmbeddedImage(embeddedResource.getName(), embeddedResource.getDataSource()
(I was hoping setting the name directly like this would force thecid
to be exactlyembeddedResource.getName()
The end result is a cid
value of E977B3EA-BC23-486B-A803-C23C9A849C51@home.png
and it breaks the embedded image because there is a mismatch between this cid
and the src:cid
.
I looked at the code and I'm pretty sure this behavior comes from MimeMessageHelper.determineResourceName()
, perhaps as a side-effect of #307 ?
Here is the original resource, from copying()
: the "name" property is the correct CID, and dataSource.getName()
returns the original file name (which is the one Gmail, Apple Mail... uses as display name for the embedded image "attachment" rather than the cid).
Here is the resource before entering into determineResourceName
:
Here is the end result: .png
was unexpectedly appended to resourceName
, and while I don't think it's as big a problem, the fileName
ignores the value of dateSource.getName()
and is always equal to resourceName
, which I'm not sure why as having a different cid name/file name could be important in some cases?
I'll look for some workaround around the fileName
because I think it's what triggers this addition of the extension at the end.
But I think it would be nice to allow some customization of how AttachmentResource
is transformed into a body part, or at least provide a way to take name
and dataSource.getName()
"as is" and trust the developer that the values are already correct?
Thanks!