Better guess attached file type

pull/169/head
M66B 5 years ago
parent abe6c136a1
commit d9a592569b

@ -155,6 +155,9 @@ public class EntityAttachment {
String getMimeType() {
// Try to guess a better content type
// For example, sometimes PDF files are sent as application/octet-stream
// https://android.googlesource.com/platform/libcore/+/refs/tags/android-9.0.0_r49/luni/src/main/java/libcore/net/MimeUtils.java
// https://blogs.msdn.microsoft.com/vsofficedeveloper/2008/05/08/office-2007-file-format-mime-types-for-http-content-streaming-2/
if (encryption != null)
return type;
@ -165,11 +168,17 @@ public class EntityAttachment {
String gtype = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT));
if (gtype != null) {
if (TextUtils.isEmpty(type) || "*/*".equals(type))
type = gtype;
// Some servers erroneously remove dots from mime types
// https://blogs.msdn.microsoft.com/vsofficedeveloper/2008/05/08/office-2007-file-format-mime-types-for-http-content-streaming-2/
if (gtype != null &&
gtype.replace(".", "").equals(type))
if (gtype.replace(".", "").equals(type))
type = gtype;
}
if ("eml".equals(extension))
return "message/rfc822";
if ("text/plain".equals(type) &&
"ovpn".equals(extension))

@ -2383,7 +2383,7 @@ public class FragmentCompose extends FragmentBase {
ftype = null;
}
if (TextUtils.isEmpty(ftype))
if (TextUtils.isEmpty(ftype) || "*/*".equals(ftype))
ftype = Helper.guessMimeType(fname);
if (fsize != null && fsize <= 0)

Loading…
Cancel
Save