From 5330a91fef160b7d1bc4bae997997416ee01922c Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sat, 19 Sep 2015 15:25:40 +0200 Subject: skip mime parsing if we already know the content type isn't suitable --- .../keychain/operations/InputDataOperation.java | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index 0bc4c1ecc..9170dc139 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -86,6 +86,11 @@ public class InputDataOperation extends BaseOperation { DecryptVerifyResult decryptResult = null; PgpDecryptVerifyInputParcel decryptInput = input.getDecryptInput(); + + if (!input.getMimeDecode() && decryptInput == null) { + throw new AssertionError("no decryption or mime decoding, this is probably a bug"); + } + if (decryptInput != null) { log.add(LogType.MSG_DATA_OPENPGP, 1); @@ -113,12 +118,20 @@ public class InputDataOperation extends BaseOperation { currentInputUri = input.getInputUri(); } - // If we aren't supposed to attempt mime decode, we are done here - if (!input.getMimeDecode()) { - - if (decryptInput == null) { - throw new AssertionError("no decryption or mime decoding, this is probably a bug"); + // don't even attempt if we know the data isn't suitable for mime content + boolean skipMimeParsing = false; + if (decryptResult != null && decryptResult.getDecryptionMetadata() != null) { + String contentType = decryptResult.getDecryptionMetadata().getMimeType(); + if (contentType != null + && !contentType.startsWith("multipart/") + && !contentType.startsWith("text/") + && !contentType.startsWith("application/")) { + skipMimeParsing = true; } + } + + // If we aren't supposed to attempt mime decode after decryption, we are done here + if (skipMimeParsing || !input.getMimeDecode()) { log.add(LogType.MSG_DATA_SKIP_MIME, 1); -- cgit v1.2.3