Search in sources :

Example 11 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_multipartSigned_UnknownProtocol.

@Test
public void extractMessage_multipartSigned_UnknownProtocol() throws Exception {
    Message message = messageFromBody(multipart("signed", "protocol=\"application/pkcs7-signature\"", bodypart("text/plain", "text"), bodypart("application/pkcs7-signature", "signature")));
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertNull(messageViewInfo.cryptoResultAnnotation);
    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)

Example 12 with MessageViewInfo

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

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

Example 14 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_openPgpEncrypted_withoutAnnotations.

@Test
public void extractMessage_openPgpEncrypted_withoutAnnotations() throws Exception {
    Message message = messageFromBody(multipart("encrypted", "protocol=\"application/pgp-encrypted\"", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream")));
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null, false);
    assertEquals(CryptoError.OPENPGP_ENCRYPTED_NO_PROVIDER, messageViewInfo.cryptoResultAnnotation.getErrorType());
    assertNull(messageViewInfo.text);
    assertNull(messageViewInfo.attachments);
    assertNull(messageViewInfo.extraAttachments);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 15 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_withCryptoAnnotation_andReplacementPart.

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

Aggregations

Message (com.fsck.k9.mail.Message)14 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)14 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)10 Test (org.junit.Test)10 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)8 LocalMessage (com.fsck.k9.mailstore.LocalMessage)5 BodyPart (com.fsck.k9.mail.BodyPart)4 Part (com.fsck.k9.mail.Part)4 MessageFormat (com.fsck.k9.Account.MessageFormat)2 MessageReference (com.fsck.k9.controller.MessageReference)2 MessagingException (com.fsck.k9.mail.MessagingException)2 SimpleMessageFormat (com.fsck.k9.message.SimpleMessageFormat)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 WorkerThread (android.support.annotation.WorkerThread)1 UiThread (androidx.annotation.UiThread)1 WorkerThread (androidx.annotation.WorkerThread)1 Account (com.fsck.k9.Account)1 ShowPictures (com.fsck.k9.Account.ShowPictures)1