inputdataoperation: guess filetype from filename for generic application/ mime types
This commit is contained in:
parent
dafa604016
commit
787b17030f
|
@ -25,10 +25,12 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import android.content.ClipDescription;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
import org.apache.james.mime4j.MimeException;
|
import org.apache.james.mime4j.MimeException;
|
||||||
import org.apache.james.mime4j.codec.DecodeMonitor;
|
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_PART, 2);
|
||||||
|
|
||||||
log.add(LogType.MSG_DATA_MIME_TYPE, 3, bd.getMimeType());
|
String mimeType = bd.getMimeType();
|
||||||
|
|
||||||
if (mFilename != null) {
|
if (mFilename != null) {
|
||||||
log.add(LogType.MSG_DATA_MIME_FILENAME, 3, mFilename);
|
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");
|
OutputStream out = mContext.getContentResolver().openOutputStream(uri, "w");
|
||||||
|
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
|
@ -318,7 +332,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
|
||||||
charset = "utf-8";
|
charset = "utf-8";
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, bd.getMimeType(), 0L, totalLength, charset);
|
OpenPgpMetadata metadata = new OpenPgpMetadata(mFilename, mimeType, 0L, totalLength, charset);
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
outputUris.add(uri);
|
outputUris.add(uri);
|
||||||
|
|
|
@ -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_TRAILING (LogLevel.WARN, R.string.msg_data_detached_trailing),
|
||||||
MSG_DATA_DETACHED_UNSUPPORTED (LogLevel.WARN, R.string.msg_data_detached_unsupported),
|
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_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_FILENAME (LogLevel.DEBUG, R.string.msg_data_mime_filename),
|
||||||
MSG_DATA_MIME_LENGTH (LogLevel.DEBUG, R.string.msg_data_mime_length),
|
MSG_DATA_MIME_LENGTH (LogLevel.DEBUG, R.string.msg_data_mime_length),
|
||||||
MSG_DATA_MIME (LogLevel.DEBUG, R.string.msg_data_mime),
|
MSG_DATA_MIME (LogLevel.DEBUG, R.string.msg_data_mime),
|
||||||
|
|
|
@ -1368,6 +1368,7 @@
|
||||||
<string name="msg_data_error_openpgp">"Error processing OpenPGP data!"</string>
|
<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_bad">"Could not parse as MIME data"</string>
|
||||||
<string name="msg_data_mime_filename">"Filename: '%s'"</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_length">"Content-Length: %s"</string>
|
||||||
<string name="msg_data_mime">"Parsing MIME data structure"</string>
|
<string name="msg_data_mime">"Parsing MIME data structure"</string>
|
||||||
<string name="msg_data_mime_ok">"Finished parsing</string>
|
<string name="msg_data_mime_ok">"Finished parsing</string>
|
||||||
|
|
Loading…
Reference in a new issue