Fix for bug 66647. Add a way to cancel a smtp process. mscott wrote the protocole part of this fix. R=ducarroz, R=varada, SR=ssptizer

git-svn-id: svn://10.0.0.236/trunk@100825 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ducarroz%netscape.com
2001-08-10 22:23:47 +00:00
parent a641af8378
commit 07620bd845
7 changed files with 56 additions and 13 deletions

View File

@@ -877,6 +877,17 @@ nsMsgAsyncWriteProtocol::nsMsgAsyncWriteProtocol(nsIURI * aURL) : nsMsgProtocol(
nsMsgAsyncWriteProtocol::~nsMsgAsyncWriteProtocol()
{}
NS_IMETHODIMP nsMsgAsyncWriteProtocol::Cancel(nsresult status)
{
if (m_request)
m_request->Cancel(status);
if (m_WriteRequest)
m_WriteRequest->Cancel(status);
return NS_OK;
}
nsresult nsMsgAsyncWriteProtocol::PostMessage(nsIURI* url, nsIFileSpec *fileSpec)
{
// convert the file spec into a nsIFile....

View File

@@ -47,7 +47,8 @@ class nsFileSpec;
class nsOutputFileStream;
%}
interface nsIURI;
interface nsIURI;
interface nsIRequest;
interface nsIMsgDBHdr;
interface nsIMsgHdr;
interface nsIDocShell;
@@ -233,6 +234,8 @@ interface nsIMsgSend : nsISupports
[noscript] nsOutputFileStream getOutputStream();
[noscript] attribute nsIRequest runningRequest;
[noscript] attribute nsresult status;
};

View File

@@ -30,6 +30,7 @@ interface nsIMsgIdentity;
interface nsIInterfaceRequestor;
interface nsIFileSpec;
interface nsIMsgStatusFeedback;
interface nsIRequest;
[scriptable, uuid(FBAF0F10-CA9B-11d2-8063-006008128C4E)]
interface nsISmtpService : nsISupports {
@@ -58,7 +59,8 @@ interface nsISmtpService : nsISupports {
in nsISmtpServer aServer,
in nsIMsgStatusFeedback aStatusListener,
in nsIInterfaceRequestor aNotificationCallbacks,
out nsIURI aURL);
out nsIURI aURL,
out nsIRequest aRequest);
/**
* A copy of the array of SMTP servers, as stored in the preferences

View File

@@ -82,12 +82,10 @@ Contributor(s):
</rows>
</grid>
<!-- remove the cancel button until we finish the backend code
<hbox id="CancelButton">
<spring flex="1"/>
<button class="dialog" id="cancel" label="&dialogCancel.label;" oncommand="doCancelButton()"/>
<spring flex="1"/>
</hbox>
-->
</window>

View File

@@ -74,6 +74,7 @@
#include "nsISmtpUrl.h"
#include "nsIInterfaceRequestor.h"
#include "nsIDocumentEncoder.h" // for editor output flags
#include "nsILoadGroup.h"
// use these macros to define a class IID for our component. Our object currently
@@ -2780,7 +2781,7 @@ SendDeliveryCallback(nsIURI *aUrl, nsresult aExitCode, nsMsgDeliveryType deliver
aExitCode = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER;
break;
default:
if (! NS_IS_MSG_ERROR(aExitCode))
if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode))
aExitCode = NS_ERROR_SEND_FAILED;
break;
}
@@ -2790,11 +2791,13 @@ SendDeliveryCallback(nsIURI *aUrl, nsresult aExitCode, nsMsgDeliveryType deliver
else if (deliveryType == nsNewsDelivery)
{
if (NS_FAILED(aExitCode))
if (! NS_IS_MSG_ERROR(aExitCode))
if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode))
aExitCode = NS_ERROR_SEND_FAILED;
msgSend->DeliverAsNewsExit(aUrl, aExitCode);
}
msgSend->SetRunningRequest(nsnull);
}
return aExitCode;
@@ -3025,7 +3028,7 @@ nsMsgComposeAndSend::DeliverFileAsMail()
rv = smtpService->SendMailMessage(aFileSpec, buf, mUserIdentity,
uriListener, nsnull, msgStatus,
callbacks, nsnull);
callbacks, nsnull, getter_AddRefs(mRunningRequest));
}
PR_FREEIF(buf); // free the buf because we are done with it....
@@ -3081,7 +3084,8 @@ nsMsgComposeAndSend::DeliverFileAsNews()
if (!msgWindow) return NS_ERROR_FAILURE;
rv = nntpService->PostMessage(fileToPost, mCompFields->GetNewsgroups(), mCompFields->GetNewspostUrl(), uriListener, msgWindow, nsnull);
rv = nntpService->PostMessage(fileToPost, mCompFields->GetNewsgroups(), mCompFields->GetNewspostUrl(),
uriListener, msgWindow, nsnull);
if (NS_FAILED(rv)) return rv;
}
@@ -4223,6 +4227,13 @@ nsresult nsMsgComposeAndSend::Abort()
rv = ma->Abort();
}
}
/* stop the current running url */
if (mRunningRequest)
{
mRunningRequest->Cancel(NS_ERROR_ABORT);
mRunningRequest = nsnull;
}
mAbortInProcess = PR_FALSE;
return NS_OK;
@@ -4277,6 +4288,21 @@ NS_IMETHODIMP nsMsgComposeAndSend::GetOutputStream(nsOutputFileStream * *_retval
}
/* [noscript] attribute nsIURI runningURL; */
NS_IMETHODIMP nsMsgComposeAndSend::GetRunningRequest(nsIRequest **request)
{
NS_ENSURE_ARG(request);
*request = mRunningRequest;
NS_IF_ADDREF(*request);
return NS_OK;
}
NS_IMETHODIMP nsMsgComposeAndSend::SetRunningRequest(nsIRequest *request)
{
mRunningRequest = request;
return NS_OK;
}
NS_IMETHODIMP nsMsgComposeAndSend::GetStatus(nsresult *aStatus)
{
NS_ENSURE_ARG(aStatus);

View File

@@ -292,6 +292,7 @@ public:
nsCOMPtr<nsIMsgProgress> mSendProgress;
nsCOMPtr<nsIMsgSendListener> mListener;
nsCOMPtr<nsIRequest> mRunningRequest;
PRBool mSendMailAlso;
nsIFileSpec *mReturnFileSpec; // a holder for file spec's to be returned to caller

View File

@@ -71,7 +71,7 @@ NS_MsgBuildSmtpUrl(nsIFileSpec * aFilePath,
nsIInterfaceRequestor* aNotificationCallbacks,
nsIURI ** aUrl);
nsresult NS_MsgLoadSmtpUrl(nsIURI * aUrl, nsISupports * aConsumer);
nsresult NS_MsgLoadSmtpUrl(nsIURI * aUrl, nsISupports * aConsumer, nsIRequest ** aRequest);
nsSmtpService::nsSmtpService() :
mSmtpServersLoaded(PR_FALSE)
@@ -96,7 +96,8 @@ nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath,
nsISmtpServer * aServer,
nsIMsgStatusFeedback *aStatusFeedback,
nsIInterfaceRequestor* aNotificationCallbacks,
nsIURI ** aURL)
nsIURI ** aURL,
nsIRequest ** aRequest)
{
nsIURI * urlToRun = nsnull;
nsresult rv = NS_OK;
@@ -134,7 +135,7 @@ nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath,
nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(urlToRun, &rv);
if (NS_SUCCEEDED(rv))
smtpUrl->SetSmtpServer(smtpServer);
rv = NS_MsgLoadSmtpUrl(urlToRun, nsnull);
rv = NS_MsgLoadSmtpUrl(urlToRun, nsnull, aRequest);
}
if (aURL) // does the caller want a handle on the url?
@@ -218,7 +219,7 @@ nsresult NS_MsgBuildSmtpUrl(nsIFileSpec * aFilePath,
return rv;
}
nsresult NS_MsgLoadSmtpUrl(nsIURI * aUrl, nsISupports * aConsumer)
nsresult NS_MsgLoadSmtpUrl(nsIURI * aUrl, nsISupports * aConsumer, nsIRequest ** aRequest)
{
// for now, assume the url is a news url and load it....
nsCOMPtr <nsISmtpUrl> smtpUrl;
@@ -232,13 +233,14 @@ nsresult NS_MsgLoadSmtpUrl(nsIURI * aUrl, nsISupports * aConsumer)
smtpUrl = do_QueryInterface(aUrl);
if (smtpUrl)
{
// almost there...now create a nntp protocol instance to run the url in...
// almost there...now create a smtp protocol instance to run the url in...
smtpProtocol = new nsSmtpProtocol(aUrl);
if (smtpProtocol == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(smtpProtocol);
rv = smtpProtocol->LoadUrl(aUrl, aConsumer); // protocol will get destroyed when url is completed...
smtpProtocol->QueryInterface(NS_GET_IID(nsIRequest), (void **) aRequest);
NS_RELEASE(smtpProtocol);
}