use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageExtractorTest method getTextFromPart_withUnknownEncoding_shouldReturnUnmodifiedBodyContents.
@Test
public void getTextFromPart_withUnknownEncoding_shouldReturnUnmodifiedBodyContents() throws Exception {
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
String bodyText = "Sample text body";
BinaryMemoryBody body = new BinaryMemoryBody(bodyText.getBytes(), "unknown encoding");
part.setBody(body);
String result = MessageExtractor.getTextFromPart(part);
assertEquals(bodyText, result);
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageExtractorTest method getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull.
@Test
public void getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull() throws Exception {
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html");
Body body = mock(Body.class);
when(body.getInputStream()).thenThrow(new MessagingException("Test"));
part.setBody(body);
String result = MessageExtractor.getTextFromPart(part);
assertNull(result);
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageExtractorTest method getTextFromPart_withRawDataBodyWithNonText_shouldReturnNull.
@Test
public void getTextFromPart_withRawDataBodyWithNonText_shouldReturnNull() throws Exception {
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "image/jpeg");
BinaryMemoryBody body = new BinaryMemoryBody("Sample text body".getBytes(), MimeUtil.ENC_8BIT);
part.setBody(body);
String result = MessageExtractor.getTextFromPart(part);
assertNull(result);
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageExtractorTest method getTextFromPart_withPlainTextWithCharsetInContentTypeRawDataBody_shouldReturnText.
@Test
public void getTextFromPart_withPlainTextWithCharsetInContentTypeRawDataBody_shouldReturnText() throws Exception {
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain; charset=UTF-8");
BinaryMemoryBody body = new BinaryMemoryBody("Sample text body".getBytes(), MimeUtil.ENC_8BIT);
part.setBody(body);
String result = MessageExtractor.getTextFromPart(part);
assertEquals("Sample text body", result);
}
use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.
the class MessageExtractorTest method getTextFromPart_withHtmlWithCharsetInHtmlRawDataBody_shouldReturnHtmlText.
@Test
public void getTextFromPart_withHtmlWithCharsetInHtmlRawDataBody_shouldReturnHtmlText() throws Exception {
String bodyText = "<html><head>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + "</head><body>Sample text body</body></html>";
BinaryMemoryBody body = new BinaryMemoryBody(bodyText.getBytes(), MimeUtil.ENC_8BIT);
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html");
part.setBody(body);
String result = MessageExtractor.getTextFromPart(part);
assertNotNull(result);
assertEquals(bodyText, result);
}
Aggregations