Loading src/com/fsck/k9/mail/store/LocalStore.java +20 −8 Original line number Diff line number Diff line Loading @@ -2692,22 +2692,34 @@ public class LocalStore extends Store implements Serializable { public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { Cursor attachmentsCursor = null; try { attachmentsCursor = db.query("attachments", new String[] { "id" }, "message_id = ?", new String[] { Long.toString(messageId) }, null, null, null); String accountUuid = mAccount.getUuid(); Context context = mApplication; // Get attachment IDs String[] whereArgs = new String[] { Long.toString(messageId) }; attachmentsCursor = db.query("attachments", new String[] { "id" }, "message_id = ?", whereArgs, null, null, null); final File attachmentDirectory = StorageManager.getInstance(mApplication) .getAttachmentDirectory(uUid, database.getStorageProviderId()); while (attachmentsCursor.moveToNext()) { long attachmentId = attachmentsCursor.getLong(0); String attachmentId = Long.toString(attachmentsCursor.getLong(0)); try { File file = new File(attachmentDirectory, Long.toString(attachmentId)); // Delete stored attachment File file = new File(attachmentDirectory, attachmentId); if (file.exists()) { file.delete(); } } catch (Exception e) { // Delete thumbnail file AttachmentProvider.deleteThumbnail(context, accountUuid, attachmentId); } catch (Exception e) { /* ignore */ } } } // Delete attachment metadata from the database db.delete("attachments", "message_id = ?", whereArgs); } finally { Utility.closeQuietly(attachmentsCursor); } Loading src/com/fsck/k9/provider/AttachmentProvider.java +25 −3 Original line number Diff line number Diff line Loading @@ -92,6 +92,30 @@ public class AttachmentProvider extends ContentProvider { } } /** * Delete the thumbnail of an attachment. * * @param context * The application context. * @param accountUuid * The UUID of the account the attachment belongs to. * @param attachmentId * The ID of the attachment the thumbnail was created for. */ public static void deleteThumbnail(Context context, String accountUuid, String attachmentId) { File file = getThumbnailFile(context, accountUuid, attachmentId); if (file.exists()) { file.delete(); } } private static File getThumbnailFile(Context context, String accountUuid, String attachmentId) { String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp"; File dir = context.getCacheDir(); return new File(dir, filename); } @Override public boolean onCreate() { Loading Loading @@ -139,9 +163,7 @@ public class AttachmentProvider extends ContentProvider { int width = Integer.parseInt(segments.get(3)); int height = Integer.parseInt(segments.get(4)); String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp"; File dir = getContext().getCacheDir(); file = new File(dir, filename); file = getThumbnailFile(getContext(), accountUuid, attachmentId); if (!file.exists()) { String type = getType(accountUuid, attachmentId, FORMAT_VIEW); try { Loading Loading
src/com/fsck/k9/mail/store/LocalStore.java +20 −8 Original line number Diff line number Diff line Loading @@ -2692,22 +2692,34 @@ public class LocalStore extends Store implements Serializable { public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { Cursor attachmentsCursor = null; try { attachmentsCursor = db.query("attachments", new String[] { "id" }, "message_id = ?", new String[] { Long.toString(messageId) }, null, null, null); String accountUuid = mAccount.getUuid(); Context context = mApplication; // Get attachment IDs String[] whereArgs = new String[] { Long.toString(messageId) }; attachmentsCursor = db.query("attachments", new String[] { "id" }, "message_id = ?", whereArgs, null, null, null); final File attachmentDirectory = StorageManager.getInstance(mApplication) .getAttachmentDirectory(uUid, database.getStorageProviderId()); while (attachmentsCursor.moveToNext()) { long attachmentId = attachmentsCursor.getLong(0); String attachmentId = Long.toString(attachmentsCursor.getLong(0)); try { File file = new File(attachmentDirectory, Long.toString(attachmentId)); // Delete stored attachment File file = new File(attachmentDirectory, attachmentId); if (file.exists()) { file.delete(); } } catch (Exception e) { // Delete thumbnail file AttachmentProvider.deleteThumbnail(context, accountUuid, attachmentId); } catch (Exception e) { /* ignore */ } } } // Delete attachment metadata from the database db.delete("attachments", "message_id = ?", whereArgs); } finally { Utility.closeQuietly(attachmentsCursor); } Loading
src/com/fsck/k9/provider/AttachmentProvider.java +25 −3 Original line number Diff line number Diff line Loading @@ -92,6 +92,30 @@ public class AttachmentProvider extends ContentProvider { } } /** * Delete the thumbnail of an attachment. * * @param context * The application context. * @param accountUuid * The UUID of the account the attachment belongs to. * @param attachmentId * The ID of the attachment the thumbnail was created for. */ public static void deleteThumbnail(Context context, String accountUuid, String attachmentId) { File file = getThumbnailFile(context, accountUuid, attachmentId); if (file.exists()) { file.delete(); } } private static File getThumbnailFile(Context context, String accountUuid, String attachmentId) { String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp"; File dir = context.getCacheDir(); return new File(dir, filename); } @Override public boolean onCreate() { Loading Loading @@ -139,9 +163,7 @@ public class AttachmentProvider extends ContentProvider { int width = Integer.parseInt(segments.get(3)); int height = Integer.parseInt(segments.get(4)); String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp"; File dir = getContext().getCacheDir(); file = new File(dir, filename); file = getThumbnailFile(getContext(), accountUuid, attachmentId); if (!file.exists()) { String type = getType(accountUuid, attachmentId, FORMAT_VIEW); try { Loading