aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java74
1 files changed, 50 insertions, 24 deletions
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 d9e48af8a..7ec33874f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
+import android.text.TextUtils;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.codec.DecodeMonitor;
@@ -86,6 +87,11 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
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);
@@ -109,16 +115,33 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
return new InputDataResult(InputDataResult.RESULT_ERROR, log);
}
+ // inform the storage provider about the mime type for this uri
+ if (decryptResult.getDecryptionMetadata() != null) {
+ TemporaryStorageProvider.setMimeType(mContext, currentInputUri,
+ decryptResult.getDecryptionMetadata().getMimeType());
+ }
+
} else {
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, or if we have a filename
+ boolean skipMimeParsing = false;
+ if (decryptResult != null && decryptResult.getDecryptionMetadata() != null) {
+ OpenPgpMetadata metadata = decryptResult.getDecryptionMetadata();
+ String fileName = metadata.getFilename();
+ String contentType = metadata.getMimeType();
+ if (!TextUtils.isEmpty(fileName)
+ || 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);
@@ -309,25 +332,32 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
log.add(LogType.MSG_DATA_MIME, 1);
- // open current uri for input
- InputStream in = mContext.getContentResolver().openInputStream(currentInputUri);
- parser.parse(in);
+ try {
- if (mSignedDataUri != null) {
+ // open current uri for input
+ InputStream in = mContext.getContentResolver().openInputStream(currentInputUri);
+ parser.parse(in);
- if (decryptResult != null) {
- decryptResult.setSignatureResult(mSignedDataResult.getSignatureResult());
- } else {
- decryptResult = mSignedDataResult;
- }
+ if (mSignedDataUri != null) {
- // the actual content is the signed data now (and will be passed verbatim, if parsing fails)
- currentInputUri = mSignedDataUri;
- in = mContext.getContentResolver().openInputStream(currentInputUri);
- // reset signed data result, to indicate to the parser that it is in the inner part
- mSignedDataResult = null;
- parser.parse(in);
+ if (decryptResult != null) {
+ decryptResult.setSignatureResult(mSignedDataResult.getSignatureResult());
+ } else {
+ decryptResult = mSignedDataResult;
+ }
+ // the actual content is the signed data now (and will be passed verbatim, if parsing fails)
+ currentInputUri = mSignedDataUri;
+ in = mContext.getContentResolver().openInputStream(currentInputUri);
+ // reset signed data result, to indicate to the parser that it is in the inner part
+ mSignedDataResult = null;
+ parser.parse(in);
+
+ }
+ } catch (MimeException e) {
+ // a mime error likely means that this wasn't mime data, after all
+ e.printStackTrace();
+ log.add(LogType.MSG_DATA_MIME_BAD, 2);
}
// if we found data, return success
@@ -363,10 +393,6 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
e.printStackTrace();
log.add(LogType.MSG_DATA_ERROR_IO, 2);
return new InputDataResult(InputDataResult.RESULT_ERROR, log);
- } catch (MimeException e) {
- e.printStackTrace();
- log.add(LogType.MSG_DATA_MIME_ERROR, 2);
- return new InputDataResult(InputDataResult.RESULT_ERROR, log);
}
}