Skip to content

Commit

Permalink
Merge pull request #312 from hayblondin/develop
Browse files Browse the repository at this point in the history
fix: resolves #311 - text/calendar as string -> ClassCastException, by taking the value as String if it is not an InputStream
  • Loading branch information
bbottema authored Apr 15, 2021
2 parents 6a7c194 + be2f7e1 commit 463bd76
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ private static void parseMimePartTree(@NotNull final MimePart currentPart, @NotN
//noinspection RedundantCast
parsedComponents.htmlContent.append((Object) parseContent(currentPart));
} else if (isMimeType(currentPart, "text/calendar") && parsedComponents.calendarContent == null && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
final InputStream calendarContent = parseContent(currentPart);
try {
parsedComponents.calendarContent = MiscUtil.readInputStreamToString(calendarContent, UTF_8);
} catch (IOException e) {
throw new MimeMessageParseException(MimeMessageParseException.ERROR_PARSING_CALENDAR_CONTENT, e);
}
parsedComponents.calendarContent = parseCalendarContent(currentPart);
parsedComponents.calendarMethod = parseCalendarMethod(currentPart);
} else if (isMimeType(currentPart, "multipart/*")) {
final Multipart mp = parseContent(currentPart);
Expand Down Expand Up @@ -205,6 +200,22 @@ public static String parseFileName(@NotNull final Part currentPart) {
throw new MimeMessageParseException(MimeMessageParseException.ERROR_GETTING_FILENAME, e);
}
}

/**
* @return Returns the "content" part as String from the Calendar content type
*/
public static String parseCalendarContent(@NotNull MimePart currentPart) {
Object content = parseContent(currentPart);
if (content instanceof InputStream) {
final InputStream calendarContent = (InputStream) content;
try {
return MiscUtil.readInputStreamToString(calendarContent, UTF_8);
} catch (IOException e) {
throw new MimeMessageParseException(MimeMessageParseException.ERROR_PARSING_CALENDAR_CONTENT, e);
}
}
return String.valueOf(content);
}

/**
* @return Returns the "method" part from the Calendar content type (such as "{@code text/calendar; charset="UTF-8"; method="REQUEST"}").
Expand Down

0 comments on commit 463bd76

Please sign in to comment.