Search in sources :

Example 6 with MessageCryptoAnnotations

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

the class MessageCryptoSplitter method split.

@Nullable
public static CryptoMessageParts split(@NonNull Message message, @Nullable MessageCryptoAnnotations annotations) {
    ArrayList<Part> extraParts = new ArrayList<>();
    Part primaryPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, extraParts);
    if (primaryPart == null) {
        return null;
    }
    if (annotations == null) {
        CryptoResultAnnotation rootPartAnnotation = CryptoResultAnnotation.createErrorAnnotation(CryptoError.OPENPGP_ENCRYPTED_NO_PROVIDER, null);
        return new CryptoMessageParts(primaryPart, rootPartAnnotation, extraParts);
    }
    CryptoResultAnnotation rootPartAnnotation = annotations.get(primaryPart);
    Part rootPart;
    if (rootPartAnnotation != null && rootPartAnnotation.hasReplacementData()) {
        rootPart = rootPartAnnotation.getReplacementData();
    } else {
        rootPart = primaryPart;
    }
    return new CryptoMessageParts(rootPart, rootPartAnnotation, extraParts);
}
Also used : Part(com.fsck.k9.mail.Part) CryptoResultAnnotation(com.fsck.k9.mailstore.CryptoResultAnnotation) ArrayList(java.util.ArrayList) Nullable(android.support.annotation.Nullable)

Example 7 with MessageCryptoAnnotations

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

the class MessageCryptoStructureDetectorTest method findEncrypted__withMultipartMixedSubSignedAndText__shouldReturnSigned.

@Test
public void findEncrypted__withMultipartMixedSubSignedAndText__shouldReturnSigned() throws Exception {
    Message message = messageFromBody(multipart("mixed", multipart("signed", "application/pgp-signature", bodypart("text/plain"), bodypart("application/pgp-signature")), bodypart("text/plain")));
    List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(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) Test(org.junit.Test)

Example 8 with MessageCryptoAnnotations

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

the class MessageCryptoStructureDetectorTest method findSigned__withComplexMultipartSigned__shouldReturnRoot.

@Test
public void findSigned__withComplexMultipartSigned__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", "protocol=\"application/pgp-signature\"", multipart("mixed", bodypart("text/plain"), bodypart("application/pdf")), 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 9 with MessageCryptoAnnotations

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

the class MessageCryptoStructureDetectorTest method findSigned__withMissingSignature__shouldReturnEmpty.

@Test
public void findSigned__withMissingSignature__shouldReturnEmpty() throws Exception {
    Message message = messageFromBody(multipart("signed", "protocol=\"application/pgp-signature\"", bodypart("text/plain")));
    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)

Example 10 with MessageCryptoAnnotations

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

the class MessageCryptoStructureDetectorTest method findEncrypted__withMultipartMixedSubSigned__shouldReturnSigned.

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