From 5839aa32bc8a6edff1f04a3a32edb40abfc09494 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Tue, 9 Nov 1999 02:04:06 +0000 Subject: [PATCH] fix for #17956 and #18084. #17956 is reply fails if message in local mail folder fix (by ducarroz) is to remove the temporary code. #18084 is sending email fails in certain cases the problem is we were sending the wrong info to the SMTP server. when we sent "MAIL FROM:
" to the SMTP server we sent the smtp username and not the full name built from the identity. most of the changes are to support passing the identity around. I also added code so that the smtp username is used on the mailto url spec. we'll need that later, when we support multiple smtp servers and ESMTP. r=alecf a=chofmann git-svn-id: svn://10.0.0.236/trunk@52980 18797224-902f-48f8-a5cc-f745e15eee43 --- .../compose/build/nsMsgCompFactory.cpp | 2 - .../mailnews/compose/public/nsIMsgCompose.idl | 1 - .../compose/public/nsIMsgComposeService.idl | 3 +- .../compose/public/nsISmtpService.idl | 3 +- .../mailnews/compose/public/nsISmtpUrl.idl | 18 +++--- mozilla/mailnews/compose/src/nsMsgCompose.cpp | 16 ++--- mozilla/mailnews/compose/src/nsMsgCompose.h | 2 +- .../compose/src/nsMsgComposeService.cpp | 50 +-------------- .../compose/src/nsMsgComposeService.h | 6 +- mozilla/mailnews/compose/src/nsMsgSend.cpp | 2 +- .../mailnews/compose/src/nsSmtpProtocol.cpp | 60 ++++++++++++------ .../mailnews/compose/src/nsSmtpService.cpp | 46 +++++++++----- mozilla/mailnews/compose/src/nsSmtpUrl.cpp | 61 ++++++++++--------- mozilla/mailnews/compose/src/nsSmtpUrl.h | 2 + .../mailnews/compose/tests/smtp/smtpTest.cpp | 8 ++- 15 files changed, 136 insertions(+), 144 deletions(-) diff --git a/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp b/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp index 72347bafaf9..158e5e8dcc7 100644 --- a/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp +++ b/mozilla/mailnews/compose/build/nsMsgCompFactory.cpp @@ -68,8 +68,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSmtpUrl); //////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////// -static PRInt32 g_InstanceCount = 0; -static PRInt32 g_LockCount = 0; static nsModuleComponentInfo components[] = { diff --git a/mozilla/mailnews/compose/public/nsIMsgCompose.idl b/mozilla/mailnews/compose/public/nsIMsgCompose.idl index 9fa6184ed0e..b7004a60544 100644 --- a/mozilla/mailnews/compose/public/nsIMsgCompose.idl +++ b/mozilla/mailnews/compose/public/nsIMsgCompose.idl @@ -82,7 +82,6 @@ interface nsIMsgCompose : nsISupports { void Initialize(in nsIDOMWindow aWindow, in wstring originalMsgURI, in MSG_ComposeType type, in MSG_ComposeFormat format, in nsIMsgCompFields compFields, - in nsISupports object, /*object is temporary*/ in nsIMsgIdentity identity); /* ... */ diff --git a/mozilla/mailnews/compose/public/nsIMsgComposeService.idl b/mozilla/mailnews/compose/public/nsIMsgComposeService.idl index 88efd4de4c5..add2ffd1db2 100644 --- a/mozilla/mailnews/compose/public/nsIMsgComposeService.idl +++ b/mozilla/mailnews/compose/public/nsIMsgComposeService.idl @@ -35,8 +35,7 @@ interface nsIMsgComposeService : nsISupports { /* ... */ void OpenComposeWindow(in wstring msgComposeWindowURL, in wstring originalMsgURI, in MSG_ComposeType type, in MSG_ComposeFormat format, - in nsISupports object, - in nsIMsgIdentity identity); /*object is temporary*/ + in nsIMsgIdentity identity); /* ... */ void OpenComposeWindowWithValues(in wstring msgComposeWindowURL, in MSG_ComposeFormat format, diff --git a/mozilla/mailnews/compose/public/nsISmtpService.idl b/mozilla/mailnews/compose/public/nsISmtpService.idl index ca5b9466c30..eb00f39d835 100644 --- a/mozilla/mailnews/compose/public/nsISmtpService.idl +++ b/mozilla/mailnews/compose/public/nsISmtpService.idl @@ -27,6 +27,7 @@ interface nsISmtpServer; interface nsIURI; interface nsIUrlListener; interface nsISupportsArray; +interface nsIMsgIdentity; [scriptable, uuid(FBAF0F10-CA9B-11d2-8063-006008128C4E)] interface nsISmtpService : nsISupports { @@ -49,7 +50,7 @@ interface nsISmtpService : nsISupports { // default server ////////////////////////////////////////////////////////////////////////// - void SendMailMessage(in nsIFileSpec aFilePath, in string aRecipients, + void SendMailMessage(in nsIFileSpec aFilePath, in string aRecipients, in nsIMsgIdentity aSenderIdentity, in nsIUrlListener aUrlListener, in nsISmtpServer aServer, out nsIURI aURL); diff --git a/mozilla/mailnews/compose/public/nsISmtpUrl.idl b/mozilla/mailnews/compose/public/nsISmtpUrl.idl index f210f585f11..9926dd8f2cf 100644 --- a/mozilla/mailnews/compose/public/nsISmtpUrl.idl +++ b/mozilla/mailnews/compose/public/nsISmtpUrl.idl @@ -28,6 +28,8 @@ #define SMTP_PORT 25 %} +interface nsIMsgIdentity; + [scriptable, uuid(16ADF2F1-BBAD-11d2-804E-006008128C4E)] interface nsISmtpUrl : nsISupports { /////////////////////////////////////////////////////////////////////////////// @@ -64,12 +66,10 @@ interface nsISmtpUrl : nsISupports { // you need to call this function if you want to force the message to be posted // to the mailserver... - // mscott -- when we have identities it would be nice to just have an identity - // interface here that would encapsulte things like username, domain, password, - // etc... - - // mscott - I found getting the user email address very cumbersome to use with an nsString --> - // particularly when it came to parsing the user name and extracting the domain.....so I'm going to - // change the get value to a const char **... - attribute string UserEmailAddress; -}; \ No newline at end of file + // the user's full name and user's email address are encapsulated in the senderIdentity. + // (the user's domain name can be glopped from the user's email address) + // + // NOTE: the SMTP username and SMTP server are in the mailto url + // mailto://sspitzer@tintin/... + attribute nsIMsgIdentity senderIdentity; +}; diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index c64c904ab22..e8c144ed96f 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -211,7 +211,6 @@ nsresult nsMsgCompose::Initialize(nsIDOMWindow *aWindow, MSG_ComposeType type, MSG_ComposeFormat format, nsIMsgCompFields *compFields, - nsISupports *object, nsIMsgIdentity *identity) { nsresult rv = NS_OK; @@ -251,7 +250,7 @@ nsresult nsMsgCompose::Initialize(nsIDOMWindow *aWindow, } - CreateMessage(originalMsgURI, type, format, compFields, object); //object is temporary + CreateMessage(originalMsgURI, type, format, compFields); return rv; } @@ -632,8 +631,7 @@ nsresult nsMsgCompose::GetWrapLength(PRInt32 *aWrapLength) nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, MSG_ComposeType type, MSG_ComposeFormat format, - nsIMsgCompFields * compFields, - nsISupports * object) + nsIMsgCompFields * compFields) { nsresult rv = NS_OK; @@ -644,12 +642,9 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, return rv; } - /* At this point, we have a list of URI of original message to reply to or forward but as the BE isn't ready yet, - we still need to use the old patch... gather the information from the object and the temp file use to display the selected message*/ - if (object) - { - nsCOMPtr message; - rv = object->QueryInterface(nsIMessage::GetIID(), getter_AddRefs(message)); + /* In case of forwarding multiple messages, originalMsgURI will contains several URI separated by a comma. */ + /* TODO: Need to extract only first URI, just in case...*/ + nsCOMPtr message = getter_AddRefs(GetIMessageFromURI(originalMsgURI)); if ((NS_SUCCEEDED(rv)) && message) { nsString aString = ""; @@ -747,7 +742,6 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI, } } } - } return rv; } diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.h b/mozilla/mailnews/compose/src/nsMsgCompose.h index e3d8e5b20d0..bc0ca1ffdb6 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.h +++ b/mozilla/mailnews/compose/src/nsMsgCompose.h @@ -89,7 +89,7 @@ class nsMsgCompose : public nsIMsgCompose private: nsresult _SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *identity, const PRUnichar *callback); - nsresult CreateMessage(const PRUnichar * originalMsgURI, MSG_ComposeType type, MSG_ComposeFormat format, nsIMsgCompFields* compFields, nsISupports* object); + nsresult CreateMessage(const PRUnichar * originalMsgURI, MSG_ComposeType type, MSG_ComposeFormat format, nsIMsgCompFields* compFields); void CleanUpRecipients(nsString& recipients); nsMsgComposeSendListener *m_sendListener; diff --git a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp index 6db46885480..0d6443c1151 100644 --- a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp @@ -40,15 +40,6 @@ nsMsgComposeService::nsMsgComposeService() NS_INIT_REFCNT(); rv = NS_NewISupportsArray(getter_AddRefs(m_msgQueue)); - - /*--- temporary hack ---*/ - int i; - for (i = 0; i < 16; i ++) - { - hack_uri[i] = ""; - hack_object[i] = nsnull; - } - /*--- temporary hack ---*/ } @@ -92,28 +83,11 @@ static nsresult openWindow( const PRUnichar *chrome, const PRUnichar *args ) { NS_IMPL_ISUPPORTS(nsMsgComposeService, nsCOMTypeInfo::GetIID()); nsresult nsMsgComposeService::OpenComposeWindow(const PRUnichar *msgComposeWindowURL, const PRUnichar *originalMsgURI, - MSG_ComposeType type, MSG_ComposeFormat format, nsISupports *object, - nsIMsgIdentity * identity) + MSG_ComposeType type, MSG_ComposeFormat format, nsIMsgIdentity * identity) { nsAutoString args = ""; nsresult rv; - /*--- temporary hack ---*/ - if (originalMsgURI) - { - int i; - for (i = 0; i < 16; i ++) - if (hack_uri[i].IsEmpty()) - { - hack_uri[i] = originalMsgURI; - hack_object[i] = object; - if (hack_object[i]) - NS_ADDREF(hack_object[i]); - break; - } - } - /*--- temporary hack ---*/ - args.Append("type="); args.Append(type); args.Append(","); @@ -224,32 +198,14 @@ nsresult nsMsgComposeService::InitCompose(nsIDOMWindow *aWindow, (void **) &msgCompose); if (NS_SUCCEEDED(rv) && msgCompose) { - /*--- temporary hack ---*/ - int i; - nsISupports * object = nsnull; - if (originalMsgURI) - for (i = 0; i < 16; i ++) - if (hack_uri[i] == originalMsgURI) - { - hack_uri[i] = ""; - object = hack_object[i]; - hack_object[i] = nsnull; - break; - } - /*--- temporary hack ---*/ - -// ducarroz: I am not quiet sure than dynamic_cast is supported on all platforms/compilers! +// ducarroz: I am not quite sure than dynamic_cast is supported on all platforms/compilers! // nsIMsgCompFields* compFields = dynamic_cast((nsIMsgCompFields *)compFieldsAddr); nsIMsgCompFields* compFields = (nsIMsgCompFields *)compFieldsAddr; msgCompose->Initialize(aWindow, originalMsgURI, type, format, - compFields, object, identity); + compFields, identity); NS_IF_RELEASE(compFields); m_msgQueue->AppendElement(msgCompose); *_retval = msgCompose; - - /*--- temporary hack ---*/ - NS_IF_RELEASE(object); - /*--- temporary hack ---*/ } return rv; diff --git a/mozilla/mailnews/compose/src/nsMsgComposeService.h b/mozilla/mailnews/compose/src/nsMsgComposeService.h index 819ef303c60..a17ede614a7 100644 --- a/mozilla/mailnews/compose/src/nsMsgComposeService.h +++ b/mozilla/mailnews/compose/src/nsMsgComposeService.h @@ -32,12 +32,8 @@ public: /* this macro defines QueryInterface, AddRef and Release for this class */ NS_DECL_ISUPPORTS - NS_DECL_NSIMSGCOMPOSESERVICE + NS_DECL_NSIMSGCOMPOSESERVICE private: nsCOMPtr m_msgQueue; - - //tempory hack - nsString hack_uri[16]; - nsISupports* hack_object[16]; }; diff --git a/mozilla/mailnews/compose/src/nsMsgSend.cpp b/mozilla/mailnews/compose/src/nsMsgSend.cpp index 1b093c8ca78..2e4f51ccc1e 100644 --- a/mozilla/mailnews/compose/src/nsMsgSend.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSend.cpp @@ -2577,7 +2577,7 @@ nsMsgComposeAndSend::DeliverFileAsMail() NS_ADDREF_THIS(); nsCOMPtr aFileSpec; NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(aFileSpec)); - rv = smtpService->SendMailMessage(aFileSpec, buf, mMailSendListener, nsnull, nsnull); + rv = smtpService->SendMailMessage(aFileSpec, buf, mUserIdentity, mMailSendListener, nsnull, nsnull); } PR_FREEIF(buf); // free the buf because we are done with it.... diff --git a/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp b/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp index 1293e3ba659..574751de599 100644 --- a/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp +++ b/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp @@ -34,6 +34,7 @@ #include "nsIPrompt.h" #include "nsString.h" #include "nsTextFormater.h" +#include "nsIMsgIdentity.h" #include "prtime.h" #include "prlog.h" @@ -297,17 +298,25 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL) const char * nsSmtpProtocol::GetUserDomainName() { + nsresult rv; NS_PRECONDITION(m_runningURL, "we must be running a url in order to get the user's domain..."); if (m_runningURL) { - const char *atSignMarker = nsnull; - m_runningURL->GetUserEmailAddress(getter_Copies(m_mailAddr)); - if (m_mailAddr) - { - atSignMarker = PL_strchr(m_mailAddr, '@'); - return atSignMarker ? atSignMarker+1 : (const char *) m_mailAddr; // return const ptr into buffer in running url... + nsCOMPtr senderIdentity; + rv = m_runningURL->GetSenderIdentity(getter_AddRefs(senderIdentity)); + if (NS_FAILED(rv) || !senderIdentity) { + return nsnull; } + + rv = senderIdentity->GetEmail(getter_Copies(m_mailAddr)); + if (NS_FAILED(rv) || !((const char *)m_mailAddr)) { + return nsnull; + } + + const char *atSignMarker = nsnull; + atSignMarker = PL_strchr(m_mailAddr, '@'); + return atSignMarker ? atSignMarker+1 : (const char *) m_mailAddr; // return const ptr into buffer in running url... } return nsnull; @@ -524,18 +533,30 @@ PRInt32 nsSmtpProtocol::ExtensionLoginResponse(nsIInputStream * inputStream, PRU PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32 length) { - PRInt32 status = 0; + PRInt32 status = 0; nsCAutoString buffer; + nsresult rv; - // extract the email addresss - nsXPIDLCString userAddress; - m_runningURL->GetUserEmailAddress(getter_Copies(userAddress)); + // extract the email address and fullname + nsXPIDLCString fullName; + nsXPIDLCString emailAddress; + + nsCOMPtr senderIdentity; + rv = m_runningURL->GetSenderIdentity(getter_AddRefs(senderIdentity)); + if (NS_FAILED(rv) || !senderIdentity) { + m_urlErrorState = NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS; + return(NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS); + } + else { + senderIdentity->GetEmail(getter_Copies(emailAddress)); + senderIdentity->GetFullName(getter_Copies(fullName)); + } /* don't check for a HELO response because it can be bogus and * we don't care */ - if(!userAddress) + if(!((const char *)emailAddress)) { m_urlErrorState = NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS; return(NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS); @@ -556,9 +577,9 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32 nsCOMTypeInfo::GetIID(), getter_AddRefs(parser)); - char * s = nsnull; + char *fullAddress = nsnull; if (parser) - parser->MakeFullAddress(nsnull, nsnull, userAddress, &s); + parser->MakeFullAddress(nsnull, fullName, emailAddress, &fullAddress); #ifdef UNREADY_CODE if (CE_URL_S->msg_pane) @@ -568,14 +589,14 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32 if (TestFlag(SMTP_EHLO_DSN_ENABLED)) { PR_snprintf(buffer, sizeof(buffer), - "MAIL FROM:<%.256s> RET=FULL ENVID=NS40112696JT" CRLF, s); + "MAIL FROM:<%.256s> RET=FULL ENVID=NS40112696JT" CRLF, fullAddress); } else { #ifdef UNREADY_CODE FE_Alert (CE_WINDOW_ID, XP_GetString(XP_RETURN_RECEIPT_NOT_SUPPORT)); #endif - PR_snprintf(buffer, sizeof(buffer), "MAIL FROM:<%.256s>" CRLF, s); + PR_snprintf(buffer, sizeof(buffer), "MAIL FROM:<%.256s>" CRLF, fullAddress); } } #ifdef UNREADY_CODE @@ -586,17 +607,17 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32 #endif else { - PR_snprintf(buffer, sizeof(buffer), "MAIL FROM:<%.256s>" CRLF, s); + PR_snprintf(buffer, sizeof(buffer), "MAIL FROM:<%.256s>" CRLF, fullAddress); } } else #endif { buffer = "MAIL FROM:<"; - buffer += s; + buffer += fullAddress; buffer += ">" CRLF; } - PR_FREEIF (s); + PR_FREEIF (fullAddress); } nsCOMPtr url = do_QueryInterface(m_runningURL); @@ -748,6 +769,9 @@ PRInt32 nsSmtpProtocol::AuthLoginResponse(nsIInputStream * stream, PRUint32 leng PRInt32 nsSmtpProtocol::AuthLoginUsername() { + // NOTE from sspitzer: + // when it comes time to implement this, get the smtp user name from + // the m_runningURL. don't get it from prefs. #ifdef UNREADY_CODE char buffer[512]; diff --git a/mozilla/mailnews/compose/src/nsSmtpService.cpp b/mozilla/mailnews/compose/src/nsSmtpService.cpp index d3680b6a9cc..d46d784521c 100644 --- a/mozilla/mailnews/compose/src/nsSmtpService.cpp +++ b/mozilla/mailnews/compose/src/nsSmtpService.cpp @@ -33,6 +33,7 @@ #include "nsSmtpProtocol.h" #include "nsIFileSpec.h" #include "nsCOMPtr.h" +#include "nsIMsgIdentity.h" typedef struct _findServerByKeyEntry { const char *key; @@ -50,9 +51,13 @@ static NS_DEFINE_CID(kCSmtpUrlCID, NS_SMTPURL_CID); nsresult NS_MsgBuildMailtoUrl(nsIFileSpec * aFilePath, - const char* aHostName, const char* aSender, - const char * aRecipients, nsIUrlListener *, + const char* aSmtpHostName, + const char* aSmtpUserName, + const char* aRecipients, + nsIMsgIdentity * aSenderIdentity, + nsIUrlListener * aUrlListener, nsIURI ** aUrl); + nsresult NS_MsgLoadMailtoUrl(nsIURI * aUrl, nsISupports * aConsumer); nsSmtpService::nsSmtpService() @@ -94,8 +99,9 @@ static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID); nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath, const char * aRecipients, - nsIUrlListener * aUrlListener, - nsISmtpServer * aServer, + nsIMsgIdentity * aSenderIdentity, + nsIUrlListener * aUrlListener, + nsISmtpServer * aServer, nsIURI ** aURL) { nsIURI * urlToRun = nsnull; @@ -109,15 +115,15 @@ nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath, if (NS_SUCCEEDED(rv) && smtpServer) { - nsXPIDLCString hostName; - nsXPIDLCString senderName; + nsXPIDLCString smtpHostName; + nsXPIDLCString smtpUserName; - smtpServer->GetHostname(getter_Copies(hostName)); - smtpServer->GetUsername(getter_Copies(senderName)); + smtpServer->GetHostname(getter_Copies(smtpHostName)); + smtpServer->GetUsername(getter_Copies(smtpUserName)); - if ((const char*)hostName) + if ((const char*)smtpHostName) { - rv = NS_MsgBuildMailtoUrl(aFilePath, hostName, senderName, aRecipients, aUrlListener, &urlToRun); // this ref counts urlToRun + rv = NS_MsgBuildMailtoUrl(aFilePath, smtpHostName, smtpUserName, aRecipients, aSenderIdentity, aUrlListener, &urlToRun); // this ref counts urlToRun if (NS_SUCCEEDED(rv) && urlToRun) rv = NS_MsgLoadMailtoUrl(urlToRun, nsnull); @@ -137,8 +143,12 @@ nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath, // short cut function for creating a mailto url... nsresult NS_MsgBuildMailtoUrl(nsIFileSpec * aFilePath, - const char* aHostName, const char* aSender, - const char * aRecipients, nsIUrlListener * aUrlListener, nsIURI ** aUrl) + const char* aSmtpHostName, + const char* aSmtpUserName, + const char * aRecipients, + nsIMsgIdentity * aSenderIdentity, + 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.... @@ -151,15 +161,19 @@ nsresult NS_MsgBuildMailtoUrl(nsIFileSpec * aFilePath, if (NS_SUCCEEDED(rv) && smtpUrl) { - char * urlSpec= PR_smprintf("mailto://%s:%d/%s", - (const char*)aHostName, 25, aRecipients ? aRecipients : ""); + // this is complicated because the smtp username can be null + char * urlSpec= PR_smprintf("mailto://%s%s%s:%d/%s", + ((const char*)aSmtpUserName)?(const char*)aSmtpUserName:"", + ((const char*)aSmtpUserName)?"@":"", + (const char*)aSmtpHostName, + SMTP_PORT, aRecipients ? aRecipients : ""); if (urlSpec) { nsCOMPtr url = do_QueryInterface(smtpUrl); url->SetSpec(urlSpec); smtpUrl->SetPostMessageFile(aFilePath); - // this cast is safe....it is necessary because of a bug to the xpidl compiler - smtpUrl->SetUserEmailAddress(aSender); + smtpUrl->SetSenderIdentity(aSenderIdentity); + url->RegisterListener(aUrlListener); PR_Free(urlSpec); } diff --git a/mozilla/mailnews/compose/src/nsSmtpUrl.cpp b/mozilla/mailnews/compose/src/nsSmtpUrl.cpp index 26e059ab50a..44c0bc3448e 100644 --- a/mozilla/mailnews/compose/src/nsSmtpUrl.cpp +++ b/mozilla/mailnews/compose/src/nsSmtpUrl.cpp @@ -25,6 +25,7 @@ #include "nsIURI.h" #include "nsSmtpUrl.h" #include "nsString.h" +#include "nsXPIDLString.h" extern "C" { char * NET_SACopy (char **destination, const char *source); @@ -281,10 +282,15 @@ nsresult nsSmtpUrl::ParseUrl() NS_LOCK_INSTANCE(); nsresult rv = NS_OK; + + // set the username + nsXPIDLCString userName; + rv = GetPreHost(getter_Copies(userName)); + if (NS_FAILED(rv)) return rv; + m_userName = (const char *)userName; // the recipients should consist of just the path part up to to the query // part - rv = GetFileName(&m_toPart); // now parse out the search field... @@ -304,31 +310,7 @@ nsresult nsSmtpUrl::ParseUrl() return rv; } -nsresult nsSmtpUrl::GetUserEmailAddress(char ** aUserName) -{ - nsresult rv = NS_OK; - if (aUserName) - *aUserName = m_userName.ToNewCString(); - else - rv = NS_ERROR_NULL_POINTER; - return rv; -} - -nsresult nsSmtpUrl::SetUserEmailAddress(const char * aUserName) -{ - nsresult rv = NS_OK; - if (aUserName) - { - m_userName = aUserName; - } - else - rv = NS_ERROR_NULL_POINTER; - - return rv; -} - - -nsresult nsSmtpUrl::GetMessageContents(char ** aToPart, char ** aCcPart, char ** aBccPart, +NS_IMETHODIMP nsSmtpUrl::GetMessageContents(char ** aToPart, char ** aCcPart, char ** aBccPart, char ** aFromPart, char ** aFollowUpToPart, char ** aOrganizationPart, char ** aReplyToPart, char ** aSubjectPart, char ** aBodyPart, char ** aHtmlPart, char ** aReferencePart, char ** aAttachmentPart, char ** aPriorityPart, @@ -371,7 +353,8 @@ nsresult nsSmtpUrl::GetMessageContents(char ** aToPart, char ** aCcPart, char ** // Caller must call PR_FREE on list when it is done with it. This list is a list of all // recipients to send the email to. each name is NULL terminated... -nsresult nsSmtpUrl::GetAllRecipients(char ** aRecipientsList) +NS_IMETHODIMP +nsSmtpUrl::GetAllRecipients(char ** aRecipientsList) { if (aRecipientsList) *aRecipientsList = m_toPart ? nsCRT::strdup(m_toPart) : nsnull; @@ -382,7 +365,7 @@ NS_IMPL_GETSET(nsSmtpUrl, PostMessage, PRBool, m_isPostMessage) // the message can be stored in a file....allow accessors for getting and setting // the file name to post... -nsresult nsSmtpUrl::SetPostMessageFile(nsIFileSpec * aFileSpec) +NS_IMETHODIMP nsSmtpUrl::SetPostMessageFile(nsIFileSpec * aFileSpec) { nsresult rv = NS_OK; if (aFileSpec) @@ -393,7 +376,7 @@ nsresult nsSmtpUrl::SetPostMessageFile(nsIFileSpec * aFileSpec) return rv; } -nsresult nsSmtpUrl::GetPostMessageFile(nsIFileSpec ** aFileSpec) +NS_IMETHODIMP nsSmtpUrl::GetPostMessageFile(nsIFileSpec ** aFileSpec) { nsresult rv = NS_OK; if (aFileSpec) @@ -406,3 +389,23 @@ nsresult nsSmtpUrl::GetPostMessageFile(nsIFileSpec ** aFileSpec) return rv; } + +NS_IMETHODIMP +nsSmtpUrl::GetSenderIdentity(nsIMsgIdentity * *aSenderIdentity) +{ + NS_ENSURE_ARG_POINTER(aSenderIdentity); + + *aSenderIdentity = m_senderIdentity; + NS_ADDREF(*aSenderIdentity); + return NS_OK; +} + +NS_IMETHODIMP +nsSmtpUrl::SetSenderIdentity(nsIMsgIdentity * aSenderIdentity) +{ + NS_ENSURE_ARG_POINTER(aSenderIdentity); + + m_senderIdentity = dont_QueryInterface(aSenderIdentity); + return NS_OK; +} + diff --git a/mozilla/mailnews/compose/src/nsSmtpUrl.h b/mozilla/mailnews/compose/src/nsSmtpUrl.h index 9f54c9ddccd..52473a402df 100644 --- a/mozilla/mailnews/compose/src/nsSmtpUrl.h +++ b/mozilla/mailnews/compose/src/nsSmtpUrl.h @@ -26,6 +26,7 @@ #include "nsISmtpUrl.h" #include "nsMsgMailNewsUrl.h" #include "nsIFileSpec.h" +#include "nsIMsgIdentity.h" #include "nsCOMPtr.h" class nsSmtpUrl : public nsISmtpUrl, public nsMsgMailNewsUrl @@ -72,6 +73,7 @@ protected: /* Smtp specific event sinks */ nsCString m_userName; nsCOMPtr m_fileName; + nsCOMPtr m_senderIdentity; // it is possible to encode the message to parse in the form of a url. // This function is used to decompose the search and path part into the bare diff --git a/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp b/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp index fa147359aa8..2cdaab131f5 100644 --- a/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp +++ b/mozilla/mailnews/compose/tests/smtp/smtpTest.cpp @@ -53,6 +53,7 @@ #include "nsFileSpec.h" #include "nsIFileSpec.h" #include "nsMsgCompCID.h" +#include "nsIMsgIdentity.h" #ifdef XP_PC #define XPCOM_DLL "xpcom32.dll" @@ -411,7 +412,12 @@ nsresult nsSmtpTestDriver::OnSendMessageInFile() nsIURI * url = nsnull; - m_smtpService->SendMailMessage(aIFileSpec, recipients, this, nsnull, &url); + nsCOMPtr senderIdentity; + senderIdentity = null_nsCOMPtr(); + + printf("passing in null for the sender identity will cause the send to fail, but at least it builds. I need to talk to rhp / mscott about this.\n"); + + m_smtpService->SendMailMessage(aIFileSpec, recipients, senderIdentity, this, nsnull, &url); if (url) m_smtpUrl = do_QueryInterface(url);