Search in sources :

Example 1 with MessageCryptoAnnotations

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

the class MessageViewInfoExtractor method extractMessageForView.

@WorkerThread
public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations annotations) throws MessagingException {
    Part rootPart;
    CryptoResultAnnotation cryptoResultAnnotation;
    List<Part> extraParts;
    CryptoMessageParts cryptoMessageParts = MessageCryptoSplitter.split(message, annotations);
    if (cryptoMessageParts != null) {
        rootPart = cryptoMessageParts.contentPart;
        cryptoResultAnnotation = cryptoMessageParts.contentCryptoAnnotation;
        extraParts = cryptoMessageParts.extraParts;
    } else {
        if (annotations != null && !annotations.isEmpty()) {
            Timber.e("Got message annotations but no crypto root part!");
        }
        rootPart = message;
        cryptoResultAnnotation = null;
        extraParts = null;
    }
    List<AttachmentViewInfo> attachmentInfos = new ArrayList<>();
    ViewableExtractedText viewable = extractViewableAndAttachments(Collections.singletonList(rootPart), attachmentInfos);
    List<AttachmentViewInfo> extraAttachmentInfos = new ArrayList<>();
    String extraViewableText = null;
    if (extraParts != null) {
        ViewableExtractedText extraViewable = extractViewableAndAttachments(extraParts, extraAttachmentInfos);
        extraViewableText = extraViewable.text;
    }
    AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart);
    boolean isMessageIncomplete = !message.isSet(Flag.X_DOWNLOADED_FULL) || MessageExtractor.hasMissingParts(message);
    return MessageViewInfo.createWithExtractedContent(message, isMessageIncomplete, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, attachmentResolver, extraViewableText, extraAttachmentInfos);
}
Also used : CryptoMessageParts(com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts) Part(com.fsck.k9.mail.Part) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Example 2 with MessageCryptoAnnotations

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

the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned.

@Test
public void findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned() throws Exception {
    Message message = messageFromBody(multipart("mixed", bodypart("text/plain"), multipart("signed", bodypart("text/plain"), bodypart("application/pgp-signature"))));
    List<Part> signedParts = MessageDecryptVerifier.findSignedParts(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) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 3 with MessageCryptoAnnotations

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

the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubSigned__shouldReturnSigned.

@Test
public void findEncrypted__withMultipartMixedSubSigned__shouldReturnSigned() throws Exception {
    Message message = messageFromBody(multipart("mixed", multipart("signed", bodypart("text/plain"), bodypart("application/pgp-signature"))));
    List<Part> signedParts = MessageDecryptVerifier.findSignedParts(message, messageCryptoAnnotations);
    assertEquals(1, signedParts.size());
    assertSame(getPart(message, 0), 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) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 4 with MessageCryptoAnnotations

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

the class MessageDecryptVerifierTest method findSigned__withSimpleMultipartSigned__shouldReturnRoot.

@Test
public void findSigned__withSimpleMultipartSigned__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", bodypart("text/plain"), bodypart("application/pgp-signature")));
    List<Part> signedParts = MessageDecryptVerifier.findSignedParts(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) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 5 with MessageCryptoAnnotations

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

the class MessageDecryptVerifierTest method findSigned__withComplexMultipartSigned__shouldReturnRoot.

@Test
public void findSigned__withComplexMultipartSigned__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", multipart("mixed", bodypart("text/plain"), bodypart("application/pdf")), bodypart("application/pgp-signature")));
    List<Part> signedParts = MessageDecryptVerifier.findSignedParts(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) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) 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