Skip to content

#139: Make MimeMessageParser support multiple body parts of same Content-Type for text/plain and text/html #140

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

Merged
merged 1 commit into from
May 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ private static void parseMimePartTree(@Nonnull final MimePart currentPart, @Nonn

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);
if (isMimeType(currentPart, "text/plain") && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.plainContent.append(parseContent(currentPart));
} else if (isMimeType(currentPart, "text/html") && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
parsedComponents.htmlContent.append(parseContent(currentPart));
} else if (isMimeType(currentPart, "multipart/*")) {
final Multipart mp = parseContent(currentPart);
for (int i = 0, count = countBodyParts(mp); i < count; i++) {
Expand Down Expand Up @@ -457,9 +457,9 @@ public static class ParsedMimeMessageComponents {
private InternetAddress dispositionNotificationTo;
private InternetAddress returnReceiptTo;
private InternetAddress bounceToAddress;
private String plainContent;
private String htmlContent;
private StringBuilder plainContent = new StringBuilder();
private StringBuilder htmlContent = new StringBuilder();

public String getMessageId() {
return messageId;
}
Expand Down Expand Up @@ -513,11 +513,11 @@ public InternetAddress getBounceToAddress() {
}

public String getPlainContent() {
return plainContent;
return plainContent.length() == 0 ? null : plainContent.toString();
}

public String getHtmlContent() {
return htmlContent;
return htmlContent.length() == 0 ? null : htmlContent.toString();
}
}
}