Search in sources :

Example 16 with MessageViewInfo

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

the class MessageViewInfoExtractor method extractMessageForView.

@WorkerThread
public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations, boolean openPgpProviderConfigured) throws MessagingException {
    ArrayList<Part> extraParts = new ArrayList<>();
    Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts);
    if (cryptoContentPart == null) {
        if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) {
            Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!");
        }
        MessageViewInfo messageViewInfo = extractSimpleMessageForView(message, message);
        return messageViewInfo.withSubject(message.getSubject(), false);
    }
    boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart);
    if (!openPgpProviderConfigured && isOpenPgpEncrypted) {
        CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation(CryptoError.OPENPGP_ENCRYPTED_NO_PROVIDER, null);
        return MessageViewInfo.createWithErrorState(message, false).withCryptoData(noProviderAnnotation, null, null);
    }
    MessageViewInfo messageViewInfo = getMessageContent(message, cryptoAnnotations, extraParts, cryptoContentPart);
    messageViewInfo = extractSubject(messageViewInfo);
    return messageViewInfo;
}
Also used : Part(com.fsck.k9.mail.Part) ArrayList(java.util.ArrayList) WorkerThread(androidx.annotation.WorkerThread)

Example 17 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_withCryptoAnnotation_andExtraText.

@Test
public void extractMessage_withCryptoAnnotation_andExtraText() throws Exception {
    MimeBodyPart signedPart = multipart("signed", "protocol=\"application/pgp-signature\"", bodypart("text/plain", "text"), bodypart("application/pgp-signature"));
    BodyPart extraText = bodypart("text/plain", "extra text");
    Message message = messageFromBody(multipart("mixed", signedPart, extraText));
    CryptoResultAnnotation annotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(null, null, null, null, null, false);
    MessageCryptoAnnotations messageCryptoAnnotations = createAnnotations(signedPart, annotation);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, messageCryptoAnnotations, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertSame(annotation, messageViewInfo.cryptoResultAnnotation);
    assertEquals("extra text", messageViewInfo.extraText);
    assertTrue(messageViewInfo.attachments.isEmpty());
    assertTrue(messageViewInfo.extraAttachments.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 18 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_multipartSigned_UnknownProtocol_withExtraAttachments.

@Test
public void extractMessage_multipartSigned_UnknownProtocol_withExtraAttachments() throws Exception {
    BodyPart extraAttachment = bodypart("application/octet-stream");
    Message message = messageFromBody(multipart("mixed", multipart("signed", "protocol=\"application/pkcs7-signature\"", bodypart("text/plain", "text"), bodypart("application/pkcs7-signature", "signature")), extraAttachment));
    AttachmentViewInfo mock = mock(AttachmentViewInfo.class);
    setupAttachmentInfoForPart(extraAttachment, mock);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertNull(messageViewInfo.cryptoResultAnnotation);
    assertSame(mock, messageViewInfo.attachments.get(0));
    assertTrue(messageViewInfo.extraAttachments.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) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 19 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_withAttachment.

@Test
public void extractMessage_withAttachment() throws Exception {
    BodyPart attachmentPart = bodypart("application/octet-stream");
    Message message = messageFromBody(multipart("mixed", bodypart("text/plain", "text"), attachmentPart));
    message.setSubject(SUBJECT);
    AttachmentViewInfo attachmentViewInfo = mock(AttachmentViewInfo.class);
    setupAttachmentInfoForPart(attachmentPart, attachmentViewInfo);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null, false);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">text</pre>", messageViewInfo.text);
    assertSame(attachmentViewInfo, messageViewInfo.attachments.get(0));
    assertNull(messageViewInfo.cryptoResultAnnotation);
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
    assertEquals(SUBJECT, messageViewInfo.subject);
}
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) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 20 with MessageViewInfo

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

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