From 9218bd8c886fb84b8f7055803a99970083394382 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Fri, 22 Jun 2012 11:38:33 -0700 Subject: [PATCH] Try to handle IMAP/POP mime types better * When we get a "generic" type, try to infer a better one from the filename extension (as Exchange already does) * Also, remove unused method Bug: 6713335 Change-Id: I540a92aabd13bc1d30ce1838129a86f5eaf3564e --- .../utility/AttachmentUtilities.java | 17 ----------------- .../com/android/email/LegacyConversions.java | 5 ++++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/email2/emailcommon/src/com/android/emailcommon/utility/AttachmentUtilities.java b/email2/emailcommon/src/com/android/emailcommon/utility/AttachmentUtilities.java index 801edaa42..f43458323 100644 --- a/email2/emailcommon/src/com/android/emailcommon/utility/AttachmentUtilities.java +++ b/email2/emailcommon/src/com/android/emailcommon/utility/AttachmentUtilities.java @@ -238,23 +238,6 @@ public class AttachmentUtilities { return resultType.toLowerCase(); } - /** - * @return mime-type for a {@link Uri}. - * - Use {@link ContentResolver#getType} for a content: URI. - * - Use {@link #inferMimeType} for a file: URI. - * - Otherwise throw {@link IllegalArgumentException}. - */ - public static String inferMimeTypeForUri(Context context, Uri uri) { - final String scheme = uri.getScheme(); - if ("content".equals(scheme)) { - return context.getContentResolver().getType(uri); - } else if ("file".equals(scheme)) { - return inferMimeType(uri.getLastPathSegment(), ""); - } else { - throw new IllegalArgumentException(); - } - } - /** * Extract and return filename's extension, converted to lower case, and not including the "." * diff --git a/email2/src/com/android/email/LegacyConversions.java b/email2/src/com/android/email/LegacyConversions.java index d45447d41..453c85459 100644 --- a/email2/src/com/android/email/LegacyConversions.java +++ b/email2/src/com/android/email/LegacyConversions.java @@ -213,8 +213,11 @@ public class LegacyConversions { String[] partIds = part.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA); String partId = partIds != null ? partIds[0] : null; + // Run the mime type through inferMimeType in case we have something generic and can do + // better using the filename extension + String mimeType = AttachmentUtilities.inferMimeType(name, part.getMimeType()); + localAttachment.mMimeType = mimeType; localAttachment.mFileName = name; - localAttachment.mMimeType = part.getMimeType(); localAttachment.mSize = size; // May be reset below if file handled localAttachment.mContentId = part.getContentId(); localAttachment.mContentUri = null; // Will be rewritten by saveAttachmentBody