From a3868c3b8bfdcfe0906e4d2a7a54da25538a96e4 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Mon, 22 May 2000 05:33:49 +0000 Subject: [PATCH] first part of fix for #28898 - switch SMTP server API to store the key not the server itself, for easier access from the account manager r=sspitzer --- .../prefs/resources/content/AccountWizard.js | 9 ++-- mailnews/base/public/nsIMsgIdentity.idl | 4 +- mailnews/base/util/nsMsgIdentity.cpp | 54 +------------------ mailnews/compose/src/nsSmtpService.cpp | 9 +++- 4 files changed, 15 insertions(+), 61 deletions(-) diff --git a/mailnews/base/prefs/resources/content/AccountWizard.js b/mailnews/base/prefs/resources/content/AccountWizard.js index 04f2e8cdf98..5a705e79ed5 100644 --- a/mailnews/base/prefs/resources/content/AccountWizard.js +++ b/mailnews/base/prefs/resources/content/AccountWizard.js @@ -234,8 +234,10 @@ function PageDataToAccountData(pageData, accountData) server.rememberPassword = pageData.login.rememberPassword.value; } + dump("pageData.server = " + pageData.server + "\n"); if (pageData.server) { - if (pageData.server.smtphostname) + dump("pageData.server.smtphostname.value = " + pageData.server.smtphostname + "\n"); + if (pageData.server.smtphostname.value) smtp.hostname = pageData.server.smtphostname.value; } } @@ -304,12 +306,13 @@ function finishAccount(account, accountData) { if (accountData.smtpCreateNewServer) smtpServer = smtpService.createSmtpServer(); - + + dump("Copying smtpServer (" + smtpServer + ") to accountData\n"); copyObjectToInterface(smtpServer, accountData.smtp); // some identities have 'preferred' if (accountData.smtpUsePreferredServer && destIdentity) - destIdentity.smtpServer = smtpServer; + destIdentity.smtpServerKey = smtpServer.key; } diff --git a/mailnews/base/public/nsIMsgIdentity.idl b/mailnews/base/public/nsIMsgIdentity.idl index b592deed60c..b6e708fbd2c 100644 --- a/mailnews/base/public/nsIMsgIdentity.idl +++ b/mailnews/base/public/nsIMsgIdentity.idl @@ -25,8 +25,6 @@ #include "nsIFileSpec.idl" #include "nsIMsgVCard.idl" -interface nsISmtpServer; - /* * this interface contains all the personal outgoing mail information * for a given person. @@ -107,7 +105,7 @@ interface nsIMsgIdentity : nsISupports { * if this is set, this the smtp server that should be used * for the message send */ - attribute nsISmtpServer smtpServer; + attribute string smtpServerKey; /* copy the attributes of the identity we pass in */ void copy(in nsIMsgIdentity identity); diff --git a/mailnews/base/util/nsMsgIdentity.cpp b/mailnews/base/util/nsMsgIdentity.cpp index e0862d90136..0b285a99deb 100644 --- a/mailnews/base/util/nsMsgIdentity.cpp +++ b/mailnews/base/util/nsMsgIdentity.cpp @@ -26,7 +26,6 @@ #include "nsIPref.h" #include "nsXPIDLString.h" -#include "nsISmtpService.h" #include "nsMsgCompCID.h" #include "nsIRDFService.h" #include "nsIRDFResource.h" @@ -402,63 +401,12 @@ nsMsgIdentity::clearPrefEnum(const char *aPref, void *aClosure) prefs->ClearUserPref(aPref); } -NS_IMETHODIMP -nsMsgIdentity::GetSmtpServer(nsISmtpServer **aResult) -{ - nsresult rv; - - nsCOMPtr smtpServer = - do_QueryReferent(m_smtpServer, &rv); - - // try to load, but ignore the error and return null if nothing - if (!smtpServer) - loadSmtpServer(getter_AddRefs(smtpServer)); - - *aResult = smtpServer; - NS_IF_ADDREF(*aResult); - - return NS_OK; -} - -nsresult -nsMsgIdentity::loadSmtpServer(nsISmtpServer** aResult) -{ - nsresult rv; - - nsXPIDLCString smtpServerKey; - rv = getCharPref("smtpServer", getter_Copies(smtpServerKey)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr smtpService = - do_GetService(NS_SMTPSERVICE_PROGID, &rv); - if (NS_FAILED(rv)) return rv; - - return smtpService->GetServerByKey(smtpServerKey, aResult); -} - -NS_IMETHODIMP -nsMsgIdentity::SetSmtpServer(nsISmtpServer *aServer) -{ - nsresult rv; - - m_smtpServer = getter_AddRefs(NS_GetWeakReference(aServer, &rv)); - - if (aServer) { - nsXPIDLCString smtpServerKey; - rv = aServer->GetKey(getter_Copies(smtpServerKey)); - if (NS_SUCCEEDED(rv)) { - setCharPref("smtpServer", smtpServerKey); - } - } - - return NS_OK; -} - NS_IMPL_GETSET(nsMsgIdentity, VCard, nsIMsgVCard*, m_vCard); NS_IMPL_GETTER_STR(nsMsgIdentity::GetKey, m_identityKey); +NS_IMPL_IDPREF_STR(SmtpServerKey, "smtpServer"); NS_IMPL_IDPREF_WSTR(FullName, "fullName"); NS_IMPL_IDPREF_STR(Email, "useremail"); NS_IMPL_IDPREF_STR(ReplyTo, "reply_to"); diff --git a/mailnews/compose/src/nsSmtpService.cpp b/mailnews/compose/src/nsSmtpService.cpp index 15374b688c0..7deb063feef 100644 --- a/mailnews/compose/src/nsSmtpService.cpp +++ b/mailnews/compose/src/nsSmtpService.cpp @@ -101,8 +101,13 @@ nsresult nsSmtpService::SendMailMessage(nsIFileSpec * aFilePath, nsCOMPtr smtpServer; // first try the identity's preferred server - if (aSenderIdentity) - rv = aSenderIdentity->GetSmtpServer(getter_AddRefs(smtpServer)); + if (aSenderIdentity) { + nsXPIDLCString smtpServerKey; + rv = aSenderIdentity->GetSmtpServerKey(getter_Copies(smtpServerKey)); + if (NS_SUCCEEDED(rv) && (const char *)smtpServerKey) + rv = smtpService->GetServerByKey(smtpServerKey, + getter_AddRefs(smtpServer)); + } // fallback to the default if (NS_FAILED(rv) || !smtpServer)