Issue #1258 - Part 8: Ifdef MailNews OAuth2 Support

Use --disable-mailnews-oauth2 to exclude it. Confvars won't be respected.
This commit is contained in:
Matt A. Tobin 2019-11-05 18:27:14 -05:00 • committed by Roy Tam
commit 1531d6498d
27 changed files with 193 additions and 23 deletions

View file

@ -309,6 +309,7 @@ def old_configure_options(*options):
'--enable-calendar', '--enable-calendar',
'--enable-incomplete-external-linkage', '--enable-incomplete-external-linkage',
'--enable-mailnews', '--enable-mailnews',
'--enable-mailnews-oauth2',
# Below are configure flags used by Pale Moon # Below are configure flags used by Pale Moon
'--disable-browser-statusbar', '--disable-browser-statusbar',

View file

@ -50,8 +50,10 @@ AccountConfig.prototype =
*/ */
incomingAlternatives : null, incomingAlternatives : null,
outgoingAlternatives : null, outgoingAlternatives : null,
#ifdef MOZ_MAILNEWS_OAUTH2
// OAuth2 configuration, if needed. // OAuth2 configuration, if needed.
oauthSettings : null, oauthSettings : null,
#endif
// just an internal string to refer to this. Do not show to user. // just an internal string to refer to this. Do not show to user.
id : null, id : null,
// who created the config. // who created the config.

View file

@ -28,10 +28,12 @@ function createAccountInBackend(config)
if (config.rememberPassword && config.incoming.password.length) if (config.rememberPassword && config.incoming.password.length)
rememberPassword(inServer, config.incoming.password); rememberPassword(inServer, config.incoming.password);
#ifdef MOZ_MAILNEWS_OAUTH2
if (inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) { if (inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) {
inServer.setCharValue("oauth2.scope", config.oauthSettings.scope); inServer.setCharValue("oauth2.scope", config.oauthSettings.scope);
inServer.setCharValue("oauth2.issuer", config.oauthSettings.issuer); inServer.setCharValue("oauth2.issuer", config.oauthSettings.issuer);
} }
#endif
// SSL // SSL
if (config.incoming.socketType == 1) // plain if (config.incoming.socketType == 1) // plain
@ -107,6 +109,7 @@ function createAccountInBackend(config)
rememberPassword(outServer, config.incoming.password); rememberPassword(outServer, config.incoming.password);
} }
#ifdef MOZ_MAILNEWS_OAUTH2
if (outServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) { if (outServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) {
let pref = "mail.smtpserver." + outServer.key + "."; let pref = "mail.smtpserver." + outServer.key + ".";
Services.prefs.setCharPref(pref + "oauth2.scope", Services.prefs.setCharPref(pref + "oauth2.scope",
@ -114,6 +117,7 @@ function createAccountInBackend(config)
Services.prefs.setCharPref(pref + "oauth2.issuer", Services.prefs.setCharPref(pref + "oauth2.issuer",
config.oauthSettings.issuer); config.oauthSettings.issuer);
} }
#endif
if (config.outgoing.socketType == 1) // no SSL if (config.outgoing.socketType == 1) // no SSL
outServer.socketType = Ci.nsMsgSocketType.plain; outServer.socketType = Ci.nsMsgSocketType.plain;

View file

@ -6,7 +6,9 @@
Components.utils.import("resource:///modules/mailServices.js"); Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource:///modules/hostnameUtils.jsm"); Components.utils.import("resource:///modules/hostnameUtils.jsm");
#ifdef MOZ_MAILNEWS_OAUTH2
Components.utils.import("resource://gre/modules/OAuth2Providers.jsm"); Components.utils.import("resource://gre/modules/OAuth2Providers.jsm");
#endif
/** /**
* This is the dialog opened by menu File | New account | Mail... . * This is the dialog opened by menu File | New account | Mail... .
@ -184,7 +186,9 @@ EmailConfigWizard.prototype =
"authPasswordEncrypted"); "authPasswordEncrypted");
setLabelFromStringBundle("in-authMethod-kerberos", "authKerberos"); setLabelFromStringBundle("in-authMethod-kerberos", "authKerberos");
setLabelFromStringBundle("in-authMethod-ntlm", "authNTLM"); setLabelFromStringBundle("in-authMethod-ntlm", "authNTLM");
#ifdef MOZ_MAILNEWS_OAUTH2
setLabelFromStringBundle("in-authMethod-oauth2", "authOAuth2"); setLabelFromStringBundle("in-authMethod-oauth2", "authOAuth2");
#endif
setLabelFromStringBundle("out-authMethod-no", "authNo"); setLabelFromStringBundle("out-authMethod-no", "authNo");
setLabelFromStringBundle("out-authMethod-password-cleartext", setLabelFromStringBundle("out-authMethod-password-cleartext",
"authPasswordCleartextViaSSL"); // will warn about insecure later "authPasswordCleartextViaSSL"); // will warn about insecure later
@ -1014,7 +1018,11 @@ EmailConfigWizard.prototype =
e("incoming_ssl").value = sanitize.enum(config.incoming.socketType, e("incoming_ssl").value = sanitize.enum(config.incoming.socketType,
[ 0, 1, 2, 3 ], 0); [ 0, 1, 2, 3 ], 0);
e("incoming_authMethod").value = sanitize.enum(config.incoming.auth, e("incoming_authMethod").value = sanitize.enum(config.incoming.auth,
#ifdef MOZ_MAILNEWS_OAUTH2
[ 0, 3, 4, 5, 6, 10 ], 0); [ 0, 3, 4, 5, 6, 10 ], 0);
#else
[ 0, 3, 4, 5, 6 ], 0);
#endif
e("incoming_username").value = config.incoming.username; e("incoming_username").value = config.incoming.username;
if (config.incoming.port) { if (config.incoming.port) {
e("incoming_port").value = config.incoming.port; e("incoming_port").value = config.incoming.port;
@ -1023,6 +1031,7 @@ EmailConfigWizard.prototype =
} }
this.fillPortDropdown(config.incoming.type); this.fillPortDropdown(config.incoming.type);
#ifdef MOZ_MAILNEWS_OAUTH2
// If the hostname supports OAuth2 and imap is enabled, enable OAuth2. // If the hostname supports OAuth2 and imap is enabled, enable OAuth2.
let iDetails = OAuth2Providers.getHostnameDetails(config.incoming.hostname); let iDetails = OAuth2Providers.getHostnameDetails(config.incoming.hostname);
gEmailWizardLogger.info("OAuth2 details for incoming hostname " + gEmailWizardLogger.info("OAuth2 details for incoming hostname " +
@ -1035,6 +1044,7 @@ EmailConfigWizard.prototype =
// store them in the base configuration. // store them in the base configuration.
this._currentConfig.oauthSettings = config.oauthSettings; this._currentConfig.oauthSettings = config.oauthSettings;
} }
#endif
// outgoing server // outgoing server
e("outgoing_hostname").value = config.outgoing.hostname; e("outgoing_hostname").value = config.outgoing.hostname;
@ -1052,6 +1062,7 @@ EmailConfigWizard.prototype =
this.adjustOutgoingPortToSSLAndProtocol(config); this.adjustOutgoingPortToSSLAndProtocol(config);
} }
#ifdef MOZ_MAILNEWS_OAUTH2
// If the hostname supports OAuth2 and imap is enabled, enable OAuth2. // If the hostname supports OAuth2 and imap is enabled, enable OAuth2.
let oDetails = OAuth2Providers.getHostnameDetails(config.outgoing.hostname); let oDetails = OAuth2Providers.getHostnameDetails(config.outgoing.hostname);
gEmailWizardLogger.info("OAuth2 details for outgoing hostname " + gEmailWizardLogger.info("OAuth2 details for outgoing hostname " +
@ -1064,6 +1075,7 @@ EmailConfigWizard.prototype =
// store them in the base configuration. // store them in the base configuration.
this._currentConfig.oauthSettings = config.oauthSettings; this._currentConfig.oauthSettings = config.oauthSettings;
} }
#endif
// populate fields even if existingServerKey, in case user changes back // populate fields even if existingServerKey, in case user changes back
if (config.outgoing.existingServerKey) { if (config.outgoing.existingServerKey) {
@ -1614,10 +1626,12 @@ EmailConfigWizard.prototype =
self._currentConfig.incoming.username = successfulConfig.incoming.username; self._currentConfig.incoming.username = successfulConfig.incoming.username;
self._currentConfig.outgoing.username = successfulConfig.outgoing.username; self._currentConfig.outgoing.username = successfulConfig.outgoing.username;
#ifdef MOZ_MAILNEWS_OAUTH2
// We loaded dynamic client registration, fill this data back in to the // We loaded dynamic client registration, fill this data back in to the
// config set. // config set.
if (successfulConfig.oauthSettings) if (successfulConfig.oauthSettings)
self._currentConfig.oauthSettings = successfulConfig.oauthSettings; self._currentConfig.oauthSettings = successfulConfig.oauthSettings;
#endif
self.finish(); self.finish();
}, },

View file

@ -309,7 +309,9 @@
<menuitem id="in-authMethod-password-encrypted" value="4"/> <menuitem id="in-authMethod-password-encrypted" value="4"/>
<menuitem id="in-authMethod-kerberos" value="5"/> <menuitem id="in-authMethod-kerberos" value="5"/>
<menuitem id="in-authMethod-ntlm" value="6"/> <menuitem id="in-authMethod-ntlm" value="6"/>
#ifdef MOZ_MAILNEWS_OAUTH2
<menuitem id="in-authMethod-oauth2" value="10" hidden="true"/> <menuitem id="in-authMethod-oauth2" value="10" hidden="true"/>
#endif
</menupopup> </menupopup>
</menulist> </menulist>
</row> </row>
@ -359,7 +361,9 @@
<menuitem id="out-authMethod-password-encrypted" value="4"/> <menuitem id="out-authMethod-password-encrypted" value="4"/>
<menuitem id="out-authMethod-kerberos" value="5"/> <menuitem id="out-authMethod-kerberos" value="5"/>
<menuitem id="out-authMethod-ntlm" value="6"/> <menuitem id="out-authMethod-ntlm" value="6"/>
#ifdef MOZ_MAILNEWS_OAUTH2
<menuitem id="out-authMethod-oauth2" value="10" hidden="true"/> <menuitem id="out-authMethod-oauth2" value="10" hidden="true"/>
#endif
</menupopup> </menupopup>
</menulist> </menulist>
</row> </row>

View file

@ -60,11 +60,13 @@ function guessConfig(domain, progressCallback, successCallback, errorCallback,
assert(typeof(successCallback) == "function", "need successCallback"); assert(typeof(successCallback) == "function", "need successCallback");
assert(typeof(errorCallback) == "function", "need errorCallback"); assert(typeof(errorCallback) == "function", "need errorCallback");
#ifdef MOZ_MAILNEWS_OAUTH2
// Servers that we know enough that they support OAuth2 do not need guessing. // Servers that we know enough that they support OAuth2 do not need guessing.
if (resultConfig.incoming.auth == Ci.nsMsgAuthMethod.OAuth2) { if (resultConfig.incoming.auth == Ci.nsMsgAuthMethod.OAuth2) {
successCallback(resultConfig); successCallback(resultConfig);
return null; return null;
} }
#endif
if (!resultConfig) if (!resultConfig)
resultConfig = new AccountConfig(); resultConfig = new AccountConfig();

View file

@ -95,7 +95,10 @@ function readFromXML(clientConfigXML)
"secure" : Ci.nsMsgAuthMethod.passwordEncrypted, "secure" : Ci.nsMsgAuthMethod.passwordEncrypted,
"GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI, "GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI,
"NTLM" : Ci.nsMsgAuthMethod.NTLM, "NTLM" : Ci.nsMsgAuthMethod.NTLM,
"OAuth2" : Ci.nsMsgAuthMethod.OAuth2 }); #ifdef MOZ_MAILNEWS_OAUTH2
"OAuth2" : Ci.nsMsgAuthMethod.OAuth2
#endif
});
break; // take first that we support break; // take first that we support
} catch (e) { exception = e; } } catch (e) { exception = e; }
} }
@ -176,7 +179,9 @@ function readFromXML(clientConfigXML)
"secure" : Ci.nsMsgAuthMethod.passwordEncrypted, "secure" : Ci.nsMsgAuthMethod.passwordEncrypted,
"GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI, "GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI,
"NTLM" : Ci.nsMsgAuthMethod.NTLM, "NTLM" : Ci.nsMsgAuthMethod.NTLM,
#ifdef MOZ_MAILNEWS_OAUTH2
"OAuth2" : Ci.nsMsgAuthMethod.OAuth2, "OAuth2" : Ci.nsMsgAuthMethod.OAuth2,
#endif
}); });
break; // take first that we support break; // take first that we support

View file

@ -30,7 +30,9 @@
*/ */
Components.utils.import("resource:///modules/mailServices.js"); Components.utils.import("resource:///modules/mailServices.js");
#ifdef MOZ_MAILNEWS_OAUTH2
Components.utils.import("resource://gre/modules/OAuth2Providers.jsm"); Components.utils.import("resource://gre/modules/OAuth2Providers.jsm");
#endif
if (typeof gEmailWizardLogger == "undefined") { if (typeof gEmailWizardLogger == "undefined") {
Cu.import("resource:///modules/gloda/log4moz.js"); Cu.import("resource:///modules/gloda/log4moz.js");
@ -74,6 +76,7 @@ function verifyConfig(config, alter, msgWindow, successCallback, errorCallback)
config.incoming.auth); config.incoming.auth);
inServer.authMethod = config.incoming.auth; inServer.authMethod = config.incoming.auth;
#ifdef MOZ_MAILNEWS_OAUTH2
try { try {
// Lookup issuer if needed. // Lookup issuer if needed.
if (config.incoming.auth == Ci.nsMsgAuthMethod.OAuth2 || if (config.incoming.auth == Ci.nsMsgAuthMethod.OAuth2 ||
@ -100,6 +103,9 @@ function verifyConfig(config, alter, msgWindow, successCallback, errorCallback)
if (inServer.password || if (inServer.password ||
inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2)
#else
if (inServer.password)
#endif
verifyLogon(config, inServer, alter, msgWindow, verifyLogon(config, inServer, alter, msgWindow,
successCallback, errorCallback); successCallback, errorCallback);
else { else {

View file

@ -31,7 +31,9 @@ function onInit(aPageId, aServerId)
setupImapDeleteUI(aServerId); setupImapDeleteUI(aServerId);
// TLS Cert (External) and OAuth2 are only supported on IMAP. // TLS Cert (External) and OAuth2 are only supported on IMAP.
#ifdef MOZ_MAILNEWS_OAUTH2
document.getElementById("authMethod-oauth2").hidden = (serverType != "imap"); document.getElementById("authMethod-oauth2").hidden = (serverType != "imap");
#endif
document.getElementById("authMethod-external").hidden = (serverType != "imap"); document.getElementById("authMethod-external").hidden = (serverType != "imap");
// "STARTTLS, if available" is vulnerable to MITM attacks so we shouldn't // "STARTTLS, if available" is vulnerable to MITM attacks so we shouldn't
@ -83,7 +85,9 @@ function initServerType()
setLabelFromStringBundle("authMethod-kerberos", "authKerberos"); setLabelFromStringBundle("authMethod-kerberos", "authKerberos");
setLabelFromStringBundle("authMethod-external", "authExternal"); setLabelFromStringBundle("authMethod-external", "authExternal");
setLabelFromStringBundle("authMethod-ntlm", "authNTLM"); setLabelFromStringBundle("authMethod-ntlm", "authNTLM");
#ifdef MOZ_MAILNEWS_OAUTH2
setLabelFromStringBundle("authMethod-oauth2", "authOAuth2"); setLabelFromStringBundle("authMethod-oauth2", "authOAuth2");
#endif
setLabelFromStringBundle("authMethod-anysecure", "authAnySecure"); setLabelFromStringBundle("authMethod-anysecure", "authAnySecure");
setLabelFromStringBundle("authMethod-any", "authAny"); setLabelFromStringBundle("authMethod-any", "authAny");
setLabelFromStringBundle("authMethod-password-encrypted", setLabelFromStringBundle("authMethod-password-encrypted",

View file

@ -139,7 +139,9 @@
<menuitem id="authMethod-kerberos" value="5"/> <menuitem id="authMethod-kerberos" value="5"/>
<menuitem id="authMethod-ntlm" value="6"/> <menuitem id="authMethod-ntlm" value="6"/>
<menuitem id="authMethod-external" value="7"/> <menuitem id="authMethod-external" value="7"/>
#ifdef MOZ_MAILNEWS_OAUTH2
<menuitem id="authMethod-oauth2" value="10"/> <menuitem id="authMethod-oauth2" value="10"/>
#endif
<menuitem id="authMethod-anysecure" value="8"/> <menuitem id="authMethod-anysecure" value="8"/>
<menuitem id="authMethod-any" value="9"/> <menuitem id="authMethod-any" value="9"/>
</menupopup> </menupopup>

View file

@ -140,9 +140,11 @@ var gSmtpServerListWindow =
? "authPasswordCleartextViaSSL" ? "authPasswordCleartextViaSSL"
: "authPasswordCleartextInsecurely"; : "authPasswordCleartextInsecurely";
break; break;
#ifdef MOZ_MAILNEWS_OAUTH2
case AuthMethod.OAuth2: case AuthMethod.OAuth2:
authStr = "authOAuth2"; authStr = "authOAuth2";
break; break;
#endif
default: default:
// leave empty // leave empty
Components.utils.reportError("Warning: unknown value for smtpserver... authMethod: " + Components.utils.reportError("Warning: unknown value for smtpserver... authMethod: " +

View file

@ -53,7 +53,9 @@ function initSmtpSettings(server) {
"authPasswordCleartextInsecurely"); "authPasswordCleartextInsecurely");
setLabelFromStringBundle("authMethod-kerberos", "authKerberos"); setLabelFromStringBundle("authMethod-kerberos", "authKerberos");
setLabelFromStringBundle("authMethod-ntlm", "authNTLM"); setLabelFromStringBundle("authMethod-ntlm", "authNTLM");
#ifdef MOZ_MAILNEWS_OAUTH2
setLabelFromStringBundle("authMethod-oauth2", "authOAuth2"); setLabelFromStringBundle("authMethod-oauth2", "authOAuth2");
#endif
setLabelFromStringBundle("authMethod-anysecure", "authAnySecure"); setLabelFromStringBundle("authMethod-anysecure", "authAnySecure");
setLabelFromStringBundle("authMethod-any", "authAny"); setLabelFromStringBundle("authMethod-any", "authAny");

View file

@ -103,7 +103,9 @@
<menuitem id="authMethod-password-encrypted" value="4"/> <menuitem id="authMethod-password-encrypted" value="4"/>
<menuitem id="authMethod-kerberos" value="5"/> <menuitem id="authMethod-kerberos" value="5"/>
<menuitem id="authMethod-ntlm" value="6"/> <menuitem id="authMethod-ntlm" value="6"/>
#ifdef MOZ_MAILNEWS_OAUTH2
<menuitem id="authMethod-oauth2" value="10"/> <menuitem id="authMethod-oauth2" value="10"/>
#endif
<menuitem id="authMethod-anysecure" value="8"/> <menuitem id="authMethod-anysecure" value="8"/>
<menuitem id="authMethod-any" value="9"/> <menuitem id="authMethod-any" value="9"/>
</menupopup> </menupopup>

View file

@ -3,11 +3,13 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
if CONFIG['MOZ_MAILNEWS_OAUTH2']:
XPIDL_SOURCES += ['msgIOAuth2Module.idl']
XPIDL_SOURCES += [ XPIDL_SOURCES += [
'MailNewsTypes2.idl', 'MailNewsTypes2.idl',
'mozINewMailListener.idl', 'mozINewMailListener.idl',
'mozINewMailNotificationService.idl', 'mozINewMailNotificationService.idl',
'msgIOAuth2Module.idl',
'nsICopyMessageListener.idl', 'nsICopyMessageListener.idl',
'nsICopyMsgStreamListener.idl', 'nsICopyMsgStreamListener.idl',
'nsIFolderListener.idl', 'nsIFolderListener.idl',

View file

@ -68,12 +68,15 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
EXTRA_COMPONENTS += [ EXTRA_COMPONENTS += [
'folderLookupService.js', 'folderLookupService.js',
'msgAsyncPrompter.js', 'msgAsyncPrompter.js',
'msgBase.manifest',
'msgOAuth2Module.js',
'newMailNotificationService.js', 'newMailNotificationService.js',
'nsMailNewsCommandLineHandler.js', 'nsMailNewsCommandLineHandler.js',
] ]
if CONFIG['MOZ_MAILNEWS_OAUTH2']:
EXTRA_COMPONENTS += ['msgOAuth2Module.js']
EXTRA_PP_COMPONENTS += ['msgBase.manifest']
EXTRA_JS_MODULES += [ EXTRA_JS_MODULES += [
'virtualFolderWrapper.js', 'virtualFolderWrapper.js',
] ]

View file

@ -8,5 +8,7 @@ contract @mozilla.org/newMailNotificationService;1 {740880E6-E299-4165-B82F-DF1D
category profile-after-change NewMailNotificationService @mozilla.org/newMailNotificationService;1 category profile-after-change NewMailNotificationService @mozilla.org/newMailNotificationService;1
component {a30be08c-afc8-4fed-9af7-79778a23db23} folderLookupService.js component {a30be08c-afc8-4fed-9af7-79778a23db23} folderLookupService.js
contract @mozilla.org/mail/folder-lookup;1 {a30be08c-afc8-4fed-9af7-79778a23db23} contract @mozilla.org/mail/folder-lookup;1 {a30be08c-afc8-4fed-9af7-79778a23db23}
#ifdef MOZ_MAILNEWS_OAUTH2
component {b63d8e4c-bf60-439b-be0e-7c9f67291042} msgOAuth2Module.js component {b63d8e4c-bf60-439b-be0e-7c9f67291042} msgOAuth2Module.js
contract @mozilla.org/mail/oauth2-module;1 {b63d8e4c-bf60-439b-be0e-7c9f67291042} contract @mozilla.org/mail/oauth2-module;1 {b63d8e4c-bf60-439b-be0e-7c9f67291042}
#endif

View file

@ -60,13 +60,17 @@ EXTRA_JS_MODULES += [
'mailnewsMigrator.js', 'mailnewsMigrator.js',
'mailServices.js', 'mailServices.js',
'msgDBCacheManager.js', 'msgDBCacheManager.js',
'OAuth2.jsm',
'OAuth2Providers.jsm',
'StringBundle.js', 'StringBundle.js',
'templateUtils.js', 'templateUtils.js',
'traceHelper.js', 'traceHelper.js',
] ]
if CONFIG['MOZ_MAILNEWS_OAUTH2']:
EXTRA_JS_MODULES += [
'OAuth2.jsm',
'OAuth2Providers.jsm',
]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/netwerk/base' '/netwerk/base'
] ]

View file

@ -216,9 +216,17 @@ esmtp_value_encode(const char *addr)
// END OF TEMPORARY HARD CODED FUNCTIONS // END OF TEMPORARY HARD CODED FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
#ifdef MOZ_MAILNEWS_OAUTH2
NS_IMPL_ISUPPORTS_INHERITED(nsSmtpProtocol, nsMsgAsyncWriteProtocol, NS_IMPL_ISUPPORTS_INHERITED(nsSmtpProtocol, nsMsgAsyncWriteProtocol,
msgIOAuth2ModuleListener) msgIOAuth2ModuleListener)
#else
NS_IMPL_ADDREF_INHERITED(nsSmtpProtocol, nsMsgAsyncWriteProtocol)
NS_IMPL_RELEASE_INHERITED(nsSmtpProtocol, nsMsgAsyncWriteProtocol)
NS_INTERFACE_MAP_BEGIN(nsSmtpProtocol)
NS_INTERFACE_MAP_END_INHERITING(nsMsgAsyncWriteProtocol)
// TODO: See if we can use NS_IMPL_ISUPPORTS_INHERITED: https://hg.mozilla.org/comm-central/diff/eae1195fde6d/mailnews/compose/src/nsSmtpProtocol.cpp
#endif
nsSmtpProtocol::nsSmtpProtocol(nsIURI * aURL) nsSmtpProtocol::nsSmtpProtocol(nsIURI * aURL)
: nsMsgAsyncWriteProtocol(aURL) : nsMsgAsyncWriteProtocol(aURL)
{ {
@ -291,6 +299,7 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL)
smtpServer->GetSocketType(&m_prefSocketType); smtpServer->GetSocketType(&m_prefSocketType);
smtpServer->GetHelloArgument(getter_Copies(m_helloArgument)); smtpServer->GetHelloArgument(getter_Copies(m_helloArgument));
#ifdef MOZ_MAILNEWS_OAUTH2
// Query for OAuth2 support. If the SMTP server preferences don't allow // Query for OAuth2 support. If the SMTP server preferences don't allow
// for OAuth2, then don't carry around the OAuth2 module any longer // for OAuth2, then don't carry around the OAuth2 module any longer
// since we won't need it. // since we won't need it.
@ -302,6 +311,7 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL)
if (!supportsOAuth) if (!supportsOAuth)
mOAuth2Support = nullptr; mOAuth2Support = nullptr;
} }
#endif
} }
InitPrefAuthMethods(authMethod); InitPrefAuthMethods(authMethod);
@ -794,9 +804,11 @@ nsresult nsSmtpProtocol::SendEhloResponse(nsIInputStream * inputStream, uint32_t
CaseInsensitiveCompare) >= 0) CaseInsensitiveCompare) >= 0)
SetFlag(SMTP_AUTH_EXTERNAL_ENABLED); SetFlag(SMTP_AUTH_EXTERNAL_ENABLED);
#ifdef MOZ_MAILNEWS_OAUTH2
if (responseLine.Find(NS_LITERAL_CSTRING("XOAUTH2"), if (responseLine.Find(NS_LITERAL_CSTRING("XOAUTH2"),
CaseInsensitiveCompare) >= 0) CaseInsensitiveCompare) >= 0)
SetFlag(SMTP_AUTH_OAUTH2_ENABLED); SetFlag(SMTP_AUTH_OAUTH2_ENABLED);
#endif
} }
else if (StringBeginsWith(responseLine, NS_LITERAL_CSTRING("SIZE"), nsCaseInsensitiveCStringComparator())) else if (StringBeginsWith(responseLine, NS_LITERAL_CSTRING("SIZE"), nsCaseInsensitiveCStringComparator()))
{ {
@ -891,9 +903,11 @@ void nsSmtpProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
case nsMsgAuthMethod::GSSAPI: case nsMsgAuthMethod::GSSAPI:
m_prefAuthMethods = SMTP_AUTH_GSSAPI_ENABLED; m_prefAuthMethods = SMTP_AUTH_GSSAPI_ENABLED;
break; break;
#ifdef MOZ_MAILNEWS_OAUTH2
case nsMsgAuthMethod::OAuth2: case nsMsgAuthMethod::OAuth2:
m_prefAuthMethods = SMTP_AUTH_OAUTH2_ENABLED; m_prefAuthMethods = SMTP_AUTH_OAUTH2_ENABLED;
break; break;
#endif
case nsMsgAuthMethod::secure: case nsMsgAuthMethod::secure:
m_prefAuthMethods = SMTP_AUTH_CRAM_MD5_ENABLED | m_prefAuthMethods = SMTP_AUTH_CRAM_MD5_ENABLED |
SMTP_AUTH_GSSAPI_ENABLED | SMTP_AUTH_GSSAPI_ENABLED |
@ -912,14 +926,18 @@ void nsSmtpProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
SMTP_AUTH_LOGIN_ENABLED | SMTP_AUTH_PLAIN_ENABLED | SMTP_AUTH_LOGIN_ENABLED | SMTP_AUTH_PLAIN_ENABLED |
SMTP_AUTH_CRAM_MD5_ENABLED | SMTP_AUTH_GSSAPI_ENABLED | SMTP_AUTH_CRAM_MD5_ENABLED | SMTP_AUTH_GSSAPI_ENABLED |
SMTP_AUTH_NTLM_ENABLED | SMTP_AUTH_MSN_ENABLED | SMTP_AUTH_NTLM_ENABLED | SMTP_AUTH_MSN_ENABLED |
#ifdef MOZ_MAILNEWS_OAUTH2
SMTP_AUTH_OAUTH2_ENABLED | SMTP_AUTH_OAUTH2_ENABLED |
#endif
SMTP_AUTH_EXTERNAL_ENABLED; SMTP_AUTH_EXTERNAL_ENABLED;
break; break;
} }
#ifdef MOZ_MAILNEWS_OAUTH2
// Only enable OAuth2 support if we can do the lookup. // Only enable OAuth2 support if we can do the lookup.
if ((m_prefAuthMethods & SMTP_AUTH_OAUTH2_ENABLED) && !mOAuth2Support) if ((m_prefAuthMethods & SMTP_AUTH_OAUTH2_ENABLED) && !mOAuth2Support)
m_prefAuthMethods &= ~SMTP_AUTH_OAUTH2_ENABLED; m_prefAuthMethods &= ~SMTP_AUTH_OAUTH2_ENABLED;
#endif
NS_ASSERTION(m_prefAuthMethods != 0, "SMTP:InitPrefAuthMethods() failed"); NS_ASSERTION(m_prefAuthMethods != 0, "SMTP:InitPrefAuthMethods() failed");
} }
@ -952,8 +970,10 @@ nsresult nsSmtpProtocol::ChooseAuthMethod()
m_currentAuthMethod = SMTP_AUTH_NTLM_ENABLED; m_currentAuthMethod = SMTP_AUTH_NTLM_ENABLED;
else if (SMTP_AUTH_MSN_ENABLED & availCaps) else if (SMTP_AUTH_MSN_ENABLED & availCaps)
m_currentAuthMethod = SMTP_AUTH_MSN_ENABLED; m_currentAuthMethod = SMTP_AUTH_MSN_ENABLED;
#ifdef MOZ_MAILNEWS_OAUTH2
else if (SMTP_AUTH_OAUTH2_ENABLED & availCaps) else if (SMTP_AUTH_OAUTH2_ENABLED & availCaps)
m_currentAuthMethod = SMTP_AUTH_OAUTH2_ENABLED; m_currentAuthMethod = SMTP_AUTH_OAUTH2_ENABLED;
#endif
else if (SMTP_AUTH_PLAIN_ENABLED & availCaps) else if (SMTP_AUTH_PLAIN_ENABLED & availCaps)
m_currentAuthMethod = SMTP_AUTH_PLAIN_ENABLED; m_currentAuthMethod = SMTP_AUTH_PLAIN_ENABLED;
else if (SMTP_AUTH_LOGIN_ENABLED & availCaps) else if (SMTP_AUTH_LOGIN_ENABLED & availCaps)
@ -1060,10 +1080,12 @@ nsresult nsSmtpProtocol::ProcessAuth()
{ {
m_nextState = SMTP_SEND_AUTH_LOGIN_STEP0; m_nextState = SMTP_SEND_AUTH_LOGIN_STEP0;
} }
#ifdef MOZ_MAILNEWS_OAUTH2
else if (m_currentAuthMethod == SMTP_AUTH_OAUTH2_ENABLED) else if (m_currentAuthMethod == SMTP_AUTH_OAUTH2_ENABLED)
{ {
m_nextState = SMTP_AUTH_OAUTH2_STEP; m_nextState = SMTP_AUTH_OAUTH2_STEP;
} }
#endif
else // All auth methods failed else // All auth methods failed
{ {
// show an appropriate error msg // show an appropriate error msg
@ -1487,6 +1509,7 @@ nsresult nsSmtpProtocol::AuthLoginStep2()
return static_cast<nsresult>(-1); return static_cast<nsresult>(-1);
} }
#ifdef MOZ_MAILNEWS_OAUTH2
nsresult nsSmtpProtocol::AuthOAuth2Step1() nsresult nsSmtpProtocol::AuthOAuth2Step1()
{ {
MOZ_ASSERT(mOAuth2Support, "Can't do anything without OAuth2 support"); MOZ_ASSERT(mOAuth2Support, "Can't do anything without OAuth2 support");
@ -1536,7 +1559,7 @@ nsresult nsSmtpProtocol::OnFailure(nsresult aError)
m_nextState = SMTP_ERROR_DONE; m_nextState = SMTP_ERROR_DONE;
return ProcessProtocolState(nullptr, nullptr, 0, 0); return ProcessProtocolState(nullptr, nullptr, 0, 0);
} }
#endif
nsresult nsSmtpProtocol::SendMailResponse() nsresult nsSmtpProtocol::SendMailResponse()
{ {
@ -2025,10 +2048,11 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp
status = AuthLoginStep2(); status = AuthLoginStep2();
break; break;
#ifdef MOZ_MAILNEWS_OAUTH2
case SMTP_AUTH_OAUTH2_STEP: case SMTP_AUTH_OAUTH2_STEP:
status = AuthOAuth2Step1(); status = AuthOAuth2Step1();
break; break;
#endif
case SMTP_SEND_MAIL_RESPONSE: case SMTP_SEND_MAIL_RESPONSE:
if (inputStream == nullptr) if (inputStream == nullptr)
@ -2086,11 +2110,13 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp
nsMsgAsyncWriteProtocol::CloseSocket(); nsMsgAsyncWriteProtocol::CloseSocket();
return NS_OK; /* final end */ return NS_OK; /* final end */
#ifdef MOZ_MAILNEWS_OAUTH2
// This state means we're going into an async loop and waiting for // This state means we're going into an async loop and waiting for
// something (say auth) to happen. ProcessProtocolState will be // something (say auth) to happen. ProcessProtocolState will be
// retriggered when necessary. // retriggered when necessary.
case SMTP_SUSPENDED: case SMTP_SUSPENDED:
return NS_OK; return NS_OK;
#endif
default: /* should never happen !!! */ default: /* should never happen !!! */
m_nextState = SMTP_ERROR_DONE; m_nextState = SMTP_ERROR_DONE;

View file

@ -7,7 +7,9 @@
#define nsSmtpProtocol_h___ #define nsSmtpProtocol_h___
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#ifdef MOZ_MAILNEWS_OAUTH2
#include "msgIOAuth2Module.h" #include "msgIOAuth2Module.h"
#endif
#include "nsMsgProtocol.h" #include "nsMsgProtocol.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsISmtpUrl.h" #include "nsISmtpUrl.h"
@ -19,8 +21,10 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsTArray.h" #include "nsTArray.h"
#ifdef MOZ_MAILNEWS_OAUTH2
class nsIVariant; class nsIVariant;
class nsIWritableVariant; class nsIWritableVariant;
#endif
/* states of the machine /* states of the machine
*/ */
@ -50,9 +54,11 @@ SMTP_AUTH_PROCESS_STATE, // 21
SMTP_AUTH_CRAM_MD5_CHALLENGE_RESPONSE, // 22 SMTP_AUTH_CRAM_MD5_CHALLENGE_RESPONSE, // 22
SMTP_SEND_AUTH_GSSAPI_FIRST, // 23 SMTP_SEND_AUTH_GSSAPI_FIRST, // 23
SMTP_SEND_AUTH_GSSAPI_STEP, // 24 SMTP_SEND_AUTH_GSSAPI_STEP, // 24
#ifdef MOZ_MAILNEWS_OAUTH2
SMTP_SUSPENDED, // 25 SMTP_SUSPENDED, // 25
SMTP_AUTH_OAUTH2_STEP, // 26 SMTP_AUTH_OAUTH2_STEP, // 26
SMTP_AUTH_OAUTH2_RESPONSE, // 27 SMTP_AUTH_OAUTH2_RESPONSE, // 27
#endif
} SmtpState; } SmtpState;
// State Flags (Note, I use the word state in terms of storing // State Flags (Note, I use the word state in terms of storing
@ -75,6 +81,7 @@ SMTP_AUTH_OAUTH2_RESPONSE, // 27
#define SMTP_AUTH_CRAM_MD5_ENABLED 0x00002000 #define SMTP_AUTH_CRAM_MD5_ENABLED 0x00002000
#define SMTP_AUTH_NTLM_ENABLED 0x00004000 #define SMTP_AUTH_NTLM_ENABLED 0x00004000
#define SMTP_AUTH_MSN_ENABLED 0x00008000 #define SMTP_AUTH_MSN_ENABLED 0x00008000
#ifdef MOZ_MAILNEWS_OAUTH2
#define SMTP_AUTH_OAUTH2_ENABLED 0x00010000 #define SMTP_AUTH_OAUTH2_ENABLED 0x00010000
// sum of all above auth mechanisms // sum of all above auth mechanisms
#define SMTP_AUTH_ANY 0x0001FF00 #define SMTP_AUTH_ANY 0x0001FF00
@ -82,13 +89,24 @@ SMTP_AUTH_OAUTH2_RESPONSE, // 27
#define SMTP_AUTH 0x00020000 #define SMTP_AUTH 0x00020000
// No login necessary (pref) // No login necessary (pref)
#define SMTP_AUTH_NONE_ENABLED 0x00040000 #define SMTP_AUTH_NONE_ENABLED 0x00040000
#else
#define SMTP_AUTH_ANY 0x0000FF00
#define SMTP_AUTH 0x00010000
#define SMTP_AUTH_NONE_ENABLED 0x00020000
#endif
#ifdef MOZ_MAILNEWS_OAUTH2
class nsSmtpProtocol : public nsMsgAsyncWriteProtocol, class nsSmtpProtocol : public nsMsgAsyncWriteProtocol,
public msgIOAuth2ModuleListener public msgIOAuth2ModuleListener
#else
class nsSmtpProtocol : public nsMsgAsyncWriteProtocol
#endif
{ {
public: public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
#ifdef MOZ_MAILNEWS_OAUTH2
NS_DECL_MSGIOAUTH2MODULELISTENER NS_DECL_MSGIOAUTH2MODULELISTENER
#endif
// Creating a protocol instance requires the URL which needs to be run. // Creating a protocol instance requires the URL which needs to be run.
nsSmtpProtocol(nsIURI * aURL); nsSmtpProtocol(nsIURI * aURL);
@ -182,7 +200,9 @@ private:
nsresult AuthLoginStep1(); nsresult AuthLoginStep1();
nsresult AuthLoginStep2(); nsresult AuthLoginStep2();
nsresult AuthLoginResponse(nsIInputStream * stream, uint32_t length); nsresult AuthLoginResponse(nsIInputStream * stream, uint32_t length);
#ifdef MOZ_MAILNEWS_OAUTH2
nsresult AuthOAuth2Step1(); nsresult AuthOAuth2Step1();
#endif
nsresult SendTLSResponse(); nsresult SendTLSResponse();
nsresult SendMailResponse(); nsresult SendMailResponse();
@ -217,9 +237,11 @@ private:
int32_t m_failedAuthMethods; // ditto int32_t m_failedAuthMethods; // ditto
int32_t m_currentAuthMethod; // exactly one capability flag, or 0 int32_t m_currentAuthMethod; // exactly one capability flag, or 0
#ifdef MOZ_MAILNEWS_OAUTH2
// The support module for OAuth2 logon, only present if OAuth2 is enabled // The support module for OAuth2 logon, only present if OAuth2 is enabled
// and working. // and working.
nsCOMPtr<msgIOAuth2Module> mOAuth2Support; nsCOMPtr<msgIOAuth2Module> mOAuth2Support;
#endif
}; };
#endif // nsSmtpProtocol_h___ #endif // nsSmtpProtocol_h___

View file

@ -147,7 +147,9 @@ const eIMAPCapabilityFlag kHasHighestModSeqCapability = 0x80000000; /* Subset o
const eIMAPCapabilityFlag kHasListExtendedCapability = 0x100000000LL; /* RFC 5258 */ const eIMAPCapabilityFlag kHasListExtendedCapability = 0x100000000LL; /* RFC 5258 */
const eIMAPCapabilityFlag kHasSpecialUseCapability = 0x200000000LL; /* RFC 6154: Sent, Draft etc. folders */ const eIMAPCapabilityFlag kHasSpecialUseCapability = 0x200000000LL; /* RFC 6154: Sent, Draft etc. folders */
const eIMAPCapabilityFlag kGmailImapCapability = 0x400000000LL; /* X-GM-EXT-1 capability extension for gmail */ const eIMAPCapabilityFlag kGmailImapCapability = 0x400000000LL; /* X-GM-EXT-1 capability extension for gmail */
#ifdef MOZ_MAILNEWS_OAUTH2
const eIMAPCapabilityFlag kHasXOAuth2Capability = 0x800000000LL; /* AUTH XOAUTH2 extension */ const eIMAPCapabilityFlag kHasXOAuth2Capability = 0x800000000LL; /* AUTH XOAUTH2 extension */
#endif
// this used to be part of the connection object class - maybe we should move it into // this used to be part of the connection object class - maybe we should move it into

View file

@ -797,7 +797,11 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
server->GetRealHostName(m_realHostName); server->GetRealHostName(m_realHostName);
int32_t authMethod; int32_t authMethod;
(void) server->GetAuthMethod(&authMethod); (void) server->GetAuthMethod(&authMethod);
#ifdef MOZ_MAILNEWS_OAUTH2
InitPrefAuthMethods(authMethod, server); InitPrefAuthMethods(authMethod, server);
#else
InitPrefAuthMethods(authMethod);
#endif
(void) server->GetSocketType(&m_socketType); (void) server->GetSocketType(&m_socketType);
bool shuttingDown; bool shuttingDown;
(void) imapServer->GetShuttingDown(&shuttingDown); (void) imapServer->GetShuttingDown(&shuttingDown);
@ -5563,8 +5567,12 @@ void nsImapProtocol::EscapeUserNamePasswordString(const char *strToEscape, nsCSt
} }
} }
#ifdef MOZ_MAILNEWS_OAUTH2
void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue, void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue,
nsIMsgIncomingServer *aServer) nsIMsgIncomingServer *aServer)
#else
void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
#endif
{ {
// for m_prefAuthMethods, using the same flags as server capablities. // for m_prefAuthMethods, using the same flags as server capablities.
switch (authMethodPrefValue) switch (authMethodPrefValue)
@ -5608,11 +5616,16 @@ void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue,
kHasAuthLoginCapability | kHasAuthPlainCapability | kHasAuthLoginCapability | kHasAuthPlainCapability |
kHasCRAMCapability | kHasAuthGssApiCapability | kHasCRAMCapability | kHasAuthGssApiCapability |
kHasAuthNTLMCapability | kHasAuthMSNCapability | kHasAuthNTLMCapability | kHasAuthMSNCapability |
#ifdef MOZ_MAILNEWS_OAUTH2
kHasAuthExternalCapability | kHasXOAuth2Capability; kHasAuthExternalCapability | kHasXOAuth2Capability;
break; break;
case nsMsgAuthMethod::OAuth2: case nsMsgAuthMethod::OAuth2:
m_prefAuthMethods = kHasXOAuth2Capability; m_prefAuthMethods = kHasXOAuth2Capability;
#else
kHasAuthExternalCapability;
#endif
break; break;
} }
if (m_prefAuthMethods & kHasXOAuth2Capability) if (m_prefAuthMethods & kHasXOAuth2Capability)
@ -5639,12 +5652,21 @@ nsresult nsImapProtocol::ChooseAuthMethod()
MOZ_LOG(IMAP, LogLevel::Debug, ("IMAP auth: server caps 0x%llx, pref 0x%llx, failed 0x%llx, avail caps 0x%llx", MOZ_LOG(IMAP, LogLevel::Debug, ("IMAP auth: server caps 0x%llx, pref 0x%llx, failed 0x%llx, avail caps 0x%llx",
serverCaps, m_prefAuthMethods, m_failedAuthMethods, availCaps)); serverCaps, m_prefAuthMethods, m_failedAuthMethods, availCaps));
#ifdef MOZ_MAILNEWS_OAUTH2
MOZ_LOG(IMAP, LogLevel::Debug, ("(GSSAPI = 0x%llx, CRAM = 0x%llx, NTLM = 0x%llx, " MOZ_LOG(IMAP, LogLevel::Debug, ("(GSSAPI = 0x%llx, CRAM = 0x%llx, NTLM = 0x%llx, "
"MSN = 0x%llx, PLAIN = 0x%llx,\n LOGIN = 0x%llx, old-style IMAP login = 0x%llx" "MSN = 0x%llx, PLAIN = 0x%llx,\n LOGIN = 0x%llx, old-style IMAP login = 0x%llx"
", auth external IMAP login = 0x%llx, OAUTH2 = 0x%llx)", ", auth external IMAP login = 0x%llx, OAUTH2 = 0x%llx)",
kHasAuthGssApiCapability, kHasCRAMCapability, kHasAuthNTLMCapability, kHasAuthGssApiCapability, kHasCRAMCapability, kHasAuthNTLMCapability,
kHasAuthMSNCapability, kHasAuthPlainCapability, kHasAuthLoginCapability, kHasAuthMSNCapability, kHasAuthPlainCapability, kHasAuthLoginCapability,
kHasAuthOldLoginCapability, kHasAuthExternalCapability, kHasXOAuth2Capability)); kHasAuthOldLoginCapability, kHasAuthExternalCapability, kHasXOAuth2Capability));
#else
MOZ_LOG(IMAP, LogLevel::Debug, ("(GSSAPI = 0x%llx, CRAM = 0x%llx, NTLM = 0x%llx, "
"MSN = 0x%llx, PLAIN = 0x%llx,\n LOGIN = 0x%llx, old-style IMAP login = 0x%llx"
", auth external IMAP login = 0x%llx",
kHasAuthGssApiCapability, kHasCRAMCapability, kHasAuthNTLMCapability,
kHasAuthMSNCapability, kHasAuthPlainCapability, kHasAuthLoginCapability,
kHasAuthOldLoginCapability, kHasAuthExternalCapability));
#endif
if (kHasAuthExternalCapability & availCaps) if (kHasAuthExternalCapability & availCaps)
m_currentAuthMethod = kHasAuthExternalCapability; m_currentAuthMethod = kHasAuthExternalCapability;
@ -5656,8 +5678,10 @@ nsresult nsImapProtocol::ChooseAuthMethod()
m_currentAuthMethod = kHasAuthNTLMCapability; m_currentAuthMethod = kHasAuthNTLMCapability;
else if (kHasAuthMSNCapability & availCaps) else if (kHasAuthMSNCapability & availCaps)
m_currentAuthMethod = kHasAuthMSNCapability; m_currentAuthMethod = kHasAuthMSNCapability;
#ifdef MOZ_MAILNEWS_OAUTH2
else if (kHasXOAuth2Capability & availCaps) else if (kHasXOAuth2Capability & availCaps)
m_currentAuthMethod = kHasXOAuth2Capability; m_currentAuthMethod = kHasXOAuth2Capability;
#endif
else if (kHasAuthPlainCapability & availCaps) else if (kHasAuthPlainCapability & availCaps)
m_currentAuthMethod = kHasAuthPlainCapability; m_currentAuthMethod = kHasAuthPlainCapability;
else if (kHasAuthLoginCapability & availCaps) else if (kHasAuthLoginCapability & availCaps)
@ -5933,6 +5957,7 @@ nsresult nsImapProtocol::AuthLogin(const char *userName, const nsCString &passwo
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
ParseIMAPandCheckForNewMail(); ParseIMAPandCheckForNewMail();
} }
#ifdef MOZ_MAILNEWS_OAUTH2
else if (flag & kHasXOAuth2Capability) else if (flag & kHasXOAuth2Capability)
{ {
MOZ_LOG(IMAP, LogLevel::Debug, ("XOAUTH2 auth")); MOZ_LOG(IMAP, LogLevel::Debug, ("XOAUTH2 auth"));
@ -5960,6 +5985,7 @@ nsresult nsImapProtocol::AuthLogin(const char *userName, const nsCString &passwo
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
ParseIMAPandCheckForNewMail(); ParseIMAPandCheckForNewMail();
} }
#endif
else if (flag & kHasAuthNoneCapability) else if (flag & kHasAuthNoneCapability)
{ {
// TODO What to do? "login <username>" like POP? // TODO What to do? "login <username>" like POP?
@ -8617,7 +8643,9 @@ bool nsImapProtocol::TryToLogon()
// Get password // Get password
if (m_currentAuthMethod != kHasAuthGssApiCapability && // GSSAPI uses no pw in apps if (m_currentAuthMethod != kHasAuthGssApiCapability && // GSSAPI uses no pw in apps
m_currentAuthMethod != kHasAuthExternalCapability && m_currentAuthMethod != kHasAuthExternalCapability &&
#ifdef MOZ_MAILNEWS_OAUTH2
m_currentAuthMethod != kHasXOAuth2Capability && m_currentAuthMethod != kHasXOAuth2Capability &&
#endif
m_currentAuthMethod != kHasAuthNoneCapability) m_currentAuthMethod != kHasAuthNoneCapability)
{ {
rv = GetPassword(password, newPasswordRequested); rv = GetPassword(password, newPasswordRequested);
@ -8654,6 +8682,7 @@ bool nsImapProtocol::TryToLogon()
break; break;
} }
#ifdef MOZ_MAILNEWS_OAUTH2
if (m_prefAuthMethods & kHasXOAuth2Capability) if (m_prefAuthMethods & kHasXOAuth2Capability)
{ {
// OAuth2 failed. We don't have an error message for this, and we // OAuth2 failed. We don't have an error message for this, and we
@ -8662,6 +8691,7 @@ bool nsImapProtocol::TryToLogon()
AlertUserEventUsingName("imapUnknownHostError"); AlertUserEventUsingName("imapUnknownHostError");
break; break;
} }
#endif
// The reason that we failed might be a wrong password, so // The reason that we failed might be a wrong password, so
// ask user what to do // ask user what to do

View file

@ -463,8 +463,11 @@ private:
// login related methods. // login related methods.
nsresult GetPassword(nsCString &password, bool aNewPasswordRequested); nsresult GetPassword(nsCString &password, bool aNewPasswordRequested);
void InitPrefAuthMethods(int32_t authMethodPrefValue, #ifdef MOZ_MAILNEWS_OAUTH2
nsIMsgIncomingServer *aServer); void InitPrefAuthMethods(int32_t authMethodPrefValue, nsIMsgIncomingServer *aServer);
#else
void InitPrefAuthMethods(int32_t authMethodPrefValue);
#endif
nsresult ChooseAuthMethod(); nsresult ChooseAuthMethod();
void MarkAuthMethodAsFailed(eIMAPCapabilityFlags failedAuthMethod); void MarkAuthMethodAsFailed(eIMAPCapabilityFlags failedAuthMethod);
void ResetAuthMethods(); void ResetAuthMethods();
@ -675,7 +678,9 @@ private:
nsString m_emptyMimePartString; nsString m_emptyMimePartString;
#ifdef MOZ_MAILNEWS_OAUTH2
RefPtr<mozilla::mailnews::OAuth2ThreadHelper> mOAuth2Support; RefPtr<mozilla::mailnews::OAuth2ThreadHelper> mOAuth2Support;
#endif
}; };
// This small class is a "mock" channel because it is a mockery of the imap channel's implementation... // This small class is a "mock" channel because it is a mockery of the imap channel's implementation...

View file

@ -2250,8 +2250,10 @@ void nsImapServerResponseParser::capability_data()
fCapabilityFlag |= kHasAuthMSNCapability; fCapabilityFlag |= kHasAuthMSNCapability;
else if (token.Equals("AUTH=EXTERNAL", nsCaseInsensitiveCStringComparator())) else if (token.Equals("AUTH=EXTERNAL", nsCaseInsensitiveCStringComparator()))
fCapabilityFlag |= kHasAuthExternalCapability; fCapabilityFlag |= kHasAuthExternalCapability;
#ifdef MOZ_MAILNEWS_OAUTH2
else if (token.Equals("AUTH=XOAUTH2", nsCaseInsensitiveCStringComparator())) else if (token.Equals("AUTH=XOAUTH2", nsCaseInsensitiveCStringComparator()))
fCapabilityFlag |= kHasXOAuth2Capability; fCapabilityFlag |= kHasXOAuth2Capability;
#endif
else if (token.Equals("STARTTLS", nsCaseInsensitiveCStringComparator())) else if (token.Equals("STARTTLS", nsCaseInsensitiveCStringComparator()))
fCapabilityFlag |= kHasStartTLSCapability; fCapabilityFlag |= kHasStartTLSCapability;
else if (token.Equals("LOGINDISABLED", nsCaseInsensitiveCStringComparator())) else if (token.Equals("LOGINDISABLED", nsCaseInsensitiveCStringComparator()))

View file

@ -457,7 +457,7 @@ NS_SYNCRUNNABLEMETHOD1(ImapServerSink, ResetServerConnection, const nsACString &
NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerDoingLsub, bool) NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerDoingLsub, bool)
NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerForceSelect, const nsACString &) NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerForceSelect, const nsACString &)
#ifdef MOZ_MAILNEWS_OAUTH2
namespace mozilla { namespace mozilla {
namespace mailnews { namespace mailnews {
@ -598,3 +598,4 @@ nsresult OAuth2ThreadHelper::OnFailure(nsresult aError)
} // namespace mailnews } // namespace mailnews
} // namespace mozilla } // namespace mozilla
#endif

View file

@ -8,8 +8,11 @@
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#ifdef MOZ_MAILNEWS_OAUTH2
#include "mozilla/Monitor.h" #include "mozilla/Monitor.h"
#include "msgIOAuth2Module.h" #include "msgIOAuth2Module.h"
#endif
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIImapMailFolderSink.h" #include "nsIImapMailFolderSink.h"
@ -110,6 +113,7 @@ private:
nsCOMPtr<nsIImapProtocolSink> mReceiver; nsCOMPtr<nsIImapProtocolSink> mReceiver;
}; };
#ifdef MOZ_MAILNEWS_OAUTH2
class msgIOAuth2Module; class msgIOAuth2Module;
class nsIMsgIncomingServer; class nsIMsgIncomingServer;
class nsIVariant; class nsIVariant;
@ -142,5 +146,6 @@ private:
} // namespace mailnews } // namespace mailnews
} // namespace mozilla } // namespace mozilla
#endif
#endif // nsSyncRunnableHelpers_h #endif // nsSyncRunnableHelpers_h

View file

@ -22,10 +22,10 @@ messenger.jar:
content/messenger/am-main.xul (base/prefs/content/am-main.xul) content/messenger/am-main.xul (base/prefs/content/am-main.xul)
content/messenger/am-main.js (base/prefs/content/am-main.js) content/messenger/am-main.js (base/prefs/content/am-main.js)
content/messenger/am-help.js (base/prefs/content/am-help.js) content/messenger/am-help.js (base/prefs/content/am-help.js)
content/messenger/am-server.xul (base/prefs/content/am-server.xul) * content/messenger/am-server.xul (base/prefs/content/am-server.xul)
content/messenger/am-serverwithnoidentities.xul (base/prefs/content/am-serverwithnoidentities.xul) content/messenger/am-serverwithnoidentities.xul (base/prefs/content/am-serverwithnoidentities.xul)
content/messenger/am-serverwithnoidentities.js (base/prefs/content/am-serverwithnoidentities.js) content/messenger/am-serverwithnoidentities.js (base/prefs/content/am-serverwithnoidentities.js)
content/messenger/am-server.js (base/prefs/content/am-server.js) * content/messenger/am-server.js (base/prefs/content/am-server.js)
content/messenger/am-server-top.xul (base/prefs/content/am-server-top.xul) content/messenger/am-server-top.xul (base/prefs/content/am-server-top.xul)
content/messenger/am-copies.xul (base/prefs/content/am-copies.xul) content/messenger/am-copies.xul (base/prefs/content/am-copies.xul)
content/messenger/am-copies.js (base/prefs/content/am-copies.js) content/messenger/am-copies.js (base/prefs/content/am-copies.js)
@ -39,7 +39,7 @@ messenger.jar:
content/messenger/am-server-advanced.xul (base/prefs/content/am-server-advanced.xul) content/messenger/am-server-advanced.xul (base/prefs/content/am-server-advanced.xul)
content/messenger/am-server-advanced.js (base/prefs/content/am-server-advanced.js) content/messenger/am-server-advanced.js (base/prefs/content/am-server-advanced.js)
content/messenger/am-smtp.xul (base/prefs/content/am-smtp.xul) content/messenger/am-smtp.xul (base/prefs/content/am-smtp.xul)
content/messenger/am-smtp.js (base/prefs/content/am-smtp.js) * content/messenger/am-smtp.js (base/prefs/content/am-smtp.js)
content/messenger/am-prefs.js (base/prefs/content/am-prefs.js) content/messenger/am-prefs.js (base/prefs/content/am-prefs.js)
content/messenger/am-identities-list.js (base/prefs/content/am-identities-list.js) content/messenger/am-identities-list.js (base/prefs/content/am-identities-list.js)
content/messenger/am-identities-list.xul (base/prefs/content/am-identities-list.xul) content/messenger/am-identities-list.xul (base/prefs/content/am-identities-list.xul)
@ -61,23 +61,23 @@ messenger.jar:
content/messenger/ispUtils.js (base/prefs/content/ispUtils.js) content/messenger/ispUtils.js (base/prefs/content/ispUtils.js)
content/messenger/SmtpServerEdit.xul (base/prefs/content/SmtpServerEdit.xul) content/messenger/SmtpServerEdit.xul (base/prefs/content/SmtpServerEdit.xul)
content/messenger/SmtpServerEdit.js (base/prefs/content/SmtpServerEdit.js) content/messenger/SmtpServerEdit.js (base/prefs/content/SmtpServerEdit.js)
content/messenger/smtpEditOverlay.xul (base/prefs/content/smtpEditOverlay.xul) * content/messenger/smtpEditOverlay.xul (base/prefs/content/smtpEditOverlay.xul)
content/messenger/smtpEditOverlay.js (base/prefs/content/smtpEditOverlay.js) * content/messenger/smtpEditOverlay.js (base/prefs/content/smtpEditOverlay.js)
content/messenger/removeAccount.xul (base/prefs/content/removeAccount.xul) content/messenger/removeAccount.xul (base/prefs/content/removeAccount.xul)
content/messenger/removeAccount.js (base/prefs/content/removeAccount.js) content/messenger/removeAccount.js (base/prefs/content/removeAccount.js)
#if defined(MOZ_THUNDERBIRD) && defined(HYPE_ICEDOVE) #if defined(MOZ_THUNDERBIRD) && defined(HYPE_ICEDOVE)
content/messenger/accountcreation/accountConfig.js (base/prefs/content/accountcreation/accountConfig.js) * content/messenger/accountcreation/accountConfig.js (base/prefs/content/accountcreation/accountConfig.js)
content/messenger/accountcreation/createInBackend.js (base/prefs/content/accountcreation/createInBackend.js) * content/messenger/accountcreation/createInBackend.js (base/prefs/content/accountcreation/createInBackend.js)
content/messenger/accountcreation/emailWizard.js (base/prefs/content/accountcreation/emailWizard.js) * content/messenger/accountcreation/emailWizard.js (base/prefs/content/accountcreation/emailWizard.js)
content/messenger/accountcreation/emailWizard.xul (base/prefs/content/accountcreation/emailWizard.xul) * content/messenger/accountcreation/emailWizard.xul (base/prefs/content/accountcreation/emailWizard.xul)
content/messenger/accountcreation/fetchConfig.js (base/prefs/content/accountcreation/fetchConfig.js) content/messenger/accountcreation/fetchConfig.js (base/prefs/content/accountcreation/fetchConfig.js)
content/messenger/accountcreation/fetchhttp.js (base/prefs/content/accountcreation/fetchhttp.js) content/messenger/accountcreation/fetchhttp.js (base/prefs/content/accountcreation/fetchhttp.js)
content/messenger/accountcreation/guessConfig.js (base/prefs/content/accountcreation/guessConfig.js) * content/messenger/accountcreation/guessConfig.js (base/prefs/content/accountcreation/guessConfig.js)
content/messenger/accountcreation/MyBadCertHandler.js (base/prefs/content/accountcreation/MyBadCertHandler.js) content/messenger/accountcreation/MyBadCertHandler.js (base/prefs/content/accountcreation/MyBadCertHandler.js)
content/messenger/accountcreation/readFromXML.js (base/prefs/content/accountcreation/readFromXML.js) * content/messenger/accountcreation/readFromXML.js (base/prefs/content/accountcreation/readFromXML.js)
content/messenger/accountcreation/sanitizeDatatypes.js (base/prefs/content/accountcreation/sanitizeDatatypes.js) content/messenger/accountcreation/sanitizeDatatypes.js (base/prefs/content/accountcreation/sanitizeDatatypes.js)
content/messenger/accountcreation/util.js (base/prefs/content/accountcreation/util.js) content/messenger/accountcreation/util.js (base/prefs/content/accountcreation/util.js)
content/messenger/accountcreation/verifyConfig.js (base/prefs/content/accountcreation/verifyConfig.js) * content/messenger/accountcreation/verifyConfig.js (base/prefs/content/accountcreation/verifyConfig.js)
#endif #endif
content/messenger/msgSynchronize.xul (base/content/msgSynchronize.xul) content/messenger/msgSynchronize.xul (base/content/msgSynchronize.xul)
content/messenger/msgSynchronize.js (base/content/msgSynchronize.js) content/messenger/msgSynchronize.js (base/content/msgSynchronize.js)

View file

@ -2265,6 +2265,7 @@ MOZ_SERVICES_HEALTHREPORT=1
MOZ_SERVICES_SYNC=1 MOZ_SERVICES_SYNC=1
MOZ_USERINFO=1 MOZ_USERINFO=1
MOZ_MAILNEWS= MOZ_MAILNEWS=
MOZ_MAILNEWS_OAUTH2=
MOZ_LDAP_XPCOM= MOZ_LDAP_XPCOM=
MOZ_MORK= MOZ_MORK=
MOZ_MAPI_SUPPORT= MOZ_MAPI_SUPPORT=
@ -2835,6 +2836,7 @@ MOZ_ARG_ENABLE_BOOL(mailnews,
MOZ_MAILNEWS=) MOZ_MAILNEWS=)
if test -n "$MOZ_MAILNEWS"; then if test -n "$MOZ_MAILNEWS"; then
MOZ_MAILNEWS_OAUTH2=1
MOZ_MORK=1 MOZ_MORK=1
MOZ_LDAP_XPCOM=1 MOZ_LDAP_XPCOM=1
@ -2854,6 +2856,20 @@ AC_SUBST(MOZ_MAILNEWS)
AC_SUBST(MOZ_MORK) AC_SUBST(MOZ_MORK)
AC_SUBST(MOZ_MOVEMAIL) AC_SUBST(MOZ_MOVEMAIL)
dnl =========================================================
dnl = Mailnews OAuth2 Support
dnl =========================================================
MOZ_ARG_DISABLE_BOOL(mailnews-oauth2,
[ --disable-mailnews-oauth2 Disable oauth2 support in mailnews],
MOZ_MAILNEWS_OAUTH2=,
MOZ_MAILNEWS_OAUTH2=1)
if test -n "$MOZ_MAILNEWS_OAUTH2"; then
AC_DEFINE(MOZ_MAILNEWS_OAUTH2)
fi
AC_SUBST(MOZ_MAILNEWS_OAUTH2)
dnl ========================================================= dnl =========================================================
dnl = LDAP dnl = LDAP
dnl ========================================================= dnl =========================================================