Fixed guessing attachments types

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

@ -640,11 +640,9 @@ public class FragmentCompose extends FragmentEx {
attachment.sequence = db.attachment().getAttachmentCount(draft.id) + 1;
attachment.name = name;
String extension = null;
if (attachment.name != null) // External attach
extension = MimeTypeMap.getFileExtensionFromUrl(attachment.name.toLowerCase());
String extension = Helper.getExtension(attachment.name);
if (extension != null)
attachment.type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
attachment.type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
if (attachment.type == null)
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) {
try {
AccountManager am = AccountManager.get(context);

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

Loading…
Cancel
Save