Fixed guessing attachments types

pull/145/head
M66B 7 years ago
parent 80a4e5ce1b
commit 679556271f

@ -640,11 +640,9 @@ public class FragmentCompose extends FragmentEx {
attachment.sequence = db.attachment().getAttachmentCount(draft.id) + 1; attachment.sequence = db.attachment().getAttachmentCount(draft.id) + 1;
attachment.name = name; attachment.name = name;
String extension = null; String extension = Helper.getExtension(attachment.name);
if (attachment.name != null) // External attach
extension = MimeTypeMap.getFileExtensionFromUrl(attachment.name.toLowerCase());
if (extension != null) if (extension != null)
attachment.type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); attachment.type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
if (attachment.type == null) if (attachment.type == null)
attachment.type = "application/octet-stream"; attachment.type = "application/octet-stream";

@ -205,6 +205,15 @@ public class Helper {
} }
} }
static String getExtension(String filename) {
if (filename == null)
return null;
int index = filename.lastIndexOf(".");
if (index < 0)
return null;
return filename.substring(index + 1);
}
static String refreshToken(Context context, String type, String name, String current) { static String refreshToken(Context context, String type, String name, String current) {
try { try {
AccountManager am = AccountManager.get(context); AccountManager am = AccountManager.get(context);

@ -459,10 +459,10 @@ public class MessageHelper {
// Try to guess a better content type // Try to guess a better content type
// Sometimes PDF files are sent using the wrong type // Sometimes PDF files are sent using the wrong type
if ("application/octet-stream".equals(attachment.type) && attachment.name != null) { if ("application/octet-stream".equals(attachment.type)) {
String extension = MimeTypeMap.getFileExtensionFromUrl(attachment.name.toLowerCase()); String extension = Helper.getExtension(attachment.name);
if (extension != null) { if (extension != null) {
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
if (type != null) { if (type != null) {
Log.w(Helper.TAG, "Guessing file=" + attachment.name + " type=" + type); Log.w(Helper.TAG, "Guessing file=" + attachment.name + " type=" + type);
attachment.type = type; attachment.type = type;

Loading…
Cancel
Save