fix for #172088. allow redirector type for smtp server to determine if we show hostname in password prompt. r=ducarroz, sr=bienvenu

This commit is contained in:
sspitzer%netscape.com 2002-10-02 18:39:32 +00:00
Родитель 593dbee451
Коммит a277c7cf50
4 изменённых файлов: 90 добавлений и 91 удалений

Просмотреть файл

@ -153,14 +153,11 @@ noIdentities=You don't have any email identities yet. Create one with the Accou
12542=Mail Server Password Required
## @name NS_SMTP_PASSWORD_PROMPT
12543=Enter your password for %1$s@%2$s:
12543=Enter your password for %S:
## @name NS_SMTP_CONNECTING_TO_SERVER
12545=Connecting to server...
## @name NS_SMTP_USERNAME_PASSWORD_PROMPT
12546=Enter your password for %s:
## @name NS_MSG_SENDING_MESSAGE
12550=Sending message...

Просмотреть файл

@ -106,10 +106,9 @@ private:
#define NS_MSG_START_COPY_MESSAGE_FAILED NS_MSG_GENERATE_FAILURE(12540)
#define NS_MSG_LARGE_MESSAGE_WARNING NS_MSG_GENERATE_FAILURE(12541)
#define NS_SMTP_PASSWORD_PROMPT_TITLE NS_MSG_GENERATE_SUCCESS(12542)
#define NS_SMTP_PASSWORD_PROMPT NS_MSG_GENERATE_SUCCESS(12543)
#define NS_SMTP_PASSWORD_PROMPT_TITLE 12542
#define NS_SMTP_PASSWORD_PROMPT 12543
#define NS_SMTP_CONNECTING_TO_SERVER NS_MSG_GENERATE_SUCCESS(12545)
#define NS_SMTP_USERNAME_PASSWORD_PROMPT NS_MSG_GENERATE_SUCCESS(12546)
#define NS_MSG_SENDING_MESSAGE NS_MSG_GENERATE_SUCCESS(12550)
#define NS_MSG_POSTING_MESSAGE NS_MSG_GENERATE_SUCCESS(12551)

Просмотреть файл

@ -69,6 +69,7 @@
#include "nsIPipe.h"
#include "nsMsgSimulateError.h"
#include "nsNetUtil.h"
#include "nsIPrefService.h"
#include "nsISSLSocketControl.h"
/* sigh, cmtcmn.h, included from nsIPSMSocketInfo.h, includes windows.h, which includes winuser.h,
@ -1507,18 +1508,18 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp
nsresult
nsSmtpProtocol::GetPassword(char **aPassword)
{
nsresult rv = NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(aPassword);
nsresult rv;
nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsISmtpServer> smtpServer;
rv = smtpUrl->GetSmtpServer(getter_AddRefs(smtpServer));
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
rv = smtpServer->GetPassword(aPassword);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
if (PL_strlen(*aPassword) > 0)
return rv;
@ -1527,72 +1528,101 @@ nsSmtpProtocol::GetPassword(char **aPassword)
nsCRT::free(*aPassword);
*aPassword = 0;
nsCOMPtr<nsIAuthPrompt> netPrompt;
rv = smtpUrl->GetAuthPrompt(getter_AddRefs(netPrompt));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString redirectorType;
rv = smtpServer->GetRedirectorType(getter_Copies(redirectorType));
NS_ENSURE_SUCCESS(rv,rv);
nsCAutoString prefName("smtp.");
prefName.Append(redirectorType);
prefName.Append(".hide_hostname_for_password");
nsCOMPtr <nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv,rv);
nsXPIDLCString username;
nsXPIDLCString hostname;
PRUnichar *passwordPromptString = nsnull;
nsXPIDLString passwordTemplate;
mSmtpBundle->GetStringByID(NS_SMTP_PASSWORD_PROMPT, getter_Copies(passwordTemplate));
if (!passwordTemplate) return NS_ERROR_NULL_POINTER;
nsXPIDLString passwordTitle;
mSmtpBundle->GetStringByID(NS_SMTP_PASSWORD_PROMPT_TITLE, getter_Copies(passwordTitle));
if (!passwordTitle)
{
rv = NS_ERROR_NULL_POINTER;
goto done;
}
rv = smtpServer->GetUsername(getter_Copies(username));
if (NS_FAILED(rv)) goto done;
rv = smtpServer->GetHostname(getter_Copies(hostname));
if (NS_FAILED(rv)) goto done;
NS_ENSURE_SUCCESS(rv, rv);
passwordPromptString = nsTextFormatter::smprintf(passwordTemplate,
(const char *) username,
(const char *) hostname);
if (!passwordPromptString)
{
rv = NS_ERROR_NULL_POINTER;
goto done;
nsCAutoString promptValue(username);
PRBool hideHostnameForPassword = PR_FALSE;
rv = prefBranch->GetBoolPref(prefName.get(), &hideHostnameForPassword);
if (NS_SUCCEEDED(rv) && hideHostnameForPassword) {
// for certain redirector types, we don't want to show the
// hostname to the user when prompting for password
}
else {
nsXPIDLCString hostname;
rv = smtpServer->GetHostname(getter_Copies(hostname));
NS_ENSURE_SUCCESS(rv, rv);
promptValue.Append("@");
promptValue.Append(hostname);
}
rv = smtpServer->GetPasswordWithUI(passwordPromptString, passwordTitle,
netPrompt, aPassword);
done:
if (passwordPromptString)
nsCRT::free(passwordPromptString);
rv = PromptForPassword(smtpServer, smtpUrl, NS_ConvertASCIItoUCS2(promptValue).get(), aPassword);
NS_ENSURE_SUCCESS(rv,rv);
return rv;
}
nsresult nsSmtpProtocol::PromptForPassword(nsISmtpServer *aSmtpServer, nsISmtpUrl *aSmtpUrl, const PRUnichar *aPromptValue, char **aPassword)
{
nsresult rv;
nsCOMPtr<nsIStringBundleService> stringService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIStringBundle> composeStringBundle;
rv = stringService->CreateBundle("chrome://messenger/locale/messengercompose/composeMsgs.properties", getter_AddRefs(composeStringBundle));
NS_ENSURE_SUCCESS(rv,rv);
const PRUnichar *formatStrings[] =
{
aPromptValue,
};
nsXPIDLString passwordPromptString;
rv = composeStringBundle->FormatStringFromID(NS_SMTP_PASSWORD_PROMPT,
formatStrings, 1,
getter_Copies(passwordPromptString));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAuthPrompt> netPrompt;
rv = aSmtpUrl->GetAuthPrompt(getter_AddRefs(netPrompt));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString passwordTitle;
rv = composeStringBundle->GetStringFromID(NS_SMTP_PASSWORD_PROMPT_TITLE, getter_Copies(passwordTitle));
NS_ENSURE_SUCCESS(rv,rv);
rv = aSmtpServer->GetPasswordWithUI(passwordPromptString.get(), passwordTitle,
netPrompt, aPassword);
NS_ENSURE_SUCCESS(rv,rv);
return rv;
}
nsresult
nsSmtpProtocol::GetUsernamePassword(char **aUsername, char **aPassword)
{
nsresult rv = NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(aUsername);
NS_ENSURE_ARG_POINTER(aPassword);
nsresult rv;
nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsISmtpServer> smtpServer;
rv = smtpUrl->GetSmtpServer(getter_AddRefs(smtpServer));
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
rv = smtpServer->GetPassword(aPassword);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
if (PL_strlen(*aPassword) > 0) {
rv = smtpServer->GetUsername(aUsername);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv,rv);
if (PL_strlen(*aUsername) > 0)
return rv;
@ -1606,43 +1636,15 @@ nsSmtpProtocol::GetUsernamePassword(char **aUsername, char **aPassword)
nsCRT::free(*aPassword);
*aPassword = 0;
nsCOMPtr<nsIAuthPrompt> netPrompt;
rv = smtpUrl->GetAuthPrompt(getter_AddRefs(netPrompt));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString hostname;
PRUnichar *passwordPromptString = nsnull;
nsXPIDLString passwordTemplate;
mSmtpBundle->GetStringByID(NS_SMTP_USERNAME_PASSWORD_PROMPT, getter_Copies(passwordTemplate));
if (!passwordTemplate) return NS_ERROR_NULL_POINTER;
nsXPIDLString passwordTitle;
mSmtpBundle->GetStringByID(NS_SMTP_PASSWORD_PROMPT_TITLE, getter_Copies(passwordTitle));
if (!passwordTitle)
return NS_ERROR_NULL_POINTER;
rv = smtpServer->GetHostname(getter_Copies(hostname));
if (NS_FAILED(rv))
return rv;
passwordPromptString = nsTextFormatter::smprintf(passwordTemplate,
(const char *) hostname);
if (!passwordPromptString)
return NS_ERROR_NULL_POINTER;
rv = smtpServer->GetUsernamePasswordWithUI(passwordPromptString, passwordTitle,
netPrompt, aUsername, aPassword);
if (passwordPromptString)
nsCRT::free(passwordPromptString);
NS_ENSURE_SUCCESS(rv, rv);
rv = PromptForPassword(smtpServer, smtpUrl, NS_ConvertASCIItoUCS2(hostname).get(), aPassword);
NS_ENSURE_SUCCESS(rv,rv);
return rv;
}
nsresult nsSmtpProtocol::RequestOverrideInfo(nsISmtpServer * aSmtpServer)
{
NS_ENSURE_ARG(aSmtpServer);

Просмотреть файл

@ -238,6 +238,7 @@ private:
const char * GetUserDomainName();
nsresult GetPassword(char **aPassword);
nsresult GetUsernamePassword(char **aUsername, char **aPassword);
nsresult PromptForPassword(nsISmtpServer *aSmtpServer, nsISmtpUrl *aSmtpUrl, const PRUnichar *aPromptValue, char **aPassword);
};
#endif // nsSmtpProtocol_h___