Support mime type in metadata

This commit is contained in:
Dominik Schürmann 2014-08-11 20:16:21 +02:00
parent d5b40de70a
commit abf50c3750
2 changed files with 27 additions and 3 deletions

View File

@ -18,6 +18,8 @@
package org.sufficientlysecure.keychain.pgp; package org.sufficientlysecure.keychain.pgp;
import android.webkit.MimeTypeMap;
import org.openintents.openpgp.OpenPgpDecryptMetadata; import org.openintents.openpgp.OpenPgpDecryptMetadata;
import org.spongycastle.bcpg.ArmoredInputStream; import org.spongycastle.bcpg.ArmoredInputStream;
import org.spongycastle.openpgp.PGPCompressedData; import org.spongycastle.openpgp.PGPCompressedData;
@ -54,6 +56,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLConnection;
import java.security.SignatureException; import java.security.SignatureException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -460,10 +463,32 @@ public class PgpDecryptVerify {
originalSize = 0; 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( OpenPgpDecryptMetadata metadata = new OpenPgpDecryptMetadata(
literalData.getFileName(), originalFilename,
mimeType,
literalData.getModificationTime().getTime(), literalData.getModificationTime().getTime(),
literalData.getFormat(),
originalSize); originalSize);
result.setDecryptMetadata(metadata); result.setDecryptMetadata(metadata);

View File

@ -281,7 +281,6 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
Preferences.getPreferences(this).getDefaultFileCompression()); Preferences.getPreferences(this).getDefaultFileCompression());
} }
// Always use armor for messages // Always use armor for messages
data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, mUseArmor || isContentMessage()); data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, mUseArmor || isContentMessage());