Search in sources :

Example 21 with MessageCryptoAnnotations

use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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 22 with MessageCryptoAnnotations

use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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)

Example 23 with MessageCryptoAnnotations

use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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 24 with MessageCryptoAnnotations

use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.

the class MessageCryptoStructureDetectorTest method findSigned__withNoProtocolAndNoBody__shouldReturnRoot.

@Test
public void findSigned__withNoProtocolAndNoBody__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", bodypart("text/plain"), bodypart("application/pgp-signature")));
    List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(message, messageCryptoAnnotations);
    assertEquals(1, signedParts.size());
    assertSame(message, 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 25 with MessageCryptoAnnotations

use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.

the class MessageCryptoStructureDetectorTest method findSigned__withBadProtocol__shouldReturnNothing.

@Test
public void findSigned__withBadProtocol__shouldReturnNothing() throws Exception {
    Message message = messageFromBody(multipart("signed", "protocol=\"application/not-pgp-signature\"", bodypart("text/plain", "content"), bodypart("application/pgp-signature")));
    List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(message, messageCryptoAnnotations);
    assertTrue(signedParts.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)

Aggregations

MimeMessage (com.fsck.k9.mail.internet.MimeMessage)22 Test (org.junit.Test)22 Message (com.fsck.k9.mail.Message)20 Part (com.fsck.k9.mail.Part)19 BodyPart (com.fsck.k9.mail.BodyPart)18 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)12 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)6 MessageCryptoAnnotations (com.fsck.k9.mailstore.MessageCryptoAnnotations)5 ArrayList (java.util.ArrayList)5 CryptoResultAnnotation (com.fsck.k9.mailstore.CryptoResultAnnotation)4 RobolectricTest (com.fsck.k9.RobolectricTest)2 Body (com.fsck.k9.mail.Body)2 Multipart (com.fsck.k9.mail.Multipart)2 Stack (java.util.Stack)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Nullable (android.support.annotation.Nullable)1 WorkerThread (android.support.annotation.WorkerThread)1 WorkerThread (androidx.annotation.WorkerThread)1 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)1