mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Support mime type in metadata
This commit is contained in:
parent
d5b40de70a
commit
abf50c3750
@ -18,6 +18,8 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpDecryptMetadata;
|
||||
import org.spongycastle.bcpg.ArmoredInputStream;
|
||||
import org.spongycastle.openpgp.PGPCompressedData;
|
||||
@ -54,6 +56,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLConnection;
|
||||
import java.security.SignatureException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
@ -460,10 +463,32 @@ public class PgpDecryptVerify {
|
||||
originalSize = 0;
|
||||
}
|
||||
|
||||
String originalFilename = literalData.getFileName();
|
||||
String mimeType = null;
|
||||
if (literalData.getFormat() == PGPLiteralData.TEXT
|
||||
|| literalData.getFormat() == PGPLiteralData.UTF8) {
|
||||
mimeType = "text/plain";
|
||||
} else {
|
||||
// TODO: better would be: https://github.com/open-keychain/open-keychain/issues/753
|
||||
|
||||
// try to guess from file ending
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(originalFilename);
|
||||
if (extension != null) {
|
||||
MimeTypeMap mime = MimeTypeMap.getSingleton();
|
||||
mimeType = mime.getMimeTypeFromExtension(extension);
|
||||
}
|
||||
if (mimeType == null) {
|
||||
mimeType = URLConnection.guessContentTypeFromName(originalFilename);
|
||||
}
|
||||
if (mimeType == null) {
|
||||
mimeType = "*/*";
|
||||
}
|
||||
}
|
||||
|
||||
OpenPgpDecryptMetadata metadata = new OpenPgpDecryptMetadata(
|
||||
literalData.getFileName(),
|
||||
originalFilename,
|
||||
mimeType,
|
||||
literalData.getModificationTime().getTime(),
|
||||
literalData.getFormat(),
|
||||
originalSize);
|
||||
result.setDecryptMetadata(metadata);
|
||||
|
||||
|
@ -281,7 +281,6 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
|
||||
Preferences.getPreferences(this).getDefaultFileCompression());
|
||||
}
|
||||
|
||||
|
||||
// Always use armor for messages
|
||||
data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, mUseArmor || isContentMessage());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user