diff --git a/app/core/src/main/java/com/fsck/k9/message/extractors/MessagePreviewCreator.java b/app/core/src/main/java/com/fsck/k9/message/extractors/MessagePreviewCreator.java index 267a8fdea..5e4ba8673 100644 --- a/app/core/src/main/java/com/fsck/k9/message/extractors/MessagePreviewCreator.java +++ b/app/core/src/main/java/com/fsck/k9/message/extractors/MessagePreviewCreator.java @@ -6,6 +6,8 @@ import androidx.annotation.NonNull; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Part; +import timber.log.Timber; + public class MessagePreviewCreator { private final TextPartFinder textPartFinder; @@ -33,6 +35,10 @@ public class MessagePreviewCreator { String previewText = previewTextExtractor.extractPreview(textPart); return PreviewResult.text(previewText); } catch (PreviewExtractionException e) { + Timber.w(e, "Failed to extract preview text"); + return PreviewResult.error(); + } catch (Exception e) { + Timber.e(e, "Unexpected error while trying to extract preview text"); return PreviewResult.error(); } } diff --git a/app/core/src/test/java/com/fsck/k9/message/extractors/MessagePreviewCreatorTest.java b/app/core/src/test/java/com/fsck/k9/message/extractors/MessagePreviewCreatorTest.java index b1bde33c0..911711d50 100644 --- a/app/core/src/test/java/com/fsck/k9/message/extractors/MessagePreviewCreatorTest.java +++ b/app/core/src/test/java/com/fsck/k9/message/extractors/MessagePreviewCreatorTest.java @@ -83,6 +83,19 @@ public class MessagePreviewCreatorTest { assertEquals(PreviewType.ERROR, result.getPreviewType()); } + @Test + public void createPreview_withPreviewTextExtractorThrowingUnexpectedException() throws Exception { + Message message = createDummyMessage(); + Part textPart = createTextPart("text/plain"); + when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart); + when(previewTextExtractor.extractPreview(textPart)).thenThrow(new IllegalStateException("")); + + PreviewResult result = previewCreator.createPreview(message); + + assertFalse(result.isPreviewTextAvailable()); + assertEquals(PreviewType.ERROR, result.getPreviewType()); + } + private Message createDummyMessage() { return new MimeMessage(); }