Always use the mime-type "message/rfc822" for eml files.
Bug 2795919 Change-Id: Ie20fccdad34d7d17d7444af25d3e57033a45de5a
This commit is contained in:
parent
407395751d
commit
1d0be30871
|
@ -178,6 +178,8 @@ public class AttachmentProvider extends ContentProvider {
|
|||
* Helper to convert unknown or unmapped attachments to something useful based on filename
|
||||
* extensions. Imperfect, but helps.
|
||||
*
|
||||
* If the file extension is ".eml", return "message/rfc822", which is necessary for the email
|
||||
* app to open it.
|
||||
* If the given mime type is non-empty and anything other than "application/octet-stream",
|
||||
* just return it. (This is the most common case.)
|
||||
* If the filename has a recognizable extension and it converts to a mime type, return that.
|
||||
|
@ -189,6 +191,9 @@ public class AttachmentProvider extends ContentProvider {
|
|||
* @return A likely mime type for the attachment
|
||||
*/
|
||||
public static String inferMimeType(String fileName, String mimeType) {
|
||||
if (fileName != null && fileName.toLowerCase().endsWith(".eml")) {
|
||||
return "message/rfc822";
|
||||
}
|
||||
// If the given mime type appears to be non-empty and non-generic - return it
|
||||
if (!TextUtils.isEmpty(mimeType) &&
|
||||
!"application/octet-stream".equalsIgnoreCase(mimeType)) {
|
||||
|
|
|
@ -270,6 +270,8 @@ public class AttachmentProviderTests extends ProviderTestCase2<AttachmentProvide
|
|||
/**
|
||||
* Test static inferMimeType()
|
||||
* From the method doc:
|
||||
* If the file extension is ".eml", return "message/rfc822", which is necessary for the email
|
||||
* app to open it.
|
||||
* If the given mime type is non-empty and anything other than "application/octet-stream",
|
||||
* just return it. (This is the most common case.)
|
||||
* If the filename has a recognizable extension and it converts to a mime type, return that.
|
||||
|
@ -304,6 +306,10 @@ public class AttachmentProviderTests extends ProviderTestCase2<AttachmentProvide
|
|||
assertEquals(DEFAULT, AttachmentProvider.inferMimeType(FILE_NO_EXT, DEFAULT));
|
||||
assertEquals(DEFAULT, AttachmentProvider.inferMimeType(null, null));
|
||||
assertEquals(DEFAULT, AttachmentProvider.inferMimeType("", ""));
|
||||
|
||||
// Test for eml files.
|
||||
assertEquals("message/rfc822", AttachmentProvider.inferMimeType("a.eMl", "text/plain"));
|
||||
assertEquals("message/rfc822", AttachmentProvider.inferMimeType("a.eml", DEFAULT));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue