From b40749547c50e31daf5fa7f12269dd7c39626e23 Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 21 Feb 2015 02:13:00 +0100 Subject: [PATCH] Don't show parts we can't (yet) decrypt as attachments --- .../com/fsck/k9/mailstore/MessageHelper.java | 10 ++++++++++ .../fsck/k9/ui/crypto/MessageCryptoHelper.java | 16 +++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/MessageHelper.java b/k9mail/src/main/java/com/fsck/k9/mailstore/MessageHelper.java index e7747aa8d..a08612e2b 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/MessageHelper.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/MessageHelper.java @@ -5,8 +5,10 @@ import java.util.Stack; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; +import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Multipart; import com.fsck.k9.mail.Part; +import com.fsck.k9.mail.internet.MimeBodyPart; public class MessageHelper { @@ -34,4 +36,12 @@ public class MessageHelper { return true; } + + public static MimeBodyPart createEmptyPart() { + try { + return new MimeBodyPart(null); + } catch (MessagingException e) { + throw new RuntimeException(e); + } + } } diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java index 9cafd55dd..695785fce 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java @@ -49,6 +49,7 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound; public class MessageCryptoHelper { private static final int REQUEST_CODE_CRYPTO = 1000; private static final int INVALID_OPENPGP_RESULT_CODE = -1; + private static final MimeBodyPart NO_REPLACEMENT_PART = null; private final Context context; @@ -83,10 +84,11 @@ public class MessageCryptoHelper { } List encryptedParts = MessageDecryptVerifier.findEncryptedParts(message); - processFoundParts(encryptedParts, CryptoPartType.ENCRYPTED, CryptoError.ENCRYPTED_BUT_INCOMPLETE); + processFoundParts(encryptedParts, CryptoPartType.ENCRYPTED, CryptoError.ENCRYPTED_BUT_INCOMPLETE, + MessageHelper.createEmptyPart()); List signedParts = MessageDecryptVerifier.findSignedParts(message); - processFoundParts(signedParts, CryptoPartType.SIGNED, CryptoError.SIGNED_BUT_INCOMPLETE); + processFoundParts(signedParts, CryptoPartType.SIGNED, CryptoError.SIGNED_BUT_INCOMPLETE, NO_REPLACEMENT_PART); List inlineParts = MessageDecryptVerifier.findPgpInlineParts(message); addFoundInlinePgpParts(inlineParts); @@ -94,22 +96,22 @@ public class MessageCryptoHelper { decryptOrVerifyNextPart(); } - private void processFoundParts(List foundParts, CryptoPartType cryptoPartType, - CryptoError errorIfIncomplete) { - + private void processFoundParts(List foundParts, CryptoPartType cryptoPartType, CryptoError errorIfIncomplete, + MimeBodyPart replacementPart) { for (Part part : foundParts) { if (MessageHelper.isCompletePartAvailable(part)) { CryptoPart cryptoPart = new CryptoPart(cryptoPartType, part); partsToDecryptOrVerify.add(cryptoPart); } else { - addErrorAnnotation(part, errorIfIncomplete); + addErrorAnnotation(part, errorIfIncomplete, replacementPart); } } } - private void addErrorAnnotation(Part part, CryptoError error) { + private void addErrorAnnotation(Part part, CryptoError error, MimeBodyPart outputData) { OpenPgpResultAnnotation annotation = new OpenPgpResultAnnotation(); annotation.setErrorType(error); + annotation.setOutputData(outputData); messageAnnotations.put(part, annotation); }