diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index d053443fe..c8be8feab 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1005,13 +1005,19 @@ public class MessagingController implements Runnable { * Remove any messages that are in the local store but no longer on the remote store or are too old */ if (account.syncRemoteDeletions()) { + ArrayList destroyMessages = new ArrayList(); for (Message localMessage : localMessages) { if (remoteUidMap.get(localMessage.getUid()) == null) { - localMessage.destroy(); + destroyMessages.add(localMessage); + } + } - for (MessagingListener l : getListeners(listener)) { - l.synchronizeMailboxRemovedMessage(account, folder, localMessage); - } + + localFolder.destroyMessages(destroyMessages.toArray(EMPTY_MESSAGE_ARRAY)); + + for (Message destroyMessage : destroyMessages) { + for (MessagingListener l : getListeners(listener)) { + l.synchronizeMailboxRemovedMessage(account, folder, destroyMessage); } } } diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index f706ed8de..672554921 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -2020,6 +2020,27 @@ public class LocalStore extends Store implements Serializable { appendMessages(messages, false); } + public void destroyMessages(final Message[] messages) throws MessagingException { + try { + database.execute(true, new DbCallback() { + @Override + public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { + for (Message message : messages) { + try { + message.destroy(); + } catch (MessagingException e) { + throw new WrappedException(e); + } + } + return null; + } + }); + } catch (MessagingException e) { + throw new WrappedException(e); + } + } + + /** * The method differs slightly from the contract; If an incoming message already has a uid * assigned and it matches the uid of an existing message then this message will replace the