use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageCryptoHelper method processFoundSignedParts.
private void processFoundSignedParts(List<Part> foundParts) {
for (Part part : foundParts) {
if (!MessageHelper.isCompletePartAvailable(part)) {
MimeBodyPart replacementPart = getMultipartSignedContentPartIfAvailable(part);
addErrorAnnotation(part, CryptoError.OPENPGP_SIGNED_BUT_INCOMPLETE, replacementPart);
continue;
}
if (MessageDecryptVerifier.isPgpMimeEncryptedOrSignedPart(part)) {
CryptoPart cryptoPart = new CryptoPart(CryptoPartType.PGP_SIGNED, part);
partsToDecryptOrVerify.add(cryptoPart);
continue;
}
MimeBodyPart replacementPart = getMultipartSignedContentPartIfAvailable(part);
addErrorAnnotation(part, CryptoError.SIGNED_BUT_UNSUPPORTED, replacementPart);
}
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageCryptoHelper method extractClearsignedTextReplacementPart.
private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) {
try {
String clearsignedText = MessageExtractor.getTextFromPart(part);
String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText);
if (replacementText == null) {
Timber.e("failed to extract clearsigned text for replacement part");
return NO_REPLACEMENT_PART;
}
return new MimeBodyPart(new TextBody(replacementText), "text/plain");
} catch (MessagingException e) {
Timber.e(e, "failed to create clearsigned text replacement part");
return NO_REPLACEMENT_PART;
}
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageCryptoHelper method getMultipartSignedContentPartIfAvailable.
@Nullable
private static MimeBodyPart getMultipartSignedContentPartIfAvailable(Part part) {
MimeBodyPart replacementPart = NO_REPLACEMENT_PART;
Body body = part.getBody();
if (body instanceof MimeMultipart) {
MimeMultipart multipart = ((MimeMultipart) part.getBody());
if (multipart.getCount() >= 1) {
replacementPart = (MimeBodyPart) multipart.getBodyPart(0);
}
}
return replacementPart;
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageCryptoHelper method callAsyncDecrypt.
private void callAsyncDecrypt(Intent intent) throws IOException {
OpenPgpDataSource dataSource = getDataSourceForEncryptedOrInlineData();
OpenPgpDataSink<MimeBodyPart> openPgpDataSink = getDataSinkForDecryptedData();
cancelableBackgroundOperation = openPgpApi.executeApiAsync(intent, dataSource, openPgpDataSink, new IOpenPgpSinkResultCallback<MimeBodyPart>() {
@Override
public void onReturn(Intent result, MimeBodyPart decryptedPart) {
cancelableBackgroundOperation = null;
currentCryptoResult = result;
onCryptoOperationReturned(decryptedPart);
}
@Override
public void onProgress(int current, int max) {
Timber.d("received progress status: %d / %d", current, max);
callbackProgress(current, max);
}
});
}
use of com.fsck.k9.mail.internet.MimeBodyPart 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;
}
Aggregations