From c0a8aaf4c591abbdfe11ecca8acdccc9e02ee4b7 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 21 Nov 2002 03:49:11 +0000 Subject: [PATCH] Clean up some mailnews array usage, fix some leaks. Bug 175540, r=dmose, sr=alecf --- mailnews/addrbook/src/nsAbCardProperty.cpp | 4 +- mailnews/addrbook/src/nsAbMDBDirProperty.cpp | 12 +- mailnews/addrbook/src/nsAbMDBDirectory.cpp | 19 +- mailnews/addrbook/src/nsAbView.cpp | 7 +- mailnews/addrbook/src/nsAddrDatabase.cpp | 9 +- mailnews/addrbook/src/nsAddressBook.cpp | 4 +- .../addrbook/src/nsDirectoryDataSource.cpp | 17 +- mailnews/base/search/src/nsMsgFilterList.cpp | 10 +- .../base/search/src/nsMsgSearchSession.cpp | 25 +- mailnews/base/search/src/nsMsgSearchSession.h | 3 +- mailnews/base/src/nsMsgAccountManager.cpp | 45 +-- mailnews/base/src/nsMsgAccountManager.h | 3 +- mailnews/base/src/nsMsgCopyService.cpp | 17 +- mailnews/base/src/nsMsgDBView.cpp | 13 +- mailnews/base/src/nsMsgFolderCompactor.cpp | 12 +- mailnews/base/src/nsMsgFolderDataSource.cpp | 19 +- mailnews/base/src/nsMsgMailSession.cpp | 211 +++++--------- mailnews/base/src/nsMsgMailSession.h | 4 +- mailnews/base/src/nsMsgRDFDataSource.cpp | 5 +- mailnews/base/src/nsMsgSearchDBView.cpp | 72 ++--- mailnews/base/src/nsMsgSearchDBView.h | 3 +- mailnews/base/util/nsMsgDBFolder.cpp | 29 +- mailnews/compose/src/nsMsgCompose.cpp | 58 ++-- mailnews/compose/src/nsMsgCopy.cpp | 4 +- mailnews/imap/src/nsImapIncomingServer.cpp | 40 +-- mailnews/imap/src/nsImapMailFolder.cpp | 68 ++--- mailnews/imap/src/nsImapMoveCoalescer.cpp | 3 +- mailnews/imap/src/nsImapUndoTxn.cpp | 4 +- mailnews/import/src/nsImportAddressBooks.cpp | 170 ++++++----- mailnews/import/src/nsImportMail.cpp | 264 +++++++++--------- mailnews/local/src/nsLocalMailFolder.cpp | 31 +- mailnews/local/src/nsMailboxUrl.cpp | 5 +- mailnews/news/src/nsNewsDownloader.cpp | 3 +- mailnews/news/src/nsNewsFolder.cpp | 7 +- mailnews/news/src/nsNntpIncomingServer.cpp | 8 +- 35 files changed, 460 insertions(+), 748 deletions(-) diff --git a/mailnews/addrbook/src/nsAbCardProperty.cpp b/mailnews/addrbook/src/nsAbCardProperty.cpp index 785f8e1f4c0..30da08e3001 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.cpp +++ b/mailnews/addrbook/src/nsAbCardProperty.cpp @@ -1459,9 +1459,7 @@ NS_IMETHODIMP nsAbCardProperty::ConvertToXMLPrintData(PRUnichar **aXMLSubstr) nsXPIDLString displayName; nsXPIDLString primaryEmail; for (i = 0; i < total; i++) { - nsCOMPtr item = getter_AddRefs(addresses->ElementAt(i)); - - nsCOMPtr listCard = do_QueryInterface(item, &rv); + nsCOMPtr listCard = do_QueryElementAt(addresses, i, &rv); NS_ENSURE_SUCCESS(rv,rv); xmlStr.Append(NS_LITERAL_STRING("\n").get()); diff --git a/mailnews/addrbook/src/nsAbMDBDirProperty.cpp b/mailnews/addrbook/src/nsAbMDBDirProperty.cpp index 40c5c449499..d7c9d49aed8 100644 --- a/mailnews/addrbook/src/nsAbMDBDirProperty.cpp +++ b/mailnews/addrbook/src/nsAbMDBDirProperty.cpp @@ -97,10 +97,8 @@ NS_IMETHODIMP nsAbMDBDirProperty::AddMailListToDirectory(nsIAbDirectory *mailLis for (i = 0; i < count; i++) { nsresult err; - nsCOMPtr pSupport = - getter_AddRefs(m_AddressList->ElementAt(i)); - nsCOMPtr pList(do_QueryInterface(pSupport, &err)); - if (mailList == pList.get()) + nsCOMPtr pList(do_QueryElementAt(m_AddressList, i, &err)); + if (mailList == pList) return NS_OK; } m_AddressList->AppendElement(mailList); @@ -117,10 +115,8 @@ NS_IMETHODIMP nsAbMDBDirProperty::AddAddressToList(nsIAbCard *card) for (i = 0; i < count; i++) { nsresult err; - nsCOMPtr pSupport = - getter_AddRefs(m_AddressList->ElementAt(i)); - nsCOMPtr pCard(do_QueryInterface(pSupport, &err)); - if (card == pCard.get()) + nsCOMPtr pCard(do_QueryElementAt(m_AddressList, i, &err)); + if (card == pCard) return NS_OK; } m_AddressList->AppendElement(card); diff --git a/mailnews/addrbook/src/nsAbMDBDirectory.cpp b/mailnews/addrbook/src/nsAbMDBDirectory.cpp index b4eba3b1dad..8b980e068ac 100644 --- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp +++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp @@ -110,11 +110,7 @@ nsresult nsAbMDBDirectory::RemoveCardFromAddressList(nsIAbCard* card) for (i = listTotal - 1; i >= 0; i--) { - nsCOMPtr pSupport = getter_AddRefs(m_AddressList->ElementAt(i)); - if (!pSupport) - continue; - - nsCOMPtr listDir(do_QueryInterface(pSupport, &rv)); + nsCOMPtr listDir(do_QueryElementAt(m_AddressList, i, &rv)); if (listDir) { nsCOMPtr pAddressLists; @@ -125,8 +121,7 @@ nsresult nsAbMDBDirectory::RemoveCardFromAddressList(nsIAbCard* card) rv = pAddressLists->Count(&total); for (j = total - 1; j >= 0; j--) { - nsCOMPtr pSupport = getter_AddRefs(pAddressLists->ElementAt(j)); - nsCOMPtr cardInList(do_QueryInterface(pSupport, &rv)); + nsCOMPtr cardInList(do_QueryElementAt(pAddressLists, j, &rv)); PRBool equals; nsresult rv = cardInList->Equals(card, &equals); // should we checking email? if (NS_SUCCEEDED(rv) && equals) { @@ -468,11 +463,9 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards) NS_ENSURE_SUCCESS(rv, rv); for (i = 0; i < cardCount; i++) { - nsCOMPtr cardSupports; nsCOMPtr card; nsCOMPtr dbcard; - cardSupports = getter_AddRefs(cards->ElementAt(i)); - card = do_QueryInterface(cardSupports, &rv); + card = do_QueryElementAt(cards, i, &rv); NS_ENSURE_SUCCESS(rv, rv); dbcard = do_QueryInterface(card, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -487,11 +480,7 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards) rv = m_AddressList->Count(&cardTotal); for (i = cardTotal - 1; i >= 0; i--) { - nsCOMPtr pSupport = getter_AddRefs(m_AddressList->ElementAt(i)); - if (!pSupport) - continue; - - nsCOMPtr dbarrayCard(do_QueryInterface(pSupport, &rv)); + nsCOMPtr dbarrayCard(do_QueryElementAt(m_AddressList, i, &rv)); if (dbarrayCard) { PRUint32 tableID, rowID, cardTableID, cardRowID; diff --git a/mailnews/addrbook/src/nsAbView.cpp b/mailnews/addrbook/src/nsAbView.cpp index 70a45406b4d..5e90239635f 100644 --- a/mailnews/addrbook/src/nsAbView.cpp +++ b/mailnews/addrbook/src/nsAbView.cpp @@ -1074,9 +1074,7 @@ nsresult nsAbView::ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard) NS_ENSURE_SUCCESS(rv, rv); for (i = 0; i < count; i++) { - nsCOMPtr cardSupports; - cardSupports = getter_AddRefs(cards->ElementAt(i)); - nsCOMPtr card = do_QueryInterface(cardSupports); + nsCOMPtr card = do_QueryElementAt(cards, i); if (card) { PRInt32 index = FindIndexForCard(card); if (index != CARD_NOT_FOUND) { @@ -1198,8 +1196,7 @@ NS_IMETHODIMP nsAbView::GetSelectedAddresses(nsISupportsArray **_retval) mailListAddresses->Count(&mailListCount); for (PRUint32 j = 0; j < mailListCount; j++) { - nsCOMPtr item = getter_AddRefs(mailListAddresses->ElementAt(j)); - nsCOMPtr mailListCard = do_QueryInterface(item, &rv); + nsCOMPtr mailListCard = do_QueryElementAt(mailListAddresses, j, &rv); NS_ENSURE_SUCCESS(rv,rv); rv = mailListCard->GetPrimaryEmail(getter_Copies(primaryEmail)); diff --git a/mailnews/addrbook/src/nsAddrDatabase.cpp b/mailnews/addrbook/src/nsAddrDatabase.cpp index d3a6564b029..1f7c6495750 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.cpp +++ b/mailnews/addrbook/src/nsAddrDatabase.cpp @@ -1521,8 +1521,7 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewListCardAndAddToDB(nsIAbDirectory *aList, PRUint32 i; for (i = 0; i < count; i++) { - nsCOMPtr support = getter_AddRefs(addressList->ElementAt(i)); - nsCOMPtr currentCard = do_QueryInterface(support, &rv); + nsCOMPtr currentCard = do_QueryElementAt(addressList, i, &rv); NS_ENSURE_SUCCESS(rv,rv); PRBool equals; @@ -1668,8 +1667,7 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM total = 0; for (i = 0; i < count; i++) { - nsCOMPtr pSupport = getter_AddRefs(pAddressLists->ElementAt(i)); - nsCOMPtr pCard(do_QueryInterface(pSupport, &err)); + nsCOMPtr pCard(do_QueryElementAt(pAddressLists, i, &err)); if (NS_FAILED(err)) continue; @@ -1684,8 +1682,7 @@ nsresult nsAddrDatabase::AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIM PRUint32 pos; for (i = 0; i < count; i++) { - nsCOMPtr pSupport = getter_AddRefs(pAddressLists->ElementAt(i)); - nsCOMPtr pCard(do_QueryInterface(pSupport, &err)); + nsCOMPtr pCard(do_QueryElementAt(pAddressLists, i, &err)); if (NS_FAILED(err)) continue; diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index e95eece9365..3ccfcb9b561 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -1664,9 +1664,7 @@ nsresult nsAddressBook::AppendLDIFForMailList(nsIAbCard *aCard, nsACString &aRes if (total) { PRUint32 i; for (i = 0; i < total; i++) { - nsCOMPtr item = getter_AddRefs(addresses->ElementAt(i)); - - nsCOMPtr listCard = do_QueryInterface(item, &rv); + nsCOMPtr listCard = do_QueryElementAt(addresses, i, &rv); NS_ENSURE_SUCCESS(rv,rv); rv = AppendDNForCard("member", listCard, aResult); diff --git a/mailnews/addrbook/src/nsDirectoryDataSource.cpp b/mailnews/addrbook/src/nsDirectoryDataSource.cpp index cebe3e60b5e..b50a366b7e1 100644 --- a/mailnews/addrbook/src/nsDirectoryDataSource.cpp +++ b/mailnews/addrbook/src/nsDirectoryDataSource.cpp @@ -365,8 +365,7 @@ nsAbDirectoryDataSource::IsCommandEnabled(nsISupportsArray/**/* PRUint32 i, cnt; rv = aSources->Count(&cnt); for (i = 0; i < cnt; i++) { - nsCOMPtr source = getter_AddRefs(aSources->ElementAt(i)); - directory = do_QueryInterface(source, &rv); + directory = do_QueryElementAt(aSources, i, &rv); if (NS_SUCCEEDED(rv)) { // we don't care about the arguments -- directory commands are always enabled if (!((aCommand == kNC_Delete) || (aCommand == kNC_DeleteCards))) { @@ -392,8 +391,7 @@ nsAbDirectoryDataSource::DoCommand(nsISupportsArray/**/* aSource rv = DoDeleteFromDirectory(aSources, aArguments); else { for (i = 0; i < cnt; i++) { - nsCOMPtr supports = getter_AddRefs(aSources->ElementAt(i)); - nsCOMPtr directory = do_QueryInterface(supports, &rv); + nsCOMPtr directory = do_QueryElementAt(aSources, i, &rv); if (NS_SUCCEEDED(rv)) { NS_ASSERTION(aCommand == kNC_DeleteCards, "unknown command"); if ((aCommand == kNC_DeleteCards)) @@ -561,11 +559,12 @@ nsAbDirectoryDataSource::createDirectoryChildNode(nsIAbDirectory *directory, } PRUint32 i; + NS_ASSERTION(total <= 1, "This code probably leaks. Please break out of the loop or something, ok?"); for (i = 0; i < total; i++) { - nsCOMPtr mailList = getter_AddRefs(pAddressLists->ElementAt(i)); + nsCOMPtr mailList = do_QueryElementAt(pAddressLists, i); if (mailList) - mailList->QueryInterface(NS_GET_IID(nsIRDFResource), (void**)target); + NS_ADDREF(*target = mailList); else return NS_RDF_NO_VALUE; } @@ -638,12 +637,10 @@ nsresult nsAbDirectoryDataSource::DoDeleteFromDirectory(nsISupportsArray *parent for (item = 0; item < itemCount; item++) { - nsCOMPtr supports = getter_AddRefs(parentDirs->ElementAt(item)); - nsCOMPtr parent = do_QueryInterface(supports, &rv); + nsCOMPtr parent = do_QueryElementAt(parentDirs, item, &rv); if (NS_SUCCEEDED(rv)) { - supports = getter_AddRefs(delDirs->ElementAt(item)); - nsCOMPtr deletedDir(do_QueryInterface(supports)); + nsCOMPtr deletedDir(do_QueryElementAt(delDirs, item)); if(deletedDir) { rv = parent->DeleteDirectory(deletedDir); diff --git a/mailnews/base/search/src/nsMsgFilterList.cpp b/mailnews/base/search/src/nsMsgFilterList.cpp index 214b84236b5..1b9dfd4e157 100644 --- a/mailnews/base/search/src/nsMsgFilterList.cpp +++ b/mailnews/base/search/src/nsMsgFilterList.cpp @@ -1018,7 +1018,7 @@ NS_IMETHODIMP nsMsgFilterList::MatchOrChangeFilterTarget(const char *oldFolderUr nsXPIDLCString folderUri; for (PRUint32 index = 0; index < numFilters; index++) { - rv = m_filters->QueryElementAt(index, NS_GET_IID(nsIMsgFilter), (void **)getter_AddRefs(filter)); + filter = do_QueryElementAt(m_filters, index, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr filterActionList; @@ -1028,8 +1028,8 @@ NS_IMETHODIMP nsMsgFilterList::MatchOrChangeFilterTarget(const char *oldFolderUr for (PRUint32 actionIndex =0; actionIndex < numActions; actionIndex++) { - nsCOMPtr filterAction; - filterActionList->QueryElementAt(actionIndex, NS_GET_IID(nsIMsgRuleAction), (void **)getter_AddRefs(filterAction)); + nsCOMPtr filterAction = + do_QueryElementAt(filterActionList, actionIndex); nsMsgRuleActionType actionType; if (filterAction) filterAction->GetType(&actionType); @@ -1085,13 +1085,11 @@ nsresult nsMsgFilterList::ComputeArbitraryHeaders() rv = m_filters->Count(&numFilters); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr filter; - nsCOMPtr filterSupports; nsMsgSearchAttribValue attrib; nsXPIDLCString arbitraryHeader; for (PRUint32 index = 0; index < numFilters; index++) { - filterSupports = getter_AddRefs(m_filters->ElementAt(index)); - filter = do_QueryInterface(filterSupports, &rv); + filter = do_QueryElementAt(m_filters, index, &rv); if (NS_SUCCEEDED(rv) && filter) { nsCOMPtr searchTerms; diff --git a/mailnews/base/search/src/nsMsgSearchSession.cpp b/mailnews/base/search/src/nsMsgSearchSession.cpp index 04241b1cf14..0b981024fc0 100644 --- a/mailnews/base/search/src/nsMsgSearchSession.cpp +++ b/mailnews/base/search/src/nsMsgSearchSession.cpp @@ -724,21 +724,13 @@ nsMsgSearchSession::EnableFolderNotifications(PRBool aEnable) NS_IMETHODIMP nsMsgSearchSession::AddFolderListener(nsIFolderListener *listener) { - nsresult rv = NS_OK; - if (!m_folderListenerList) - rv = NS_NewISupportsArray(getter_AddRefs(m_folderListenerList)); - - if (NS_SUCCEEDED(rv) && m_folderListenerList) - m_folderListenerList->AppendElement(listener); - - return rv; + return m_folderListenerList.AppendObject(listener) ? NS_OK : NS_ERROR_FAILURE; } NS_IMETHODIMP nsMsgSearchSession::RemoveFolderListener(nsIFolderListener *listener) { - if (m_folderListenerList) - m_folderListenerList->RemoveElement(listener); + m_folderListenerList.RemoveObject(listener); return NS_OK; } @@ -748,18 +740,11 @@ NS_IMETHODIMP nsMsgSearchSession::OnItemEvent(nsIFolder *aFolder, nsIAtom *aEvent) { - nsresult rv; - PRUint32 count; + PRInt32 count = m_folderListenerList.Count(); - NS_ASSERTION(m_folderListenerList, "no listeners"); - if (!m_folderListenerList) return NS_ERROR_FAILURE; - - rv = m_folderListenerList->Count(&count); - if (NS_FAILED(rv)) return rv; - - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)m_folderListenerList->ElementAt(i)); + nsIFolderListener* listener = m_folderListenerList[i]; if(listener) listener->OnItemEvent(aFolder, aEvent); } diff --git a/mailnews/base/search/src/nsMsgSearchSession.h b/mailnews/base/search/src/nsMsgSearchSession.h index f08fc21aed7..1a93fd2fe4f 100644 --- a/mailnews/base/search/src/nsMsgSearchSession.h +++ b/mailnews/base/search/src/nsMsgSearchSession.h @@ -47,6 +47,7 @@ #include "nsITimer.h" #include "nsMsgSearchArray.h" #include "nsISupportsArray.h" +#include "nsCOMArray.h" #include "nsWeakReference.h" class nsMsgSearchAdapter; @@ -83,7 +84,7 @@ protected: nsMsgSearchScopeTermArray m_scopeList; nsCOMPtr m_termList; nsCOMPtr m_listenerList; - nsCOMPtr m_folderListenerList; + nsCOMArray m_folderListenerList; nsMsgResultArray m_resultList; diff --git a/mailnews/base/src/nsMsgAccountManager.cpp b/mailnews/base/src/nsMsgAccountManager.cpp index acfb812909d..92fb5c44730 100644 --- a/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mailnews/base/src/nsMsgAccountManager.cpp @@ -181,9 +181,6 @@ nsresult nsMsgAccountManager::Init() rv = NS_NewISupportsArray(getter_AddRefs(m_accounts)); if(NS_FAILED(rv)) return rv; - rv = NS_NewISupportsArray(getter_AddRefs(m_incomingServerListeners)); - if(NS_FAILED(rv)) return rv; - rv = NS_NewISupportsArray(getter_AddRefs(mFolderListeners)); nsCOMPtr observerService = @@ -661,8 +658,7 @@ nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount) NS_ENSURE_SUCCESS(rv,rv); for (PRUint32 i=0; i< cnt;i++) { - nsCOMPtr supports = getter_AddRefs(allDescendents->ElementAt(i)); - nsCOMPtr folder = do_QueryInterface(supports, &rv); + nsCOMPtr folder = do_QueryElementAt(allDescendents, i, &rv); folder->ForceDBClosed(); } @@ -1753,29 +1749,24 @@ nsMsgAccountManager::findAccountByKey(nsISupports* element, void *aData) NS_IMETHODIMP nsMsgAccountManager::AddIncomingServerListener(nsIIncomingServerListener *serverListener) { - m_incomingServerListeners->AppendElement(serverListener); + m_incomingServerListeners.AppendObject(serverListener); return NS_OK; } NS_IMETHODIMP nsMsgAccountManager::RemoveIncomingServerListener(nsIIncomingServerListener *serverListener) { - m_incomingServerListeners->RemoveElement(serverListener); + m_incomingServerListeners.RemoveObject(serverListener); return NS_OK; } NS_IMETHODIMP nsMsgAccountManager::NotifyServerLoaded(nsIMsgIncomingServer *server) { - nsresult rv; - PRUint32 count; - rv = m_incomingServerListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - + PRInt32 count = m_incomingServerListeners.Count(); - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - nsCOMPtr listener = - getter_AddRefs((nsIIncomingServerListener*)m_incomingServerListeners->ElementAt(i)); + nsIIncomingServerListener* listener = m_incomingServerListeners[i]; listener->OnServerLoaded(server); } @@ -1784,17 +1775,12 @@ NS_IMETHODIMP nsMsgAccountManager::NotifyServerLoaded(nsIMsgIncomingServer *serv NS_IMETHODIMP nsMsgAccountManager::NotifyServerUnloaded(nsIMsgIncomingServer *server) { - nsresult rv; - PRUint32 count; - server->SetFilterList(nsnull); // clear this to cut shutdown leaks. we are always passing valid non-null server here. - rv = m_incomingServerListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - + PRInt32 count = m_incomingServerListeners.Count(); + server->SetFilterList(nsnull); // clear this to cut shutdown leaks. we are always passing valid non-null server here. - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - nsCOMPtr listener = - getter_AddRefs((nsIIncomingServerListener*)m_incomingServerListeners->ElementAt(i)); + nsIIncomingServerListener* listener = m_incomingServerListeners[i]; listener->OnServerUnloaded(server); } @@ -1803,16 +1789,11 @@ NS_IMETHODIMP nsMsgAccountManager::NotifyServerUnloaded(nsIMsgIncomingServer *se NS_IMETHODIMP nsMsgAccountManager::NotifyServerChanged(nsIMsgIncomingServer *server) { - nsresult rv; - PRUint32 count; - rv = m_incomingServerListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - + PRInt32 count = m_incomingServerListeners.Count(); - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - nsCOMPtr listener = - getter_AddRefs((nsIIncomingServerListener*)m_incomingServerListeners->ElementAt(i)); + nsIIncomingServerListener* listener = m_incomingServerListeners[i]; listener->OnServerChanged(server); } diff --git a/mailnews/base/src/nsMsgAccountManager.h b/mailnews/base/src/nsMsgAccountManager.h index 1a5f7510a0b..bdc9d8eeaf6 100644 --- a/mailnews/base/src/nsMsgAccountManager.h +++ b/mailnews/base/src/nsMsgAccountManager.h @@ -37,6 +37,7 @@ #include "nsIObserver.h" #include "nsWeakReference.h" #include "nsIUrlListener.h" +#include "nsCOMArray.h" class nsMsgAccountManager : public nsIMsgAccountManager, @@ -70,7 +71,7 @@ private: nsHashtable m_identities; nsHashtable m_incomingServers; nsCOMPtr m_defaultAccount; - nsCOMPtr m_incomingServerListeners; + nsCOMArray m_incomingServerListeners; nsCOMPtr m_folderDoingEmptyTrash; nsCOMPtr m_folderDoingCleanupInbox; PRBool m_emptyTrashInProgress; diff --git a/mailnews/base/src/nsMsgCopyService.cpp b/mailnews/base/src/nsMsgCopyService.cpp index 7b4f563280b..f68f3a9ae36 100644 --- a/mailnews/base/src/nsMsgCopyService.cpp +++ b/mailnews/base/src/nsMsgCopyService.cpp @@ -282,10 +282,8 @@ nsMsgCopyService::DoNextCopy() nsCOMPtr aMessage; if (copySource) { - nsCOMPtr aSupport; - aSupport = - getter_AddRefs(copySource->m_messageArray->ElementAt(0)); - aMessage = do_QueryInterface(aSupport, &rv); + aMessage = do_QueryElementAt(copySource->m_messageArray, + 0, &rv); copySource->m_processed = PR_TRUE; } copyRequest->m_processed = PR_TRUE; @@ -341,7 +339,7 @@ nsMsgCopyService::CopyMessages(nsIMsgFolder* srcFolder, /* UI src folder */ nsCopyRequest* copyRequest; nsCopySource* copySource = nsnull; nsCOMPtr msgArray; - PRUint32 i, cnt; + PRUint32 cnt; nsCOMPtr msg; nsCOMPtr curFolder; nsCOMPtr aSupport; @@ -366,11 +364,7 @@ nsMsgCopyService::CopyMessages(nsIMsgFolder* srcFolder, /* UI src folder */ // duplicate the message array so we could sort the messages by it's // folder easily - for (i=0; iElementAt(i)); - msgArray->AppendElement(aSupport); - } + msgArray->AppendElements(messages); rv = msgArray->Count(&cnt); if (NS_FAILED(rv)) @@ -378,8 +372,7 @@ nsMsgCopyService::CopyMessages(nsIMsgFolder* srcFolder, /* UI src folder */ while (cnt-- > 0) { - aSupport = getter_AddRefs(msgArray->ElementAt(cnt)); - msg = do_QueryInterface(aSupport, &rv); + msg = do_QueryElementAt(msgArray, cnt, &rv); if (NS_FAILED(rv)) goto done; diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index cbdf651d9f9..73b1614412e 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -2686,9 +2686,9 @@ nsresult nsMsgDBView::ReverseSort() { // swap folders -- // needed when search is done across multiple folders - nsCOMPtr tmpSupports - = getter_AddRefs(folders->ElementAt(i)); - folders->SetElementAt(i, folders->ElementAt(end)); + nsCOMPtr tmpSupports = dont_AddRef(folders->ElementAt(i)); + nsCOMPtr endSupports = dont_AddRef(folders->ElementAt(end)); + folders->SetElementAt(i, endSupports); folders->SetElementAt(end, tmpSupports); } // no need to swap elements in m_levels, @@ -3227,11 +3227,8 @@ NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOr if (folders) { - nsCOMPtr tmpSupports - = getter_AddRefs(folders->ElementAt(numSoFar)); - nsCOMPtr curFolder; - if(tmpSupports) { - curFolder = do_QueryInterface(tmpSupports); + nsCOMPtr curFolder = do_QueryElementAt(folders, numSoFar);; + if(curFolder) { info->folder = curFolder; } } diff --git a/mailnews/base/src/nsMsgFolderCompactor.cpp b/mailnews/base/src/nsMsgFolderCompactor.cpp index 432c93c3af1..98726f4db04 100644 --- a/mailnews/base/src/nsMsgFolderCompactor.cpp +++ b/mailnews/base/src/nsMsgFolderCompactor.cpp @@ -172,8 +172,8 @@ NS_IMETHODIMP nsFolderCompactState::CompactAll(nsISupportsArray *aArrayOfFolders m_offlineFolderArray = do_QueryInterface(aOfflineFolderArray); m_folderIndex = 0; - nsCOMPtr supports = getter_AddRefs(m_folderArray->ElementAt(m_folderIndex)); - nsCOMPtr firstFolder = do_QueryInterface(supports, &rv); + nsCOMPtr firstFolder = do_QueryElementAt(m_folderArray, + m_folderIndex, &rv); if (NS_SUCCEEDED(rv) && firstFolder) Compact(firstFolder, aMsgWindow); //start with first folder from here. @@ -437,8 +437,8 @@ nsFolderCompactState::CompactNextFolder() { if (m_compactOfflineAlso) { - nsCOMPtr supports = getter_AddRefs(m_folderArray->ElementAt(m_folderIndex-1)); - nsCOMPtr folder = do_QueryInterface(supports, &rv); + nsCOMPtr folder = do_QueryElementAt(m_folderArray, + m_folderIndex-1, &rv); if (NS_SUCCEEDED(rv) && folder) folder->CompactAllOfflineStores(m_window, m_offlineFolderArray); } @@ -446,8 +446,8 @@ nsFolderCompactState::CompactNextFolder() return rv; } - nsCOMPtr supports = getter_AddRefs(m_folderArray->ElementAt(m_folderIndex)); - nsCOMPtr folder = do_QueryInterface(supports, &rv); + nsCOMPtr folder = do_QueryElementAt(m_folderArray, + m_folderIndex, &rv); if (NS_SUCCEEDED(rv) && folder) rv = Compact(folder, m_window); diff --git a/mailnews/base/src/nsMsgFolderDataSource.cpp b/mailnews/base/src/nsMsgFolderDataSource.cpp index f2039568719..69501514e0c 100644 --- a/mailnews/base/src/nsMsgFolderDataSource.cpp +++ b/mailnews/base/src/nsMsgFolderDataSource.cpp @@ -701,8 +701,7 @@ nsMsgFolderDataSource::IsCommandEnabled(nsISupportsArray/**/* aS rv = aSources->Count(&cnt); if (NS_FAILED(rv)) return rv; for (PRUint32 i = 0; i < cnt; i++) { - nsCOMPtr source = getter_AddRefs(aSources->ElementAt(i)); - folder = do_QueryInterface(source, &rv); + folder = do_QueryElementAt(aSources, i, &rv); if (NS_SUCCEEDED(rv)) { // we don't care about the arguments -- folder commands are always enabled if (!((aCommand == kNC_Delete) || @@ -745,8 +744,7 @@ nsMsgFolderDataSource::DoCommand(nsISupportsArray/**/* aSources, if (NS_FAILED(rv)) return rv; for ( ; i < cnt; i++) { - supports = getter_AddRefs(aSources->ElementAt(i)); - nsCOMPtr folder = do_QueryInterface(supports, &rv); + nsCOMPtr folder = do_QueryElementAt(aSources, i, &rv); if (NS_SUCCEEDED(rv)) { if ((aCommand == kNC_Delete)) @@ -799,8 +797,7 @@ nsMsgFolderDataSource::DoCommand(nsISupportsArray/**/* aSources, } else if ((aCommand == kNC_Rename)) { - nsCOMPtr elem = getter_AddRefs(aArguments->ElementAt(0)); - nsCOMPtr literal = do_QueryInterface(elem, &rv); + nsCOMPtr literal = do_QueryElementAt(aArguments, 0, &rv); if(NS_SUCCEEDED(rv)) { nsXPIDLString name; @@ -1991,8 +1988,7 @@ nsresult nsMsgFolderDataSource::DoCopyToFolder(nsIMsgFolder *dstFolder, nsISuppo return NS_ERROR_FAILURE; - nsCOMPtr srcFolderSupports = getter_AddRefs(arguments->ElementAt(0)); - nsCOMPtr srcFolder(do_QueryInterface(srcFolderSupports)); + nsCOMPtr srcFolder(do_QueryElementAt(arguments, 0)); if(!srcFolder) return NS_ERROR_FAILURE; @@ -2052,12 +2048,10 @@ nsresult nsMsgFolderDataSource::DoFolderCopyToFolder(nsIMsgFolder *dstFolder, ns else //within the same server therefore no need for copy service { - nsCOMPtr supports; nsCOMPtr msgFolder; for (PRUint32 i=0;i< itemCount; i++) { - supports = getter_AddRefs(arguments->ElementAt(i)); - msgFolder = do_QueryInterface(supports,&rv); + msgFolder = do_QueryElementAt(arguments, i, &rv); if (NS_SUCCEEDED(rv)) { rv = dstFolder->CopyFolder(msgFolder, isMoveFolder , msgWindow, nsnull); @@ -2116,8 +2110,7 @@ nsresult nsMsgFolderDataSource::DoDeleteFromFolder( nsresult nsMsgFolderDataSource::DoNewFolder(nsIMsgFolder *folder, nsISupportsArray *arguments) { nsresult rv = NS_OK; - nsCOMPtr elem = getter_AddRefs(arguments->ElementAt(0)); - nsCOMPtr literal = do_QueryInterface(elem, &rv); + nsCOMPtr literal = do_QueryElementAt(arguments, 0, &rv); if(NS_SUCCEEDED(rv)) { nsXPIDLString name; diff --git a/mailnews/base/src/nsMsgMailSession.cpp b/mailnews/base/src/nsMsgMailSession.cpp index 10ba7fae992..499a404bbde 100644 --- a/mailnews/base/src/nsMsgMailSession.cpp +++ b/mailnews/base/src/nsMsgMailSession.cpp @@ -78,12 +78,7 @@ nsMsgMailSession::~nsMsgMailSession() nsresult nsMsgMailSession::Init() { - nsresult rv = NS_NewISupportsArray(getter_AddRefs(mListeners)); - if(NS_FAILED(rv)) - return rv; - - rv = NS_NewISupportsArray(getter_AddRefs(mWindows)); - return rv; + return NS_NewISupportsArray(getter_AddRefs(mWindows)); } nsresult nsMsgMailSession::Shutdown() @@ -93,27 +88,19 @@ nsresult nsMsgMailSession::Shutdown() NS_IMETHODIMP nsMsgMailSession::AddFolderListener(nsIFolderListener * listener, PRUint32 notifyFlags) { - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - mListeners->AppendElement(listener); + mListeners.AppendObject(listener); mListenerNotifyFlags.Add(notifyFlags); return NS_OK; } NS_IMETHODIMP nsMsgMailSession::RemoveFolderListener(nsIFolderListener * listener) { - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - PRInt32 index; - nsresult rv = mListeners->GetIndexOf(listener, &index); - NS_ENSURE_SUCCESS(rv,rv); + PRInt32 index = mListeners.IndexOf(listener); NS_ASSERTION(index >= 0, "removing non-existent listener"); if (index >= 0) { mListenerNotifyFlags.RemoveAt(index); - mListeners->RemoveElement(listener); + mListeners.RemoveObjectAt(index); } return NS_OK; @@ -125,26 +112,18 @@ nsMsgMailSession::OnItemPropertyChanged(nsISupports *item, const char* oldValue, const char* newValue) { - nsresult rv; - PRUint32 count; - - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - + PRInt32 count = mListeners.Count(); - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::propertyChanged) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - NS_ASSERTION(listener, "listener is null"); - if (!listener) return NS_ERROR_FAILURE; - listener->OnItemPropertyChanged(item, property, oldValue, newValue); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::propertyChanged) { + nsCOMPtr listener = mListeners[i]; + NS_ASSERTION(listener, "listener is null"); + if (!listener) return NS_ERROR_FAILURE; + listener->OnItemPropertyChanged(item, property, oldValue, newValue); + } } - + return NS_OK; } @@ -155,24 +134,16 @@ nsMsgMailSession::OnItemUnicharPropertyChanged(nsISupports *item, const PRUnichar* oldValue, const PRUnichar* newValue) { - nsresult rv; - PRUint32 count; + PRInt32 count = mListeners.Count(); - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - - - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::unicharPropertyChanged) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - NS_ASSERTION(listener, "listener is null"); - if (!listener) return NS_ERROR_FAILURE; - listener->OnItemUnicharPropertyChanged(item, property, oldValue, newValue); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::unicharPropertyChanged) { + nsCOMPtr listener = mListeners[i]; + NS_ASSERTION(listener, "listener is null"); + if (!listener) return NS_ERROR_FAILURE; + listener->OnItemUnicharPropertyChanged(item, property, oldValue, newValue); + } } return NS_OK; @@ -185,24 +156,16 @@ nsMsgMailSession::OnItemIntPropertyChanged(nsISupports *item, PRInt32 oldValue, PRInt32 newValue) { - nsresult rv; - PRUint32 count; - - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - - - for(PRUint32 i = 0; i < count; i++) + PRInt32 count = mListeners.Count(); + + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::intPropertyChanged) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - NS_ASSERTION(listener, "listener is null"); - if (!listener) return NS_ERROR_FAILURE; - listener->OnItemIntPropertyChanged(item, property, oldValue, newValue); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::intPropertyChanged) { + nsCOMPtr listener = mListeners[i]; + NS_ASSERTION(listener, "listener is null"); + if (!listener) return NS_ERROR_FAILURE; + listener->OnItemIntPropertyChanged(item, property, oldValue, newValue); + } } return NS_OK; @@ -215,24 +178,16 @@ nsMsgMailSession::OnItemBoolPropertyChanged(nsISupports *item, PRBool oldValue, PRBool newValue) { - nsresult rv; - PRUint32 count; + PRInt32 count = mListeners.Count(); - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - - - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::boolPropertyChanged) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - NS_ASSERTION(listener, "listener is null"); - if (!listener) return NS_ERROR_FAILURE; - listener->OnItemBoolPropertyChanged(item, property, oldValue, newValue); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::boolPropertyChanged) { + nsCOMPtr listener = mListeners[i]; + NS_ASSERTION(listener, "listener is null"); + if (!listener) return NS_ERROR_FAILURE; + listener->OnItemBoolPropertyChanged(item, property, oldValue, newValue); + } } return NS_OK; @@ -244,19 +199,12 @@ nsMsgMailSession::OnItemPropertyFlagChanged(nsISupports *item, PRUint32 oldValue, PRUint32 newValue) { - nsresult rv; - PRUint32 count; + PRInt32 count = mListeners.Count(); - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { if (mListenerNotifyFlags[i] & nsIFolderListener::propertyFlagChanged) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); + nsCOMPtr listener = mListeners[i]; NS_ASSERTION(listener, "listener is null"); if (!listener) return NS_ERROR_FAILURE; listener->OnItemPropertyFlagChanged(item, property, oldValue, newValue); @@ -268,24 +216,15 @@ nsMsgMailSession::OnItemPropertyFlagChanged(nsISupports *item, NS_IMETHODIMP nsMsgMailSession::OnItemAdded(nsISupports *parentItem, nsISupports *item, const char* viewString) { - nsresult rv; - PRUint32 count; - - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - - - for(PRUint32 i = 0; i < count; i++) + PRInt32 count = mListeners.Count(); + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::added) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - NS_ASSERTION(listener, "listener is null"); - if (!listener) return NS_ERROR_FAILURE; - listener->OnItemAdded(parentItem, item, viewString); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::added) { + nsCOMPtr listener = mListeners[i]; + NS_ASSERTION(listener, "listener is null"); + if (!listener) return NS_ERROR_FAILURE; + listener->OnItemAdded(parentItem, item, viewString); + } } return NS_OK; @@ -294,24 +233,16 @@ NS_IMETHODIMP nsMsgMailSession::OnItemAdded(nsISupports *parentItem, nsISupports NS_IMETHODIMP nsMsgMailSession::OnItemRemoved(nsISupports *parentItem, nsISupports *item, const char* viewString) { - nsresult rv; - PRUint32 count; - - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - + PRInt32 count = mListeners.Count(); - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::removed) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - NS_ASSERTION(listener, "listener is null"); - if (!listener) return NS_ERROR_FAILURE; - listener->OnItemRemoved(parentItem, item, viewString); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::removed) { + nsCOMPtr listener = mListeners[i]; + NS_ASSERTION(listener, "listener is null"); + if (!listener) return NS_ERROR_FAILURE; + listener->OnItemRemoved(parentItem, item, viewString); + } } return NS_OK; @@ -321,22 +252,15 @@ NS_IMETHODIMP nsMsgMailSession::OnItemRemoved(nsISupports *parentItem, nsISuppor NS_IMETHODIMP nsMsgMailSession::OnItemEvent(nsIFolder *aFolder, nsIAtom *aEvent) { - nsresult rv; - PRUint32 count; + PRInt32 count = mListeners.Count(); - NS_ASSERTION(mListeners, "no listeners"); - if (!mListeners) return NS_ERROR_FAILURE; - - rv = mListeners->Count(&count); - if (NS_FAILED(rv)) return rv; - - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - if (mListenerNotifyFlags[i] & nsIFolderListener::event) { - nsCOMPtr listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i)); - if(listener) - listener->OnItemEvent(aFolder, aEvent); - } + if (mListenerNotifyFlags[i] & nsIFolderListener::event) { + nsCOMPtr listener = mListeners[i]; + if(listener) + listener->OnItemEvent(aFolder, aEvent); + } } return NS_OK; } @@ -355,13 +279,11 @@ nsresult nsMsgMailSession::GetTopmostMsgWindow(nsIMsgWindow* *aMsgWindow) rv = mWindows->Count(&count); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr windowSupports; nsCOMPtr msgWindow; if (count == 1) { - windowSupports = getter_AddRefs(mWindows->ElementAt(0)); - msgWindow = do_QueryInterface(windowSupports, &rv); + msgWindow = do_QueryElementAt(mWindows, 0, &rv); NS_ENSURE_SUCCESS(rv, rv); NS_IF_ADDREF(*aMsgWindow = msgWindow); } @@ -428,8 +350,7 @@ nsresult nsMsgMailSession::GetTopmostMsgWindow(nsIMsgWindow* *aMsgWindow) nsCOMPtr docShell; while (count) { - windowSupports = getter_AddRefs(mWindows->ElementAt(count - 1)); - msgWindow = do_QueryInterface(windowSupports, &rv); + msgWindow = do_QueryElementAt(mWindows, count-1, &rv); NS_ENSURE_SUCCESS(rv,rv); rv = msgWindow->GetRootDocShell(getter_AddRefs(docShell)); diff --git a/mailnews/base/src/nsMsgMailSession.h b/mailnews/base/src/nsMsgMailSession.h index 524031d5886..6293fe33601 100644 --- a/mailnews/base/src/nsMsgMailSession.h +++ b/mailnews/base/src/nsMsgMailSession.h @@ -43,7 +43,7 @@ #include "nsCOMPtr.h" #include "nsIMsgStatusFeedback.h" #include "nsIMsgWindow.h" -#include "nsISupportsArray.h" +#include "nsCOMArray.h" /////////////////////////////////////////////////////////////////////////////////// // The mail session is a replacement for the old 4.x MSG_Master object. It contains @@ -69,7 +69,7 @@ public: nsresult GetSelectedLocaleDataDir(nsIFile *defaultsDir); protected: - nsCOMPtr mListeners; + nsCOMArray mListeners; nsUInt32Array mListenerNotifyFlags; nsCOMPtr mWindows; diff --git a/mailnews/base/src/nsMsgRDFDataSource.cpp b/mailnews/base/src/nsMsgRDFDataSource.cpp index 12ab4b39ba1..7593b309f9d 100644 --- a/mailnews/base/src/nsMsgRDFDataSource.cpp +++ b/mailnews/base/src/nsMsgRDFDataSource.cpp @@ -439,10 +439,7 @@ nsMsgRDFDataSource::GetTransactionManager(nsISupportsArray *aSources, nsITransac if (cnt > 0) { - nsCOMPtr supports; - - supports = getter_AddRefs(aSources->ElementAt(0)); - transactionManager = do_QueryInterface(supports, &rv); + transactionManager = do_QueryElementAt(aSources, 0, &rv); if (NS_SUCCEEDED(rv) && transactionManager) { aSources->RemoveElementAt(0); diff --git a/mailnews/base/src/nsMsgSearchDBView.cpp b/mailnews/base/src/nsMsgSearchDBView.cpp index dcdd6713f76..0a2fabbbd3c 100644 --- a/mailnews/base/src/nsMsgSearchDBView.cpp +++ b/mailnews/base/src/nsMsgSearchDBView.cpp @@ -69,9 +69,6 @@ NS_IMETHODIMP nsMsgSearchDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTypeVal m_folders = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - m_dbToUseList = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - rv = nsMsgDBView::Open(folder, sortType, sortOrder, viewFlags, aTreatRecipientAsAuthor, pCount); NS_ENSURE_SUCCESS(rv, rv); @@ -82,18 +79,11 @@ NS_IMETHODIMP nsMsgSearchDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTypeVal NS_IMETHODIMP nsMsgSearchDBView::Close() { - nsresult rv; - PRUint32 count; + PRInt32 count = m_dbToUseList.Count(); - NS_ASSERTION(m_dbToUseList, "no db used"); - //if (!m_dbToUseList) return NS_ERROR_FAILURE; - - rv = m_dbToUseList->Count(&count); - if (NS_FAILED(rv)) return rv; - - for(PRUint32 i = 0; i < count; i++) + for(PRInt32 i = 0; i < count; i++) { - ((nsIMsgDatabase*)m_dbToUseList->ElementAt(i))->RemoveListener(this); + m_dbToUseList[i]->RemoveListener(this); } return NS_OK; } @@ -131,11 +121,8 @@ nsresult nsMsgSearchDBView::OnNewHeader(nsMsgKey newKey, nsMsgKey aParentKey, PR nsresult nsMsgSearchDBView::GetMsgHdrForViewIndex(nsMsgViewIndex index, nsIMsgDBHdr **msgHdr) { nsresult rv = NS_MSG_INVALID_DBVIEW_INDEX; - nsCOMPtr supports = getter_AddRefs(m_folders->ElementAt(index)); - if(supports) - { - nsCOMPtr folder = do_QueryInterface(supports); - if (folder) + nsCOMPtr folder = do_QueryElementAt(m_folders, index); + if (folder) { nsCOMPtr db; rv = folder->GetMsgDatabase(mMsgWindow, getter_AddRefs(db)); @@ -143,7 +130,6 @@ nsresult nsMsgSearchDBView::GetMsgHdrForViewIndex(nsMsgViewIndex index, nsIMsgDB if (db) rv = db->GetMsgHdrForKey(m_keys.GetAt(index), msgHdr); } - } return rv; } @@ -177,8 +163,7 @@ nsMsgSearchDBView::OnSearchHit(nsIMsgDBHdr* aMsgHdr, nsIMsgFolder *folder) if (dbToUse) { dbToUse->AddListener(this); - nsCOMPtr dbSupports = do_QueryInterface(dbToUse); - m_dbToUseList->AppendElement(dbSupports); + m_dbToUseList.AppendObject(dbToUse); } } @@ -205,8 +190,7 @@ nsMsgSearchDBView::OnSearchDone(nsresult status) //message after deletion will happen before deleting the message and search scope //can change with every search. mDeleteModel = nsMsgImapDeleteModels::MoveToTrash; //set to default in case it is non-imap folder - nsCOMPtr curSupports = getter_AddRefs(m_folders->ElementAt(0)); - nsCOMPtr curFolder = do_QueryInterface(curSupports); + nsCOMPtr curFolder = do_QueryElementAt(m_folders, 0); if (curFolder) GetImapDeleteModel(curFolder); return NS_OK; @@ -219,11 +203,11 @@ nsMsgSearchDBView::OnNewSearch() { PRInt32 oldSize = GetSize(); - PRUint32 count=0; - m_dbToUseList->Count(&count); - for(PRUint32 j = 0; j < count; j++) - ((nsIMsgDatabase*)m_dbToUseList->ElementAt(j))->RemoveListener(this); - m_dbToUseList->Clear(); + PRInt32 count = m_dbToUseList.Count(); + for(PRInt32 j = 0; j < count; j++) { + m_dbToUseList[j]->RemoveListener(this); + } + m_dbToUseList.Clear(); m_folders->Clear(); m_keys.RemoveAll(); @@ -333,14 +317,14 @@ nsMsgSearchDBView::InitializeGlobalsForDeleteAndFile(nsMsgViewIndex *indices, PR NS_ENSURE_SUCCESS(rv,rv); for (PRUint32 folderIndex=0; folderIndex < numFolders; folderIndex++) { - nsCOMPtr curSupports = getter_AddRefs(m_uniqueFoldersSelected->ElementAt(folderIndex)); - nsCOMPtr curFolder = do_QueryInterface(curSupports, &rv); + nsCOMPtr curFolder = + do_QueryElementAt(m_uniqueFoldersSelected, folderIndex, &rv); nsCOMPtr msgHdrsForOneFolder; NS_NewISupportsArray(getter_AddRefs(msgHdrsForOneFolder)); for (nsMsgViewIndex i = 0; i < (nsMsgViewIndex) numIndices; i++) { - nsCOMPtr folderSupports = getter_AddRefs(m_folders->ElementAt(indices[i])); - nsCOMPtr msgFolder = do_QueryInterface(folderSupports, &rv); + nsCOMPtr msgFolder = do_QueryElementAt(m_folders, + indices[i], &rv); if (NS_SUCCEEDED(rv) && msgFolder && msgFolder == curFolder) { nsCOMPtr msgHdr; @@ -409,12 +393,12 @@ nsresult nsMsgSearchDBView::ProcessRequestsInOneFolder(nsIMsgWindow *window) { nsresult rv = NS_OK; - nsCOMPtr curSupports = getter_AddRefs(m_uniqueFoldersSelected->ElementAt(mCurIndex)); - NS_ASSERTION(curSupports, "curSupports is null"); - nsCOMPtr curFolder = do_QueryInterface(curSupports); - nsCOMPtr msgSupports = getter_AddRefs(m_hdrsForEachFolder->ElementAt(mCurIndex)); - NS_ASSERTION(msgSupports, "msgSupports is null"); - nsCOMPtr messageArray = do_QueryInterface(msgSupports); + nsCOMPtr curFolder = + do_QueryElementAt(m_uniqueFoldersSelected, mCurIndex); + NS_ASSERTION(curFolder, "curFolder is null"); + nsCOMPtr messageArray = + do_QueryElementAt(m_hdrsForEachFolder, mCurIndex); + NS_ASSERTION(messageArray, "messageArray is null"); // called for delete with trash, copy and move if (mCommand == nsMsgViewCommandType::deleteMsg) @@ -444,13 +428,13 @@ nsresult nsMsgSearchDBView::ProcessRequestsInAllFolders(nsIMsgWindow *window) NS_ENSURE_SUCCESS(rv,rv); for (PRUint32 folderIndex=0; folderIndex < numFolders; folderIndex++) { - nsCOMPtr curSupports = getter_AddRefs(m_uniqueFoldersSelected->ElementAt(folderIndex)); - NS_ASSERTION (curSupports, "curSupports is null"); - nsCOMPtr curFolder = do_QueryInterface(curSupports); + nsCOMPtr curFolder = + do_QueryElementAt(m_uniqueFoldersSelected, folderIndex); + NS_ASSERTION (curFolder, "curFolder is null"); - nsCOMPtr msgSupports = getter_AddRefs(m_hdrsForEachFolder->ElementAt(folderIndex)); - NS_ASSERTION(msgSupports, "msgSupports is null"); - nsCOMPtr messageArray = do_QueryInterface(msgSupports); + nsCOMPtr messageArray = + do_QueryElementAt(m_hdrsForEachFolder, folderIndex); + NS_ASSERTION(messageArray, "messageArray is null"); curFolder->DeleteMessages(messageArray, window, PR_TRUE /* delete storage */, PR_FALSE /* is move*/, nsnull/*copyServListener*/, PR_FALSE /*allowUndo*/ ); } diff --git a/mailnews/base/src/nsMsgSearchDBView.h b/mailnews/base/src/nsMsgSearchDBView.h index 338a3f76213..7892571d5cb 100644 --- a/mailnews/base/src/nsMsgSearchDBView.h +++ b/mailnews/base/src/nsMsgSearchDBView.h @@ -41,6 +41,7 @@ #include "nsMsgDBView.h" #include "nsIMsgCopyServiceListener.h" #include "nsIMsgSearchNotify.h" +#include "nsCOMArray.h" class nsMsgSearchDBView : public nsMsgDBView, public nsIMsgCopyServiceListener, public nsIMsgSearchNotify { @@ -85,7 +86,7 @@ protected: nsMsgViewIndex* mIndicesForChainedDeleteAndFile; nsUInt32Array* mTestIndices; PRInt32 mTotalIndices; - nsCOMPtr m_dbToUseList; + nsCOMArray m_dbToUseList; nsMsgViewCommandTypeValue mCommand; nsCOMPtr mDestFolder; nsresult ProcessRequestsInOneFolder(nsIMsgWindow *window); diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp index 587099bf96a..9acc42158ec 100644 --- a/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mailnews/base/util/nsMsgDBFolder.cpp @@ -128,13 +128,9 @@ NS_IMETHODIMP nsMsgDBFolder::Shutdown(PRBool shutdownChildren) { for (PRUint32 i = 0; i < count; i++) { - nsCOMPtr childFolderSupports = getter_AddRefs(mSubFolders->ElementAt(i)); - if(childFolderSupports) - { - nsCOMPtr childFolder = do_QueryInterface(childFolderSupports); - if(childFolder) - childFolder->Shutdown(PR_TRUE); - } + nsCOMPtr childFolder = do_QueryElementAt(mSubFolders, i); + if(childFolder) + childFolder->Shutdown(PR_TRUE); } } // Ask base class shutdown itself. @@ -151,14 +147,12 @@ NS_IMETHODIMP nsMsgDBFolder::ForceDBClosed () PRUint32 cnt = 0, i; if (mSubFolders) { - nsCOMPtr aSupport; nsCOMPtr child; mSubFolders->Count(&cnt); if (cnt > 0) for (i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(mSubFolders->ElementAt(i)); - child = do_QueryInterface(aSupport); + child = do_QueryElementAt(mSubFolders, i); if (child) child->ForceDBClosed(); } @@ -1401,8 +1395,8 @@ nsMsgDBFolder::AutoCompact(nsIMsgWindow *aWindow) PRInt32 offlineSupportLevel; if ( numServers > 0 ) { - nsCOMPtr serverSupports = getter_AddRefs(allServers->ElementAt(serverIndex)); - nsCOMPtr server = do_QueryInterface(serverSupports); + nsCOMPtr server = + do_QueryElementAt(allServers, serverIndex); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr folderArray; nsCOMPtr offlineFolderArray; @@ -1460,8 +1454,7 @@ nsMsgDBFolder::AutoCompact(nsIMsgWindow *aWindow) } } } - serverSupports = getter_AddRefs(allServers->ElementAt(++serverIndex)); - server = do_QueryInterface(serverSupports, &rv); + server = do_QueryElementAt(allServers, ++serverIndex); } while (serverIndex < numServers); totalExpungedBytes = localExpungedBytes + offlineExpungedBytes; @@ -1479,8 +1472,8 @@ nsMsgDBFolder::AutoCompact(nsIMsgWindow *aWindow) { if ( localExpungedBytes > 0) { - nsCOMPtr aSupports = getter_AddRefs(folderArray->ElementAt(0)); - nsCOMPtr msgFolder = do_QueryInterface(aSupports, &rv); + nsCOMPtr msgFolder = + do_QueryElementAt(folderArray, 0, &rv); if (msgFolder && NS_SUCCEEDED(rv)) if (offlineExpungedBytes > 0) msgFolder->CompactAll(nsnull, aWindow, folderArray, PR_TRUE, offlineFolderArray); @@ -1572,8 +1565,8 @@ nsMsgDBFolder::MatchOrChangeFilterDestination(nsIMsgFolder *newFolder, PRBool ca rv = allServers->Count(&numServers); for (PRUint32 serverIndex=0; serverIndex < numServers; serverIndex++) { - nsCOMPtr serverSupports = getter_AddRefs(allServers->ElementAt(serverIndex)); - nsCOMPtr server = do_QueryInterface(serverSupports, &rv); + nsCOMPtr server = + do_QueryElementAt(allServers, serverIndex, &rv); if (server && NS_SUCCEEDED(rv)) { PRBool canHaveFilters; diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index e5b2a873b34..42c9aada7c4 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -90,6 +90,7 @@ #include "nsIDocShellTreeOwner.h" #include "nsIWindowMediator.h" #include "nsISupportsArray.h" +#include "nsCOMArray.h" #include "nsIIOService.h" #include "nsIURL.h" #include "nsIMsgMailSession.h" @@ -418,7 +419,6 @@ nsresult nsMsgCompose::TagEmbeddedObjects(nsIEditorMailSupport *aEditor) if (NS_FAILED(aNodeList->Count(&count))) return NS_ERROR_FAILURE; - nsCOMPtr isupp; nsCOMPtr node; nsCOMPtr originalUrl; @@ -446,17 +446,15 @@ nsresult nsMsgCompose::TagEmbeddedObjects(nsIEditorMailSupport *aEditor) nsCOMPtr domElement; for (i = 0; i < count; i ++) { - isupp = getter_AddRefs(aNodeList->ElementAt(i)); - if (!isupp) + node = do_QueryElementAt(aNodeList, i); + if (!node) continue; - - node = do_QueryInterface(isupp); if (IsEmbeddedObjectSafe(originalScheme.get(), originalHost.get(), originalPath.get(), node)) continue; //Don't need to tag this object, it safe to send it. //The source of this object should not be sent with the message - domElement = do_QueryInterface(isupp); + domElement = do_QueryInterface(node); if (domElement) domElement->SetAttribute(NS_LITERAL_STRING("moz-do-not-send"), NS_LITERAL_STRING("true")); } @@ -3425,8 +3423,8 @@ nsresult nsMsgCompose::NotifyStateListeners(TStateListenerNotification aNotifica PRUint32 i; for (i = 0; i < numListeners;i++) { - nsCOMPtr iSupports = getter_AddRefs(mStateListeners->ElementAt(i)); - nsCOMPtr thisListener = do_QueryInterface(iSupports); + nsCOMPtr thisListener = + do_QueryElementAt(mStateListeners, i); if (thisListener) { switch (aNotificationType) @@ -3686,7 +3684,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, *_retval = nsIAbPreferMailFormat::unknown; /* First, build an array with original recipients */ - nsCOMPtr recipientsList[MAX_OF_RECIPIENT_ARRAY]; + nsCOMArray recipientsList[MAX_OF_RECIPIENT_ARRAY]; nsXPIDLString originalRecipients[MAX_OF_RECIPIENT_ARRAY]; m_compFields->GetTo(getter_Copies(originalRecipients[0])); @@ -3707,10 +3705,6 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, nsXPIDLString addr; addressArray->GetCount(&nbrRecipients); - recipientsList[i] = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - for (j = 0; j < nbrRecipients; j ++) { rv = addressArray->StringAt(j, getter_Copies(addr)); @@ -3725,12 +3719,11 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (!recipient) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(recipient); - - rv = recipientsList[i]->AppendElement(recipient); + rv = recipientsList[i].AppendObject(recipient) ? NS_OK : NS_ERROR_FAILURE; NS_RELEASE(recipient); if (NS_FAILED(rv)) return rv; - } + } } else return rv; @@ -3753,7 +3746,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, { nsString dirPath; GetABDirectories(kAllDirectoryRoot, addrbookDirArray, PR_TRUE); - PRUint32 nbrRecipients; + PRInt32 nbrRecipients; PRUint32 nbrAddressbook; addrbookDirArray->Count(&nbrAddressbook); @@ -3789,12 +3782,12 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, stillNeedToSearch = PR_FALSE; for (i = 0; i < MAX_OF_RECIPIENT_ARRAY; i ++) { - if (!recipientsList[i]) + nbrRecipients = recipientsList[i].Count(); + if (nbrRecipients == 0) continue; - recipientsList[i]->Count(&nbrRecipients); - for (j = 0; j < (PRInt32)nbrRecipients; j ++, recipientsList[i]->Count(&nbrRecipients)) + for (j = 0; j < nbrRecipients; j++, nbrRecipients = recipientsList[i].Count()) { - nsMsgRecipient* recipient = NS_STATIC_CAST(nsMsgRecipient*, recipientsList[i]->ElementAt(j)); + nsMsgRecipient* recipient = recipientsList[i][j]; if (recipient && !recipient->mProcessed) { /* First check if it's a mailing list */ @@ -3805,8 +3798,8 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRUint32 nbrAddresses = 0; for (mailListAddresses->Count(&nbrAddresses); nbrAddresses > 0; nbrAddresses --) { - item = getter_AddRefs(mailListAddresses->ElementAt(nbrAddresses - 1)); - existingCard = do_QueryInterface(item, &rv); + existingCard = do_QueryElementAt(mailListAddresses, + nbrAddresses - 1, &rv); if (NS_FAILED(rv)) return rv; @@ -3867,7 +3860,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (!recipient) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(newRecipient); - + if (bIsMailList) { //TODO: we must to something to avoid recursivity @@ -3880,18 +3873,18 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (NS_SUCCEEDED(rv)) recipient->mProcessed = PR_TRUE; } - rv = recipientsList[i]->InsertElementAt(newRecipient, j + 1); + rv = recipientsList[i].InsertObjectAt(newRecipient, + j + 1) ? NS_OK : NS_ERROR_FAILURE; NS_RELEASE(newRecipient); if (NS_FAILED(rv)) return rv; } - rv = recipientsList[i]->RemoveElementAt(j); + rv = recipientsList[i].RemoveObjectAt(j) ? NS_OK : NS_ERROR_FAILURE; j --; } else recipient->mProcessed = PR_TRUE; - NS_RELEASE(recipient); continue; } @@ -3909,7 +3902,6 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, } else stillNeedToSearch = PR_TRUE; - NS_RELEASE(recipient); } } } @@ -3941,15 +3933,14 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, *_retval = -1; for (i = 0; i < MAX_OF_RECIPIENT_ARRAY; i ++) { - if (!recipientsList[i]) + PRInt32 nbrRecipients = recipientsList[i].Count(); + if (nbrRecipients == 0) continue; recipientsStr.SetLength(0); - PRUint32 nbrRecipients; - recipientsList[i]->Count(&nbrRecipients); - for (j = 0; j < (PRInt32)nbrRecipients; j ++) + for (j = 0; j < nbrRecipients; j ++) { - nsMsgRecipient* recipient = NS_STATIC_CAST(nsMsgRecipient*, recipientsList[i]->ElementAt(j)); + nsMsgRecipient* recipient = recipientsList[i][j]; if (recipient) { /* if we don't have a prefer format for a recipient, check the domain in case we have a format defined for it */ @@ -4000,7 +3991,6 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, nonHtmlRecipientsStr.Append(recipient->mEmail); } - NS_RELEASE(recipient); } } diff --git a/mailnews/compose/src/nsMsgCopy.cpp b/mailnews/compose/src/nsMsgCopy.cpp index f0f1ec469e8..fed8f4049c0 100644 --- a/mailnews/compose/src/nsMsgCopy.cpp +++ b/mailnews/compose/src/nsMsgCopy.cpp @@ -544,10 +544,8 @@ LocateMessageFolder(nsIMsgIdentity *userIdentity, for (i=0; i inServer; - nsCOMPtrptr; - ptr = getter_AddRefs(retval->ElementAt(i)); - inServer = do_QueryInterface(ptr, &rv); + inServer = do_QueryElementAt(retval, i, &rv); if(NS_FAILED(rv) || (!inServer)) continue; diff --git a/mailnews/imap/src/nsImapIncomingServer.cpp b/mailnews/imap/src/nsImapIncomingServer.cpp index a00f684fdbd..a33e44a17cd 100644 --- a/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mailnews/imap/src/nsImapIncomingServer.cpp @@ -481,9 +481,8 @@ nsImapIncomingServer::LoadNextQueuedUrl(PRBool *aResult) while (cnt > 0 && !urlRun && keepGoing) { - nsCOMPtr aSupport(getter_AddRefs(m_urlQueue->ElementAt(0))); - nsCOMPtr aImapUrl(do_QueryInterface(aSupport, &rv)); - nsCOMPtr aMailNewsUrl(do_QueryInterface(aSupport, &rv)); + nsCOMPtr aImapUrl(do_QueryElementAt(m_urlQueue, 0, &rv)); + nsCOMPtr aMailNewsUrl(do_QueryInterface(aImapUrl, &rv)); PRBool removeUrlFromQueue = PR_FALSE; if (aImapUrl) @@ -538,8 +537,7 @@ nsImapIncomingServer::AbortQueuedUrls() while (cnt > 0) { - nsCOMPtr aSupport(getter_AddRefs(m_urlQueue->ElementAt(cnt - 1))); - nsCOMPtr aImapUrl(do_QueryInterface(aSupport, &rv)); + nsCOMPtr aImapUrl(do_QueryElementAt(m_urlQueue, cnt - 1, &rv)); PRBool removeUrlFromQueue = PR_FALSE; if (aImapUrl) @@ -691,14 +689,12 @@ nsImapIncomingServer::CreateImapConnection(nsIEventQueue *aEventQueue, *aImapConnection = nsnull; // iterate through the connection cache for a connection that can handle this url. - nsCOMPtr aSupport; PRBool userCancelled = PR_FALSE; // loop until we find a connection that can run the url, or doesn't have to wait? for (PRUint32 i = 0; i < cnt && !canRunUrlImmediately && !canRunButBusy; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i); if (connection) { if (ConnectionTimeOut(connection)) @@ -841,7 +837,6 @@ NS_IMETHODIMP nsImapIncomingServer::CloseConnectionForFolder(nsIMsgFolder *aMsgF { nsresult rv = NS_OK; nsCOMPtr connection; - nsCOMPtr aSupport; PRBool isBusy = PR_FALSE, isInbox = PR_FALSE; PRUint32 cnt = 0; nsXPIDLCString inFolderName; @@ -859,8 +854,7 @@ NS_IMETHODIMP nsImapIncomingServer::CloseConnectionForFolder(nsIMsgFolder *aMsgF for (PRUint32 i=0; i < cnt; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i); if (connection) { rv = connection->GetSelectedMailboxName(getter_Copies(connectionFolderName)); @@ -882,7 +876,6 @@ NS_IMETHODIMP nsImapIncomingServer::ResetConnection(const char* folderName) { nsresult rv = NS_OK; nsCOMPtr connection; - nsCOMPtr aSupport; PRBool isBusy = PR_FALSE, isInbox = PR_FALSE; PRUint32 cnt = 0; nsXPIDLCString curFolderName; @@ -894,8 +887,7 @@ NS_IMETHODIMP nsImapIncomingServer::ResetConnection(const char* folderName) for (PRUint32 i=0; i < cnt; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i); if (connection) { rv = connection->GetSelectedMailboxName(getter_Copies(curFolderName)); @@ -976,15 +968,13 @@ nsImapIncomingServer::CloseCachedConnections() // iterate through the connection cache closing open connections. PRUint32 cnt; - nsCOMPtr aSupport; nsresult rv = m_connectionCache->Count(&cnt); if (NS_FAILED(rv)) return rv; for (PRUint32 i = cnt; i>0; i--) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i-1)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i-1); if (connection) connection->TellThreadToDie(PR_TRUE); } @@ -2488,14 +2478,12 @@ NS_IMETHODIMP nsImapIncomingServer::PseudoInterruptMsgLoad(nsIMsgFolder *aImapFo // iterate through the connection cache for a connection that is loading // a message in this folder and should be pseudo-interrupted. PRUint32 cnt; - nsCOMPtr aSupport; rv = m_connectionCache->Count(&cnt); if (NS_FAILED(rv)) return rv; for (PRUint32 i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i); if (connection) rv = connection->PseudoInterruptMsgLoad(aImapFolder, aMsgWindow, interrupted); } @@ -2738,13 +2726,11 @@ NS_IMETHODIMP nsImapIncomingServer::OnLogonRedirectionReply(const PRUnichar *pHo m_urlQueue->Count(&cnt); if (cnt > 0) { - nsCOMPtr aSupport(getter_AddRefs(m_urlQueue->ElementAt(0))); - nsCOMPtr aImapUrl(do_QueryInterface(aSupport, &rv)); + nsCOMPtr aImapUrl(do_QueryElementAt(m_urlQueue, 0, &rv)); if (aImapUrl) { - nsISupports *aConsumer = (nsISupports*)m_urlConsumers.ElementAt(0); - NS_IF_ADDREF(aConsumer); + nsCOMPtr aConsumer = (nsISupports*)m_urlConsumers.ElementAt(0); nsCOMPtr protocolInstance ; rv = CreateImapConnection(aEventQueue, aImapUrl, getter_AddRefs(protocolInstance)); @@ -2762,8 +2748,6 @@ NS_IMETHODIMP nsImapIncomingServer::OnLogonRedirectionReply(const PRUnichar *pHo m_urlQueue->RemoveElementAt(0); m_urlConsumers.RemoveElementAt(0); } - - NS_IF_RELEASE(aConsumer); } } else @@ -3346,15 +3330,13 @@ nsImapIncomingServer::GetNumIdleConnections(PRInt32 *aNumIdleConnections) PR_CEnterMonitor(this); PRUint32 cnt; - nsCOMPtr aSupport; rv = m_connectionCache->Count(&cnt); if (NS_FAILED(rv)) return rv; // loop counting idle connections for (PRUint32 i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i); if (connection) { rv = connection->IsBusy(&isBusy, &isInboxConnection); diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 9a7630cff1b..331124812e4 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -1226,9 +1226,8 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *msgWindow, aSupportsArray->Count(&cnt); for (PRInt32 i = cnt-1; i >= 0; i--) { - aSupport = getter_AddRefs(aSupportsArray->ElementAt(i)); + aFolder = do_QueryElementAt(aSupportsArray, i); aSupportsArray->RemoveElementAt(i); - aFolder = do_QueryInterface(aSupport); if (aFolder) trashFolder->PropagateDelete(aFolder, PR_TRUE, msgWindow); } @@ -1321,15 +1320,13 @@ NS_IMETHODIMP nsImapMailFolder::RecursiveCloseActiveConnections(nsIImapIncomingS nsresult rv; if (mSubFolders) { - nsCOMPtr aSupport; nsCOMPtr folder; mSubFolders->Count(&cnt); if (cnt > 0) { for (i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(mSubFolders->ElementAt(i)); - folder = do_QueryInterface(aSupport); + folder = do_QueryElementAt(mSubFolders, i); if (folder) folder->RecursiveCloseActiveConnections(incomingImapServer); nsCOMPtr msgFolder = do_QueryInterface(folder, &rv); @@ -1347,15 +1344,13 @@ NS_IMETHODIMP nsImapMailFolder::PrepareToRename() PRUint32 cnt = 0, i; if (mSubFolders) { - nsCOMPtr aSupport; nsCOMPtr folder; mSubFolders->Count(&cnt); if (cnt > 0) { for (i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(mSubFolders->ElementAt(i)); - folder = do_QueryInterface(aSupport); + folder = do_QueryElementAt(mSubFolders, i); if (folder) folder->PrepareToRename(); } @@ -1829,7 +1824,6 @@ nsImapMailFolder::BuildIdsAndKeyArray(nsISupportsArray* messages, nsresult rv = NS_ERROR_NULL_POINTER; PRUint32 count = 0; PRUint32 i; - nsCOMPtr msgSupports; if (!messages) return rv; @@ -1839,9 +1833,8 @@ nsImapMailFolder::BuildIdsAndKeyArray(nsISupportsArray* messages, // build up message keys. for (i = 0; i < count; i++) { - msgSupports = getter_AddRefs(messages->ElementAt(i)); nsMsgKey key; - nsCOMPtr msgDBHdr = do_QueryInterface(msgSupports, &rv); + nsCOMPtr msgDBHdr = do_QueryElementAt(messages, i, &rv); if (msgDBHdr) rv = msgDBHdr->GetMessageKey(&key); if (NS_SUCCEEDED(rv)) @@ -1999,8 +1992,7 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMessages(nsISupportsArray *messages, deleteMsgs = PR_FALSE; for (PRUint32 i=0; i msgSupports = getter_AddRefs(messages->ElementAt(i)); - nsCOMPtr msgHdr = do_QueryInterface(msgSupports); + nsCOMPtr msgHdr = do_QueryElementAt(messages, i); if (msgHdr) { msgHdr->GetFlags(&flags); @@ -2086,7 +2078,6 @@ NS_IMETHODIMP nsImapMailFolder::DeleteSubFolders(nsISupportsArray* folders, nsIMsgWindow *msgWindow) { nsCOMPtr curFolder; - nsCOMPtr folderSupport; nsCOMPtr urlListener; nsCOMPtr trashFolder; PRUint32 i, folderCount = 0; @@ -2157,8 +2148,7 @@ nsImapMailFolder::DeleteSubFolders(nsISupportsArray* folders, nsIMsgWindow *msgW { for (i = 0; i < folderCount; i++) { - folderSupport = getter_AddRefs(folders->ElementAt(i)); - curFolder = do_QueryInterface(folderSupport, &rv); + curFolder = do_QueryElementAt(folders, i, &rv); if (NS_SUCCEEDED(rv)) { urlListener = do_QueryInterface(curFolder); @@ -4620,11 +4610,8 @@ void nsImapMailFolder::UpdatePendingCounts(PRBool countUnread, PRBool missingAre if (!m_copyState->m_isCrossServerOp) for (PRUint32 keyIndex=0; keyIndex < m_copyState->m_totalCount; keyIndex++) { - nsCOMPtr message; - - nsCOMPtr aSupport = - getter_AddRefs(m_copyState->m_messages->ElementAt(keyIndex)); - message = do_QueryInterface(aSupport, &rv); + nsCOMPtr message = + do_QueryElementAt(m_copyState->m_messages, keyIndex, &rv); // if the key is not there, then assume what the caller tells us to. PRBool isRead = missingAreRead; PRUint32 flags; @@ -4639,11 +4626,9 @@ void nsImapMailFolder::UpdatePendingCounts(PRBool countUnread, PRBool missingAre } else { - nsCOMPtr message; - - nsCOMPtr aSupport = - getter_AddRefs(m_copyState->m_messages->ElementAt(m_copyState->m_curIndex)); - message = do_QueryInterface(aSupport, &rv); + nsCOMPtr message = + do_QueryElementAt(m_copyState->m_messages, + m_copyState->m_curIndex, &rv); // if the key is not there, then assume what the caller tells us to. PRBool isRead = missingAreRead; PRUint32 flags; @@ -5616,10 +5601,8 @@ nsImapMailFolder::CopyNextStreamMessage(PRBool copySucceeded, nsISupports *copyS if (mailCopyState->m_curIndex < mailCopyState->m_totalCount) { - nsCOMPtr aSupport = - getter_AddRefs(mailCopyState->m_messages->ElementAt - (mailCopyState->m_curIndex)); - mailCopyState->m_message = do_QueryInterface(aSupport, + mailCopyState->m_message = do_QueryElementAt(mailCopyState->m_messages, + mailCopyState->m_curIndex, &rv); if (NS_SUCCEEDED(rv)) { @@ -5755,22 +5738,12 @@ nsImapMailFolder::CopyMessagesWithStream(nsIMsgFolder* srcFolder, NS_GET_IID(nsImapMoveCopyMsgTxn), getter_AddRefs(m_copyState->m_undoMsgTxn) ); } - nsCOMPtr msgSupport; - msgSupport = getter_AddRefs(messages->ElementAt(0)); - if (msgSupport) - { - nsCOMPtr aMessage; - aMessage = do_QueryInterface(msgSupport, &rv); - if (NS_SUCCEEDED(rv)) + nsCOMPtr aMessage; + aMessage = do_QueryElementAt(messages, 0, &rv); + if (NS_SUCCEEDED(rv)) CopyStreamMessage(aMessage, this, msgWindow, isMove); - else - return rv; //we are clearing copy state in CopyMessages on failure - } - else - { - rv = NS_ERROR_FAILURE; - } - return rv; + + return rv; //we are clearing copy state in CopyMessages on failure } nsresult nsImapMailFolder::GetClearedOriginalOp(nsIMsgOfflineImapOperation *op, nsIMsgOfflineImapOperation **originalOp, nsIMsgDatabase **originalDB) @@ -5979,11 +5952,8 @@ nsresult nsImapMailFolder::CopyMessagesOffline(nsIMsgFolder* srcFolder, nsXPIDLCString originalSrcFolderURI; if (sourceFolderURI.get()) originalSrcFolderURI.Adopt(nsCRT::strdup(sourceFolderURI.get())); - nsCOMPtr msgSupports; nsCOMPtr message; - - msgSupports = getter_AddRefs(messages->ElementAt(sourceKeyIndex)); - message = do_QueryInterface(msgSupports); + message = do_QueryElementAt(messages, sourceKeyIndex); nsMsgKey originalKey; if (message) { diff --git a/mailnews/imap/src/nsImapMoveCoalescer.cpp b/mailnews/imap/src/nsImapMoveCoalescer.cpp index 9e00a6fbf48..8ba0cd65f4b 100644 --- a/mailnews/imap/src/nsImapMoveCoalescer.cpp +++ b/mailnews/imap/src/nsImapMoveCoalescer.cpp @@ -112,8 +112,7 @@ nsresult nsImapMoveCoalescer::PlaybackMoves() m_destFolders->Count(&numFolders); for (PRUint32 i = 0; i < numFolders; i++) { - nsCOMPtr destSupports = getter_AddRefs(m_destFolders->ElementAt(i)); - nsCOMPtr destFolder(do_QueryInterface(destSupports)); + nsCOMPtr destFolder(do_QueryElementAt(m_destFolders, i)); nsCOMPtr imapService = do_GetService(kCImapService, &rv); if (NS_SUCCEEDED(rv) && imapService) diff --git a/mailnews/imap/src/nsImapUndoTxn.cpp b/mailnews/imap/src/nsImapUndoTxn.cpp index 9b34c6896c9..d0e43d2cb8f 100644 --- a/mailnews/imap/src/nsImapUndoTxn.cpp +++ b/mailnews/imap/src/nsImapUndoTxn.cpp @@ -383,11 +383,9 @@ nsImapMoveCopyMsgTxn::UndoMailboxDelete() PRUint32 i; nsCOMPtr oldHdr; nsCOMPtr newHdr; - nsCOMPtr aSupport; for (i=0; iElementAt(i)); - oldHdr = do_QueryInterface(aSupport); + oldHdr = do_QueryElementAt(m_srcHdrs, i); NS_ASSERTION(oldHdr, "fatal ... cannot get old msg header\n"); rv = srcDB->CopyHdrFromExistingHdr(m_srcKeyArray.GetAt(i), oldHdr,PR_TRUE, diff --git a/mailnews/import/src/nsImportAddressBooks.cpp b/mailnews/import/src/nsImportAddressBooks.cpp index 8be1e9e0566..fb35ca4e66c 100644 --- a/mailnews/import/src/nsImportAddressBooks.cpp +++ b/mailnews/import/src/nsImportAddressBooks.cpp @@ -507,26 +507,22 @@ NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(PRBool *_retval) if (m_pBooks) { PRUint32 count = 0; nsresult rv = m_pBooks->Count( &count); - nsISupports * pSupports; PRUint32 i; PRBool import; PRUint32 size; for (i = 0; i < count; i++) { - pSupports = m_pBooks->ElementAt( i); - if (pSupports) { - nsCOMPtr interface( dont_AddRef( pSupports)); - nsCOMPtr book( do_QueryInterface( pSupports)); - if (book) { - import = PR_FALSE; - size = 0; - rv = book->GetImport( &import); - if (import) { - rv = book->GetSize( &size); - result = PR_TRUE; - } - totalSize += size; + nsCOMPtr book = + do_QueryElementAt(m_pBooks, i); + if (book) { + import = PR_FALSE; + size = 0; + rv = book->GetImport( &import); + if (import) { + rv = book->GetSize( &size); + result = PR_TRUE; } + totalSize += size; } } @@ -860,7 +856,6 @@ PR_STATIC_CALLBACK( void) ImportAddressThread( void *stuff) PRUint32 count = 0; nsresult rv = pData->books->Count( &count); - nsISupports * pSupports; PRUint32 i; PRBool import; PRUint32 size; @@ -871,90 +866,87 @@ PR_STATIC_CALLBACK( void) ImportAddressThread( void *stuff) nsString error; for (i = 0; (i < count) && !(pData->abort); i++) { - pSupports = pData->books->ElementAt( i); - if (pSupports) { - nsCOMPtr interface( dont_AddRef( pSupports)); - nsCOMPtr book( do_QueryInterface( pSupports)); - if (book) { - import = PR_FALSE; - size = 0; - rv = book->GetImport( &import); - if (import) - rv = book->GetSize( &size); - - if (size && import) { - PRUnichar *pName; - book->GetPreferredName( &pName); - if (destDB) { - pDestDB = destDB; - } - else { - pDestDB = GetAddressBook( pName, PR_TRUE); - } + nsCOMPtr book = + do_QueryElementAt(pData->books, i); + if (book) { + import = PR_FALSE; + size = 0; + rv = book->GetImport( &import); + if (import) + rv = book->GetSize( &size); + + if (size && import) { + PRUnichar *pName; + book->GetPreferredName( &pName); + if (destDB) { + pDestDB = destDB; + } + else { + pDestDB = GetAddressBook( pName, PR_TRUE); + } - nsCOMPtr proxyAddrDatabase; - rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, - NS_GET_IID(nsIAddrDatabase), - pDestDB, - PROXY_SYNC | PROXY_ALWAYS, - getter_AddRefs(proxyAddrDatabase)); - if (NS_FAILED(rv)) - return; + nsCOMPtr proxyAddrDatabase; + rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, + NS_GET_IID(nsIAddrDatabase), + pDestDB, + PROXY_SYNC | PROXY_ALWAYS, + getter_AddRefs(proxyAddrDatabase)); + if (NS_FAILED(rv)) + return; - PRBool fatalError = PR_FALSE; - pData->currentSize = size; - if (proxyAddrDatabase) { - PRUnichar *pSuccess = nsnull; - PRUnichar *pError = nsnull; + PRBool fatalError = PR_FALSE; + pData->currentSize = size; + if (proxyAddrDatabase) { + PRUnichar *pSuccess = nsnull; + PRUnichar *pError = nsnull; - /* - if (pData->fieldMap) { - PRInt32 sz = 0; - PRInt32 mapIndex; - PRBool active; - pData->fieldMap->GetMapSize( &sz); - IMPORT_LOG1( "**** Field Map Size: %d\n", (int) sz); - for (PRInt32 i = 0; i < sz; i++) { - pData->fieldMap->GetFieldMap( i, &mapIndex); - pData->fieldMap->GetFieldActive( i, &active); - IMPORT_LOG3( "Field map #%d: index=%d, active=%d\n", (int) i, (int) mapIndex, (int) active); - } - } - */ - - rv = pData->addressImport->ImportAddressBook( book, - proxyAddrDatabase, // destination - pData->fieldMap, // fieldmap - pData->bAddrLocInput, - &pError, - &pSuccess, - &fatalError); - if (pSuccess) { - success.Append( pSuccess); - nsCRT::free( pSuccess); - } - if (pError) { - error.Append( pError); - nsCRT::free( pError); + /* + if (pData->fieldMap) { + PRInt32 sz = 0; + PRInt32 mapIndex; + PRBool active; + pData->fieldMap->GetMapSize( &sz); + IMPORT_LOG1( "**** Field Map Size: %d\n", (int) sz); + for (PRInt32 i = 0; i < sz; i++) { + pData->fieldMap->GetFieldMap( i, &mapIndex); + pData->fieldMap->GetFieldActive( i, &active); + IMPORT_LOG3( "Field map #%d: index=%d, active=%d\n", (int) i, (int) mapIndex, (int) active); } } - else { - nsImportGenericAddressBooks::ReportError( pName, &error); + */ + + rv = pData->addressImport->ImportAddressBook( book, + proxyAddrDatabase, // destination + pData->fieldMap, // fieldmap + pData->bAddrLocInput, + &pError, + &pSuccess, + &fatalError); + if (pSuccess) { + success.Append( pSuccess); + nsCRT::free( pSuccess); } + if (pError) { + error.Append( pError); + nsCRT::free( pError); + } + } + else { + nsImportGenericAddressBooks::ReportError( pName, &error); + } - nsCRT::free( pName); + nsCRT::free( pName); - pData->currentSize = 0; - pData->currentTotal += size; + pData->currentSize = 0; + pData->currentTotal += size; - if (!proxyAddrDatabase) { - proxyAddrDatabase->Close( PR_TRUE); - } + if (!proxyAddrDatabase) { + proxyAddrDatabase->Close( PR_TRUE); + } - if (fatalError) { - pData->fatalError = PR_TRUE; - break; - } + if (fatalError) { + pData->fatalError = PR_TRUE; + break; } } } diff --git a/mailnews/import/src/nsImportMail.cpp b/mailnews/import/src/nsImportMail.cpp index 2df07eab2a8..a567de98cd6 100644 --- a/mailnews/import/src/nsImportMail.cpp +++ b/mailnews/import/src/nsImportMail.cpp @@ -420,7 +420,6 @@ NS_IMETHODIMP nsImportGenericMail::WantsProgress(PRBool *_retval) PRBool result = PR_FALSE; if (m_pMailboxes) { - nsISupports * pSupports; PRUint32 i; PRBool import; PRUint32 count = 0; @@ -430,20 +429,17 @@ NS_IMETHODIMP nsImportGenericMail::WantsProgress(PRBool *_retval) rv = m_pMailboxes->Count( &count); for (i = 0; i < count; i++) { - pSupports = m_pMailboxes->ElementAt( i); - if (pSupports) { - nsCOMPtr interface( dont_AddRef( pSupports)); - nsCOMPtr box( do_QueryInterface( pSupports)); - if (box) { - import = PR_FALSE; - size = 0; - rv = box->GetImport( &import); - if (import) { - rv = box->GetSize( &size); - result = PR_TRUE; - } - totalSize += size; + nsCOMPtr box = + do_QueryElementAt(m_pMailboxes, i); + if (box) { + import = PR_FALSE; + size = 0; + rv = box->GetImport( &import); + if (import) { + rv = box->GetSize( &size); + result = PR_TRUE; } + totalSize += size; } } @@ -460,19 +456,15 @@ NS_IMETHODIMP nsImportGenericMail::WantsProgress(PRBool *_retval) void nsImportGenericMail::GetMailboxName( PRUint32 index, nsISupportsString *pStr) { if (m_pMailboxes) { - nsISupports *pSupports = m_pMailboxes->ElementAt( index); - if (pSupports) { - nsCOMPtr iFace( dont_AddRef( pSupports)); - nsCOMPtr box( do_QueryInterface( pSupports)); - if (box) { - nsXPIDLString name; - box->GetDisplayName(getter_Copies(name)); - if (!name.IsEmpty()) { - pStr->SetData(name); - } + nsCOMPtr box(do_QueryElementAt(m_pMailboxes, index)); + if (box) { + nsXPIDLString name; + box->GetDisplayName(getter_Copies(name)); + if (!name.IsEmpty()) { + pStr->SetData(name); } } - } + } } NS_IMETHODIMP nsImportGenericMail::BeginImport(nsISupportsString *successLog, nsISupportsString *errorLog, PRBool isAddrLocHome, PRBool *_retval) @@ -731,7 +723,6 @@ ImportMailThread( void *stuff) PRUint32 count = 0; rv = pData->boxes->Count( &count); - nsISupports * pSupports; PRUint32 i; PRBool import; PRUint32 size; @@ -779,132 +770,129 @@ ImportMailThread( void *stuff) // we combine both good and bad import status into one string (in var 'success'). for (i = 0; (i < count) && !(pData->abort); i++) { - pSupports = pData->boxes->ElementAt( i); - if (pSupports) { - nsCOMPtr iFace( dont_AddRef( pSupports)); - nsCOMPtr box( do_QueryInterface( pSupports)); - if (box) { - pData->currentMailbox = i; + nsCOMPtr box = + do_QueryElementAt(pData->boxes, i); + if (box) { + pData->currentMailbox = i; - import = PR_FALSE; - size = 0; - rv = box->GetImport( &import); - if (import) - rv = box->GetSize( &size); - rv = box->GetDepth( &newDepth); - if (newDepth > depth) { + import = PR_FALSE; + size = 0; + rv = box->GetImport( &import); + if (import) + rv = box->GetSize( &size); + rv = box->GetDepth( &newDepth); + if (newDepth > depth) { // OK, we are going to add a subfolder under the last/previous folder we processed, so // find this folder (stored in 'lastName') who is going to be the new parent folder. - IMPORT_LOG1( "* Finding folder for child named: %s\n", lastName.get()); - rv = curProxy->GetChildNamed( lastName.get(), getter_AddRefs( subFolder)); - if (NS_FAILED( rv)) { - nsImportGenericMail::ReportError( IMPORT_ERROR_MB_FINDCHILD, lastName.get(), &success); - pData->fatalError = PR_TRUE; - break; - } - - rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder), - subFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy)); - if (NS_FAILED( rv)) { - nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle); - pData->fatalError = PR_TRUE; - break; - } - - // Make sure this new parent folder obj has the correct subfolder list so far. - rv = curProxy->GetSubFolders(getter_AddRefs(enumerator)); - - IMPORT_LOG1( "Created proxy for new subFolder: 0x%lx\n", (long) rv); - } - else if (newDepth < depth) { - rv = NS_OK; - while ((newDepth < depth) && NS_SUCCEEDED( rv)) { - nsCOMPtr parFolder; - curProxy->GetParent( getter_AddRefs( parFolder)); - rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder), - parFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy)); - depth--; - } - if (NS_FAILED( rv)) { - nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle); - pData->fatalError = PR_TRUE; - break; - } - } - depth = newDepth; - pName = nsnull; - box->GetDisplayName( &pName); - if (pName) { - lastName = pName; - nsCRT::free( pName); - } - else - lastName.Assign(NS_LITERAL_STRING("Unknown!")); - - exists = PR_FALSE; - rv = curProxy->ContainsChildNamed( lastName.get(), &exists); - if (exists) { - nsXPIDLString subName; - curProxy->GenerateUniqueSubfolderName( lastName.get(), nsnull, getter_Copies(subName)); - if (!subName.IsEmpty()) - lastName.Assign(subName); - } - - IMPORT_LOG1( "* Creating new import folder: %s\n", lastName.get()); - - rv = curProxy->CreateSubfolder( lastName.get(),nsnull); - - IMPORT_LOG1( "New folder created, rv: 0x%lx\n", (long) rv); - if (NS_SUCCEEDED( rv)) { - rv = curProxy->GetChildNamed( lastName.get(), getter_AddRefs( subFolder)); - IMPORT_LOG1( "GetChildNamed for new folder returned rv: 0x%lx\n", (long) rv); - if (NS_SUCCEEDED( rv)) { - newFolder = do_QueryInterface( subFolder); - if (newFolder) { - newFolder->GetPath( getter_AddRefs( outBox)); - IMPORT_LOG0( "Got path for newly created folder\n"); - } - else { - IMPORT_LOG0( "Newly created folder not found\n"); - } - } - } - + IMPORT_LOG1( "* Finding folder for child named: %s\n", lastName.get()); + rv = curProxy->GetChildNamed( lastName.get(), getter_AddRefs( subFolder)); if (NS_FAILED( rv)) { - nsImportGenericMail::ReportError( IMPORT_ERROR_MB_CREATE, lastName.get(), &success); + nsImportGenericMail::ReportError( IMPORT_ERROR_MB_FINDCHILD, lastName.get(), &success); + pData->fatalError = PR_TRUE; + break; } - if (size && import && newFolder && outBox && NS_SUCCEEDED( rv)) { - PRBool fatalError = PR_FALSE; - pData->currentSize = size; - PRUnichar *pSuccess = nsnull; - PRUnichar *pError = nsnull; - rv = pData->mailImport->ImportMailbox( box, outBox, &pError, &pSuccess, &fatalError); - if (pError) { - error.Append( pError); - nsCRT::free( pError); - } - if (pSuccess) { - success.Append( pSuccess); - nsCRT::free( pSuccess); - } + rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder), + subFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy)); + if (NS_FAILED( rv)) { + nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle); + pData->fatalError = PR_TRUE; + break; + } - pData->currentSize = 0; - pData->currentTotal += size; + // Make sure this new parent folder obj has the correct subfolder list so far. + rv = curProxy->GetSubFolders(getter_AddRefs(enumerator)); + + IMPORT_LOG1( "Created proxy for new subFolder: 0x%lx\n", (long) rv); + } + else if (newDepth < depth) { + rv = NS_OK; + while ((newDepth < depth) && NS_SUCCEEDED( rv)) { + nsCOMPtr parFolder; + curProxy->GetParent( getter_AddRefs( parFolder)); + rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder), + parFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy)); + depth--; + } + if (NS_FAILED( rv)) { + nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle); + pData->fatalError = PR_TRUE; + break; + } + } + depth = newDepth; + pName = nsnull; + box->GetDisplayName( &pName); + if (pName) { + lastName = pName; + nsCRT::free( pName); + } + else + lastName.Assign(NS_LITERAL_STRING("Unknown!")); + + exists = PR_FALSE; + rv = curProxy->ContainsChildNamed( lastName.get(), &exists); + if (exists) { + nsXPIDLString subName; + curProxy->GenerateUniqueSubfolderName( lastName.get(), nsnull, getter_Copies(subName)); + if (!subName.IsEmpty()) + lastName.Assign(subName); + } + + IMPORT_LOG1( "* Creating new import folder: %s\n", lastName.get()); + + rv = curProxy->CreateSubfolder( lastName.get(),nsnull); + + IMPORT_LOG1( "New folder created, rv: 0x%lx\n", (long) rv); + if (NS_SUCCEEDED( rv)) { + rv = curProxy->GetChildNamed( lastName.get(), getter_AddRefs( subFolder)); + IMPORT_LOG1( "GetChildNamed for new folder returned rv: 0x%lx\n", (long) rv); + if (NS_SUCCEEDED( rv)) { + newFolder = do_QueryInterface( subFolder); + if (newFolder) { + newFolder->GetPath( getter_AddRefs( outBox)); + IMPORT_LOG0( "Got path for newly created folder\n"); + } + else { + IMPORT_LOG0( "Newly created folder not found\n"); + } + } + } + + if (NS_FAILED( rv)) { + nsImportGenericMail::ReportError( IMPORT_ERROR_MB_CREATE, lastName.get(), &success); + } + + if (size && import && newFolder && outBox && NS_SUCCEEDED( rv)) { + PRBool fatalError = PR_FALSE; + pData->currentSize = size; + PRUnichar *pSuccess = nsnull; + PRUnichar *pError = nsnull; + rv = pData->mailImport->ImportMailbox( box, outBox, &pError, &pSuccess, &fatalError); + if (pError) { + error.Append( pError); + nsCRT::free( pError); + } + if (pSuccess) { + success.Append( pSuccess); + nsCRT::free( pSuccess); + } + + pData->currentSize = 0; + pData->currentTotal += size; - outBox->CloseStream(); + outBox->CloseStream(); // OK, we've copied the actual folder/file over if the folder size is not 0 // (ie, the msg summary is no longer valid) so close the msg database so that // when the folder is reopened the folder db can be reconstructed (which // validates msg summary and forces folder to be reparsed). - newFolder->ForceDBClosed(); + newFolder->ForceDBClosed(); - if (fatalError) { - IMPORT_LOG1( "*** ImportMailbox returned fatalError, mailbox #%d\n", (int) i); - pData->fatalError = PR_TRUE; - break; - } + if (fatalError) { + IMPORT_LOG1( "*** ImportMailbox returned fatalError, mailbox #%d\n", (int) i); + pData->fatalError = PR_TRUE; + break; } } } diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index c2bbae8b483..7950d002154 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -519,8 +519,7 @@ nsMsgLocalMailFolder::GetSubFolders(nsIEnumerator* *result) nsCOMPtr enumerator; for (PRUint32 i=0; i< cnt;i++) { - nsCOMPtr supports = getter_AddRefs(mSubFolders->ElementAt(i)); - nsCOMPtr folder = do_QueryInterface(supports, &rv); + nsCOMPtr folder = do_QueryElementAt(mSubFolders, i, &rv); if (folder && NS_SUCCEEDED(rv)) { rv = folder->GetSubFolders(getter_AddRefs(enumerator)); @@ -1127,8 +1126,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::DeleteSubFolders( if (NS_SUCCEEDED(rv)) { // we don't allow multiple folder selection so this is ok. - nsCOMPtr folder; - folders->QueryElementAt(0, NS_GET_IID(nsIMsgFolder), (void **) getter_AddRefs(folder)); + nsCOMPtr folder = do_QueryElementAt(folders, 0); if (folder) trashFolder->CopyFolder(folder, PR_TRUE, msgWindow, nsnull); } @@ -2290,9 +2288,8 @@ nsresult nsMsgLocalMailFolder::WriteStartOfNewMessage() nsresult rv; nsCOMPtr curSourceMessage; - nsCOMPtr aSupport = - getter_AddRefs(mCopyState->m_messages->ElementAt(mCopyState->m_curCopyIndex)); - curSourceMessage = do_QueryInterface(aSupport, &rv); + curSourceMessage = do_QueryElementAt(mCopyState->m_messages, + mCopyState->m_curCopyIndex, &rv); char statusStrBuf[50]; if (curSourceMessage) @@ -2825,17 +2822,12 @@ nsresult nsMsgLocalMailFolder::CopyMessagesTo(nsISupportsArray *messages, messages->Count(&numMessages); for (PRUint32 i = 0; i < numMessages; i++) { - nsCOMPtr msgSupport; - msgSupport = getter_AddRefs(messages->ElementAt(i)); - if (msgSupport) + nsCOMPtr aMessage = do_QueryElementAt(messages, i, &rv); + if(NS_SUCCEEDED(rv) && aMessage) { - nsCOMPtr aMessage = do_QueryInterface(msgSupport, &rv); - if(NS_SUCCEEDED(rv) && aMessage) - { - nsMsgKey key; - aMessage->GetMessageKey(&key); - keyArray.Add(key); - } + nsMsgKey key; + aMessage->GetMessageKey(&key); + keyArray.Add(key); } } keyArray.QuickSort(); @@ -2980,10 +2972,7 @@ nsMsgLocalMailFolder::MarkMsgsOnPop3Server(nsISupportsArray *messages, PRBool de { /* get uidl for this message */ uidl = nsnull; - nsCOMPtr aSupport = - getter_AddRefs(messages->ElementAt(i)); - - nsCOMPtr msgDBHdr (do_QueryInterface(aSupport, &rv)); + nsCOMPtr msgDBHdr (do_QueryElementAt(messages, i, &rv)); PRUint32 flags = 0; diff --git a/mailnews/local/src/nsMailboxUrl.cpp b/mailnews/local/src/nsMailboxUrl.cpp index 071df16ae60..c171a0da965 100644 --- a/mailnews/local/src/nsMailboxUrl.cpp +++ b/mailnews/local/src/nsMailboxUrl.cpp @@ -97,10 +97,7 @@ static char *nsMailboxGetURI(const char *nativepath) PRInt32 i; for (i=0; iElementAt(i); - nsCOMPtr server = - do_QueryInterface(serverSupports); - NS_RELEASE(serverSupports); + nsCOMPtr server = do_QueryElementAt(serverArray, i); if (!server) continue; diff --git a/mailnews/news/src/nsNewsDownloader.cpp b/mailnews/news/src/nsNewsDownloader.cpp index 42a08f0d200..ec97598c2f8 100644 --- a/mailnews/news/src/nsNewsDownloader.cpp +++ b/mailnews/news/src/nsNewsDownloader.cpp @@ -431,10 +431,9 @@ nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer(PRBool *done) while (serverIndex < numServers) { - nsCOMPtr serverSupports = getter_AddRefs(m_allServers->ElementAt(serverIndex)); + nsCOMPtr server = do_QueryElementAt(m_allServers, serverIndex); serverIndex++; - nsCOMPtr server = do_QueryInterface(serverSupports); nsCOMPtr newsServer = do_QueryInterface(server); if (!newsServer) // we're only looking for news servers continue; diff --git a/mailnews/news/src/nsNewsFolder.cpp b/mailnews/news/src/nsNewsFolder.cpp index 648bae5f563..b9cb1316363 100644 --- a/mailnews/news/src/nsNewsFolder.cpp +++ b/mailnews/news/src/nsNewsFolder.cpp @@ -950,8 +950,7 @@ nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages, nsIMsgWindow *aMsgWi nsCOMPtr nntpService = do_GetService(NS_NNTPSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr msgSupports = getter_AddRefs(messages->ElementAt(0)); - nsCOMPtr msgHdr(do_QueryInterface(msgSupports)); + nsCOMPtr msgHdr(do_QueryElementAt(messages, 0)); // for cancel, we need to // turn "newsmessage://sspitzer@news.mozilla.org/netscape.test#5428" @@ -1704,16 +1703,14 @@ NS_IMETHODIMP nsMsgNewsFolder::DownloadMessagesForOffline(nsISupportsArray *mess SetSaveArticleOffline(PR_TRUE); // ### TODO need to clear this when we've finished PRUint32 count = 0; PRUint32 i; - nsCOMPtr msgSupports; nsresult rv = messages->Count(&count); NS_ENSURE_SUCCESS(rv, rv); // build up message keys. for (i = 0; i < count; i++) { - msgSupports = getter_AddRefs(messages->ElementAt(i)); nsMsgKey key; - nsCOMPtr msgDBHdr = do_QueryInterface(msgSupports, &rv); + nsCOMPtr msgDBHdr = do_QueryElementAt(messages, i, &rv); if (msgDBHdr) rv = msgDBHdr->GetMessageKey(&key); if (NS_SUCCEEDED(rv)) diff --git a/mailnews/news/src/nsNntpIncomingServer.cpp b/mailnews/news/src/nsNntpIncomingServer.cpp index cd5accf4a13..f748031f39e 100644 --- a/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mailnews/news/src/nsNntpIncomingServer.cpp @@ -438,7 +438,6 @@ nsNntpIncomingServer::CloseCachedConnections() { nsresult rv; PRUint32 cnt; - nsCOMPtr aSupport; nsCOMPtr connection; // iterate through the connection cache and close the connections. @@ -448,8 +447,7 @@ nsNntpIncomingServer::CloseCachedConnections() if (NS_FAILED(rv)) return rv; for (PRUint32 i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(0)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, 0); if (connection) { rv = connection->CloseConnection(); @@ -547,7 +545,6 @@ nsNntpIncomingServer::GetNntpConnection(nsIURI * aUri, nsIMsgWindow *aMsgWindow, *aNntpConnection = nsnull; // iterate through the connection cache for a connection that can handle this url. PRUint32 cnt; - nsCOMPtr aSupport; rv = m_connectionCache->Count(&cnt); if (NS_FAILED(rv)) return rv; @@ -556,8 +553,7 @@ nsNntpIncomingServer::GetNntpConnection(nsIURI * aUri, nsIMsgWindow *aMsgWindow, #endif for (PRUint32 i = 0; i < cnt && isBusy; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); - connection = do_QueryInterface(aSupport); + connection = do_QueryElementAt(m_connectionCache, i); if (connection) rv = connection->GetIsBusy(&isBusy); if (NS_FAILED(rv))