use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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());
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.
the class MessageDecryptVerifier method findSignedParts.
public static List<Part> findSignedParts(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;
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations in project k-9 by k9mail.
the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubSignedAndText__shouldReturnSigned.
@Test
public void findEncrypted__withMultipartMixedSubSignedAndText__shouldReturnSigned() throws Exception {
Message message = messageFromBody(multipart("mixed", multipart("signed", bodypart("text/plain"), bodypart("application/pgp-signature")), bodypart("text/plain")));
List<Part> signedParts = MessageDecryptVerifier.findSignedParts(message, messageCryptoAnnotations);
assertEquals(1, signedParts.size());
assertSame(getPart(message, 0), signedParts.get(0));
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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;
}
use of com.fsck.k9.mailstore.MessageCryptoAnnotations 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());
}
Aggregations