1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 03:32:16 -05:00

Make MimeUtility.getMimeTypeForViewing() return lower case MIME types

MIME type matching in Android is case-sensitive. So we convert the MIME
types we read from the email to lower case.
This commit is contained in:
cketti 2011-11-06 02:05:47 +01:00
parent 6f2be3226e
commit 70dc27c481

View File

@ -1207,31 +1207,34 @@ public class MimeUtility {
} }
/** /**
* Convert some wrong MIME types encountered in the wild to canonical MIME * Convert some wrong MIME types encountered in the wild to canonical MIME types.
* types.
* *
* @param mimeType The original MIME type * @param mimeType
* @return If {@code mimeType} is known to be wrong the correct MIME type * The original MIME type
* is returned. Otherwise the value of {@code mimeType} is returned *
* unmodified. * @return If {@code mimeType} is known to be wrong the correct MIME type is returned.
* Otherwise the lower case version of {@code mimeType} is returned.
* *
* @see #MIME_TYPE_REPLACEMENT_MAP * @see #MIME_TYPE_REPLACEMENT_MAP
*/ */
public static String canonicalizeMimeType(String mimeType) { public static String canonicalizeMimeType(String mimeType) {
String lowerCaseMimeType = mimeType.toLowerCase(Locale.US);
for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) { for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) {
if (mimeTypeMapEntry[0].equals(mimeType)) { if (mimeTypeMapEntry[0].equals(lowerCaseMimeType)) {
return mimeTypeMapEntry[1]; return mimeTypeMapEntry[1];
} }
} }
return mimeType; return lowerCaseMimeType;
} }
/** /**
* When viewing the attachment we want the MIME type to be as sensible as * When viewing the attachment we want the MIME type to be as sensible as possible. So we fix
* possible. So we fix it up if necessary. * it up if necessary.
* *
* @param mimeType The original MIME type of the attachment. * @param mimeType
* @param name The (file)name of the attachment. * 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. * @return The best MIME type we can come up with.
*/ */
@ -1240,10 +1243,10 @@ public class MimeUtility {
// If the MIME type is the generic "application/octet-stream" // If the MIME type is the generic "application/octet-stream"
// we try to find a better one by looking at the file extension. // we try to find a better one by looking at the file extension.
return getMimeTypeByExtension(name); return getMimeTypeByExtension(name);
} else {
// Some messages contain wrong MIME types. See if we know better.
return canonicalizeMimeType(mimeType);
} }
// Some messages contain wrong MIME types. See if we know better.
return canonicalizeMimeType(mimeType);
} }
private static Message getMessageFromPart(Part part) { private static Message getMessageFromPart(Part part) {