Bug 1599335 - Remove unused SpamFilterClassifyMessage(s) functions in nsMsgDBFolder. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Thu, 28 Nov 2019 10:54:36 +1300
changeset 36758 7dcc5e7050596410102eb42e30fdf1003e3477d8
parent 36757 693ecddb204ff925eb351f44f38b0442e76214f9
child 36759 8c2f8de771068d5bc849a4e1c5c33329f1e7ea01
push id2534
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:52:51 +0000
treeherdercomm-beta@055c50840778 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1599335
Bug 1599335 - Remove unused SpamFilterClassifyMessage(s) functions in nsMsgDBFolder. r=mkmelin
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgDBFolder.h
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -2116,63 +2116,16 @@ nsMsgDBFolder::GetInheritedStringPropert
     if (parent)
       return parent->GetInheritedStringProperty(aPropertyName, aPropertyValue);
   }
 
   aPropertyValue.Assign(value);
   return NS_OK;
 }
 
-nsresult nsMsgDBFolder::SpamFilterClassifyMessage(
-    const char *aURI, nsIMsgWindow *aMsgWindow,
-    nsIJunkMailPlugin *aJunkMailPlugin) {
-  nsresult rv;
-  nsCOMPtr<nsIMsgTraitService> traitService(
-      do_GetService("@mozilla.org/msg-trait-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsTArray<uint32_t> proIndices;
-  rv = traitService->GetEnabledProIndices(proIndices);
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsTArray<uint32_t> antiIndices;
-  rv = traitService->GetEnabledAntiIndices(antiIndices);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = aJunkMailPlugin->ClassifyTraitsInMessage(nsDependentCString(aURI),
-                                                proIndices, antiIndices, this,
-                                                aMsgWindow, this);
-  return rv;
-}
-
-nsresult nsMsgDBFolder::SpamFilterClassifyMessages(
-    const char **aURIArray, uint32_t aURICount, nsIMsgWindow *aMsgWindow,
-    nsIJunkMailPlugin *aJunkMailPlugin) {
-  MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
-          ("Running Spam classification on %" PRIu32 " messages", aURICount));
-
-  nsresult rv;
-  nsCOMPtr<nsIMsgTraitService> traitService(
-      do_GetService("@mozilla.org/msg-trait-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsTArray<uint32_t> proIndices;
-  rv = traitService->GetEnabledProIndices(proIndices);
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsTArray<uint32_t> antiIndices;
-  rv = traitService->GetEnabledAntiIndices(antiIndices);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsTArray<nsCString> tmpURIs(aURICount);
-  tmpURIs.AppendElements(aURIArray, aURICount);
-
-  rv = aJunkMailPlugin->ClassifyTraitsInMessages(
-      tmpURIs, proIndices, antiIndices, this, aMsgWindow, this);
-  return rv;
-}
-
 NS_IMETHODIMP
 nsMsgDBFolder::OnMessageClassified(const char *aMsgURI,
                                    nsMsgJunkStatus aClassification,
                                    uint32_t aJunkPercent) {
   if (!aMsgURI)  // This signifies end of batch.
   {
     nsresult rv = NS_OK;
     // Apply filters if needed.
@@ -2617,38 +2570,41 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgW
     // Remember what classifications are the source of this decision for when
     // we perform the notification in OnMessageClassified at the conclusion of
     // classification.
     mBayesJunkClassifying = filterForJunk;
     mBayesTraitClassifying = filterForOther;
 
     uint32_t numMessagesToClassify = classifyMsgKeys.Length();
     MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
-            ("%" PRIu32 " messages to be classified", numMessagesToClassify));
-    char **messageURIs =
-        (char **)PR_MALLOC(sizeof(const char *) * numMessagesToClassify);
-    if (!messageURIs) return NS_ERROR_OUT_OF_MEMORY;
-
+            ("Running Spam classification on %" PRIu32 " messages",
+             numMessagesToClassify));
+
+    nsTArray<nsCString> messageURIs(numMessagesToClassify);
     for (uint32_t msgIndex = 0; msgIndex < numMessagesToClassify; ++msgIndex) {
       nsCString tmpStr;
       rv = GenerateMessageURI(classifyMsgKeys[msgIndex], tmpStr);
-      messageURIs[msgIndex] = ToNewCString(tmpStr);
-      if (NS_FAILED(rv))
+      if (NS_SUCCEEDED(rv)) {
+        messageURIs.AppendElement(tmpStr);
+      } else {
         NS_WARNING(
             "nsMsgDBFolder::CallFilterPlugins(): could not"
             " generate URI for message");
+      }
     }
     // filterMsgs
     *aFiltersRun = true;
-    rv = SpamFilterClassifyMessages((const char **)messageURIs,
-                                    numMessagesToClassify, aMsgWindow,
-                                    junkMailPlugin);
-    for (uint32_t freeIndex = 0; freeIndex < numMessagesToClassify; ++freeIndex)
-      PR_Free(messageURIs[freeIndex]);
-    PR_Free(messageURIs);
+
+    // Already got proIndices, but need antiIndices too.
+    nsTArray<uint32_t> antiIndices;
+    rv = traitService->GetEnabledAntiIndices(antiIndices);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = junkMailPlugin->ClassifyTraitsInMessages(
+        messageURIs, proIndices, antiIndices, this, aMsgWindow, this);
   } else if (filterPostPlugin) {
     // Nothing to classify, so need to end batch ourselves. We do this so that
     // post analysis filters will run consistently on a folder, even if
     // disabled junk processing, which could be dynamic through whitelisting,
     // makes the bayes analysis unnecessary.
     OnMessageClassified(nullptr, nsIJunkMailPlugin::UNCLASSIFIED, 0);
   }
 
--- a/mailnews/base/util/nsMsgDBFolder.h
+++ b/mailnews/base/util/nsMsgDBFolder.h
@@ -180,22 +180,16 @@ class NS_MSG_BASE nsMsgDBFolder : public
   bool VerifyOfflineMessage(nsIMsgDBHdr *msgHdr, nsIInputStream *fileStream);
   nsresult AddMarkAllReadUndoAction(nsIMsgWindow *msgWindow,
                                     nsMsgKey *thoseMarked, uint32_t numMarked);
 
   nsresult PerformBiffNotifications(
       void);  // if there are new, non spam messages, do biff
   nsresult CloseDBIfFolderNotOpen();
 
-  virtual nsresult SpamFilterClassifyMessage(
-      const char *aURI, nsIMsgWindow *aMsgWindow,
-      nsIJunkMailPlugin *aJunkMailPlugin);
-  virtual nsresult SpamFilterClassifyMessages(
-      const char **aURIArray, uint32_t aURICount, nsIMsgWindow *aMsgWindow,
-      nsIJunkMailPlugin *aJunkMailPlugin);
   // Helper function for Move code to call to update the MRU and MRM time.
   void UpdateTimestamps(bool allowUndo);
   void SetMRUTime();
   void SetMRMTime();
   /**
    * Clear all processing flags, presumably because message keys are no longer
    * valid.
    */