diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org')
4 files changed, 27 insertions, 19 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 0de878232..43fc11b84 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -355,8 +355,8 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> { log.add(LogType.MSG_DATA_MIME_CHARSET, 3, charsetVerifier.getCharset()); } - metadata = new OpenPgpMetadata(mFilename, mimeType, 0L, totalLength, - charsetVerifier.getCharset(), charsetVerifier.isProbablyText()); + metadata = new OpenPgpMetadata(mFilename, charsetVerifier.getGuessedMimeType(), 0L, totalLength, + charsetVerifier.getCharset()); } out.close(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index b0d39d88f..e15139a7f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -417,7 +417,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp metadata = new OpenPgpMetadata( originalFilename, mimeType, literalData.getModificationTime().getTime(), - originalSize == null ? 0 : originalSize, charset, false); + originalSize == null ? 0 : originalSize, charset); log.add(LogType.MSG_DC_OK_META_ONLY, indent); DecryptVerifyResult result = @@ -483,24 +483,20 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp Log.d(Constants.TAG, "decrypt time taken: " + String.format("%.2f", opTime / 1000.0) + "s"); // special treatment to detect pgp mime types + // TODO move into CharsetVerifier? seems like that would be a plausible place for this logic if (matchesPrefix(firstBytes, "-----BEGIN PGP PUBLIC KEY BLOCK-----") || matchesPrefix(firstBytes, "-----BEGIN PGP PRIVATE KEY BLOCK-----")) { mimeType = Constants.MIME_TYPE_KEYS; } else if (matchesPrefix(firstBytes, "-----BEGIN PGP MESSAGE-----")) { // this is NOT application/pgp-encrypted, see RFC 3156! mimeType = Constants.MIME_TYPE_ENCRYPTED_ALTERNATE; - } - - log.add(LogType.MSG_DC_CLEAR_META_MIME, indent + 1, mimeType); - - if (charsetVerifier.isDefinitelyBinary()) { - metadata = new OpenPgpMetadata(originalFilename, mimeType, literalData.getModificationTime().getTime(), - alreadyWritten); } else { - metadata = new OpenPgpMetadata(originalFilename, mimeType, literalData.getModificationTime().getTime(), - alreadyWritten, charsetVerifier.getCharset(), charsetVerifier.isProbablyText()); + mimeType = charsetVerifier.getGuessedMimeType(); } + metadata = new OpenPgpMetadata(originalFilename, mimeType, literalData.getModificationTime().getTime(), + alreadyWritten, charsetVerifier.getCharset()); + log.add(LogType.MSG_DC_CLEAR_META_MIME, indent + 1, mimeType); Log.d(Constants.TAG, metadata.toString()); indent -= 1; @@ -883,7 +879,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp log.add(LogType.MSG_DC_OK, indent); - OpenPgpMetadata metadata = new OpenPgpMetadata("", "text/plain", -1, clearText.length, "utf-8", true); + OpenPgpMetadata metadata = new OpenPgpMetadata("", "text/plain", -1, clearText.length, "utf-8"); DecryptVerifyResult result = new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log); result.setSignatureResult(signatureChecker.getSignatureResult()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java index 9ffd95ae9..6f85342d6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -592,7 +592,7 @@ public class DecryptListFragment Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show)); chooserIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - if (!share && metadata.isLooksLikeText()) { + if (!share && ClipDescription.compareMimeTypes(metadata.getMimeType(), "text/*")) { LabeledIntent internalIntent = new LabeledIntent( new Intent(intent) .setClass(activity, DisplayTextActivity.class) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/CharsetVerifier.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/CharsetVerifier.java index c1d11cc26..c03decc89 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/CharsetVerifier.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/CharsetVerifier.java @@ -33,19 +33,21 @@ public class CharsetVerifier { private boolean isPossibleTextMimeType; private boolean isTextMimeType; private String charset; + private String mimeType; - public CharsetVerifier(@NonNull byte[] buf, String mimeType, @Nullable String charset) { + public CharsetVerifier(@NonNull byte[] buf, @NonNull String mimeType, @Nullable String charset) { - isPossibleTextMimeType = ClipDescription.compareMimeTypes(mimeType, "application/octet-stream") - || ClipDescription.compareMimeTypes(mimeType, "application/x-download") - || ClipDescription.compareMimeTypes(mimeType, "text/*"); + this.mimeType = mimeType; + isTextMimeType = ClipDescription.compareMimeTypes(mimeType, "text/*"); + isPossibleTextMimeType = isTextMimeType + || ClipDescription.compareMimeTypes(mimeType, "application/octet-stream") + || ClipDescription.compareMimeTypes(mimeType, "application/x-download"); if (!isPossibleTextMimeType) { charsetDecoder = null; bufWrap = null; dummyOutput = null; return; } - isTextMimeType = ClipDescription.compareMimeTypes(mimeType, "text/*"); bufWrap = ByteBuffer.wrap(buf); dummyOutput = CharBuffer.allocate(buf.length); @@ -96,6 +98,16 @@ public class CharsetVerifier { } } + public String getGuessedMimeType() { + if (isTextMimeType) { + return mimeType; + } + if (isProbablyText()) { + return "text/plain"; + } + return mimeType; + } + public boolean isCharsetFaulty() { finishIfNecessary(); return isFaulty; |