Repository: thundernest/k-9
Issue: v5.802 doesn't retract android notification on delete of unread message

**Describe the bug**
Separate IMAP client deletes unread message, v5.802 does not retract New Message notification previously posted when IMAP PUSH saw new msg arrive

**To Reproduce**
1.  send message to an account watched via IMAP PUSH by K-9 v5.802
2. K-9 posts a notification immediately (cool)
3. via another IMAP client (desktop, even K-9 v5.600 on another android), delete the message before marking it read
4. Android notification previously posted by K-9 v5.802 is not retracted and stays visible  (note that v5.600 properly retracts in such a case)

**Expected behavior**
A message never marked read but deleted by another client should retract K-9's previously posted new-message notification.

**Environment:**
 - K-9 Mail version: v5.802
 - Android version: 8.0 // old, I know
 - Device: LG V20 // old, I know
 - Account type: IMAP (gmail)

**Additional context**
Note as mentioned above, v5.600 (K-9) does retract notifications in such cases

A work-around that the end-user may practice is as follows:

Whichever separate non-K9(v5.802) IMAP client is being used (desktop client of some form on another machine, K-9 v5.600 itself on another Android device), if you FIRST mark the newest message read, THEN delete that newest message, K-9 v5.802 DOES properly retract the previously posted new-msg android-notification.

So I'm wondering if K-9 v5.802 could be changed to treat a message deletion (for a message just received and for which the android system notification was posted, and which is still an unread message) as experiencing both an "is read" and "is deleted" state change?

I realize, having briefly scanned the issues list here that there are many challenges surrounding android notifications, and that this may not be an easy thing to track down and solve.  I hope I've provided enough info.

In summary:

message arrives, remains new/unread, is deleted from another IMAP client, K-9 v5.802 leaves the android notif up (while 5.600 removes the notif under the same conditions).

conversely:

message arrives, remains new/unrerad, is first marked read from another IMAP client, then deleted from another IMAP client, K-9 v5.802 tears down the android notif previously posted for the new message.



Changed files:
app/core/src/main/java/com/fsck/k9/controller/MessagingController.java

diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java
index d84f5ec96..716322605 100644
--- a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java
+++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java
@@ -2775,6 +2775,11 @@ public class MessagingController {
             for (MessagingListener messagingListener : getListeners(listener)) {
                 messagingListener.synchronizeMailboxRemovedMessage(account, folderServerId, messageServerId);
             }
+
+            String accountUuid = account.getUuid();
+            long folderId = getFolderIdOrThrow(account, folderServerId);
+            MessageReference messageReference = new MessageReference(accountUuid, folderId, messageServerId, null);
+            notificationController.removeNewMailNotification(account, messageReference);
         }
 
         @Override