diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index 34c629b9f..288d57193 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -957,12 +957,12 @@ public class MessagingController implements Runnable { * @param account * @throws MessagingException */ - private void processPendingTrash(PendingCommand command, Account account) + private void processPendingTrash(PendingCommand command, final Account account) throws MessagingException { String folder = command.arguments[0]; String uid = command.arguments[1]; - LocalStore localStore = (LocalStore) Store.getInstance( + final LocalStore localStore = (LocalStore) Store.getInstance( account.getLocalStoreUri(), mApplication, null); LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); @@ -998,7 +998,23 @@ public class MessagingController implements Runnable { } if (remoteTrashFolder.exists()) { - remoteFolder.copyMessages(new Message[] { remoteMessage }, remoteTrashFolder); + remoteFolder.copyMessages(new Message[] { remoteMessage }, remoteTrashFolder, + new Folder.MessageUpdateCallbacks() { + public void onMessageUidChange(Message message, String newUid) + throws MessagingException { + // update the UID in the local trash folder, because some stores will + // have to change it when copying to remoteTrashFolder + LocalFolder localTrashFolder = + (LocalFolder) localStore.getFolder(account.getTrashFolderName()); + LocalMessage localMessage = + (LocalMessage) localTrashFolder.getMessage(message.getUid()); + if(localMessage != null) { + localMessage.setUid(newUid); + localTrashFolder.updateMessage(localMessage); + } + } + } + ); } remoteMessage.setFlag(Flag.DELETED, true); @@ -1369,7 +1385,7 @@ public class MessagingController implements Runnable { message.setFlag(Flag.X_SEND_IN_PROGRESS, false); localFolder.copyMessages( new Message[] { message }, - localSentFolder); + localSentFolder, null); PendingCommand command = new PendingCommand(); command.command = PENDING_COMMAND_APPEND; @@ -1425,7 +1441,7 @@ public class MessagingController implements Runnable { Folder localFolder = localStore.getFolder(folder); Folder localTrashFolder = localStore.getFolder(account.getTrashFolderName()); - localFolder.copyMessages(new Message[] { message }, localTrashFolder); + localFolder.copyMessages(new Message[] { message }, localTrashFolder, null); message.setFlag(Flag.DELETED, true); if (account.getDeletePolicy() == Account.DELETE_POLICY_ON_DELETE) { diff --git a/src/com/android/email/mail/Folder.java b/src/com/android/email/mail/Folder.java index 444915579..8bb0e7caa 100644 --- a/src/com/android/email/mail/Folder.java +++ b/src/com/android/email/mail/Folder.java @@ -122,7 +122,8 @@ public abstract class Folder { public abstract void appendMessages(Message[] messages) throws MessagingException; - public abstract void copyMessages(Message[] msgs, Folder folder) throws MessagingException; + public abstract void copyMessages(Message[] msgs, Folder folder, + MessageUpdateCallbacks callbacks) throws MessagingException; public abstract void setFlags(Message[] messages, Flag[] flags, boolean value) throws MessagingException; @@ -200,6 +201,19 @@ public abstract class Folder { Flag[] setFlags, Flag[] clearFlags) throws MessagingException; } + /** + * Callback interface by which a folder can report UID changes caused by certain operations. + */ + public interface MessageUpdateCallbacks { + /** + * The operation caused the message's UID to change + * @param message The message for which the UID changed + * @param newUid The new UID for the message + */ + public void onMessageUidChange(Message message, String newUid) + throws MessagingException; + } + @Override public String toString() { return getName(); diff --git a/src/com/android/email/mail/exchange/ExchangeFolderExample.java b/src/com/android/email/mail/exchange/ExchangeFolderExample.java index 3434f15a1..ec25865e8 100644 --- a/src/com/android/email/mail/exchange/ExchangeFolderExample.java +++ b/src/com/android/email/mail/exchange/ExchangeFolderExample.java @@ -57,7 +57,8 @@ public class ExchangeFolderExample extends Folder { } @Override - public void copyMessages(Message[] msgs, Folder folder) throws MessagingException { + public void copyMessages(Message[] msgs, Folder folder, MessageUpdateCallbacks callbacks) + throws MessagingException { // TODO Implement this function } diff --git a/src/com/android/email/mail/store/ImapStore.java b/src/com/android/email/mail/store/ImapStore.java index 1b09b6c85..7b234bbe0 100644 --- a/src/com/android/email/mail/store/ImapStore.java +++ b/src/com/android/email/mail/store/ImapStore.java @@ -29,7 +29,6 @@ import com.android.email.mail.MessagingException; import com.android.email.mail.Part; import com.android.email.mail.Store; import com.android.email.mail.Transport; -import com.android.email.mail.Folder.PersistentDataCallbacks; import com.android.email.mail.internet.MimeBodyPart; import com.android.email.mail.internet.MimeHeader; import com.android.email.mail.internet.MimeMessage; @@ -482,7 +481,8 @@ public class ImapStore extends Store { } @Override - public void copyMessages(Message[] messages, Folder folder) throws MessagingException { + public void copyMessages(Message[] messages, Folder folder, + MessageUpdateCallbacks callbacks) throws MessagingException { checkOpen(); String[] uids = new String[messages.length]; for (int i = 0, count = messages.length; i < count; i++) { diff --git a/src/com/android/email/mail/store/LocalStore.java b/src/com/android/email/mail/store/LocalStore.java index 205a2863e..de55513fd 100644 --- a/src/com/android/email/mail/store/LocalStore.java +++ b/src/com/android/email/mail/store/LocalStore.java @@ -878,7 +878,8 @@ public class LocalStore extends Store { } @Override - public void copyMessages(Message[] msgs, Folder folder) throws MessagingException { + public void copyMessages(Message[] msgs, Folder folder, MessageUpdateCallbacks callbacks) + throws MessagingException { if (!(folder instanceof LocalFolder)) { throw new MessagingException("copyMessages called with incorrect Folder"); } diff --git a/src/com/android/email/mail/store/Pop3Store.java b/src/com/android/email/mail/store/Pop3Store.java index 57aaef91b..25e2e1c4e 100644 --- a/src/com/android/email/mail/store/Pop3Store.java +++ b/src/com/android/email/mail/store/Pop3Store.java @@ -28,7 +28,6 @@ import com.android.email.mail.MessagingException; import com.android.email.mail.Store; import com.android.email.mail.Transport; import com.android.email.mail.Folder.OpenMode; -import com.android.email.mail.Folder.PersistentDataCallbacks; import com.android.email.mail.internet.MimeMessage; import com.android.email.mail.transport.LoggingInputStream; import com.android.email.mail.transport.MailTransport; @@ -790,7 +789,8 @@ public class Pop3Store extends Store { } @Override - public void copyMessages(Message[] msgs, Folder folder) throws MessagingException { + public void copyMessages(Message[] msgs, Folder folder, MessageUpdateCallbacks callbacks) + throws MessagingException { throw new UnsupportedOperationException("copyMessages is not supported in POP3"); } diff --git a/tests/src/com/android/email/mail/MockFolder.java b/tests/src/com/android/email/mail/MockFolder.java index bd57be26d..7cb45daaf 100644 --- a/tests/src/com/android/email/mail/MockFolder.java +++ b/tests/src/com/android/email/mail/MockFolder.java @@ -31,7 +31,8 @@ public class MockFolder extends Folder { } @Override - public void copyMessages(Message[] msgs, Folder folder) throws MessagingException { + public void copyMessages(Message[] msgs, Folder folder, + MessageUpdateCallbacks callbacks) throws MessagingException { // TODO Auto-generated method stub } diff --git a/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java b/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java index 45751437d..cbdf5e125 100644 --- a/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java +++ b/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java @@ -241,7 +241,7 @@ public class Pop3StoreUnitTests extends AndroidTestCase { // copyMessages() is unsupported try { - mFolder.copyMessages(null, null); + mFolder.copyMessages(null, null, null); fail("Exception not thrown by copyMessages()"); } catch (UnsupportedOperationException e) { // expected - succeed