-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Handle embedded (INLINE) resources as attachments if the cid identifier doesn't occur in the HTML body #179
Comments
Can you perform the same check for EmailConverter.emlToMimeMessage() please? |
I can't parse any thing either. return new MimeMessage(session, new ByteArrayInputStream(eml.getBytes(UTF_8))); Maybe |
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. |
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. |
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.
|
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 |
If an embedded attachment isn't actually embedded it is treated as an attachment. Is it being used in the body? |
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!!! |
Hmm, finally I got the root cause. When export EML by client foxmail which does't specify header See org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.java private static void parseMimePartTree(@Nonnull final MimePart currentPart, @Nonnull final ParsedMimeMessageComponents parsedComponents) {
for (final Header header : retrieveAllHeaders(currentPart)) {
parseHeader(header, parsedComponents);
}
final String disposition = parseDisposition(currentPart);
if (isMimeType(currentPart, "text/plain") && parsedComponents.plainContent == null && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.plainContent = parseContent(currentPart);
} else if (isMimeType(currentPart, "text/html") && parsedComponents.htmlContent == null && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.htmlContent = parseContent(currentPart);
} else if (isMimeType(currentPart, "multipart/*")) {
final Multipart mp = parseContent(currentPart);
for (int i = 0, count = countBodyParts(mp); i < count; i++) {
parseMimePartTree(getBodyPartAtIndex(mp, i), parsedComponents);
}
} else {
final DataSource ds = createDataSource(currentPart);
// If the diposition is not provided, the part should be treated as attachment
if (disposition == null || Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.attachmentList.put(parseResourceName(parseContentID(currentPart), parseFileName(currentPart)), ds);
} else if (Part.INLINE.equalsIgnoreCase(disposition)) {
if (parseContentID(currentPart) != null) {
parsedComponents.cidMap.put(parseContentID(currentPart), ds);
} else {
// contentID missing -> treat as standard attachment
parsedComponents.attachmentList.put(parseResourceName(null, parseFileName(currentPart)), ds);
}
} else {
throw new IllegalStateException("invalid attachment type");
}
}
} If I add So my question is coming, why can't I treated as embedded image if |
BTW, Outlook, Mac Mail, Foxmail can parse hello.eml correctly, one attachment + one embedded image. |
… if the cid does not occur in the HTML
… if the cid does not occur in the HTML
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. |
@jkxyx205, I've released a new SNAPSHOT with the fix. Can you please verify (you'll need to add the snapshot repo). |
I tested it, and the performance was as good as I expected. It was really great. |
Released in 5.1.0 |
Hi, Benny Bottema
I have a problem, the details are as follows。
1. Scene description
Here is my hello.eml file which include a attachment and a embedded image exported by client application Foxmail. Open with outlook screenshot below:
2. Parse eml but can't get any information
The text was updated successfully, but these errors were encountered: