Search in sources :

Example 71 with Part

use of com.fsck.k9.mail.Part 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);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 72 with Part

use of com.fsck.k9.mail.Part 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);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 73 with Part

use of com.fsck.k9.mail.Part 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);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) Body(com.fsck.k9.mail.Body) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 74 with Part

use of com.fsck.k9.mail.Part 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);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 75 with Part

use of com.fsck.k9.mail.Part 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);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Aggregations

Part (com.fsck.k9.mail.Part)113 Test (org.junit.Test)92 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)78 BodyPart (com.fsck.k9.mail.BodyPart)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)39 Message (com.fsck.k9.mail.Message)32 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)30 Body (com.fsck.k9.mail.Body)29 Multipart (com.fsck.k9.mail.Multipart)27 ArrayList (java.util.ArrayList)27 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)20 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)19 MessagingException (com.fsck.k9.mail.MessagingException)16 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)16 TextBody (com.fsck.k9.mail.internet.TextBody)14 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)13 Viewable (com.fsck.k9.mail.internet.Viewable)10 Uri (android.net.Uri)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)6 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)6