Bug #7811 --> nsISmtpService is now expressed in idl and several of the interfaces changed.

This commit is contained in:
mscott%netscape.com 1999-08-27 21:12:46 +00:00
parent ad166748ef
commit 763631d74d
3 changed files with 27 additions and 56 deletions

View File

@ -15,9 +15,9 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "msgCore.h"
#include "nsCRT.h"
#include "rosetta_mailnews.h"
#include "nsMsgLocalFolderHdrs.h"
#include "nsMsgSendPart.h"
@ -54,15 +54,17 @@
#include "nsIMIMEService.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsMsgCompCID.h"
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
// use these macros to define a class IID for our component. Our object currently
// supports two interfaces (nsISupports and nsIMsgCompose) so we want to define constants
// for these two interfaces
//
static NS_DEFINE_IID(kIMsgSend, NS_IMSGSEND_IID);
static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID);
static NS_DEFINE_CID(kNntpServiceCID, NS_NNTPSERVICE_CID);
static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kMimeURLUtilsCID, NS_IMIME_URLUTILS_CID);
static NS_DEFINE_CID(kMimeServiceCID, NS_MIMESERVICE_CID);
@ -123,7 +125,7 @@ nsresult NS_NewMsgSend(const nsIID &aIID, void ** aInstancePtrResult)
{
nsMsgComposeAndSend *pSend = new nsMsgComposeAndSend();
if (pSend)
return pSend->QueryInterface(kIMsgSend, aInstancePtrResult);
return pSend->QueryInterface(NS_GET_IID(nsIMsgSend), aInstancePtrResult);
else
return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
}
@ -132,7 +134,7 @@ nsresult NS_NewMsgSend(const nsIID &aIID, void ** aInstancePtrResult)
}
/* the following macro actually implement addref, release and query interface for our component. */
NS_IMPL_ISUPPORTS(nsMsgComposeAndSend, nsCOMTypeInfo<nsIMsgSend>::GetIID());
NS_IMPL_ISUPPORTS(nsMsgComposeAndSend, NS_GET_IID(nsIMsgSend));
nsMsgComposeAndSend::nsMsgComposeAndSend() :
m_messageKey(0xffffffff)
@ -2489,9 +2491,10 @@ nsMsgComposeAndSend::DeliverFileAsMail()
// Note: Don't do a SetMsgComposeAndSendObject since we are in the same thread, and
// using callbacks for notification
//
nsFilePath filePath(*mTempFileSpec);
AddRef();
rv = smtpService->SendMailMessage(filePath, buf, mSendListener, nsnull, nsnull);
NS_ADDREF_THIS();
nsCOMPtr<nsIFileSpec> aFileSpec;
NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(aFileSpec));
rv = smtpService->SendMailMessage(aFileSpec, buf, mSendListener, nsnull, nsnull);
}
PR_FREEIF(buf); // free the buf because we are done with it....
@ -2521,6 +2524,7 @@ nsMsgComposeAndSend::DeliverFileAsNews()
// using callbacks for notification
//
nsFilePath filePath (*mTempFileSpec);
NS_ADDREF_THIS();
AddRef();
rv = nntpService->PostMessage(filePath, mCompFields->GetNewsgroups(), mSendListener, nsnull);
}

View File

@ -17,9 +17,7 @@
*/
#include "msgCore.h" // precompiled header...
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsSmtpService.h"
#include "nsIMsgMailSession.h"
#include "nsIMsgIdentity.h"
@ -28,16 +26,17 @@
#include "nsSmtpUrl.h"
#include "nsSmtpProtocol.h"
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
static NS_DEFINE_CID(kCSmtpUrlCID, NS_SMTPURL_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
// foward declarations...
nsresult
NS_MsgBuildMailtoUrl(const nsFilePath& aFilePath,
NS_MsgBuildMailtoUrl(nsIFileSpec * aFilePath,
const char* aHostName, const char* aSender,
const nsString& aRecipients, nsIUrlListener *,
const char * aRecipients, nsIUrlListener *,
nsIURI ** aUrl);
nsresult NS_MsgLoadMailtoUrl(nsIURI * aUrl, nsISupports * aConsumer);
@ -77,8 +76,8 @@ nsresult nsSmtpService::QueryInterface(const nsIID &aIID, void** aInstancePtr)
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
nsresult nsSmtpService::SendMailMessage(const nsFilePath& aFilePath,
const nsString& aRecipients,
nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath,
const char * aRecipients,
nsIUrlListener * aUrlListener,
nsISmtpServer * aServer,
nsIURI ** aURL)
@ -128,9 +127,9 @@ nsresult nsSmtpService::SendMailMessage(const nsFilePath& aFilePath,
// The following are two convience functions I'm using to help expedite building and running a mail to url...
// short cut function for creating a mailto url...
nsresult NS_MsgBuildMailtoUrl(const nsFilePath& aFilePath,
nsresult NS_MsgBuildMailtoUrl(nsIFileSpec * aFilePath,
const char* aHostName, const char* aSender,
const nsString& aRecipients, nsIUrlListener * aUrlListener, nsIURI ** aUrl)
const char * aRecipients, nsIUrlListener * aUrlListener, nsIURI ** aUrl)
{
// mscott: this function is a convience hack until netlib actually dispatches smtp urls.
// in addition until we have a session to get a password, host and other stuff from, we need to use default values....
@ -142,20 +141,13 @@ nsresult NS_MsgBuildMailtoUrl(const nsFilePath& aFilePath,
if (NS_SUCCEEDED(rv) && smtpUrl)
{
// assemble a url spec...
char *recipients = aRecipients.ToNewCString();
char * urlSpec= PR_smprintf("mailto://%s:%d/%s",
(const char*)aHostName, 25, recipients ? recipients : "");
if (recipients)
delete [] recipients;
(const char*)aHostName, 25, aRecipients ? aRecipients : "");
if (urlSpec)
{
nsCOMPtr<nsIMsgMailNewsUrl> url = do_QueryInterface(smtpUrl);
url->SetSpec(urlSpec);
nsFileSpec aFileSpec (aFilePath);
nsCOMPtr<nsIFileSpec> aIFileSpec;
NS_NewFileSpecWithSpec(aFileSpec, getter_AddRefs(aIFileSpec));
smtpUrl->SetPostMessageFile(aIFileSpec);
smtpUrl->SetPostMessageFile(aFilePath);
// this cast is safe....it is necessary because of a bug to the xpidl compiler
smtpUrl->SetUserEmailAddress((char *) aSender);
url->RegisterListener(aUrlListener);

View File

@ -23,6 +23,7 @@
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsISmtpService.h"
#include "nsISmtpServer.h"
#include "nsIProtocolHandler.h"
////////////////////////////////////////////////////////////////////////////////////////
@ -43,40 +44,14 @@ public:
////////////////////////////////////////////////////////////////////////
// we suppport the nsISmtpService interface
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// SendMailMessage requires the file name of the message to send, the
// sender, a comma delimited list of recipients.
// It builds an Smtp url, makes an smtp connection and runs the url. If
// you want a handle on the running task, pass in a valid nsIURI ptr.
// You can later interrupt this action by asking the netlib service
// manager to interrupt the url you are given back. Remember to release
// aURL when you are done with it.
// Pass nsnull in for aURL if you don't care about the returned URL.
////////////////////////////////////////////////////////////////////////
NS_IMETHOD SendMailMessage(const nsFilePath& aFilePath,
const nsString& aRecipients,
nsIUrlListener * aUrlListener,
nsISmtpServer * aServer,
nsIURI ** aURL);
NS_IMETHOD GetSmtpServers(nsISupportsArray ** aResult);
NS_IMETHOD GetDefaultSmtpServer(nsISmtpServer **aServer);
NS_IMETHOD SetDefaultSmtpServer(nsISmtpServer *aServer);
//////////////////////////////////////////////////////////////////////////
// End support of nsISmtpService interface
//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
NS_DECL_NSISMTPSERVICE
//////////////////////////////////////////////////////////////////////////
// we suppport the nsIProtocolHandler interface
//////////////////////////////////////////////////////////////////////////
NS_DECL_NSIPROTOCOLHANDLER
//////////////////////////////////////////////////////////////////////////
// End support of nsIProtocolHandler interface
//////////////////////////////////////////////////////////////////////////
private:
nsCOMPtr<nsISupportsArray> mSmtpServers;