Bug 1594892 - xpidl [array] removal from nsIMsgDatabase.deleteMessages(). r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Thu, 19 Dec 2019 14:13:38 +0200
changeset 37783 8f61543e6276bcef818dc2f5952cb4ecb30d6da9
parent 37782 f6484bfeb6afeb5b28322713847e6e4d4563c1b4
child 37784 fb1646d8e45c239e5e94bd3fbdbef16e2650f8f2
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1594892
Bug 1594892 - xpidl [array] removal from nsIMsgDatabase.deleteMessages(). r=mkmelin
mailnews/db/msgdb/public/nsIMsgDatabase.idl
mailnews/db/msgdb/public/nsImapMailDatabase.h
mailnews/db/msgdb/public/nsMailDatabase.h
mailnews/db/msgdb/src/nsImapMailDatabase.cpp
mailnews/db/msgdb/src/nsMailDatabase.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapUndoTxn.cpp
mailnews/local/src/nsLocalUndoTxn.cpp
mailnews/mapi/mapihook/src/msgMapiImp.cpp
mailnews/news/src/nsNewsFolder.cpp
--- a/mailnews/db/msgdb/public/nsIMsgDatabase.idl
+++ b/mailnews/db/msgdb/public/nsIMsgDatabase.idl
@@ -412,18 +412,17 @@ interface nsIMsgDatabase : nsIDBChangeAn
   boolean IsWatched(in nsMsgKey key);
   /// Is the message flagged/starred.
   boolean IsMarked(in nsMsgKey key);
   /// Does the message have attachments.
   boolean HasAttachments(in nsMsgKey key);
 
   Array<nsMsgKey> markAllRead();
 
-  void deleteMessages(in unsigned long aNumKeys,
-                      [array, size_is(aNumKeys)] in nsMsgKey nsMsgKeys,
+  void deleteMessages(in Array<nsMsgKey> nsMsgKeys,
                       in nsIDBChangeListener instigator);
   void DeleteMessage(in nsMsgKey key,
                            in nsIDBChangeListener instigator,
                            in boolean commit);
   void DeleteHeader(in nsIMsgDBHdr msgHdr, in nsIDBChangeListener instigator,
                           in boolean commit, in boolean notify);
 
   // lower level routine that doesn't remove hdr from thread or adjust counts
--- a/mailnews/db/msgdb/public/nsImapMailDatabase.h
+++ b/mailnews/db/msgdb/public/nsImapMailDatabase.h
@@ -26,17 +26,17 @@ class nsImapMailDatabase : public nsMail
                                       const char *property,
                                       const char *propertyVal) override;
   NS_IMETHOD SetUint32AttributeOnPendingHdr(nsIMsgDBHdr *pendingHdr,
                                             const char *property,
                                             uint32_t propertyVal) override;
   NS_IMETHOD SetUint64AttributeOnPendingHdr(nsIMsgDBHdr *aPendingHdr,
                                             const char *aProperty,
                                             uint64_t aPropertyVal) override;
-  NS_IMETHOD DeleteMessages(uint32_t aNumKeys, nsMsgKey *nsMsgKeys,
+  NS_IMETHOD DeleteMessages(nsTArray<nsMsgKey> const &nsMsgKeys,
                             nsIDBChangeListener *instigator) override;
   NS_IMETHOD UpdatePendingAttributes(nsIMsgDBHdr *aNewHdr) override;
 
  protected:
   // IMAP does not set local file flags, override does nothing
   virtual void UpdateFolderFlag(nsIMsgDBHdr *msgHdr, bool bSet,
                                 nsMsgMessageFlagType flag,
                                 nsIOutputStream **ppFileStream);
--- a/mailnews/db/msgdb/public/nsMailDatabase.h
+++ b/mailnews/db/msgdb/public/nsMailDatabase.h
@@ -17,17 +17,17 @@
 
 // This is the subclass of nsMsgDatabase that handles local mail messages.
 
 class nsMailDatabase : public nsMsgDatabase {
  public:
   nsMailDatabase();
   virtual ~nsMailDatabase();
   NS_IMETHOD ForceClosed() override;
-  NS_IMETHOD DeleteMessages(uint32_t aNumKeys, nsMsgKey *nsMsgKeys,
+  NS_IMETHOD DeleteMessages(nsTArray<nsMsgKey> const &nsMsgKeys,
                             nsIDBChangeListener *instigator) override;
 
   nsresult Open(nsMsgDBService *aDBService, nsIFile *aSummaryFile, bool create,
                 bool upgrading) override;
   virtual nsMailDatabase *GetMailDB() { return this; }
 
   virtual uint32_t GetCurVersion() override { return kMsgDBVersion; }
 
--- a/mailnews/db/msgdb/src/nsImapMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsImapMailDatabase.cpp
@@ -42,18 +42,18 @@ NS_IMETHODIMP nsImapMailDatabase::SetSum
 // IMAP does not set local file flags, override does nothing
 void nsImapMailDatabase::UpdateFolderFlag(
     nsIMsgDBHdr * /* msgHdr */, bool /* bSet */,
     nsMsgMessageFlagType /* flag */, nsIOutputStream ** /* ppFileStream */) {}
 
 // We override this to avoid our parent class (nsMailDatabase)'s
 // grabbing of the folder semaphore, and bailing on failure.
 NS_IMETHODIMP nsImapMailDatabase::DeleteMessages(
-    uint32_t aNumKeys, nsMsgKey *nsMsgKeys, nsIDBChangeListener *instigator) {
-  return nsMsgDatabase::DeleteMessages(aNumKeys, nsMsgKeys, instigator);
+    nsTArray<nsMsgKey> const &nsMsgKeys, nsIDBChangeListener *instigator) {
+  return nsMsgDatabase::DeleteMessages(nsMsgKeys, instigator);
 }
 
 nsresult nsImapMailDatabase::AdjustExpungedBytesOnDelete(nsIMsgDBHdr *msgHdr) {
   uint32_t msgFlags;
   msgHdr->GetFlags(&msgFlags);
   if (msgFlags & nsMsgMessageFlags::Offline && m_dbFolderInfo) {
     uint32_t size = 0;
     (void)msgHdr->GetOfflineMessageSize(&size);
--- a/mailnews/db/msgdb/src/nsMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp
@@ -60,30 +60,29 @@ nsresult nsMailDatabase::GetAllOfflineOp
   if (!m_mdbAllOfflineOpsTable)
     rv = GetTableCreateIfMissing(kOfflineOpsScope, kOfflineOpsTableKind,
                                  getter_AddRefs(m_mdbAllOfflineOpsTable),
                                  m_offlineOpsRowScopeToken,
                                  m_offlineOpsTableKindToken);
   return rv;
 }
 
-NS_IMETHODIMP nsMailDatabase::DeleteMessages(uint32_t aNumKeys,
-                                             nsMsgKey *nsMsgKeys,
-                                             nsIDBChangeListener *instigator) {
+NS_IMETHODIMP nsMailDatabase::DeleteMessages(
+    nsTArray<nsMsgKey> const &nsMsgKeys, nsIDBChangeListener *instigator) {
   nsresult rv;
   if (m_folder) {
     bool isLocked;
     m_folder->GetLocked(&isLocked);
     if (isLocked) {
       NS_ASSERTION(false, "Some other operation is in progress");
       return NS_MSG_FOLDER_BUSY;
     }
   }
 
-  rv = nsMsgDatabase::DeleteMessages(aNumKeys, nsMsgKeys, instigator);
+  rv = nsMsgDatabase::DeleteMessages(nsMsgKeys, instigator);
   SetSummaryValid(true);
   return rv;
 }
 
 NS_IMETHODIMP nsMailDatabase::GetSummaryValid(bool *aResult) {
   uint32_t version;
   m_dbFolderInfo->GetVersion(&version);
   if (GetCurVersion() != version) {
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -1751,23 +1751,22 @@ NS_IMETHODIMP nsMsgDatabase::DeleteMessa
 
   nsresult rv = GetMsgHdrForKey(key, getter_AddRefs(msgHdr));
   if (!msgHdr) return NS_MSG_MESSAGE_NOT_FOUND;
 
   rv = DeleteHeader(msgHdr, instigator, commit, true);
   return rv;
 }
 
-NS_IMETHODIMP nsMsgDatabase::DeleteMessages(uint32_t aNumKeys,
-                                            nsMsgKey *nsMsgKeys,
+NS_IMETHODIMP nsMsgDatabase::DeleteMessages(nsTArray<nsMsgKey> const &nsMsgKeys,
                                             nsIDBChangeListener *instigator) {
   nsresult err = NS_OK;
 
   uint32_t kindex;
-  for (kindex = 0; kindex < aNumKeys; kindex++) {
+  for (kindex = 0; kindex < nsMsgKeys.Length(); kindex++) {
     nsMsgKey key = nsMsgKeys[kindex];
     nsCOMPtr<nsIMsgDBHdr> msgHdr;
 
     bool hasKey;
 
     if (NS_SUCCEEDED(ContainsKey(key, &hasKey)) && hasKey) {
       err = GetMsgHdrForKey(key, getter_AddRefs(msgHdr));
       if (NS_FAILED(err)) {
@@ -4802,17 +4801,17 @@ nsresult nsMsgDatabase::PurgeMessagesOld
       pHeader->GetMessageKey(&msgKey);
       keysToDelete.AppendElement(msgKey);
       if (hdrsToDelete) hdrsToDelete->AppendElement(pHeader);
     }
     NS_RELEASE(pHeader);
   }
 
   if (!hdrsToDelete) {
-    DeleteMessages(keysToDelete.Length(), keysToDelete.Elements(), nullptr);
+    DeleteMessages(keysToDelete, nullptr);
 
     if (keysToDelete.Length() >
         10)  // compress commit if we deleted more than 10
       Commit(nsMsgDBCommitType::kCompressCommit);
     else if (!keysToDelete.IsEmpty())
       Commit(nsMsgDBCommitType::kLargeCommit);
   }
   return rv;
@@ -4859,17 +4858,17 @@ nsresult nsMsgDatabase::PurgeExcessMessa
       if (hdrsToDelete) hdrsToDelete->AppendElement(pHeader);
     }
     NS_RELEASE(pHeader);
   }
 
   if (!hdrsToDelete) {
     int32_t numKeysToDelete = keysToDelete.Length();
     if (numKeysToDelete > 0) {
-      DeleteMessages(keysToDelete.Length(), keysToDelete.Elements(), nullptr);
+      DeleteMessages(keysToDelete, nullptr);
       if (numKeysToDelete > 10)  // compress commit if we deleted more than 10
         Commit(nsMsgDBCommitType::kCompressCommit);
       else
         Commit(nsMsgDBCommitType::kLargeCommit);
     }
   }
   return rv;
 }
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -2059,18 +2059,17 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMe
                               false);  //"remove it immediately" model
           // Notify if this is an actual delete.
           if (!isMove) {
             nsCOMPtr<nsIMsgFolderNotificationService> notifier(
                 do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
             if (notifier) notifier->NotifyMsgsDeleted(messages);
           }
           DeleteStoreMessages(messages);
-          database->DeleteMessages(srcKeyArray.Length(), srcKeyArray.Elements(),
-                                   nullptr);
+          database->DeleteMessages(srcKeyArray, nullptr);
           EnableNotifications(allMessageCountNotifications, true);
         }
         if (listener) {
           listener->OnStartCopy();
           listener->OnStopCopy(NS_OK);
         }
         NotifyFolderEvent(kDeleteOrMoveMsgCompleted);
       }
@@ -2543,18 +2542,17 @@ NS_IMETHODIMP nsImapMailFolder::UpdateIm
     hdrsToDelete->GetLength(&numHdrs);
     if (numHdrs) {
       nsCOMPtr<nsIMsgFolderNotificationService> notifier(
           do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
       if (notifier) notifier->NotifyMsgsDeleted(hdrsToDelete);
     }
     DeleteStoreMessages(hdrsToDelete);
     EnableNotifications(nsIMsgFolder::allMessageCountNotifications, false);
-    mDatabase->DeleteMessages(keysToDelete.Length(), keysToDelete.Elements(),
-                              nullptr);
+    mDatabase->DeleteMessages(keysToDelete, nullptr);
     EnableNotifications(nsIMsgFolder::allMessageCountNotifications, true);
   }
   int32_t numUnreadFromServer;
   aSpec->GetNumUnseenMessages(&numUnreadFromServer);
 
   bool partialUIDFetch;
   flagState->GetPartialUIDFetch(&partialUIDFetch);
 
@@ -4684,18 +4682,17 @@ nsImapMailFolder::NotifyMessageDeleted(c
 
   if (!ShowDeletedMessages()) {
     GetDatabase();
     NS_ENSURE_TRUE(mDatabase, NS_OK);
     if (!ShowDeletedMessages()) {
       if (!affectedMessages.IsEmpty())  // perhaps Search deleted these messages
       {
         DeleteStoreMessages(affectedMessages);
-        mDatabase->DeleteMessages(affectedMessages.Length(),
-                                  affectedMessages.Elements(), nullptr);
+        mDatabase->DeleteMessages(affectedMessages, nullptr);
       }
     } else  // && !imapDeleteIsMoveToTrash // TODO: can this ever be executed?
       SetIMAPDeletedFlag(mDatabase, affectedMessages, false);
   }
   return NS_OK;
 }
 
 bool nsImapMailFolder::ShowDeletedMessages() {
@@ -4951,18 +4948,17 @@ nsImapMailFolder::OnStopRunningUrl(nsIUR
                   }
 
                   if (!ShowDeletedMessages()) {
                     // We only reach here for same-server operations
                     // (!m_copyState->m_isCrossServerOp in if above), so we can
                     // assume that the src is also imap that uses offline
                     // storage.
                     DeleteStoreMessages(srcKeyArray, srcFolder);
-                    srcDB->DeleteMessages(srcKeyArray.Length(),
-                                          srcKeyArray.Elements(), nullptr);
+                    srcDB->DeleteMessages(srcKeyArray, nullptr);
                   } else
                     MarkMessagesImapDeleted(&srcKeyArray, true, srcDB);
                 }
                 srcFolder->EnableNotifications(allMessageCountNotifications,
                                                true);
                 // even if we're showing deleted messages,
                 // we still need to notify FE so it will show the imap deleted
                 // flag
@@ -5075,18 +5071,17 @@ nsImapMailFolder::OnStopRunningUrl(nsIUR
                   // time, it silently fails to delete. This is why we're also
                   // checking whether the array is empty.
                   notifier->NotifyMsgsDeleted(msgHdrs);
                 }
 
                 if (!supportsCompaction && numHdrs)
                   DeleteStoreMessages(msgHdrs);
 
-                db->DeleteMessages(keyArray.Length(), keyArray.Elements(),
-                                   nullptr);
+                db->DeleteMessages(keyArray, nullptr);
                 db->SetSummaryValid(true);
                 db->Commit(nsMsgDBCommitType::kLargeCommit);
               }
             }
           }
         } break;
         case nsIImapUrl::nsImapAppendMsgFromFile:
         case nsIImapUrl::nsImapAppendDraftFromFile:
@@ -6775,18 +6770,17 @@ nsresult nsImapMailFolder::CopyMessagesO
       notifier->NotifyMsgsMoveCopyCompleted(isMove, msgHdrsCopied, this,
                                             destMsgHdrs);
   }
 
   if (isMove && NS_SUCCEEDED(rv) && (deleteToTrash || deleteImmediately)) {
     DeleteStoreMessages(keysToDelete, srcFolder);
     srcFolder->EnableNotifications(nsIMsgFolder::allMessageCountNotifications,
                                    false);
-    sourceMailDB->DeleteMessages(keysToDelete.Length(), keysToDelete.Elements(),
-                                 nullptr);
+    sourceMailDB->DeleteMessages(keysToDelete, nullptr);
     srcFolder->EnableNotifications(nsIMsgFolder::allMessageCountNotifications,
                                    true);
   }
 
   nsCOMPtr<nsISupports> srcSupport = do_QueryInterface(srcFolder);
   OnCopyCompleted(srcSupport, rv);
 
   if (isMove)
--- a/mailnews/imap/src/nsImapUndoTxn.cpp
+++ b/mailnews/imap/src/nsImapUndoTxn.cpp
@@ -288,18 +288,17 @@ nsresult nsImapMoveCopyMsgTxn::UndoMailb
 nsresult nsImapMoveCopyMsgTxn::RedoMailboxDelete() {
   nsresult rv = NS_ERROR_FAILURE;
   if (m_srcIsPop3) {
     nsCOMPtr<nsIMsgDatabase> srcDB;
     nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
     if (NS_FAILED(rv) || !srcFolder) return rv;
     rv = srcFolder->GetMsgDatabase(getter_AddRefs(srcDB));
     if (NS_SUCCEEDED(rv)) {
-      srcDB->DeleteMessages(m_srcKeyArray.Length(), m_srcKeyArray.Elements(),
-                            nullptr);
+      srcDB->DeleteMessages(m_srcKeyArray, nullptr);
       srcDB->SetSummaryValid(true);
     }
     return NS_OK;  // always return NS_OK
   }
   return NS_ERROR_FAILURE;
 }
 
 nsresult nsImapMoveCopyMsgTxn::GetImapDeleteModel(
--- a/mailnews/local/src/nsLocalUndoTxn.cpp
+++ b/mailnews/local/src/nsLocalUndoTxn.cpp
@@ -262,18 +262,17 @@ nsresult nsLocalMoveCopyMsgTxn::UndoTran
       } else {
         // Nothing to do, probably because original messages were deleted.
         NS_WARNING("Undo did not find any messages to move");
       }
     }
     srcDB->SetSummaryValid(true);
   }
 
-  dstDB->DeleteMessages(m_dstKeyArray.Length(), m_dstKeyArray.Elements(),
-                        nullptr);
+  dstDB->DeleteMessages(m_dstKeyArray, nullptr);
   dstDB->SetSummaryValid(true);
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsLocalMoveCopyMsgTxn::RedoTransaction() {
   nsresult rv;
@@ -335,18 +334,17 @@ nsLocalMoveCopyMsgTxn::RedoTransaction()
       rv = UndoImapDeleteFlag(srcFolder, m_srcKeyArray, deleteFlag);
     } else if (m_canUndelete) {
       nsCOMPtr<nsIMsgLocalMailFolder> localFolder =
           do_QueryInterface(srcFolder);
       if (localFolder)
         localFolder->MarkMsgsOnPop3Server(srcMessages,
                                           POP3_DELETE /*deleteMsgs*/);
 
-      rv = srcDB->DeleteMessages(m_srcKeyArray.Length(),
-                                 m_srcKeyArray.Elements(), nullptr);
+      rv = srcDB->DeleteMessages(m_srcKeyArray, nullptr);
       srcDB->SetSummaryValid(true);
     } else {
       nsCOMPtr<nsIMsgDBHdr> srcHdr;
       m_numHdrsCopied = 0;
       m_dstKeyArray.Clear();
       for (i = 0; i < count; i++) {
         srcDB->GetMsgHdrForKey(m_srcKeyArray[i], getter_AddRefs(srcHdr));
         NS_ASSERTION(srcHdr, "fatal ... cannot get old msg header");
--- a/mailnews/mapi/mapihook/src/msgMapiImp.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiImp.cpp
@@ -767,17 +767,18 @@ extern "C" bool MsgMarkMapiMessageRead(n
   }
   return success;
 }
 
 bool MsgMapiListContext::DeleteMessage(nsMsgKey key) {
   if (!m_db) return FALSE;
 
   if (!IsIMAPHost()) {
-    return NS_SUCCEEDED((m_db->DeleteMessages(1, &key, nullptr)));
+    nsTArray<nsMsgKey> doomed({key});
+    return NS_SUCCEEDED((m_db->DeleteMessages(doomed, nullptr)));
   }
 #if 0
   else if ( m_folder->GetIMAPFolderInfoMail() )
   {
     AutoTArray<nsMsgKey, 1> messageKeys;
     messageKeys.AppendElement(key);
 
     (m_folder->GetIMAPFolderInfoMail())->DeleteSpecifiedMessages(pane, messageKeys, nsMsgKey_None);
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -1394,18 +1394,17 @@ NS_IMETHODIMP nsMsgNewsFolder::RemoveMes
   if (notifier) {
     nsCOMPtr<nsIMutableArray> msgHdrs(do_CreateInstance(NS_ARRAY_CONTRACTID));
     rv = MsgGetHeadersFromKeys(mDatabase, aMsgKeys, msgHdrs);
     NS_ENSURE_SUCCESS(rv, rv);
 
     notifier->NotifyMsgsDeleted(msgHdrs);
   }
 
-  return mDatabase->DeleteMessages(aMsgKeys.Length(), aMsgKeys.Elements(),
-                                   nullptr);
+  return mDatabase->DeleteMessages(aMsgKeys, nullptr);
 }
 
 NS_IMETHODIMP nsMsgNewsFolder::CancelComplete() {
   NotifyFolderEvent(kDeleteOrMoveMsgCompleted);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgNewsFolder::CancelFailed() {