You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle embedded (INLINE) resources as attachments if the cid identifier doesn't occur in the HTML body #179
Hmm, maybe this EML requires a specific javax.mail version? I'll give it a try as well, but I'm affraid this is a limitation of the underlying Java Mail framework.
When export EML by client foxmail which does't specify header Content-Disposition: inline; filename=image.png when it is a embedded image. If the disposition is not provided, the part be treated as attachment by simple-java-mail.
See org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.java
privatestaticvoidparseMimePartTree(@NonnullfinalMimePartcurrentPart, @NonnullfinalParsedMimeMessageComponentsparsedComponents) {
for (finalHeaderheader : retrieveAllHeaders(currentPart)) {
parseHeader(header, parsedComponents);
}
finalStringdisposition = parseDisposition(currentPart);
if (isMimeType(currentPart, "text/plain") && parsedComponents.plainContent == null && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.plainContent = parseContent(currentPart);
} elseif (isMimeType(currentPart, "text/html") && parsedComponents.htmlContent == null && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.htmlContent = parseContent(currentPart);
} elseif (isMimeType(currentPart, "multipart/*")) {
finalMultipartmp = parseContent(currentPart);
for (inti = 0, count = countBodyParts(mp); i < count; i++) {
parseMimePartTree(getBodyPartAtIndex(mp, i), parsedComponents);
}
} else {
finalDataSourceds = createDataSource(currentPart);
// If the diposition is not provided, the part should be treated as attachmentif (disposition == null || Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.attachmentList.put(parseResourceName(parseContentID(currentPart), parseFileName(currentPart)), ds);
} elseif (Part.INLINE.equalsIgnoreCase(disposition)) {
if (parseContentID(currentPart) != null) {
parsedComponents.cidMap.put(parseContentID(currentPart), ds);
} else {
// contentID missing -> treat as standard attachmentparsedComponents.attachmentList.put(parseResourceName(null, parseFileName(currentPart)), ds);
}
} else {
thrownewIllegalStateException("invalid attachment type");
}
}
}
If I add Content-Disposition: inline; filename=image.png manually, it works fine. ˆ-ˆ
So my question is coming, why can't I treated as embedded image if disposition is not provided,behaves normally like Outlook.
changed the title [-]Can't parse .eml file to email correctly[/-][+]Handle embedded (INLINE) resources as attachments if the cid identifier doesn't occur in the HTML body[/+]on Nov 7, 2018
So my question is coming, why can't I treated as embedded image if disposition is not provided,behaves normally like Outlook.
The spec says the following about default Content-Disposition in case of absence:
The Content-Disposition Header Field
Content-Disposition is an optional header field. In its absence, the
MUA may use whatever presentation method it deems suitable.
So spec-wise, we're free to do as we see fit. However, I'm unsure of the best handling here. So all the clients you mention don't parse it 'correctly' so much as rather how they see fit. It's all correct.
Here's what I'm going to do: treat all resources with missing Content-Disposition header as INLINE. Then if an INLINE resource (like an embedded image) does not occur in the HTML body (ie. cid:myImage), treat it as an attachment instead.
This also treats embedded images with proper INLINE disposition as attachment if the image is not actually used in the HTML body.
Activity
bbottema commentedon Oct 29, 2018
Can you perform the same check for EmailConverter.emlToMimeMessage() please?
jkxyx205 commentedon Oct 29, 2018
I can't parse any thing either.
Maybe
java.maildoes not have the ability to parse this file but outlook can.bbottema commentedon Oct 29, 2018
Hmm, maybe this EML requires a specific javax.mail version? I'll give it a try as well, but I'm affraid this is a limitation of the underlying Java Mail framework.
bbottema commentedon Oct 29, 2018
I'm getting a completely empty result without errors.
For what it's worth, the EML is not validating the following validation tools:
But mimevalidator.net thinks it's fine.
bbottema commentedon Oct 29, 2018
Sorry, I got confused. It's working fine for me. Here's my result:
Perhaps it wasn't clear from the API, but the method you used expetcs EML data, not a filepath string.
Email oldEmail = EmailConverter.emlToEmail("/Users/rick/jkxyx205/tmp/hello.eml"); // <-- this should be file contentjkxyx205 commentedon Oct 29, 2018
Yes, you are right, what a ridiculous mistake I did.
But I found another problem, lost a embeded image as I metioned #173, but 2 attachments
bbottema commentedon Oct 29, 2018
If an embedded attachment isn't actually embedded it is treated as an attachment. Is it being used in the body?
jkxyx205 commentedon Oct 29, 2018
Outlook treat the mail as a attachment and a embedded image.
Ok,I will continue to track it later. Thank you for your help, simple-java-mail excellent framework!!!
jkxyx205 commentedon Oct 30, 2018
Hmm, finally I got the root cause.
When export EML by client foxmail which does't specify header
Content-Disposition: inline; filename=image.pngwhen it is a embedded image. If thedispositionis not provided, the part be treated as attachment by simple-java-mail.See org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.java
If I add
Content-Disposition: inline; filename=image.pngmanually, it works fine. ˆ-ˆSo my question is coming, why can't I treated as embedded image if
dispositionis not provided,behaves normally like Outlook.jkxyx205 commentedon Oct 30, 2018
BTW, Outlook, Mac Mail, Foxmail can parse hello.eml correctly, one attachment + one embedded image.
1 remaining item
#179: Convert all embedded / INLINE resources to ATTACHMENT resources…
#179: Convert all embedded / INLINE resources to ATTACHMENT resources…
[-]Can't parse .eml file to email correctly[/-][+]Handle embedded (INLINE) resources as attachments if the cid identifier doesn't occur in the HTML body[/+]bbottema commentedon Nov 7, 2018
The spec says the following about default Content-Disposition in case of absence:
So spec-wise, we're free to do as we see fit. However, I'm unsure of the best handling here. So all the clients you mention don't parse it 'correctly' so much as rather how they see fit. It's all correct.
Here's what I'm going to do: treat all resources with missing Content-Disposition header as INLINE. Then if an INLINE resource (like an embedded image) does not occur in the HTML body (ie. cid:myImage), treat it as an attachment instead.
This also treats embedded images with proper INLINE disposition as attachment if the image is not actually used in the HTML body.
#179: Fixed NPE (change ported from different branch where String was…
bbottema commentedon Nov 7, 2018
@jkxyx205, I've released a new SNAPSHOT with the fix. Can you please verify (you'll need to add the snapshot repo).
jkxyx205 commentedon Nov 13, 2018
I tested it, and the performance was as good as I expected. It was really great.
bbottema commentedon Nov 21, 2018
Released in 5.1.0