Search in sources :

Example 91 with BodyPart

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

the class MessageBuilderTest method build_usingHtmlFormat_shouldUseMultipartAlternativeInCorrectOrder.

@Test
public void build_usingHtmlFormat_shouldUseMultipartAlternativeInCorrectOrder() {
    MessageBuilder messageBuilder = createHtmlMessageBuilder();
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals(MimeMultipart.class, message.getBody().getClass());
    assertEquals("multipart/alternative", ((MimeMultipart) message.getBody()).getMimeType());
    List<BodyPart> parts = ((MimeMultipart) message.getBody()).getBodyParts();
    // RFC 2046 - 5.1.4. - Best type is last displayable
    assertEquals("text/plain", parts.get(0).getMimeType());
    assertEquals("text/html", parts.get(1).getMimeType());
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 92 with BodyPart

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

the class AttachmentResolverTest method buildCidMap__onMultipartWithEmptyBodyPart__shouldReturnEmptyMap.

@Test
public void buildCidMap__onMultipartWithEmptyBodyPart__shouldReturnEmptyMap() throws Exception {
    Multipart multipartBody = MimeMultipart.newInstance();
    BodyPart bodyPart = spy(new MimeBodyPart());
    Part multipartPart = new MimeBodyPart(multipartBody);
    multipartBody.addBodyPart(bodyPart);
    Map<String, Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart);
    verify(bodyPart).getContentId();
    assertTrue(result.isEmpty());
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Uri(android.net.Uri) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 93 with BodyPart

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

the class MessageCryptoStructureDetectorTest method findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned.

@Test
public void findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned() throws Exception {
    Message message = messageFromBody(multipart("mixed", bodypart("text/plain"), multipart("signed", "application/pgp-signature", bodypart("text/plain"), bodypart("application/pgp-signature"))));
    List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(message, messageCryptoAnnotations);
    assertEquals(1, signedParts.size());
    assertSame(getPart(message, 1), signedParts.get(0));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Test(org.junit.Test)

Example 94 with BodyPart

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

the class MessageCryptoStructureDetectorTest method findEncrypted__withBadProtocol__shouldReturnEmpty.

@Test
public void findEncrypted__withBadProtocol__shouldReturnEmpty() throws Exception {
    Message message = messageFromBody(multipart("encrypted", "protocol=\"application/not-pgp-encrypted\"", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream", "content")));
    List<Part> encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message);
    assertTrue(encryptedParts.isEmpty());
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Test(org.junit.Test)

Example 95 with BodyPart

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

the class MessageCryptoStructureDetectorTest method findEncrypted__withMultipartMixedSubTextAndEncrypted__shouldReturnEncrypted.

@Test
public void findEncrypted__withMultipartMixedSubTextAndEncrypted__shouldReturnEncrypted() throws Exception {
    Message message = messageFromBody(multipart("mixed", bodypart("text/plain"), multipart("encrypted", "protocol=\"application/pgp-encrypted\"", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream"))));
    List<Part> encryptedParts = MessageCryptoStructureDetector.findMultipartEncryptedParts(message);
    assertEquals(1, encryptedParts.size());
    assertSame(getPart(message, 1), encryptedParts.get(0));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Test(org.junit.Test)

Aggregations

BodyPart (com.fsck.k9.mail.BodyPart)86 Test (org.junit.Test)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)65 Part (com.fsck.k9.mail.Part)64 Message (com.fsck.k9.mail.Message)58 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)50 Multipart (com.fsck.k9.mail.Multipart)28 Body (com.fsck.k9.mail.Body)25 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)22 ArrayList (java.util.ArrayList)13 RobolectricTest (com.fsck.k9.RobolectricTest)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 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 OutputStream (java.io.OutputStream)11 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)10 MessagingException (com.fsck.k9.mail.MessagingException)10 Stack (java.util.Stack)9 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)8