From 61ac19e99306c339132541df0e7cae522b17be42 Mon Sep 17 00:00:00 2001 From: "rhp%netscape.com" Date: Thu, 22 Jul 1999 21:35:58 +0000 Subject: [PATCH] Fix for send later operations --- mailnews/compose/src/nsMsgSendLater.cpp | 47 +++++++++++++++++++------ mailnews/compose/src/nsMsgSendLater.h | 17 +++++---- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/mailnews/compose/src/nsMsgSendLater.cpp b/mailnews/compose/src/nsMsgSendLater.cpp index 2d25f82e04eb..3a40380b0a6a 100644 --- a/mailnews/compose/src/nsMsgSendLater.cpp +++ b/mailnews/compose/src/nsMsgSendLater.cpp @@ -118,12 +118,9 @@ nsMsgSendLater::nsMsgSendLater() nsMsgSendLater::~nsMsgSendLater() { - if (mEnumerator) - NS_RELEASE(mEnumerator); - if (mTempIFileSpec) - NS_RELEASE(mTempIFileSpec); - if (mSaveListener) - NS_RELEASE(mSaveListener); + NS_IF_RELEASE(mEnumerator); + NS_IF_RELEASE(mTempIFileSpec); + NS_IF_RELEASE(mSaveListener); PR_FREEIF(m_to); PR_FREEIF(m_fcc); PR_FREEIF(m_bcc); @@ -289,7 +286,12 @@ SaveMessageCompleteCallback(nsIURI *aUrl, nsresult aExitCode, void *tagData) // If the send operation failed..try the next one... if (NS_FAILED(rv)) + { rv = ptr->StartNextMailFileSend(); + if (NS_FAILED(rv)) + ptr->NotifyListenersOnStopSending(rv, nsnull, ptr->mTotalSendCount, + ptr->mTotalSentSuccessfully); + } NS_RELEASE(ptr); } @@ -300,6 +302,9 @@ SaveMessageCompleteCallback(nsIURI *aUrl, nsresult aExitCode, void *tagData) // Save failed, but we will still keep trying to send the rest... rv = ptr->StartNextMailFileSend(); + if (NS_FAILED(rv)) + ptr->NotifyListenersOnStopSending(rv, nsnull, ptr->mTotalSendCount, + ptr->mTotalSentSuccessfully); NS_RELEASE(ptr); } } @@ -382,7 +387,22 @@ SendOperationListener::OnStopSending(const char *aMsgID, nsresult aStatus, const prefs->GetBoolPref("mail.really_delete_unsent_messages", &deleteMsgs); if (deleteMsgs) + { mSendLater->DeleteCurrentMessage(); + // + // Since we are deleting entries from the enumeration set, we need to + // refresh the enumerator + // + NS_IF_RELEASE(mSendLater->mEnumerator); + mSendLater->mEnumerator = nsnull; + + nsresult ret = mSendLater->mMessageFolder->GetMessages(&(mSendLater->mEnumerator)); + if (NS_FAILED(ret) || (!(mSendLater->mEnumerator))) + mSendLater->mEnumerator = nsnull; // just to be sure! + + // Do the first call next time through! + mSendLater->mFirstTime = PR_TRUE; + } ++(mSendLater->mTotalSentSuccessfully); } @@ -394,6 +414,9 @@ SendOperationListener::OnStopSending(const char *aMsgID, nsresult aStatus, const // Regardless, we will still keep trying to send the rest... rv = mSendLater->StartNextMailFileSend(); + if (NS_FAILED(rv)) + mSendLater->NotifyListenersOnStopSending(rv, nsnull, mSendLater->mTotalSendCount, + mSendLater->mTotalSentSuccessfully); NS_RELEASE(mSendLater); } @@ -519,18 +542,22 @@ nsMsgSendLater::StartNextMailFileSend() char *aMessageURI = nsnull; // - // First, go to the next entry and check where we are in the + // Now, go to the next entry and check where we are in the // enumerator! // if (mFirstTime) { mFirstTime = PR_FALSE; - mEnumerator->First(); + if (mEnumerator) + mEnumerator->First(); } else - mEnumerator->Next(); + { + if (mEnumerator) + mEnumerator->Next(); + } - if (mEnumerator->IsDone() == NS_OK) + if ( (!mEnumerator) || (mEnumerator->IsDone() == NS_OK) ) { // Call any listeners on this operation and then exit cleanly #ifdef NS_DEBUG diff --git a/mailnews/compose/src/nsMsgSendLater.h b/mailnews/compose/src/nsMsgSendLater.h index 48b8c8e4876a..00e700eda0d6 100644 --- a/mailnews/compose/src/nsMsgSendLater.h +++ b/mailnews/compose/src/nsMsgSendLater.h @@ -102,10 +102,6 @@ public: // nsresult DriveFakeStream(nsIOutputStream *stream); - // counters - PRUint32 mTotalSentSuccessfully; - PRUint32 mTotalSendCount; - // methods for listener array processing... NS_IMETHOD SetListenerArray(nsIMsgSendLaterListener **aListener); NS_IMETHOD AddListener(nsIMsgSendLaterListener *aListener); @@ -117,6 +113,14 @@ public: NS_IMETHOD NotifyListenersOnStopSending(nsresult aStatus, const PRUnichar *aMsg, PRUint32 aTotalTried, PRUint32 aSuccessful); + // counters and things for enumeration + PRUint32 mTotalSentSuccessfully; + PRUint32 mTotalSendCount; + nsIEnumerator *mEnumerator; + nsIMsgIdentity *mIdentity; + nsCOMPtr mMessageFolder; + PRBool mFirstTime; + // Private Information private: nsIMsgSendLaterListener **mListenerArray; @@ -125,8 +129,6 @@ private: nsMsgSendUnsentMessagesCallback mCompleteCallback; SendOperationListener *mSendListener; - nsIMsgIdentity *mIdentity; - nsCOMPtr mMessageFolder; nsCOMPtr mMessage; // RICHIE @@ -142,9 +144,6 @@ private: nsIFileSpec *mTempIFileSpec; nsOutputFileStream *mOutFile; - nsIEnumerator *mEnumerator; - PRBool mFirstTime; - void *mTagData; nsMsgDeliveryListener *mSaveListener;