support IMAP TLS 60377 sr=mscott

This commit is contained in:
bienvenu%nventure.com 2005-01-24 17:29:05 +00:00
Родитель 0bee01864f
Коммит 65ad4299f9
8 изменённых файлов: 65 добавлений и 10 удалений

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

@ -178,6 +178,14 @@ interface nsIMsgIncomingServer : nsISupports {
/* should we use secure authentication? */
attribute boolean useSecAuth;
const long defaultSocket = 0;
const long tryTLS = 1;
const long alwaysUseTLS = 2;
const long useSSL = 3;
/* use above values */
attribute long socketType;
/* if a logon mechanism fails, should we fallback to a different
mechanism?
*/

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

@ -1791,6 +1791,37 @@ NS_IMETHODIMP nsMsgIncomingServer::GetIntAttribute(const char *aName, PRInt32 *v
return GetIntValue(aName, val);
}
NS_IMETHODIMP nsMsgIncomingServer::GetSocketType(PRInt32 *aSocketType)
{
nsCAutoString fullPrefName;
getPrefName(m_serverKey.get(), "socketType", fullPrefName);
nsresult rv = m_prefBranch->GetIntPref(fullPrefName.get(), aSocketType);
// socketType is set to default value. Look at isSecure setting
if (NS_FAILED(rv))
{
PRBool isSecure;
rv = GetBoolValue("isSecure", &isSecure);
if (NS_SUCCEEDED(rv) && isSecure)
{
*aSocketType = nsIMsgIncomingServer::useSSL;
SetSocketType(*aSocketType);
}
else
{
getDefaultIntPref("socketType", aSocketType);
}
}
return rv;
}
NS_IMETHODIMP nsMsgIncomingServer::SetSocketType(PRInt32 aSocketType)
{
return SetIntValue("socketType", aSocketType);
}
// Check if the password is available and return a boolean indicating whether
// it is being authenticated or not.
NS_IMETHODIMP

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

@ -136,7 +136,8 @@ typedef enum {
kQuotaCapability = 0x00040000, /* RFC 2087 quota extension */
kHasIdleCapability = 0x00080000, /* RFC 2177 idle extension */
kHasAuthNTLMCapability = 0x00100000, /* AUTH NTLM extension */
kHasAuthMSNCapability = 0x00200000 /* AUTH MSN extension */
kHasAuthMSNCapability = 0x00200000, /* AUTH MSN extension */
kHasStartTLSCapability = 0x00400000 /* STARTTLS support */
} eIMAPCapabilityFlag;
// this used to be part of the connection object class - maybe we should move it into

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

@ -3363,9 +3363,10 @@ nsImapIncomingServer::GeneratePrettyNameForMigration(PRUnichar **aPrettyName)
NS_ENSURE_SUCCESS(rv,rv);
// Is the server secure ?
PRBool isSecure = PR_FALSE;
rv = GetIsSecure(&isSecure);
PRInt32 socketType;
rv = GetSocketType(&socketType);
NS_ENSURE_SUCCESS(rv,rv);
PRBool isSecure = (socketType == nsIMsgIncomingServer::useSSL);
// Is server port a default port ?
PRBool isItDefaultPort = PR_FALSE;

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

@ -356,6 +356,7 @@ nsImapProtocol::nsImapProtocol() : nsMsgProtocol(nsnull),
m_useIdle = PR_TRUE; // by default, use it
m_ignoreExpunges = PR_FALSE;
m_useSecAuth = PR_FALSE;
m_socketType = nsIMsgIncomingServer::tryTLS;
m_connectionStatus = 0;
m_hostSessionList = nsnull;
m_flagState = nsnull;
@ -721,6 +722,7 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
GetServerStateParser().SetCapabilityFlag(capability);
(void) server->GetUseSecAuth(&m_useSecAuth);
(void) server->GetSocketType(&m_socketType);
if (imapServer)
{
nsXPIDLCString redirectorType;
@ -737,12 +739,11 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
if (port <= 0)
{
PRBool isSecure = PR_FALSE;
PRInt32 socketType;
// Be a bit smarter about setting the default port
if (NS_SUCCEEDED(server->GetIsSecure(&isSecure)) && isSecure)
port = SECURE_IMAP_PORT;
else
port = IMAP_PORT;
port = (NS_SUCCEEDED(server->GetSocketType(&socketType))
&& socketType == nsIMsgIncomingServer::useSSL)
? SECURE_IMAP_PORT :IMAP_PORT;
}
nsXPIDLCString hostName;
@ -759,8 +760,11 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
PRBool isSecure = PR_FALSE;
const char *connectionType = nsnull;
if (NS_SUCCEEDED(server->GetIsSecure(&isSecure)) && isSecure)
if (m_socketType == nsIMsgIncomingServer::useSSL)
connectionType = "ssl";
else if ((m_socketType == nsIMsgIncomingServer::tryTLS && (capability & kHasStartTLSCapability))
|| m_socketType == nsIMsgIncomingServer::alwaysUseTLS)
connectionType = "starttls";
nsCOMPtr<nsIProxyInfo> proxyInfo;
rv = NS_ExamineForProxy("imap", hostName.get(), port, getter_AddRefs(proxyInfo));
@ -782,7 +786,13 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
rv = socketService->CreateTransport(&connectionType, connectionType != nsnull,
*socketHost, socketPort, proxyInfo,
getter_AddRefs(m_transport));
if (NS_FAILED(rv) && m_socketType == nsIMsgIncomingServer::tryTLS)
{
connectionType = nsnull;
rv = socketService->CreateTransport(&connectionType, connectionType != nsnull,
*socketHost, socketPort, proxyInfo,
getter_AddRefs(m_transport));
}
if (m_transport)
{
// Ensure that the socket can get the notification callbacks

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

@ -585,6 +585,7 @@ private:
PRBool m_fetchByChunks;
PRBool m_ignoreExpunges;
PRBool m_useSecAuth;
PRInt32 m_socketType;
PRInt32 m_chunkSize;
PRInt32 m_chunkThreshold;
nsMsgImapLineDownloadCache m_downloadLineCache;

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

@ -2116,6 +2116,8 @@ void nsImapServerResponseParser::capability_data()
fCapabilityFlag |= kHasAuthNTLMCapability;
else if (! PL_strcasecmp(fNextToken, "AUTH=MSN"))
fCapabilityFlag |= kHasAuthMSNCapability;
else if (! PL_strcasecmp(fNextToken, "STARTTLS"))
fCapabilityFlag |= kHasStartTLSCapability;
else if (! PL_strcasecmp(fNextToken, "X-NETSCAPE"))
fCapabilityFlag |= kHasXNetscapeCapability;
else if (! PL_strcasecmp(fNextToken, "XSENDER"))

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

@ -374,6 +374,7 @@ pref("mail.server.default.valid", true);
pref("mail.server.default.abbreviate",true);
pref("mail.server.default.isSecure", false);
pref("mail.server.default.useSecAuth", false);
pref("mail.server.default.socketType", 1);
pref("mail.server.default.override_namespaces", true);
pref("mail.server.default.deferred_to_account", "");