Bug 476628 Switch nsMsgSendLater from nsISupportsArray to nsCOMArray. r/sr=Neil
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 03 Feb 2009 13:59:12 +0000
changeset 1841 896a340449d2487ea4a27e2102b3a45d12dc1ea1
parent 1840 1791f2d1a2b85ca11abce0169f8e4a9b6b779707
child 1842 4cf8dffa24c73019d7fbd618712b6fad3d3edf00
push idunknown
push userunknown
push dateunknown
bugs476628
Bug 476628 Switch nsMsgSendLater from nsISupportsArray to nsCOMArray. r/sr=Neil
mailnews/compose/src/nsMsgSendLater.cpp
mailnews/compose/src/nsMsgSendLater.h
--- a/mailnews/compose/src/nsMsgSendLater.cpp
+++ b/mailnews/compose/src/nsMsgSendLater.cpp
@@ -52,16 +52,17 @@
 #include "nsIChannel.h"
 #include "nsNetUtil.h"
 #include "prlog.h"
 #include "prmem.h"
 #include "nsIMimeConverter.h"
 #include "nsMsgMimeCID.h"
 #include "nsComposeStrings.h"
 #include "nsIMutableArray.h"
+#include "nsArrayEnumerator.h"
 
 NS_IMPL_ISUPPORTS3(nsMsgSendLater,
                    nsIMsgSendLater,
                    nsIRequestObserver,
                    nsIStreamListener)
 
 nsMsgSendLater::nsMsgSendLater()
 {
@@ -83,18 +84,16 @@ nsMsgSendLater::nsMsgSendLater()
 
   m_bytesRead = 0;
   m_position = 0;
   m_flagsPosition = 0;
   m_headersSize = 0;
 
   mIdentityKey = nsnull;
   mAccountKey = nsnull;
-
-  NS_NewISupportsArray(getter_AddRefs(mMessagesToSend));
 }
 
 nsMsgSendLater::~nsMsgSendLater()
 {
   PR_Free(m_to);
   PR_Free(m_fcc);
   PR_Free(m_bcc);
   PR_Free(m_newsgroups);
@@ -546,51 +545,53 @@ nsMsgSendLater::CompleteMailFileSend()
 }
 
 nsresult
 nsMsgSendLater::StartNextMailFileSend()
 {
   nsresult      rv = NS_OK;
   nsCString  messageURI;
 
-  if ( (!mEnumerator) || (mEnumerator->IsDone() == NS_OK) )
+  PRBool hasMoreElements = PR_FALSE;
+  if ((!mEnumerator) ||
+      NS_FAILED(mEnumerator->HasMoreElements(&hasMoreElements)) ||
+      !hasMoreElements)
   {
     // Call any listeners on this operation and then exit cleanly
 #ifdef NS_DEBUG
     printf("nsMsgSendLater: Finished \"Send Later\" operation.\n");
 #endif
 
-    mMessagesToSend->Clear(); // clear out our array
+    mMessagesToSend.Clear();
     mSendingMessages = PR_FALSE;
     NotifyListenersOnStopSending(NS_OK, nsnull, mTotalSendCount, mTotalSentSuccessfully);
     // XXX Should we be releasing references so that we don't hold onto items
     // unnecessarily.
     return NS_OK;
   }
 
-  nsCOMPtr<nsISupports>   currentItem;
-  mEnumerator->CurrentItem(getter_AddRefs(currentItem));
-  // advance to the next item for the next pass.
-  mEnumerator->Next();
+  nsCOMPtr<nsISupports> currentItem;
+  rv = mEnumerator->GetNext(getter_AddRefs(currentItem));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   mMessage = do_QueryInterface(currentItem); 
-  if(!mMessage)
+  if (!mMessage)
     return NS_ERROR_NOT_AVAILABLE;
 
   nsCOMPtr<nsIMsgDBHdr>  myRDFNode ;
   myRDFNode = do_QueryInterface(mMessage, &rv);
   if(NS_FAILED(rv) || (!myRDFNode))
     return NS_ERROR_NOT_AVAILABLE;
 
   mMessageFolder->GetUriForMsg(mMessage, messageURI);
 
   rv = nsMsgCreateTempFile("nsqmail.tmp", getter_AddRefs(mTempFile)); 
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr <nsIMsgMessageService> messageService;
+  nsCOMPtr<nsIMsgMessageService> messageService;
   rv = GetMessageServiceFromURI(messageURI, getter_AddRefs(messageService));
   if (NS_FAILED(rv) && !messageService)
     return NS_ERROR_FACTORY_NOT_LOADED;
 
   ++mTotalSendCount;
 
   // Setup what we need to parse the data stream correctly
   m_inhead = PR_TRUE;
@@ -669,36 +670,38 @@ nsMsgSendLater::SendUnsentMessages(nsIMs
 
   // ### fix me - if we need to reparse the folder, this will be asynchronous
   nsCOMPtr<nsISimpleEnumerator> enumerator;
   rv = mMessageFolder->GetMessages(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // copy all the elements in the enumerator into our isupports array....
 
-  nsCOMPtr<nsISupports>   currentItem;
+  nsCOMPtr<nsISupports> currentItem;
+  nsCOMPtr<nsIMsgDBHdr> messageHeader;
   PRBool hasMoreElements = PR_FALSE;
   while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreElements)) && hasMoreElements)
   {
     rv = enumerator->GetNext(getter_AddRefs(currentItem));
-    if (NS_SUCCEEDED(rv) && currentItem)
-      mMessagesToSend->AppendElement(currentItem);
+    if (NS_SUCCEEDED(rv))
+    {
+      messageHeader = do_QueryInterface(currentItem, &rv);
+      if (NS_SUCCEEDED(rv))
+        mMessagesToSend.AppendObject(messageHeader);
+    }
   }
 
   // now get an enumerator for our array
-  mMessagesToSend->Enumerate(getter_AddRefs(mEnumerator));
+  rv = NS_NewArrayEnumerator(getter_AddRefs(mEnumerator), mMessagesToSend);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   mSendingMessages = PR_TRUE;
 
   // Notify the listeners that we are starting a send.
-  PRUint32 count;
-  rv = mMessagesToSend->Count(&count);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NotifyListenersOnStartSending(count);
+  NotifyListenersOnStartSending(mMessagesToSend.Count());
 
   return StartNextMailFileSend();
 }
 
 nsresult nsMsgSendLater::SetOrigMsgDisposition()
 {
   // We're finished sending a queued message. We need to look at mMessage 
   // and see if we need to set replied/forwarded
--- a/mailnews/compose/src/nsMsgSendLater.h
+++ b/mailnews/compose/src/nsMsgSendLater.h
@@ -35,18 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _nsMsgSendLater_H_
 #define _nsMsgSendLater_H_
 
 #include "nsIMsgSendLater.h"
 
-#include "nsIEnumerator.h"
-#include "nsISupportsArray.h"
+#include "nsCOMArray.h"
 #include "nsIMsgFolder.h"
 #include "nsIMsgSendListener.h"
 #include "nsIMsgSendLaterListener.h"
 #include "nsIMsgSendLater.h"
 #include "nsIMsgWindow.h"
 #include "nsTObserverArray.h"
 
 ////////////////////////////////////////////////////////////////////////////////////
@@ -109,18 +108,18 @@ public:
                                  PRUint32 aTotalMessage);
   void NotifyListenersOnStatus(const PRUnichar *aMsg);
   void NotifyListenersOnStopSending(nsresult aStatus, const PRUnichar *aMsg, 
                                     PRUint32 aTotalTried, PRUint32 aSuccessful);
 
   // counters and things for enumeration 
   PRUint32                  mTotalSentSuccessfully;
   PRUint32                  mTotalSendCount;
-  nsCOMPtr<nsISupportsArray> mMessagesToSend;
-  nsCOMPtr<nsIEnumerator> mEnumerator;
+  nsCOMArray<nsIMsgDBHdr> mMessagesToSend;
+  nsCOMPtr<nsISimpleEnumerator> mEnumerator;
   nsCOMPtr<nsIMsgFolder>    mMessageFolder;
   nsCOMPtr<nsIMsgWindow>    m_window;
  
   // Private Information
 private:
   nsresult GetIdentityFromKey(const char *aKey, nsIMsgIdentity **aIdentity);
 
   nsTObserverArray<nsCOMPtr<nsIMsgSendLaterListener> > mListenerArray;