Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95f6fba3 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

handle encrypted parts in multipart/alternative

parent 6beb9902
Loading
Loading
Loading
Loading
+49 −10
Original line number Diff line number Diff line
@@ -35,9 +35,9 @@ public class MessageDecryptVerifier {
    // APPLICATION/PGP is a special case which occurs from mutt. see http://www.mutt.org/doc/PGP-Notes.txt
    private static final String APPLICATION_PGP = "application/pgp";

    public static final String PGP_INLINE_START_MARKER = "-----BEGIN PGP MESSAGE-----";
    public static final String PGP_INLINE_SIGNED_START_MARKER = "-----BEGIN PGP SIGNED MESSAGE-----";
    public static final int TEXT_LENGTH_FOR_INLINE_CHECK = 36;
    private static final String PGP_INLINE_START_MARKER = "-----BEGIN PGP MESSAGE-----";
    private static final String PGP_INLINE_SIGNED_START_MARKER = "-----BEGIN PGP SIGNED MESSAGE-----";
    private static final int TEXT_LENGTH_FOR_INLINE_CHECK = 36;


    public static Part findPrimaryEncryptedOrSignedPart(Part part, List<Part> outputExtraParts) {
@@ -45,16 +45,55 @@ public class MessageDecryptVerifier {
            return part;
        }

        Part foundPart;

        foundPart = findPrimaryPartInAlternative(part);
        if (foundPart != null) {
            return foundPart;
        }

        foundPart = findPrimaryPartInMixed(part, outputExtraParts);
        if (foundPart != null) {
            return foundPart;
        }

        return null;
    }

    @Nullable
    private static Part findPrimaryPartInMixed(Part part, List<Part> outputExtraParts) {
        Body body = part.getBody();
        if (part.isMimeType("multipart/mixed") && body instanceof Multipart) {

        boolean isMultipartMixed = part.isMimeType("multipart/mixed") && body instanceof Multipart;
        if (!isMultipartMixed) {
            return null;
        }

        Multipart multipart = (Multipart) body;
        BodyPart firstBodyPart = multipart.getBodyPart(0);

        Part foundPart;
        if (isPartEncryptedOrSigned(firstBodyPart)) {
                if (outputExtraParts != null) {
            foundPart = firstBodyPart;
        } else {
            foundPart = findPrimaryPartInAlternative(firstBodyPart);
        }

        if (foundPart != null && outputExtraParts != null) {
            for (int i = 1; i < multipart.getCount(); i++) {
                outputExtraParts.add(multipart.getBodyPart(i));
            }
        }

        return foundPart;
    }

    private static Part findPrimaryPartInAlternative(Part part) {
        Body body = part.getBody();
        if (part.isMimeType("multipart/alternative") && body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            BodyPart firstBodyPart = multipart.getBodyPart(0);
            if (isPartPgpInlineEncryptedOrSigned(firstBodyPart)) {
                return firstBodyPart;
            }
        }
+5 −0
Original line number Diff line number Diff line
@@ -9,8 +9,10 @@ import java.util.List;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import android.util.Log;

import com.fsck.k9.Globals;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.helper.HtmlSanitizer;
@@ -78,6 +80,9 @@ public class MessageViewInfoExtractor {
            cryptoResultAnnotation = cryptoMessageParts.contentCryptoAnnotation;
            extraParts = cryptoMessageParts.extraParts;
        } else {
            if (!annotations.isEmpty()) {
                Log.e(K9.LOG_TAG, "Got message annotations but no crypto root part!");
            }
            rootPart = message;
            cryptoResultAnnotation = null;
            extraParts = null;
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ public class MessageCryptoAnnotations {
        return annotations.containsKey(part);
    }

    public boolean isEmpty() {
        return annotations.isEmpty();
    }

    public Part findKeyForAnnotationWithReplacementPart(Part part) {
        for (HashMap.Entry<Part, CryptoResultAnnotation> entry : annotations.entrySet()) {
            if (part == entry.getValue().getReplacementData()) {