use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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());
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method extractMessage_openPgpEncrypted_withProtectedSubject.
@Test
public void extractMessage_openPgpEncrypted_withProtectedSubject() 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")));
encryptedPayload.setHeader("Content-Type", encryptedPayload.getHeader("Content-Type")[0] + "; protected-headers=v1");
encryptedPayload.setHeader("Subject", PROTECTED_SUBJECT);
MessageCryptoAnnotations cryptoAnnotations = new MessageCryptoAnnotations();
OpenPgpDecryptionResult decryptionResult = new OpenPgpDecryptionResult(OpenPgpDecryptionResult.RESULT_ENCRYPTED);
CryptoResultAnnotation openPgpResultAnnotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(decryptionResult, 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);
assertEquals(PROTECTED_SUBJECT, messageViewInfo.subject);
assertTrue(messageViewInfo.attachments.isEmpty());
assertTrue(messageViewInfo.extraAttachments.isEmpty());
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.
the class MessageCryptoStructureDetectorTest method findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned.
@Test
public void findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned() throws Exception {
Message message = messageFromBody(multipart("mixed", bodypart("text/plain"), multipart("signed", "application/pgp-signature", bodypart("text/plain"), bodypart("application/pgp-signature"))));
List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(message, messageCryptoAnnotations);
assertEquals(1, signedParts.size());
assertSame(getPart(message, 1), signedParts.get(0));
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.
the class MessageCryptoStructureDetectorTest method findSigned__withNoProtocolAndNoBody__shouldReturnRoot.
@Test
public void findSigned__withNoProtocolAndNoBody__shouldReturnRoot() throws Exception {
Message message = messageFromBody(multipart("signed", bodypart("text/plain"), bodypart("application/pgp-signature")));
List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(message, messageCryptoAnnotations);
assertEquals(1, signedParts.size());
assertSame(message, signedParts.get(0));
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.
the class MessageCryptoStructureDetectorTest method findSigned__withBadProtocol__shouldReturnNothing.
@Test
public void findSigned__withBadProtocol__shouldReturnNothing() throws Exception {
Message message = messageFromBody(multipart("signed", "protocol=\"application/not-pgp-signature\"", bodypart("text/plain", "content"), bodypart("application/pgp-signature")));
List<Part> signedParts = MessageCryptoStructureDetector.findMultipartSignedParts(message, messageCryptoAnnotations);
assertTrue(signedParts.isEmpty());
}
Aggregations