Merge pull request #2867 from jyn514/issue-2847

Avoid exception when processing draft message

Fixes #2847
This commit is contained in:
cketti 2017-10-28 01:41:25 +02:00 committed by GitHub
commit 24de0df747
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -246,22 +246,28 @@ public class QuotedMessagePresenter {
}
if (messageFormat == MessageFormat.HTML) {
String bodyText; // defaults to null
Part part = MimeUtility.findFirstPartByMimeType(messageViewInfo.message, "text/html");
if (part != null) { // Shouldn't happen if we were the one who saved it.
quotedTextFormat = SimpleMessageFormat.HTML;
String text = MessageExtractor.getTextFromPart(part);
Timber.d("Loading message with offset %d, length %d. Text length is %d.",
bodyOffset, bodyLength, text.length());
if (text == null) {
Timber.d("Empty message; skipping.");
bodyText = "";
} else {
Timber.d("Loading message with offset %d, length %d. Text length is %d.",
bodyOffset, bodyLength, text.length());
if (bodyOffset + bodyLength > text.length()) {
// The draft was edited outside of K-9 Mail?
Timber.d("The identity field from the draft contains an invalid LENGTH/OFFSET");
bodyOffset = 0;
bodyLength = 0;
if (bodyOffset + bodyLength > text.length()) {
// The draft was edited outside of K-9 Mail?
Timber.d("The identity field from the draft contains an invalid LENGTH/OFFSET");
bodyOffset = 0;
bodyLength = 0;
}
// Grab our reply text.
bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
}
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
view.setMessageContentCharacters(HtmlConverter.htmlToText(bodyText));
// Regenerate the quoted html without our user content in it.