use of com.fsck.k9.mail.Body 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);
}
use of com.fsck.k9.mail.Body 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.Body in project k-9 by k9mail.
the class MessageExtractorTest method getTextFromPart_withTextBody_shouldReturnText.
@Test
public void getTextFromPart_withTextBody_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.Body 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.Body in project k-9 by k9mail.
the class PgpMessageBuilder method createOpenPgpDataSourceFromBodyPart.
@NonNull
private OpenPgpDataSource createOpenPgpDataSourceFromBodyPart(final MimeBodyPart bodyPart, final boolean writeBodyContentOnly) throws MessagingException {
return new OpenPgpDataSource() {
@Override
public void writeTo(OutputStream os) throws IOException {
try {
if (writeBodyContentOnly) {
Body body = bodyPart.getBody();
InputStream inputStream = body.getInputStream();
IOUtils.copy(inputStream, os);
} else {
bodyPart.writeTo(os);
}
} catch (MessagingException e) {
throw new IOException(e);
}
}
};
}
Aggregations