aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java20
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java1
-rw-r--r--OpenKeychain/src/main/res/values/strings.xml1
3 files changed, 19 insertions, 3 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 2b91cd06c..a09cf4f27 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
@@ -25,10 +25,12 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import android.content.ClipDescription;
import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.text.TextUtils;
+import android.webkit.MimeTypeMap;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.codec.DecodeMonitor;
@@ -292,12 +294,24 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
log.add(LogType.MSG_DATA_MIME_PART, 2);
- log.add(LogType.MSG_DATA_MIME_TYPE, 3, bd.getMimeType());
+ String mimeType = bd.getMimeType();
+
if (mFilename != null) {
log.add(LogType.MSG_DATA_MIME_FILENAME, 3, mFilename);
+ boolean isGenericMimeType = ClipDescription.compareMimeTypes(mimeType, "application/octet-stream")
+ || ClipDescription.compareMimeTypes(mimeType, "application/x-download");
+ if (isGenericMimeType) {
+ String extension = MimeTypeMap.getFileExtensionFromUrl(mFilename);
+ String extMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
+ if (extMimeType != null) {
+ mimeType = extMimeType;
+ log.add(LogType.MSG_DATA_MIME_FROM_EXTENSION, 3);
+ }
+ }
}
+ log.add(LogType.MSG_DATA_MIME_TYPE, 3, mimeType);
- Uri uri = TemporaryFileProvider.createFile(mContext, mFilename, bd.getMimeType());
+ Uri uri = TemporaryFileProvider.createFile(mContext, mFilename, mimeType);
OutputStream out = mContext.getContentResolver().openOutputStream(uri, "w");
if (out == null) {
@@ -318,7 +332,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
charset = "utf-8";
}
- OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, bd.getMimeType(), 0L, totalLength, charset);
+ OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, mimeType, 0L, totalLength, charset);
out.close();
outputUris.add(uri);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
index ca5931f8d..0b8c3e6c7 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
@@ -836,6 +836,7 @@ public abstract class OperationResult implements Parcelable {
MSG_DATA_DETACHED_TRAILING (LogLevel.WARN, R.string.msg_data_detached_trailing),
MSG_DATA_DETACHED_UNSUPPORTED (LogLevel.WARN, R.string.msg_data_detached_unsupported),
MSG_DATA_MIME_BAD(LogLevel.INFO, R.string.msg_data_mime_bad),
+ MSG_DATA_MIME_FROM_EXTENSION (LogLevel.DEBUG, R.string.msg_data_mime_from_extension),
MSG_DATA_MIME_FILENAME (LogLevel.DEBUG, R.string.msg_data_mime_filename),
MSG_DATA_MIME_LENGTH (LogLevel.DEBUG, R.string.msg_data_mime_length),
MSG_DATA_MIME (LogLevel.DEBUG, R.string.msg_data_mime),
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index 10ec9f039..fa745cb5b 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -1368,6 +1368,7 @@
<string name="msg_data_error_openpgp">"Error processing OpenPGP data!"</string>
<string name="msg_data_mime_bad">"Could not parse as MIME data"</string>
<string name="msg_data_mime_filename">"Filename: '%s'"</string>
+ <string name="msg_data_mime_from_extension">"Guessing MIME type from extension"</string>
<string name="msg_data_mime_length">"Content-Length: %s"</string>
<string name="msg_data_mime">"Parsing MIME data structure"</string>
<string name="msg_data_mime_ok">"Finished parsing</string>