1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Don't show parts we can't (yet) decrypt as attachments

This commit is contained in:
cketti 2015-02-21 02:13:00 +01:00
parent e5e4c29736
commit b40749547c
2 changed files with 19 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -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<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
processFoundParts(encryptedParts, CryptoPartType.ENCRYPTED, CryptoError.ENCRYPTED_BUT_INCOMPLETE);
processFoundParts(encryptedParts, CryptoPartType.ENCRYPTED, CryptoError.ENCRYPTED_BUT_INCOMPLETE,
MessageHelper.createEmptyPart());
List<Part> signedParts = MessageDecryptVerifier.findSignedParts(message);
processFoundParts(signedParts, CryptoPartType.SIGNED, CryptoError.SIGNED_BUT_INCOMPLETE);
processFoundParts(signedParts, CryptoPartType.SIGNED, CryptoError.SIGNED_BUT_INCOMPLETE, NO_REPLACEMENT_PART);
List<Part> inlineParts = MessageDecryptVerifier.findPgpInlineParts(message);
addFoundInlinePgpParts(inlineParts);
@ -94,22 +96,22 @@ public class MessageCryptoHelper {
decryptOrVerifyNextPart();
}
private void processFoundParts(List<Part> foundParts, CryptoPartType cryptoPartType,
CryptoError errorIfIncomplete) {
private void processFoundParts(List<Part> 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);
}