Search in sources :

Example 86 with BodyPart

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

the class MessageViewInfoExtractorTest method extractMessage_withCryptoAnnotation_andExtraText.

@Test
public void extractMessage_withCryptoAnnotation_andExtraText() throws Exception {
    MimeBodyPart signedPart = multipart("signed", "protocol=\"application/pgp-signature\"", bodypart("text/plain", "text"), bodypart("application/pgp-signature"));
    BodyPart extraText = bodypart("text/plain", "extra text");
    Message message = messageFromBody(multipart("mixed", signedPart, extraText));
    CryptoResultAnnotation annotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(null, null, null, null, null, false);
    MessageCryptoAnnotations messageCryptoAnnotations = createAnnotations(signedPart, annotation);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, messageCryptoAnnotations, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertSame(annotation, messageViewInfo.cryptoResultAnnotation);
    assertEquals("extra text", messageViewInfo.extraText);
    assertTrue(messageViewInfo.attachments.isEmpty());
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 87 with BodyPart

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

the class MessageViewInfoExtractorTest method extractMessage_multipartSigned_UnknownProtocol_withExtraAttachments.

@Test
public void extractMessage_multipartSigned_UnknownProtocol_withExtraAttachments() throws Exception {
    BodyPart extraAttachment = bodypart("application/octet-stream");
    Message message = messageFromBody(multipart("mixed", multipart("signed", "protocol=\"application/pkcs7-signature\"", bodypart("text/plain", "text"), bodypart("application/pkcs7-signature", "signature")), extraAttachment));
    AttachmentViewInfo mock = mock(AttachmentViewInfo.class);
    setupAttachmentInfoForPart(extraAttachment, mock);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertNull(messageViewInfo.cryptoResultAnnotation);
    assertSame(mock, messageViewInfo.attachments.get(0));
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 88 with BodyPart

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

the class MessageViewInfoExtractorTest method extractMessage_withAttachment.

@Test
public void extractMessage_withAttachment() throws Exception {
    BodyPart attachmentPart = bodypart("application/octet-stream");
    Message message = messageFromBody(multipart("mixed", bodypart("text/plain", "text"), attachmentPart));
    message.setSubject(SUBJECT);
    AttachmentViewInfo attachmentViewInfo = mock(AttachmentViewInfo.class);
    setupAttachmentInfoForPart(attachmentPart, attachmentViewInfo);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertSame(attachmentViewInfo, messageViewInfo.attachments.get(0));
    assertNull(messageViewInfo.cryptoResultAnnotation);
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
    assertEquals(SUBJECT, messageViewInfo.subject);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 89 with BodyPart

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

the class MessageViewInfoExtractorTest method extractMessage_withCryptoAnnotation_andExtraAttachment.

@Test
public void extractMessage_withCryptoAnnotation_andExtraAttachment() throws Exception {
    MimeBodyPart signedPart = multipart("signed", "protocol=\"application/pgp-signature\"", bodypart("text/plain", "text"), bodypart("application/pgp-signature"));
    BodyPart extraAttachment = bodypart("application/octet-stream");
    Message message = messageFromBody(multipart("mixed", signedPart, extraAttachment));
    CryptoResultAnnotation annotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(null, null, null, null, null, false);
    MessageCryptoAnnotations messageCryptoAnnotations = createAnnotations(signedPart, annotation);
    AttachmentViewInfo attachmentViewInfo = mock(AttachmentViewInfo.class);
    setupAttachmentInfoForPart(extraAttachment, attachmentViewInfo);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, messageCryptoAnnotations, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertSame(annotation, messageViewInfo.cryptoResultAnnotation);
    assertSame(attachmentViewInfo, messageViewInfo.extraAttachments.get(0));
    assertTrue(messageViewInfo.attachments.isEmpty());
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 90 with BodyPart

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

the class MessageViewInfoExtractorTest method extractMessage_openPgpEncrypted_withProtectedSubject.

@Test
public void extractMessage_openPgpEncrypted_withProtectedSubject() throws Exception {
    MimeBodyPart encryptedPayload = bodypart("text/plain", "encrypted text");
    Message message = messageFromBody(multipart("encrypted", "protocol=\"application/pgp-encrypted\"", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream")));
    encryptedPayload.setHeader("Content-Type", encryptedPayload.getHeader("Content-Type")[0] + "; protected-headers=v1");
    encryptedPayload.setHeader("Subject", PROTECTED_SUBJECT);
    MessageCryptoAnnotations cryptoAnnotations = new MessageCryptoAnnotations();
    OpenPgpDecryptionResult decryptionResult = new OpenPgpDecryptionResult(OpenPgpDecryptionResult.RESULT_ENCRYPTED);
    CryptoResultAnnotation openPgpResultAnnotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(decryptionResult, null, null, null, encryptedPayload, false);
    cryptoAnnotations.put(message, openPgpResultAnnotation);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, cryptoAnnotations, true);
    assertSame(openPgpResultAnnotation, messageViewInfo.cryptoResultAnnotation);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">encrypted text</pre>", messageViewInfo.text);
    assertEquals(PROTECTED_SUBJECT, messageViewInfo.subject);
    assertTrue(messageViewInfo.attachments.isEmpty());
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) OpenPgpDecryptionResult(org.openintents.openpgp.OpenPgpDecryptionResult) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) 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