mirror of https://github.com/moparisthebest/k-9
Move MIME type fixing to AttachmentProvider
This commit is contained in:
parent
f3e4618702
commit
7c5c29e87e
|
@ -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<String>() {
|
|
||||||
@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 {
|
public AttachmentInfo getAttachmentInfo(final String attachmentId) throws UnavailableStorageException {
|
||||||
return database.execute(false, new DbCallback<AttachmentInfo>() {
|
return database.execute(false, new DbCallback<AttachmentInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public AttachmentInfo doDbWork(final SQLiteDatabase db) throws WrappedException {
|
public AttachmentInfo doDbWork(final SQLiteDatabase db) throws WrappedException {
|
||||||
String name;
|
String name;
|
||||||
|
String type;
|
||||||
int size;
|
int size;
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = db.query(
|
cursor = db.query(
|
||||||
"attachments",
|
"attachments",
|
||||||
new String[] { "name", "size" },
|
new String[] { "name", "size", "mime_type" },
|
||||||
"id = ?",
|
"id = ?",
|
||||||
new String[] { attachmentId },
|
new String[] { attachmentId },
|
||||||
null,
|
null,
|
||||||
|
@ -1041,9 +1010,11 @@ public class LocalStore extends Store implements Serializable {
|
||||||
}
|
}
|
||||||
name = cursor.getString(0);
|
name = cursor.getString(0);
|
||||||
size = cursor.getInt(1);
|
size = cursor.getInt(1);
|
||||||
|
type = cursor.getString(2);
|
||||||
final AttachmentInfo attachmentInfo = new AttachmentInfo();
|
final AttachmentInfo attachmentInfo = new AttachmentInfo();
|
||||||
attachmentInfo.name = name;
|
attachmentInfo.name = name;
|
||||||
attachmentInfo.size = size;
|
attachmentInfo.size = size;
|
||||||
|
attachmentInfo.type = type;
|
||||||
return attachmentInfo;
|
return attachmentInfo;
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
|
@ -1057,6 +1028,7 @@ public class LocalStore extends Store implements Serializable {
|
||||||
public static class AttachmentInfo {
|
public static class AttachmentInfo {
|
||||||
public String name;
|
public String name;
|
||||||
public int size;
|
public int size;
|
||||||
|
public String type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createFolders(final List<LocalFolder> foldersToCreate, final int visibleLimit) throws UnavailableStorageException {
|
public void createFolders(final List<LocalFolder> foldersToCreate, final int visibleLimit) throws UnavailableStorageException {
|
||||||
|
|
|
@ -105,7 +105,16 @@ public class AttachmentProvider extends ContentProvider {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app);
|
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) {
|
} catch (MessagingException e) {
|
||||||
Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e);
|
Log.e(K9.LOG_TAG, "Unable to retrieve LocalStore for " + account, e);
|
||||||
|
|
Loading…
Reference in New Issue