Search in sources :

Example 21 with BodyPart

use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.

the class PgpMessageBuilderTest method assertContentOfBodyPartEquals.

private static void assertContentOfBodyPartEquals(String reason, BodyPart signatureBodyPart, String expected) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InputStream inputStream = MimeUtility.decodeBody(signatureBodyPart.getBody());
        IOUtils.copy(inputStream, bos);
        Assert.assertEquals(reason, expected, new String(bos.toByteArray(), Charsets.UTF_8));
    } catch (IOException | MessagingException e) {
        Assert.fail();
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 22 with BodyPart

use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.

the class PgpMessageBuilderTest method assertContentOfBodyPartEquals.

private static void assertContentOfBodyPartEquals(String reason, BodyPart signatureBodyPart, byte[] expected) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        signatureBodyPart.getBody().writeTo(bos);
        Assert.assertArrayEquals(reason, expected, bos.toByteArray());
    } catch (IOException | MessagingException e) {
        Assert.fail();
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 23 with BodyPart

use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.

the class TextPartFinderTest method findFirstTextPart_withMultipartMixedContainingMultipartAlternativeWithTextPlainPartLast.

@Test
public void findFirstTextPart_withMultipartMixedContainingMultipartAlternativeWithTextPlainPartLast() throws Exception {
    BodyPart expected = createTextPart("text/plain");
    Part part = createMultipart("multipart/mixed", createMultipart("multipart/alternative", createTextPart("text/html"), expected));
    Part result = textPartFinder.findFirstTextPart(part);
    assertEquals(expected, result);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createPart(com.fsck.k9.message.MessageCreationHelper.createPart) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Example 24 with BodyPart

use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.

the class TextPartFinderTest method findFirstTextPart_withMultipartAlternativeContainingOnlyTextHtmlPart.

@Test
public void findFirstTextPart_withMultipartAlternativeContainingOnlyTextHtmlPart() throws Exception {
    BodyPart expected = createTextPart("text/html");
    Part part = createMultipart("multipart/alternative", createPart("image/gif"), expected, createTextPart("text/html"));
    Part result = textPartFinder.findFirstTextPart(part);
    assertEquals(expected, result);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createPart(com.fsck.k9.message.MessageCreationHelper.createPart) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Example 25 with BodyPart

use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.

the class TextPartFinderTest method findFirstTextPart_withMultipartAlternativeContainingMultipartRelatedContainingTextHtmlFirst.

@Test
public void findFirstTextPart_withMultipartAlternativeContainingMultipartRelatedContainingTextHtmlFirst() throws Exception {
    BodyPart expected = createTextPart("text/plain");
    Part part = createMultipart("multipart/alternative", createMultipart("multipart/related", createTextPart("text/html"), createPart("image/jpeg")), expected);
    Part result = textPartFinder.findFirstTextPart(part);
    assertEquals(expected, result);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createPart(com.fsck.k9.message.MessageCreationHelper.createPart) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Aggregations

BodyPart (com.fsck.k9.mail.BodyPart)49 Part (com.fsck.k9.mail.Part)38 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)33 Test (org.junit.Test)32 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)22 Multipart (com.fsck.k9.mail.Multipart)21 Body (com.fsck.k9.mail.Body)17 Message (com.fsck.k9.mail.Message)17 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)13 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)11 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)11 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 MessagingException (com.fsck.k9.mail.MessagingException)9 OutputStream (java.io.OutputStream)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)7 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)7 ArrayList (java.util.ArrayList)6 Stack (java.util.Stack)6 TextBody (com.fsck.k9.mail.internet.TextBody)5