From fa5901d404be822d590b834fd508ef89676addef Mon Sep 17 00:00:00 2001 From: Apoorv Khatreja Date: Thu, 24 Mar 2011 05:06:50 +0800 Subject: [PATCH 1/7] Fixed issue 873 where JPEG images with the MIME type "image/jpg" failed to open on some Motorola phones. --- src/com/fsck/k9/provider/AttachmentProvider.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index fc9c8c4f6..9cb492f9b 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -105,7 +105,11 @@ public class AttachmentProvider extends ContentProvider { try { final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app); - return localStore.getAttachmentType(id); + if (localStore.getAttachmentType(id).equals("image/jpg")) { + return "image/jpeg"; + } else { + return localStore.getAttachmentType(id); + } } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e); return null; From 80d99baf29be8966a008e1ea863d46ab722ac441 Mon Sep 17 00:00:00 2001 From: Apoorv Khatreja Date: Fri, 25 Mar 2011 04:52:25 +0800 Subject: [PATCH 2/7] Implemented table lookup for mime type replacement (issue 873 and similar), added javadocs, moved to MimeUtility.java. --- .../fsck/k9/mail/internet/MimeUtility.java | 28 +++++++++++++++---- src/com/fsck/k9/mail/store/LocalStore.java | 2 +- .../fsck/k9/provider/AttachmentProvider.java | 7 ++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index be318d998..42033eda1 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -875,8 +875,10 @@ public class MimeUtility { { "zirz", "application/vnd.zul"}, { "zmm", "application/vnd.handheld-entertainment+xml"} }; - - + + private static final String[][] MIME_TYPE_REPLACEMENT_MAP = new String[][] { + {"image/jpg","image/jpeg"} + }; public static String unfold(String s) { if (s == null) { @@ -1181,17 +1183,33 @@ public class MimeUtility { // If the MIME type set by the user's mailer is application/octet-stream, try to figure // out whether there's a sane file type extension. if (returnedType != null && !DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(returnedType)) { - return returnedType; + return getCorrectedMimeType(returnedType); } else if (extension != null) { for (String[] contentTypeMapEntry : MIME_TYPE_BY_EXTENSION_MAP) { if (contentTypeMapEntry[0].equals(extension)) { - return contentTypeMapEntry[1]; + return getCorrectedMimeType(contentTypeMapEntry[1]); } } } - return DEFAULT_ATTACHMENT_MIME_TYPE; + return getCorrectedMimeType(DEFAULT_ATTACHMENT_MIME_TYPE); } + + /** + * Table lookup for MIME type replacement, enabling easy fixes for issues similar to issue 873. + * To map any MIME type to a different one, add a {originalMimeType, replacementMimeType} string pair to MIME_TYPE_REPLACEMENT_MAP. + * + * @param mimeType the MIME type + * @return the corrected MIME type + */ + public static String getCorrectedMimeType(String mimeType) { + for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) { + if (mimeTypeMapEntry[0].equals(mimeType)) { + return mimeTypeMapEntry[1]; + } + } + return mimeType; + } private static Message getMessageFromPart(Part part) { while (part != null) { diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index e90e5a64e..7141d18c4 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -1010,7 +1010,7 @@ public class LocalStore extends Store implements Serializable { if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(type)) { type = MimeUtility.getMimeTypeByExtension(name); } - return type; + return MimeUtility.getCorrectedMimeType(type); } finally { if (cursor != null) { cursor.close(); diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index 9cb492f9b..90ac52c89 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -105,11 +105,8 @@ public class AttachmentProvider extends ContentProvider { try { final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app); - if (localStore.getAttachmentType(id).equals("image/jpg")) { - return "image/jpeg"; - } else { - return localStore.getAttachmentType(id); - } + return localStore.getAttachmentType(id); + } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e); return null; From 168f6277dac48b8837f461aef91bb1857753a2c5 Mon Sep 17 00:00:00 2001 From: Apoorv Khatreja Date: Fri, 25 Mar 2011 05:25:10 +0800 Subject: [PATCH 3/7] Mime type rewriting must be done only when an attachment is viewed. Therefore, removed conflicting references to rewriting code from LocalStore. --- src/com/fsck/k9/mail/internet/MimeUtility.java | 8 ++++---- src/com/fsck/k9/mail/store/LocalStore.java | 2 +- src/com/fsck/k9/provider/AttachmentProvider.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 42033eda1..32a8b1679 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -1183,16 +1183,16 @@ public class MimeUtility { // If the MIME type set by the user's mailer is application/octet-stream, try to figure // out whether there's a sane file type extension. if (returnedType != null && !DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(returnedType)) { - return getCorrectedMimeType(returnedType); + return returnedType; } else if (extension != null) { for (String[] contentTypeMapEntry : MIME_TYPE_BY_EXTENSION_MAP) { if (contentTypeMapEntry[0].equals(extension)) { - return getCorrectedMimeType(contentTypeMapEntry[1]); + return contentTypeMapEntry[1]; } } } - return getCorrectedMimeType(DEFAULT_ATTACHMENT_MIME_TYPE); + return DEFAULT_ATTACHMENT_MIME_TYPE; } /** @@ -1202,7 +1202,7 @@ public class MimeUtility { * @param mimeType the MIME type * @return the corrected MIME type */ - public static String getCorrectedMimeType(String mimeType) { + public static String canonicalizeMimeType(String mimeType) { for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) { if (mimeTypeMapEntry[0].equals(mimeType)) { return mimeTypeMapEntry[1]; diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 7141d18c4..e90e5a64e 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -1010,7 +1010,7 @@ public class LocalStore extends Store implements Serializable { if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(type)) { type = MimeUtility.getMimeTypeByExtension(name); } - return MimeUtility.getCorrectedMimeType(type); + return type; } finally { if (cursor != null) { cursor.close(); diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index 90ac52c89..5deeecd61 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -105,7 +105,7 @@ public class AttachmentProvider extends ContentProvider { try { final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app); - return localStore.getAttachmentType(id); + return MimeUtility.canonicalizeMimeType(localStore.getAttachmentType(id)); } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e); From f3e46187027d19cdaf0e8b9af212e08c4d122e66 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 24 Mar 2011 23:04:58 +0100 Subject: [PATCH 4/7] Cosmetic + documentation changes --- .../fsck/k9/mail/internet/MimeUtility.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 32a8b1679..7eb4fa2ed 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -875,10 +875,15 @@ public class MimeUtility { { "zirz", "application/vnd.zul"}, { "zmm", "application/vnd.handheld-entertainment+xml"} }; - + + /** + * Table for MIME type replacements. + * + * Table format: wrong type, correct type + */ private static final String[][] MIME_TYPE_REPLACEMENT_MAP = new String[][] { - {"image/jpg","image/jpeg"} - }; + {"image/jpg", "image/jpeg"} + }; public static String unfold(String s) { if (s == null) { @@ -1194,13 +1199,17 @@ public class MimeUtility { return DEFAULT_ATTACHMENT_MIME_TYPE; } - + /** - * Table lookup for MIME type replacement, enabling easy fixes for issues similar to issue 873. - * To map any MIME type to a different one, add a {originalMimeType, replacementMimeType} string pair to MIME_TYPE_REPLACEMENT_MAP. + * Convert some wrong MIME types encountered in the wild to canonical MIME + * types. * - * @param mimeType the MIME type - * @return the corrected MIME type + * @param mimeType The original MIME type + * @return If {@code mimeType} is known to be wrong the correct MIME type + * is returned. Otherwise the value of {@code mimeType} is returned + * unmodified. + * + * @see #MIME_TYPE_REPLACEMENT_MAP */ public static String canonicalizeMimeType(String mimeType) { for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) { From 7c5c29e87e29a5195b15902ac539f27dd0a3eada Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 24 Mar 2011 23:07:46 +0100 Subject: [PATCH 5/7] Move MIME type fixing to AttachmentProvider --- src/com/fsck/k9/mail/store/LocalStore.java | 38 +++---------------- .../fsck/k9/provider/AttachmentProvider.java | 13 ++++++- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index e90e5a64e..4c2ede1e5 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -988,49 +988,18 @@ public class LocalStore extends Store implements Serializable { } - public String getAttachmentType(final String attachmentId) throws UnavailableStorageException { - return database.execute(false, new DbCallback() { - @Override - public String doDbWork(final SQLiteDatabase db) throws WrappedException { - Cursor cursor = null; - try { - cursor = db.query( - "attachments", - new String[] { "mime_type", "name" }, - "id = ?", - new String[] { attachmentId }, - null, - null, - null); - cursor.moveToFirst(); - String type = cursor.getString(0); - String name = cursor.getString(1); - cursor.close(); - - if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(type)) { - type = MimeUtility.getMimeTypeByExtension(name); - } - return type; - } finally { - if (cursor != null) { - cursor.close(); - } - } - } - }); - } - public AttachmentInfo getAttachmentInfo(final String attachmentId) throws UnavailableStorageException { return database.execute(false, new DbCallback() { @Override public AttachmentInfo doDbWork(final SQLiteDatabase db) throws WrappedException { String name; + String type; int size; Cursor cursor = null; try { cursor = db.query( "attachments", - new String[] { "name", "size" }, + new String[] { "name", "size", "mime_type" }, "id = ?", new String[] { attachmentId }, null, @@ -1041,9 +1010,11 @@ public class LocalStore extends Store implements Serializable { } name = cursor.getString(0); size = cursor.getInt(1); + type = cursor.getString(2); final AttachmentInfo attachmentInfo = new AttachmentInfo(); attachmentInfo.name = name; attachmentInfo.size = size; + attachmentInfo.type = type; return attachmentInfo; } finally { if (cursor != null) { @@ -1057,6 +1028,7 @@ public class LocalStore extends Store implements Serializable { public static class AttachmentInfo { public String name; public int size; + public String type; } public void createFolders(final List foldersToCreate, final int visibleLimit) throws UnavailableStorageException { diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index 5deeecd61..2442278b5 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -105,8 +105,17 @@ public class AttachmentProvider extends ContentProvider { try { final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app); - return MimeUtility.canonicalizeMimeType(localStore.getAttachmentType(id)); - + + AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id); + if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(attachmentInfo.type)) { + // If the MIME type is the generic "application/octet-stream" + // we try to find a better one by looking at the file extension. + return MimeUtility.getMimeTypeByExtension(attachmentInfo.name); + } else { + // Some messages contain wrong MIME types. See if we know better. + return MimeUtility.canonicalizeMimeType(attachmentInfo.type); + } + } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e); return null; From 522634fba7eee0c6bb7c8b3ca201e591f8db8b51 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 24 Mar 2011 23:36:59 +0100 Subject: [PATCH 6/7] Extend AttachmentProvider to be able to get "raw" attachment AttachmentProvider can now return an attachment with an unmodified MIME type. However, when viewing attachments this is not desirable. So we try hard to return a sensible MIME type (use extension to look up a MIME type if it's originally "application/octet-stream"; or replace with canonical MIME type if it's known to be wrong, e.g. "image/jpg" -> "image/jpeg") --- .../fsck/k9/provider/AttachmentProvider.java | 39 +++++++++++++------ src/com/fsck/k9/view/AttachmentView.java | 4 +- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index 2442278b5..a2f466b10 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -30,6 +30,7 @@ public class AttachmentProvider extends ContentProvider { public static final Uri CONTENT_URI = Uri.parse("content://com.fsck.k9.attachmentprovider"); private static final String FORMAT_RAW = "RAW"; + private static final String FORMAT_VIEW = "VIEW"; private static final String FORMAT_THUMBNAIL = "THUMBNAIL"; public static class AttachmentProviderColumns { @@ -40,7 +41,11 @@ public class AttachmentProvider extends ContentProvider { } public static Uri getAttachmentUri(Account account, long id) { - return getAttachmentUri(account.getUuid(), id); + return getAttachmentUri(account.getUuid(), id, true); + } + + public static Uri getAttachmentUriForViewing(Account account, long id) { + return getAttachmentUri(account.getUuid(), id, false); } public static Uri getAttachmentThumbnailUri(Account account, long id, int width, int height) { @@ -53,11 +58,11 @@ public class AttachmentProvider extends ContentProvider { .build(); } - private static Uri getAttachmentUri(String db, long id) { + private static Uri getAttachmentUri(String db, long id, boolean raw) { return CONTENT_URI.buildUpon() .appendPath(db) .appendPath(Long.toString(id)) - .appendPath(FORMAT_RAW) + .appendPath(raw ? FORMAT_RAW : FORMAT_VIEW) .build(); } @@ -98,6 +103,11 @@ public class AttachmentProvider extends ContentProvider { String dbName = segments.get(0); String id = segments.get(1); String format = segments.get(2); + + return getType(dbName, id, format); + } + + private String getType(String dbName, String id, String format) { if (FORMAT_THUMBNAIL.equals(format)) { return "image/png"; } else { @@ -107,15 +117,21 @@ public class AttachmentProvider extends ContentProvider { final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app); AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id); - if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(attachmentInfo.type)) { - // If the MIME type is the generic "application/octet-stream" - // we try to find a better one by looking at the file extension. - return MimeUtility.getMimeTypeByExtension(attachmentInfo.name); + if (FORMAT_VIEW.equals(format)) { + // When viewing the attachment we want the MIME type to be + // as sensible as possible. So we fix it up if necessary. + if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(attachmentInfo.type)) { + // If the MIME type is the generic "application/octet-stream" + // we try to find a better one by looking at the file extension. + return MimeUtility.getMimeTypeByExtension(attachmentInfo.name); + } else { + // Some messages contain wrong MIME types. See if we know better. + return MimeUtility.canonicalizeMimeType(attachmentInfo.type); + } } else { - // Some messages contain wrong MIME types. See if we know better. - return MimeUtility.canonicalizeMimeType(attachmentInfo.type); + // When accessing the "raw" message we deliver the original MIME type. + return attachmentInfo.type; } - } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e); return null; @@ -158,8 +174,7 @@ public class AttachmentProvider extends ContentProvider { File dir = getContext().getCacheDir(); File file = new File(dir, filename); if (!file.exists()) { - Uri attachmentUri = getAttachmentUri(dbName, Long.parseLong(id)); - String type = getType(attachmentUri); + String type = getType(dbName, id, FORMAT_VIEW); try { FileInputStream in = new FileInputStream(getFile(dbName, id)); try { diff --git a/src/com/fsck/k9/view/AttachmentView.java b/src/com/fsck/k9/view/AttachmentView.java index 21fea308b..ef911c897 100644 --- a/src/com/fsck/k9/view/AttachmentView.java +++ b/src/com/fsck/k9/view/AttachmentView.java @@ -196,7 +196,7 @@ public class AttachmentView extends FrameLayout { public void showFile() { - Uri uri = AttachmentProvider.getAttachmentUri(mAccount, part.getAttachmentId()); + Uri uri = AttachmentProvider.getAttachmentUriForViewing(mAccount, part.getAttachmentId()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); @@ -227,7 +227,7 @@ public class AttachmentView extends FrameLayout { return; } try { - Uri uri = AttachmentProvider.getAttachmentUri(mAccount, part.getAttachmentId()); + Uri uri = AttachmentProvider.getAttachmentUriForViewing(mAccount, part.getAttachmentId()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); From 0aa03ccdc42043c7c7752883c31166ff2679c541 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 25 Mar 2011 00:37:53 +0100 Subject: [PATCH 7/7] Extract MIME type fixup code to method MimeUtility.getMimeTypeForViewing() --- .../fsck/k9/mail/internet/MimeUtility.java | 20 +++++++++++++++++++ .../fsck/k9/provider/AttachmentProvider.java | 11 +--------- src/com/fsck/k9/view/AttachmentView.java | 5 +---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 7eb4fa2ed..24f9da2da 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -1220,6 +1220,26 @@ public class MimeUtility { return mimeType; } + /** + * When viewing the attachment we want the MIME type to be as sensible as + * possible. So we fix it up if necessary. + * + * @param mimeType The original MIME type of the attachment. + * @param name The (file)name of the attachment. + * + * @return The best MIME type we can come up with. + */ + public static String getMimeTypeForViewing(String mimeType, String name) { + if (DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(mimeType)) { + // If the MIME type is the generic "application/octet-stream" + // we try to find a better one by looking at the file extension. + return getMimeTypeByExtension(name); + } else { + // Some messages contain wrong MIME types. See if we know better. + return canonicalizeMimeType(mimeType); + } + } + private static Message getMessageFromPart(Part part) { while (part != null) { if (part instanceof Message) diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index a2f466b10..126223d72 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -118,16 +118,7 @@ public class AttachmentProvider extends ContentProvider { AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id); if (FORMAT_VIEW.equals(format)) { - // When viewing the attachment we want the MIME type to be - // as sensible as possible. So we fix it up if necessary. - if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(attachmentInfo.type)) { - // If the MIME type is the generic "application/octet-stream" - // we try to find a better one by looking at the file extension. - return MimeUtility.getMimeTypeByExtension(attachmentInfo.name); - } else { - // Some messages contain wrong MIME types. See if we know better. - return MimeUtility.canonicalizeMimeType(attachmentInfo.type); - } + return MimeUtility.getMimeTypeForViewing(attachmentInfo.type, attachmentInfo.name); } else { // When accessing the "raw" message we deliver the original MIME type. return attachmentInfo.type; diff --git a/src/com/fsck/k9/view/AttachmentView.java b/src/com/fsck/k9/view/AttachmentView.java index ef911c897..1fff23319 100644 --- a/src/com/fsck/k9/view/AttachmentView.java +++ b/src/com/fsck/k9/view/AttachmentView.java @@ -78,10 +78,7 @@ public class AttachmentView extends FrameLayout { mListener = listener; size = Integer.parseInt(MimeUtility.getHeaderParameter(contentDisposition, "size")); - contentType = part.getMimeType(); - if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equalsIgnoreCase(contentType)) { - contentType = MimeUtility.getMimeTypeByExtension(name); - } + contentType = MimeUtility.getMimeTypeForViewing(part.getMimeType(), name); TextView attachmentName = (TextView) findViewById(R.id.attachment_name); TextView attachmentInfo = (TextView) findViewById(R.id.attachment_info); ImageView attachmentIcon = (ImageView) findViewById(R.id.attachment_icon);