From e7185bd1b80b2ccf87b8ec534d04a410fa5037a1 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sat, 19 Sep 2015 15:25:18 +0200 Subject: fix fallback for non-mime data --- .../keychain/operations/InputDataOperation.java | 41 ++++++++++++---------- 1 file changed, 22 insertions(+), 19 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 d9e48af8a..0bc4c1ecc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -309,25 +309,32 @@ public class InputDataOperation extends BaseOperation { 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 +370,6 @@ public class InputDataOperation extends BaseOperation { 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); } } -- cgit v1.2.3