Fix SMTP/SSL: bug 32018 sr=mscott

git-svn-id: svn://10.0.0.236/trunk@86131 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jgmyers%netscape.com
2001-02-03 00:17:52 +00:00
parent 3f0e9b60a8
commit 5a4ce93882
8 changed files with 41 additions and 28 deletions

View File

@@ -30,6 +30,7 @@ var gSmtpUsernameLabel;
var gSmtpHostname;
var gSmtpUseUsername;
var gSmtpAuthMethod;
var gSmtpTrySSL;
var gSavedUsername="";
@@ -40,14 +41,19 @@ function initSmtpSettings(server) {
gSmtpHostname = document.getElementById("smtp.hostname");
gSmtpUseUsername = document.getElementById("smtp.useUsername");
gSmtpAuthMethod = document.getElementById("smtp.authMethod");
gSmtpTrySSL = document.getElementById("smtp.trySSL");
if (server) {
gSmtpHostname.value = server.hostname;
gSmtpUsername.value = server.username;
gSmtpAuthMethod.setAttribute("value", server.authMethod);
// radio groups not implemented
//document.getElementById("smtp.trySSL").value = server.trySSL;
var elements = [];
if (server.trySSL != "")
elements = gSmtpTrySSL.getElementsByAttribute("data", server.trySSL);
if (elements.length == 0)
elements = gSmtpTrySSL.getElementsByAttribute("data", "1");
gSmtpTrySSL.selectedItem = elements[0];
}
if (gSmtpAuthMethod.getAttribute("value") == "1")
@@ -75,6 +81,7 @@ function saveSmtpSettings(server)
//dump("Saved authmethod = " + server.authMethod +
// " but checked = " + gSmtpUseUsername.checked + "\n");
server.username = gSmtpUsername.value;
server.trySSL = gSmtpTrySSL.selectedItem.data;
}
}

View File

@@ -52,15 +52,16 @@
</box>
</box>
</box>
<!-- remove for now - bug 46393
<checkbox wsm_persist="true" id="smtp.isSecure" value="&isSecure.label;" oncommand="updateControls();"/>
<box autostretch="never">
<text class="label" value="&isSecure.label;"/>
</box>
<radiogroup id="smtp.trySSL">
<box orient="horizontal">
<radio group="smtp.trySSL" value="&alwaysSecure.label;" id="smtp.alwaysSecure"/>
<radio group="smtp.trySSL" value="&sometimesSecure.label;" id="smtp.sometimesSecure"/>
</box>
<hbox style="margin-left: 2em">
<radio group="smtp.trySSL" data="0" value="&neverSecure.label;" id="smtp.neverSecure"/>
<radio group="smtp.trySSL" data="1" value="&sometimesSecure.label;" id="smtp.sometimesSecure"/>
<radio group="smtp.trySSL" data="2" value="&alwaysSecure.label;" id="smtp.alwaysSecure"/>
</hbox>
</radiogroup>
-->
</box>
</overlay>

View File

@@ -3,5 +3,6 @@
<!ENTITY userName.label "User Name:">
<!ENTITY savePassword.label "Save my password">
<!ENTITY isSecure.label "Use secure connection (SSL)">
<!ENTITY neverSecure.label "Never">
<!ENTITY alwaysSecure.label "Always">
<!ENTITY sometimesSecure.label "When available">

View File

@@ -296,6 +296,7 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL)
m_flags = 0;
m_prefAuthMethod = PREF_AUTH_NONE;
m_prefTrySSL = PREF_SSL_TRY;
m_port = SMTP_PORT;
m_tlsInitiated = PR_FALSE;
@@ -336,10 +337,10 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL)
// round trip communication between the client and server
nsCOMPtr<nsISmtpServer> smtpServer;
m_runningURL->GetSmtpServer(getter_AddRefs(smtpServer));
if (smtpServer)
if (smtpServer) {
smtpServer->GetAuthMethod(&m_prefAuthMethod);
else
m_prefAuthMethod = PREF_AUTH_NONE;
smtpServer->GetTrySSL(&m_prefTrySSL);
}
rv = RequestOverrideInfo(smtpServer);
// if we aren't waiting for a login override, then go ahead an
@@ -349,11 +350,15 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL)
aURL->GetHost(getter_Copies(hostName));
PR_LOG(SMTPLogModule, PR_LOG_ALWAYS, ("SMTP Connecting to: %s", (const char *) hostName));
// pass in "ssl" for the last arg if you want this to be over SSL
if (m_prefAuthMethod == PREF_AUTH_TLS_ONLY)
if (m_prefTrySSL != PREF_SSL_NEVER) {
rv = OpenNetworkSocket(aURL, "tls");
else
if (NS_FAILED(rv) && m_prefTrySSL == PREF_SSL_TRY) {
m_prefTrySSL = PREF_SSL_NEVER;
rv = OpenNetworkSocket(aURL, nsnull);
}
} else {
rv = OpenNetworkSocket(aURL, nsnull);
}
}
}
@@ -709,8 +714,8 @@ PRInt32 nsSmtpProtocol::SendEhloResponse(nsIInputStream * inputStream, PRUint32
/* EHLO must not be implemented by the server so fall back to the HELO case */
if (m_prefAuthMethod == PREF_AUTH_ANY ||
m_prefAuthMethod == PREF_AUTH_TLS_ONLY ||
m_prefAuthMethod == PREF_AUTH_LOGIN)
m_prefAuthMethod == PREF_AUTH_LOGIN ||
m_prefTrySSL == PREF_SSL_ALWAYS)
{
m_nextState = SMTP_ERROR_DONE;
m_urlErrorState = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER;
@@ -794,9 +799,7 @@ PRInt32 nsSmtpProtocol::ProcessAuth()
{
if(TestFlag(SMTP_EHLO_STARTTLS_ENABLED))
{
if (m_prefAuthMethod == PREF_AUTH_ANY ||
m_prefAuthMethod == PREF_AUTH_TLS_TRY ||
m_prefAuthMethod == PREF_AUTH_TLS_ONLY)
if (m_prefTrySSL != PREF_SSL_NEVER)
{
buffer = "STARTTLS";
buffer += CRLF;
@@ -812,7 +815,7 @@ PRInt32 nsSmtpProtocol::ProcessAuth()
return status;
}
}
else if (m_prefAuthMethod == PREF_AUTH_TLS_ONLY)
else if (m_prefTrySSL == PREF_SSL_ALWAYS)
{
m_nextState = SMTP_ERROR_DONE;
m_urlErrorState = NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER;

View File

@@ -89,15 +89,13 @@ SMTP_AUTH_PROCESS_STATE // 21
typedef enum _PrefAuthMethod {
PREF_AUTH_NONE = 0,
PREF_AUTH_ANY = 1,
PREF_AUTH_LOGIN = 2,
PREF_AUTH_TLS_TRY = 3,
PREF_AUTH_TLS_ONLY = 4
PREF_AUTH_LOGIN = 2
} PrefAuthMethod;
typedef enum _PrefTrySSL {
PREF_NO_SSL = 0,
PREF_TRY_SSL = 1,
PREF_ALWAYS_SSL = 2
PREF_SSL_NEVER = 0,
PREF_SSL_TRY = 1,
PREF_SSL_ALWAYS = 2
} PrefTrySSL;
class nsSmtpProtocol : public nsMsgProtocol,
@@ -160,6 +158,7 @@ private:
// *** the following should move to the smtp server when we support
// multiple smtp servers
PRInt32 m_prefAuthMethod;
PRInt32 m_prefTrySSL;
PRBool m_tlsEnabled;
PRBool m_tlsInitiated;

View File

@@ -102,7 +102,7 @@ nsSmtpServer::GetTrySSL(PRInt32 *trySSL)
*trySSL= 0;
getPrefString("try_ssl", pref);
rv = prefs->GetIntPref(pref, trySSL);
if (NS_FAILED(rv)) *trySSL = 0;
if (NS_FAILED(rv)) *trySSL = 1;
return NS_OK;
}

View File

@@ -278,6 +278,7 @@ pref("mail.server.default.canDelete", false);
pref("mail.server.default.login_at_startup", false);
pref("mail.smtpserver.default.auth_method", 2); // auth login
pref("mail.smtpserver.default.try_ssl", 1);
pref("mail.display_glyph", true); // see <http://www.bucksch.org/1/projects/mozilla/16507>
pref("mail.display_struct", true); // ditto

View File

@@ -278,6 +278,7 @@ pref("mail.server.default.canDelete", false);
pref("mail.server.default.login_at_startup", false);
pref("mail.smtpserver.default.auth_method", 2); // auth login
pref("mail.smtpserver.default.try_ssl", 1);
pref("mail.display_glyph", true); // see <http://www.bucksch.org/1/projects/mozilla/16507>
pref("mail.display_struct", true); // ditto