Bug 1604950 - Remove xpidl [array] use in nsIMsgMessageService. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Tue, 31 Dec 2019 12:21:10 +0200
changeset 37837 97cfef598a7607d3c722d91f46ec5d1db924f84b
parent 37836 e71712f49a91e1aba5123a0a5e841abd92bd0634
child 37838 12ccfeff4905f909f93dc2252a71ee106c34dc28
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1604950
Bug 1604950 - Remove xpidl [array] use in nsIMsgMessageService. r=mkmelin
mailnews/base/public/nsIMsgMessageService.idl
mailnews/base/src/nsMsgFolderCompactor.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/imap/src/nsImapUtils.cpp
mailnews/imap/src/nsImapUtils.h
mailnews/local/public/nsIMailboxUrl.idl
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMailboxService.cpp
mailnews/local/src/nsMailboxUrl.cpp
mailnews/local/src/nsMailboxUrl.h
mailnews/news/src/nsNntpService.cpp
--- a/mailnews/base/public/nsIMsgMessageService.idl
+++ b/mailnews/base/public/nsIMsgMessageService.idl
@@ -52,18 +52,17 @@ interface nsIMsgMessageService : nsISupp
    * @param keys
    * @param srcFolder
    * @param aCopyListener
    * @param aMoveMessage
    * @param aUrlListener
    * @param aMsgWindow
    * @returns URI that's run to perform the copy
    */
-  nsIURI CopyMessages(in unsigned long aNumKeys,
-                      [array, size_is (aNumKeys)] in nsMsgKey aKeys,
+  nsIURI CopyMessages(in Array<nsMsgKey> aKeys,
                       in nsIMsgFolder srcFolder,
                       in nsIStreamListener aCopyListener,
                       in boolean aMoveMessage,
                       in nsIUrlListener aUrlListener,
                       in nsIMsgWindow aMsgWindow);
 
 
   /**
--- a/mailnews/base/src/nsMsgFolderCompactor.cpp
+++ b/mailnews/base/src/nsMsgFolderCompactor.cpp
@@ -415,19 +415,19 @@ nsresult nsFolderCompactState::StartComp
   // TODO: test whether sorting the messages (m_keyArray) by messageOffset
   // would improve performance on large files (less seeks).
   // The m_keyArray is in the order as stored in DB and on IMAP or News
   // the messages stored on the mbox file are not necessarily in the same order.
   if (m_size > 0) {
     nsCOMPtr<nsIURI> notUsed;
     ShowCompactingStatusMsg();
     NS_ADDREF_THIS();
-    rv = m_messageService->CopyMessages(m_size, m_keyArray->m_keys.Elements(),
-                                        m_folder, this, false, nullptr,
-                                        m_window, getter_AddRefs(notUsed));
+    rv = m_messageService->CopyMessages(m_keyArray->m_keys, m_folder, this,
+                                        false, nullptr, m_window,
+                                        getter_AddRefs(notUsed));
   } else {  // no messages to copy with
     FinishCompact();
   }
   return rv;
 }
 
 nsresult nsFolderCompactState::FinishCompact() {
   NS_ENSURE_TRUE(m_folder, NS_ERROR_NOT_INITIALIZED);
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -711,21 +711,21 @@ NS_IMETHODIMP nsImapService::CopyMessage
                         EmptyCString(), aURL);
       // clang-format on
     }  // if we got an imap message sink
   }    // if we decomposed the imap message
   return rv;
 }
 
 NS_IMETHODIMP nsImapService::CopyMessages(
-    uint32_t aNumKeys, nsMsgKey *aKeys, nsIMsgFolder *srcFolder,
+    const nsTArray<nsMsgKey> &aKeys, nsIMsgFolder *srcFolder,
     nsIStreamListener *aMailboxCopy, bool moveMessage,
     nsIUrlListener *aUrlListener, nsIMsgWindow *aMsgWindow, nsIURI **aURL) {
   NS_ENSURE_ARG_POINTER(aMailboxCopy);
-  NS_ENSURE_ARG_POINTER(aKeys);
+  NS_ENSURE_TRUE(!aKeys.IsEmpty(), NS_ERROR_INVALID_ARG);
 
   nsresult rv;
   nsCOMPtr<nsISupports> streamSupport = do_QueryInterface(aMailboxCopy, &rv);
   if (!streamSupport || NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsIMsgFolder> folder = srcFolder;
   if (NS_SUCCEEDED(rv)) {
     nsCOMPtr<nsIImapMessageSink> imapMessageSink(
@@ -733,17 +733,21 @@ NS_IMETHODIMP nsImapService::CopyMessage
     if (NS_SUCCEEDED(rv)) {
       // we generate the uri for the first message so that way on down the line,
       // GetMessage in nsCopyMessageStreamListener will get an unescaped
       // username and be able to find the msg hdr. See bug 259656 for details
       nsCString uri;
       srcFolder->GenerateMessageURI(aKeys[0], uri);
 
       nsCString messageIds;
-      AllocateImapUidString(aKeys, aNumKeys, nullptr, messageIds);
+      // TODO: AllocateImapUidString() maxes out at 950 keys or so... it
+      // updates the numKeys passed in, but here the resulting value is
+      // ignored. Does this need sorting out?
+      uint32_t numKeys = aKeys.Length();
+      AllocateImapUidString(aKeys.Elements(), numKeys, nullptr, messageIds);
       nsCOMPtr<nsIImapUrl> imapUrl;
       nsAutoCString urlSpec;
       char hierarchyDelimiter = GetHierarchyDelimiter(folder);
       rv = CreateStartOfImapUrl(uri, getter_AddRefs(imapUrl), folder,
                                 aUrlListener, urlSpec, hierarchyDelimiter);
       nsImapAction action;
       if (moveMessage)  // don't use ?: syntax here, it seems to break the Mac.
         action = nsIImapUrl::nsImapOnlineToOfflineMove;
--- a/mailnews/imap/src/nsImapUtils.cpp
+++ b/mailnews/imap/src/nsImapUtils.cpp
@@ -223,17 +223,17 @@ nsImapMailboxSpec &nsImapMailboxSpec::op
   mOnlineVerified = aCopy.mOnlineVerified;
 
   return *this;
 }
 
 // use the flagState to determine if the gaps in the msgUids correspond to gaps
 // in the mailbox, in which case we can still use ranges. If flagState is null,
 // we won't do this.
-void AllocateImapUidString(uint32_t *msgUids, uint32_t &msgCount,
+void AllocateImapUidString(const uint32_t *msgUids, uint32_t &msgCount,
                            nsImapFlagAndUidState *flagState,
                            nsCString &returnString) {
   uint32_t startSequence = (msgCount > 0) ? msgUids[0] : 0xFFFFFFFF;
   uint32_t curSequenceEnd = startSequence;
   uint32_t total = msgCount;
   int32_t curFlagStateIndex = -1;
 
   // a partial fetch flag state doesn't help us, so don't use it.
--- a/mailnews/imap/src/nsImapUtils.h
+++ b/mailnews/imap/src/nsImapUtils.h
@@ -28,17 +28,17 @@ extern nsresult nsParseImapMessageURI(co
                                       uint32_t *key, char **part);
 
 extern nsresult nsBuildImapMessageURI(const char *baseURI, uint32_t key,
                                       nsCString &uri);
 
 extern nsresult nsCreateImapBaseMessageURI(const nsACString &baseURI,
                                            nsCString &baseMessageURI);
 
-void AllocateImapUidString(uint32_t *msgUids, uint32_t &msgCount,
+void AllocateImapUidString(const uint32_t *msgUids, uint32_t &msgCount,
                            nsImapFlagAndUidState *flagState,
                            nsCString &returnString);
 void ParseUidString(const char *uidString, nsTArray<nsMsgKey> &keys);
 void AppendUid(nsCString &msgIds, uint32_t uid);
 
 class nsImapMailboxSpec : public nsIMailboxSpec {
  public:
   nsImapMailboxSpec();
--- a/mailnews/local/public/nsIMailboxUrl.idl
+++ b/mailnews/local/public/nsIMailboxUrl.idl
@@ -30,17 +30,17 @@ interface nsIMailboxUrl : nsISupports {
   // performs the copy.
   /////////////////////////////////////////////////////////////////////////
   attribute nsIStreamListener mailboxCopyHandler;
 
   // Some mailbox urls include a message key for the message in question.
   readonly attribute nsMsgKey messageKey;
 
   // this is to support multiple msg move/copy in one url
-  void setMoveCopyMsgKeys(out nsMsgKey keysToFlag, in long numKeys);
+  void setMoveCopyMsgKeys(in Array<nsMsgKey> keysToFlag);
   void getMoveCopyMsgHdrForIndex(in unsigned long msgIndex, out nsIMsgDBHdr msgHdr);
   readonly attribute unsigned long numMoveCopyMsgs;
   attribute unsigned long curMoveCopyMsgIndex;
   // mailbox urls to fetch a mail message can specify the size of
   // the message...
   // this saves us the trouble of having to open up the msg db and ask
   // ourselves...
   attribute unsigned long messageSize;
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -2534,18 +2534,18 @@ nsresult nsMsgLocalMailFolder::CopyMessa
     // each message that gets downloaded, and news doesn't go through here
     // because news only downloads one message at a time, and this routine
     // is for multiple message copy.
     nsCOMPtr<nsIMsgLocalMailFolder> srcLocalFolder =
         do_QueryInterface(srcFolder);
     if (srcLocalFolder) StartMessage();
     nsCOMPtr<nsIURI> dummyNull;
     rv = mCopyState->m_messageService->CopyMessages(
-        keyArray.Length(), keyArray.Elements(), srcFolder, streamListener,
-        isMove, nullptr, aMsgWindow, getter_AddRefs(dummyNull));
+        keyArray, srcFolder, streamListener, isMove, nullptr, aMsgWindow,
+        getter_AddRefs(dummyNull));
   }
   return rv;
 }
 
 nsresult nsMsgLocalMailFolder::CopyMessageTo(
     nsISupports *message, nsIMsgFolder *dstFolder /* dst same as "this" */,
     nsIMsgWindow *aMsgWindow, bool isMove) {
   if (!mCopyState) return NS_ERROR_OUT_OF_MEMORY;
--- a/mailnews/local/src/nsMailboxService.cpp
+++ b/mailnews/local/src/nsMailboxService.cpp
@@ -91,22 +91,22 @@ nsresult nsMailboxService::CopyMessage(c
                                        nsIURI **aURL) {
   nsMailboxAction mailboxAction = nsIMailboxUrl::ActionMoveMessage;
   if (!moveMessage) mailboxAction = nsIMailboxUrl::ActionCopyMessage;
   return FetchMessage(aSrcMailboxURI, aMailboxCopyHandler, aMsgWindow,
                       aUrlListener, nullptr, mailboxAction, nullptr, aURL);
 }
 
 nsresult nsMailboxService::CopyMessages(
-    uint32_t aNumKeys, nsMsgKey *aMsgKeys, nsIMsgFolder *srcFolder,
+    const nsTArray<nsMsgKey> &aMsgKeys, nsIMsgFolder *srcFolder,
     nsIStreamListener *aMailboxCopyHandler, bool moveMessage,
     nsIUrlListener *aUrlListener, nsIMsgWindow *aMsgWindow, nsIURI **aURL) {
   nsresult rv = NS_OK;
   NS_ENSURE_ARG(srcFolder);
-  NS_ENSURE_ARG(aMsgKeys);
+  NS_ENSURE_TRUE(!aMsgKeys.IsEmpty(), NS_ERROR_INVALID_ARG);
   nsCOMPtr<nsIMailboxUrl> mailboxurl;
 
   nsMailboxAction actionToUse = nsIMailboxUrl::ActionMoveMessage;
   if (!moveMessage) actionToUse = nsIMailboxUrl::ActionCopyMessage;
 
   nsCOMPtr<nsIMsgDBHdr> msgHdr;
   nsCOMPtr<nsIMsgDatabase> db;
   srcFolder->GetMsgDatabase(getter_AddRefs(db));
@@ -119,17 +119,17 @@ nsresult nsMailboxService::CopyMessages(
                              getter_AddRefs(mailboxurl), aMsgWindow);
 
       if (NS_SUCCEEDED(rv)) {
         nsCOMPtr<nsIURI> url = do_QueryInterface(mailboxurl);
         nsCOMPtr<nsIMsgMailNewsUrl> msgUrl(do_QueryInterface(url));
         nsCOMPtr<nsIMailboxUrl> mailboxUrl(do_QueryInterface(url));
         msgUrl->SetMsgWindow(aMsgWindow);
 
-        mailboxUrl->SetMoveCopyMsgKeys(aMsgKeys, aNumKeys);
+        mailboxUrl->SetMoveCopyMsgKeys(aMsgKeys);
         rv = RunMailboxUrl(url, aMailboxCopyHandler);
       }
     }
   }
   if (aURL && mailboxurl) CallQueryInterface(mailboxurl, aURL);
 
   return rv;
 }
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -505,20 +505,19 @@ NS_IMETHODIMP nsMailboxUrl::GetCharsetOv
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMailboxUrl::SetCharsetOverRide(const char *aCharacterSet) {
   mCharsetOverride = aCharacterSet;
   return NS_OK;
 }
 
-/* void setMoveCopyMsgKeys (out nsMsgKey keysToFlag, in long numKeys); */
-NS_IMETHODIMP nsMailboxUrl::SetMoveCopyMsgKeys(nsMsgKey *keysToFlag,
-                                               int32_t numKeys) {
-  m_keys.ReplaceElementsAt(0, m_keys.Length(), keysToFlag, numKeys);
+NS_IMETHODIMP nsMailboxUrl::SetMoveCopyMsgKeys(
+    const nsTArray<nsMsgKey> &keysToFlag) {
+  m_keys = keysToFlag;
   if (!m_keys.IsEmpty() && m_messageKey == nsMsgKey_None)
     m_messageKey = m_keys[0];
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMailboxUrl::GetMoveCopyMsgHdrForIndex(uint32_t msgIndex,
                                                       nsIMsgDBHdr **msgHdr) {
   NS_ENSURE_ARG(msgHdr);
--- a/mailnews/local/src/nsMailboxUrl.h
+++ b/mailnews/local/src/nsMailboxUrl.h
@@ -39,17 +39,17 @@ class nsMailboxUrl : public nsIMailboxUr
     *result = m_mailboxAction;
     return NS_OK;
   }
   NS_IMETHOD SetMailboxAction(nsMailboxAction aAction) override {
     m_mailboxAction = aAction;
     return NS_OK;
   }
   NS_IMETHOD IsUrlType(uint32_t type, bool *isType) override;
-  NS_IMETHOD SetMoveCopyMsgKeys(nsMsgKey *keysToFlag, int32_t numKeys) override;
+  NS_IMETHOD SetMoveCopyMsgKeys(const nsTArray<nsMsgKey> &keysToFlag) override;
   NS_IMETHOD GetMoveCopyMsgHdrForIndex(uint32_t msgIndex,
                                        nsIMsgDBHdr **msgHdr) override;
   NS_IMETHOD GetNumMoveCopyMsgs(uint32_t *numMsgs) override;
   NS_IMETHOD GetCurMoveCopyMsgIndex(uint32_t *result) override {
     NS_ENSURE_ARG_POINTER(result);
     *result = m_curMsgIndex;
     return NS_OK;
   }
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -588,17 +588,17 @@ nsNntpService::CopyMessage(const char *a
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = DisplayMessage(aSrcMessageURI, streamSupport, aMsgWindow, aUrlListener,
                       nullptr, aURL);
   return rv;
 }
 
 NS_IMETHODIMP
-nsNntpService::CopyMessages(uint32_t aNumKeys, nsMsgKey *akeys,
+nsNntpService::CopyMessages(const nsTArray<nsMsgKey> &akeys,
                             nsIMsgFolder *srcFolder,
                             nsIStreamListener *aMailboxCopyHandler,
                             bool moveMessage, nsIUrlListener *aUrlListener,
                             nsIMsgWindow *aMsgWindow, nsIURI **aURL) {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult nsNntpService::FindServerWithNewsgroup(nsCString &host,