Search in sources :

Example 11 with MessageCryptoAnnotations

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

the class MessageCryptoStructureDetector method findMultipartSignedParts.

public static List<Part> findMultipartSignedParts(Part startPart, MessageCryptoAnnotations messageCryptoAnnotations) {
    List<Part> signedParts = new ArrayList<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(startPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        if (messageCryptoAnnotations.has(part)) {
            CryptoResultAnnotation resultAnnotation = messageCryptoAnnotations.get(part);
            MimeBodyPart replacementData = resultAnnotation.getReplacementData();
            if (replacementData != null) {
                part = replacementData;
            }
        }
        Body body = part.getBody();
        if (isPartMultipartSigned(part)) {
            signedParts.add(part);
            continue;
        }
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (int i = multipart.getCount() - 1; i >= 0; i--) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                partsToCheck.push(bodyPart);
            }
        }
    }
    return signedParts;
}
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) CryptoResultAnnotation(com.fsck.k9.mailstore.CryptoResultAnnotation) ArrayList(java.util.ArrayList) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Example 12 with MessageCryptoAnnotations

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

the class MessageCryptoHelperTest method textPlain.

@Test
public void textPlain() throws Exception {
    MimeMessage message = new MimeMessage();
    message.setUid("msguid");
    message.setHeader("Content-Type", "text/plain");
    MessageCryptoCallback messageCryptoCallback = mock(MessageCryptoCallback.class);
    messageCryptoHelper.asyncStartOrResumeProcessingMessage(message, messageCryptoCallback, null, false);
    ArgumentCaptor<MessageCryptoAnnotations> captor = ArgumentCaptor.forClass(MessageCryptoAnnotations.class);
    verify(messageCryptoCallback).onCryptoOperationsFinished(captor.capture());
    MessageCryptoAnnotations annotations = captor.getValue();
    assertTrue(annotations.isEmpty());
    verifyNoMoreInteractions(messageCryptoCallback);
    verify(autocryptOperations).hasAutocryptHeader(message);
    verifyNoMoreInteractions(autocryptOperations);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MessageCryptoAnnotations(com.fsck.k9.mailstore.MessageCryptoAnnotations) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 13 with MessageCryptoAnnotations

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

the class MessageCryptoHelperTest method textPlain_withAutocrypt.

@Test
public void textPlain_withAutocrypt() throws Exception {
    MimeMessage message = new MimeMessage();
    message.setUid("msguid");
    message.setHeader("Content-Type", "text/plain");
    when(autocryptOperations.hasAutocryptHeader(message)).thenReturn(true);
    when(autocryptOperations.addAutocryptPeerUpdateToIntentIfPresent(same(message), any(Intent.class))).thenReturn(true);
    MessageCryptoCallback messageCryptoCallback = mock(MessageCryptoCallback.class);
    messageCryptoHelper.asyncStartOrResumeProcessingMessage(message, messageCryptoCallback, null, false);
    ArgumentCaptor<MessageCryptoAnnotations> captor = ArgumentCaptor.forClass(MessageCryptoAnnotations.class);
    verify(messageCryptoCallback).onCryptoOperationsFinished(captor.capture());
    MessageCryptoAnnotations annotations = captor.getValue();
    assertTrue(annotations.isEmpty());
    verifyNoMoreInteractions(messageCryptoCallback);
    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(autocryptOperations).addAutocryptPeerUpdateToIntentIfPresent(same(message), intentCaptor.capture());
    verify(openPgpApi).executeApiAsync(same(intentCaptor.getValue()), same((InputStream) null), same((OutputStream) null), any(IOpenPgpCallback.class));
}
Also used : IOpenPgpCallback(org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MessageCryptoAnnotations(com.fsck.k9.mailstore.MessageCryptoAnnotations) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 14 with MessageCryptoAnnotations

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

the class MessageViewInfoExtractorTest method extractMessage_openPgpEncrypted.

@Test
public void extractMessage_openPgpEncrypted() 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")));
    MessageCryptoAnnotations cryptoAnnotations = new MessageCryptoAnnotations();
    CryptoResultAnnotation openPgpResultAnnotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(null, 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);
    assertTrue(messageViewInfo.attachments.isEmpty());
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
}
Also used : 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 15 with MessageCryptoAnnotations

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

the class MessageViewInfoExtractorTest method extractMessage_withCryptoAnnotation.

@Test
public void extractMessage_withCryptoAnnotation() throws Exception {
    Message message = messageFromBody(SUBJECT, multipart("signed", "protocol=\"application/pgp-signature\"", bodypart("text/plain", "text"), bodypart("application/pgp-signature")));
    CryptoResultAnnotation annotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(null, null, null, null, null, false);
    MessageCryptoAnnotations messageCryptoAnnotations = createAnnotations(message, annotation);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, messageCryptoAnnotations, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertSame(annotation, messageViewInfo.cryptoResultAnnotation);
    assertSame(message, messageViewInfo.message);
    assertSame(message, messageViewInfo.rootPart);
    assertEquals(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) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) 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