Part of
bug 440794, when sending in background fix sending more than one email in the same session. r/sr=bienvenu
--- a/mailnews/compose/src/nsMsgSendLater.cpp
+++ b/mailnews/compose/src/nsMsgSendLater.cpp
@@ -72,16 +72,17 @@ NS_IMPL_ISUPPORTS6(nsMsgSendLater,
nsIRequestObserver,
nsIStreamListener,
nsIObserver,
nsIMsgShutdownTask)
nsMsgSendLater::nsMsgSendLater()
{
mSendingMessages = PR_FALSE;
+ mTimerSet = PR_FALSE;
mTotalSentSuccessfully = 0;
mTotalSendCount = 0;
mLeftoverBuffer = nsnull;
m_to = nsnull;
m_bcc = nsnull;
m_fcc = nsnull;
m_newsgroups = nsnull;
@@ -153,16 +154,17 @@ nsMsgSendLater::Init()
NS_IMETHODIMP
nsMsgSendLater::Observe(nsISupports *aSubject, const char* aTopic,
const PRUnichar *aData)
{
if (aSubject == mTimer && !strcmp(aTopic, "timer-callback"))
{
mTimer->Cancel();
+ mTimerSet = PR_FALSE;
// If we've already started a send since the timer fired, don't start
// another
if (!mSendingMessages)
InternalSendMessages(PR_FALSE, nsnull);
}
else if (!strcmp(aTopic, "quit-application"))
{
// We're shutting down. Unsubscribe from the unsentFolder notifications
@@ -1336,17 +1338,17 @@ nsMsgSendLater::GetIdentityFromKey(const
NS_ENSURE_SUCCESS(rv,rv);
return rv;
}
NS_IMETHODIMP
nsMsgSendLater::OnItemAdded(nsIMsgFolder *aParentItem, nsISupports *aItem)
{
// No need to trigger if timer is already set
- if (mTimer)
+ if (mTimerSet)
return NS_OK;
// XXX only trigger for non-queued headers
// Items from this function return NS_OK because the callee won't care about
// the result anyway.
nsresult rv;
if (!mTimer)
@@ -1354,16 +1356,18 @@ nsMsgSendLater::OnItemAdded(nsIMsgFolder
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
}
rv = mTimer->Init(static_cast<nsIObserver*>(this), kInitialMessageSendTime,
nsITimer::TYPE_ONE_SHOT);
NS_ENSURE_SUCCESS(rv, NS_OK);
+ mTimerSet = PR_TRUE;
+
return NS_OK;
}
NS_IMETHODIMP
nsMsgSendLater::OnItemRemoved(nsIMsgFolder *aParentItem, nsISupports *aItem)
{
return NS_OK;
}
--- a/mailnews/compose/src/nsMsgSendLater.h
+++ b/mailnews/compose/src/nsMsgSendLater.h
@@ -118,18 +118,19 @@ public:
// Private Information
private:
nsresult GetIdentityFromKey(const char *aKey, nsIMsgIdentity **aIdentity);
nsresult InternalSendMessages(PRBool aUserInitiated,
nsIMsgIdentity *aIdentity);
nsTObserverArray<nsCOMPtr<nsIMsgSendLaterListener> > mListenerArray;
- nsCOMPtr<nsIMsgDBHdr> mMessage;
+ nsCOMPtr<nsIMsgDBHdr> mMessage;
nsCOMPtr<nsITimer> mTimer;
+ PRBool mTimerSet;
nsCOMPtr<nsIUrlListener> mShutdownListener;
//
// File output stuff...
//
nsCOMPtr<nsIFile> mTempFile;
nsCOMPtr<nsIOutputStream> mOutFile;