ditch isLikelyText flag, set mimeType to text/plain in that case
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
} else {
|
||||
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);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user