1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Implemented table lookup for mime type replacement (issue 873 and similar), added javadocs, moved to MimeUtility.java.

This commit is contained in:
Apoorv Khatreja 2011-03-25 04:52:25 +08:00 committed by cketti
parent fa5901d404
commit 80d99baf29
3 changed files with 26 additions and 11 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -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;