Search in sources :

Example 21 with MimeBodyPart

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);
    }
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 22 with MimeBodyPart

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;
    }
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MessagingException(com.fsck.k9.mail.MessagingException) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 23 with MimeBodyPart

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;
}
Also used : MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) TextBody(com.fsck.k9.mail.internet.TextBody) Body(com.fsck.k9.mail.Body) Nullable(android.support.annotation.Nullable)

Example 24 with MimeBodyPart

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);
        }
    });
}
Also used : IOpenPgpSinkResultCallback(org.openintents.openpgp.util.OpenPgpApi.IOpenPgpSinkResultCallback) OpenPgpDataSource(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 25 with MimeBodyPart

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;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) CryptoResultAnnotation(com.fsck.k9.mailstore.CryptoResultAnnotation) ArrayList(java.util.ArrayList) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Aggregations

MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)42 Test (org.junit.Test)22 Part (com.fsck.k9.mail.Part)15 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)15 TextBody (com.fsck.k9.mail.internet.TextBody)11 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)11 BodyPart (com.fsck.k9.mail.BodyPart)9 MessagingException (com.fsck.k9.mail.MessagingException)7 Uri (android.net.Uri)5 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)5 PendingIntent (android.app.PendingIntent)4 Body (com.fsck.k9.mail.Body)4 Multipart (com.fsck.k9.mail.Multipart)4 CryptoResultAnnotation (com.fsck.k9.mailstore.CryptoResultAnnotation)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)4 Intent (android.content.Intent)3 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)3 InputStream (java.io.InputStream)3