Bug 1211261 - Notify when messages are moved by 'before junk' filter. r=rkent
authorJorg K <mozilla@jorgk.com>
Tue, 20 Oct 2015 10:47:00 +0200
changeset 23635 7abe3eb0e95845e5ce52f3639cc65832725fe726
parent 23634 a948473f4ed9fd6096202a2f5f7cbae9e5018f89
child 23636 b65f89541ec444346abd811fbb8f886c1d0275b4
push idunknown
push userunknown
push dateunknown
reviewersrkent
bugs1211261
Bug 1211261 - Notify when messages are moved by 'before junk' filter. r=rkent
mail/components/activity/modules/moveCopy.js
mailnews/base/public/nsIMsgFolderListener.idl
mailnews/local/src/nsMsgMaildirStore.cpp
mailnews/local/src/nsParseMailbox.cpp
--- a/mail/components/activity/modules/moveCopy.js
+++ b/mail/components/activity/modules/moveCopy.js
@@ -294,20 +294,84 @@ var moveCopyModule =
 
     event.addSubject(aOrigFolder);
     event.addSubject(aNewFolder);
 
     this.activityMgr.addActivity(event);
   },
 
   itemEvent: function(aItem, aEvent, aData) {
+    if (aEvent == "UnincorporatedMessageMoved") {
+      let srcFolder = aItem.QueryInterface(Components.interfaces.nsIMsgFolder);
+      let msgHdr = aData.QueryInterface(Components.interfaces.nsIMsgDBHdr);
+
+      try {
+        this.log.info("in UnincorporatedMessageMoved");
+
+        // get the folder of the moved/copied messages
+        let destFolder = msgHdr.folder;
+        this.log.info("got folder");
+
+        let displayCount = 1;
+
+        let activities = this.activityMgr.getActivities({});
+        if (activities.length > 0 &&
+            activities[activities.length-1].id == this.lastMessage.id &&
+            this.lastMessage.type == "moveMail" &&
+            this.lastMessage.sourceFolder == srcFolder.prettiestName &&
+            this.lastMessage.destFolder == destFolder.prettiestName)
+        {
+          displayCount += this.lastMessage.count;
+          this.activityMgr.removeActivity(this.lastMessage.id);
+        }
+
+        let statusText = '';
+        if (srcFolder.server != destFolder.server)
+        {
+          statusText = this.getString("fromServerToServer");
+          statusText = statusText.replace("#1", srcFolder.server.prettyName);
+          statusText = statusText.replace("#2", destFolder.server.prettyName);
+        }
+        else
+        {
+          statusText = srcFolder.server.prettyName;
+        }
+
+        this.lastMessage = {};
+        let displayText;
+        displayText = PluralForm.get(displayCount,
+                                     this.getString("movedMessages"));
+
+        displayText = displayText.replace("#1", displayCount)
+        this.lastMessage.count = displayCount;
+        displayText = displayText.replace("#2", srcFolder.prettiestName)
+        this.lastMessage.sourceFolder = srcFolder.prettiestName;
+        displayText = displayText.replace("#3", destFolder.prettiestName)
+        this.lastMessage.destFolder = destFolder.prettiestName;
+
+        // create an activity event
+        let event = new nsActEvent(displayText,
+                                   srcFolder,
+                                   statusText,
+                                   Date.now(),    // start time
+                                   Date.now());   // completion time
+
+        event.iconClass = "moveMail";
+        this.lastMessage.type = event.iconClass;
+        event.addSubject(msgHdr.messageId);
+        this.lastMessage.id = this.activityMgr.addActivity(event);
+      } catch (e) {
+        this.log.error("Exception: " + e)
+      }
+    }
   },
 
   init: function() {
     // XXX when do we need to remove ourselves?
     MailServices.mfn.addListener(this,
                                  MailServices.mfn.msgsDeleted |
                                  MailServices.mfn.msgsMoveCopyCompleted |
                                  MailServices.mfn.folderDeleted |
                                  MailServices.mfn.folderMoveCopyCompleted |
-                                 MailServices.mfn.folderRenamed);
+                                 MailServices.mfn.folderRenamed |
+                                 MailServices.mfn.itemEvent);
   }
 }
--- a/mailnews/base/public/nsIMsgFolderListener.idl
+++ b/mailnews/base/public/nsIMsgFolderListener.idl
@@ -196,14 +196,17 @@ interface nsIMsgFolderListener : nsISupp
    *    messages; msgsClassified will tell you about those messages.  This
    *    notification may be promoted to an explicit callback function at some
    *    point.  This is not guaranteed to be a comprehensive source of junk
    *    notification events; right now any time an nsMsgDBView marks things as
    *    junk/non-junk a notification is produced.  aItem is an nsIArray of
    *    messages, aData is either a "junk" or "notjunk" atom if all of the
    *    messages have the same state.
    *
+   * - UnincorporatedMessageMoved: A messages received via POP was moved
+   *    by a "before junk" rule.
+   *
    * @param aItem The item the event takes place on
    * @param aEvent String describing the event
    * @param aData Data relevant to the event
    */
   void itemEvent(in nsISupports aItem, in ACString aEvent, in nsISupports aData);
 };
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -842,19 +842,27 @@ nsMsgMaildirStore::MoveNewlyDownloadedMe
     }
   }
 
   nsCOMPtr<nsIMsgFolderNotificationService> notifier(
     do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
   if (notifier)
     notifier->NotifyMsgAdded(newHdr);
 
-  if (movedMsgIsNew)
+  if (movedMsgIsNew) {
     aDestFolder->SetHasNewMessages(true);
 
+    // Notify the message was moved.
+    if (notifier) {
+      notifier->NotifyItemEvent(folder,
+                                NS_LITERAL_CSTRING("UnincorporatedMessageMoved"),
+                                newHdr);
+    }
+  }
+
   nsCOMPtr<nsIMsgDatabase> sourceDB;
   rv = folder->GetMsgDatabase(getter_AddRefs(sourceDB));
 
   if (NS_SUCCEEDED(rv) && sourceDB)
     sourceDB->RemoveHeaderMdbRow(aHdr);
 
   destMailDB->SetSummaryValid(true);
   aDestFolder->UpdateSummaryTotals(true);
--- a/mailnews/local/src/nsParseMailbox.cpp
+++ b/mailnews/local/src/nsParseMailbox.cpp
@@ -2586,16 +2586,29 @@ nsresult nsParseNewMailState::MoveIncorp
   if (!m_filterTargetFolders.Contains(destIFolder))
     m_filterTargetFolders.AppendObject(destIFolder);
 
   destIFolder->ReleaseSemaphore (myISupports);
 
   (void) localFolder->RefreshSizeOnDisk();
   destIFolder->SetFlag(nsMsgFolderFlags::GotNew);
 
+  // Notify the message was moved.
+  if (notifier) {
+    nsCOMPtr<nsIMsgFolder> folder;
+    nsresult rv = mailHdr->GetFolder(getter_AddRefs(folder));
+    if (NS_SUCCEEDED(rv)) {
+      notifier->NotifyItemEvent(folder,
+                                NS_LITERAL_CSTRING("UnincorporatedMessageMoved"),
+                                newHdr);
+    } else {
+      NS_WARNING("Can't get folder for message that was moved.");
+    }
+  }
+
   nsCOMPtr<nsIMsgPluggableStore> store;
   rv = m_downloadFolder->GetMsgStore(getter_AddRefs(store));
   if (store)
     store->DiscardNewMessage(m_outputStream, mailHdr);
   if (sourceDB)
     sourceDB->RemoveHeaderMdbRow(mailHdr);
 
   // update the folder size so we won't reparse.