Skip to content

Commit

Permalink
Merge pull request #140 from CupSoftware/master
Browse files Browse the repository at this point in the history
#139: Make MimeMessageParser support multiple body parts of same Content-Type for text/plain and text/html
  • Loading branch information
bbottema authored May 4, 2018
2 parents a386f0d + f7476f1 commit 6f03523
Showing 1 changed file with 10 additions and 10 deletions.
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();
}
}
}

0 comments on commit 6f03523

Please sign in to comment.