diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java index f55d2f0bc..55bd68fce 100644 --- a/src/com/android/email/Email.java +++ b/src/com/android/email/Email.java @@ -386,6 +386,7 @@ public class Email extends Application public class EmailReceived { public static final String ACTION_EMAIL_RECEIVED = "com.android.email.intent.action.EMAIL_RECEIVED"; + public static final String ACTION_EMAIL_DELETED = "com.android.email.intent.action.EMAIL_DELETED"; public static final String EXTRA_ACCOUNT = "com.android.email.intent.extra.ACCOUNT"; public static final String EXTRA_FOLDER = "com.android.email.intent.extra.FOLDER"; public static final String EXTRA_SENT_DATE = "com.android.email.intent.extra.SENT_DATE"; @@ -506,13 +507,12 @@ public class Email extends Application MessagingController.getInstance(this).addListener(new MessagingListener() { - @Override - public void synchronizeMailboxNewMessage(Account account, String folder, Message message) + private void broadcastIntent(String action, Account account, String folder, Message message) { try { Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid())); - Intent intent = new Intent(Email.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, uri); + Intent intent = new Intent(action, uri); intent.putExtra(Email.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription()); intent.putExtra(Email.Intents.EmailReceived.EXTRA_FOLDER, folder); intent.putExtra(Email.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate()); @@ -523,13 +523,41 @@ public class Email extends Application intent.putExtra(Email.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject()); intent.putExtra(Email.Intents.EmailReceived.EXTRA_FROM_SELF, account.isAnIdentity(message.getFrom())); Email.this.sendBroadcast(intent); - Log.d(Email.LOG_TAG, "Broadcasted intent: " + message.getSubject()); + Log.d(Email.LOG_TAG, "Broadcasted: action=" + action + + " account=" + account.getDescription() + + " folder=" + folder + + " message uid=" + message.getUid() + ); } catch (MessagingException e) { - Log.w(Email.LOG_TAG, "Account=" + account.getName() + " folder=" + folder + "message uid=" + message.getUid(), e); + Log.w(Email.LOG_TAG, "Error: action=" + action + + " account=" + account.getDescription() + + " folder=" + folder + + " message uid=" + message.getUid() + ); + } } + + @Override + public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message) + { + broadcastIntent(Email.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message); + } + + @Override + public void messageDeleted(Account account, String folder, Message message) + { + broadcastIntent(Email.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message); + } + + @Override + public void synchronizeMailboxNewMessage(Account account, String folder, Message message) + { + broadcastIntent(Email.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message); + } + }); } diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index ca9b45703..89167b6e7 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -3357,6 +3357,20 @@ public class MessagingController implements Runnable String[] uids = getUidsFromMessages(messages); try { + //We need to make these callbacks before moving the messages to the trash + //as messages get a new UID after being moved + for (Message message : messages) + { + unsuppressMessage(account, folder, message); + if (listener != null) + { + listener.messageDeleted(account, folder, message); + } + for (MessagingListener l : getListeners()) + { + l.messageDeleted(account, folder, message); + } + } Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); localFolder = localStore.getFolder(folder); if (folder.equals(account.getTrashFolderName())) @@ -3385,14 +3399,6 @@ public class MessagingController implements Runnable } } - for (Message message : messages) - { - unsuppressMessage(account, folder, message); - if (listener != null) - { - listener.messageDeleted(account, folder, message); - } - } for (MessagingListener l : getListeners()) {