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

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

Loading…
Cancel
Save