From 03590a6711d601ef3ddb48787e9f3f556705b5db Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Tue, 5 Nov 2019 18:27:14 -0500 Subject: Issue #1258 - Part 8: Ifdef MailNews OAuth2 Support Use --disable-mailnews-oauth2 to exclude it. Confvars won't be respected. --- build/moz.configure/old.configure | 1 + .../prefs/content/accountcreation/accountConfig.js | 2 ++ .../content/accountcreation/createInBackend.js | 4 +++ .../prefs/content/accountcreation/emailWizard.js | 14 ++++++++++ .../prefs/content/accountcreation/emailWizard.xul | 4 +++ .../prefs/content/accountcreation/guessConfig.js | 2 ++ .../prefs/content/accountcreation/readFromXML.js | 7 ++++- .../prefs/content/accountcreation/verifyConfig.js | 6 +++++ mailnews/base/prefs/content/am-server.js | 4 +++ mailnews/base/prefs/content/am-server.xul | 2 ++ mailnews/base/prefs/content/am-smtp.js | 2 ++ mailnews/base/prefs/content/smtpEditOverlay.js | 2 ++ mailnews/base/prefs/content/smtpEditOverlay.xul | 2 ++ mailnews/base/public/moz.build | 4 ++- mailnews/base/src/moz.build | 7 +++-- mailnews/base/src/msgBase.manifest | 2 ++ mailnews/base/util/moz.build | 8 ++++-- mailnews/compose/src/nsSmtpProtocol.cpp | 30 ++++++++++++++++++++-- mailnews/compose/src/nsSmtpProtocol.h | 22 ++++++++++++++++ mailnews/imap/src/nsImapCore.h | 2 ++ mailnews/imap/src/nsImapProtocol.cpp | 30 ++++++++++++++++++++++ mailnews/imap/src/nsImapProtocol.h | 9 +++++-- mailnews/imap/src/nsImapServerResponseParser.cpp | 2 ++ mailnews/imap/src/nsSyncRunnableHelpers.cpp | 3 ++- mailnews/imap/src/nsSyncRunnableHelpers.h | 5 ++++ mailnews/jar.mn | 24 ++++++++--------- old-configure.in | 16 ++++++++++++ 27 files changed, 193 insertions(+), 23 deletions(-) diff --git a/build/moz.configure/old.configure b/build/moz.configure/old.configure index d6e8a287d..65add5cdc 100644 --- a/build/moz.configure/old.configure +++ b/build/moz.configure/old.configure @@ -308,6 +308,7 @@ def old_configure_options(*options): '--enable-calendar', '--enable-incomplete-external-linkage', '--enable-mailnews', + '--enable-mailnews-oauth2', # Below are configure flags used by Pale Moon '--disable-browser-statusbar', diff --git a/mailnews/base/prefs/content/accountcreation/accountConfig.js b/mailnews/base/prefs/content/accountcreation/accountConfig.js index 3a757d8ee..752c72624 100644 --- a/mailnews/base/prefs/content/accountcreation/accountConfig.js +++ b/mailnews/base/prefs/content/accountcreation/accountConfig.js @@ -50,8 +50,10 @@ AccountConfig.prototype = */ incomingAlternatives : null, outgoingAlternatives : null, +#ifdef MOZ_MAILNEWS_OAUTH2 // OAuth2 configuration, if needed. oauthSettings : null, +#endif // just an internal string to refer to this. Do not show to user. id : null, // who created the config. diff --git a/mailnews/base/prefs/content/accountcreation/createInBackend.js b/mailnews/base/prefs/content/accountcreation/createInBackend.js index d959c3ae9..cd984fd3c 100644 --- a/mailnews/base/prefs/content/accountcreation/createInBackend.js +++ b/mailnews/base/prefs/content/accountcreation/createInBackend.js @@ -28,10 +28,12 @@ function createAccountInBackend(config) if (config.rememberPassword && config.incoming.password.length) rememberPassword(inServer, config.incoming.password); +#ifdef MOZ_MAILNEWS_OAUTH2 if (inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) { inServer.setCharValue("oauth2.scope", config.oauthSettings.scope); inServer.setCharValue("oauth2.issuer", config.oauthSettings.issuer); } +#endif // SSL if (config.incoming.socketType == 1) // plain @@ -107,6 +109,7 @@ function createAccountInBackend(config) rememberPassword(outServer, config.incoming.password); } +#ifdef MOZ_MAILNEWS_OAUTH2 if (outServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) { let pref = "mail.smtpserver." + outServer.key + "."; Services.prefs.setCharPref(pref + "oauth2.scope", @@ -114,6 +117,7 @@ function createAccountInBackend(config) Services.prefs.setCharPref(pref + "oauth2.issuer", config.oauthSettings.issuer); } +#endif if (config.outgoing.socketType == 1) // no SSL outServer.socketType = Ci.nsMsgSocketType.plain; diff --git a/mailnews/base/prefs/content/accountcreation/emailWizard.js b/mailnews/base/prefs/content/accountcreation/emailWizard.js index b4e6854da..389feab6c 100644 --- a/mailnews/base/prefs/content/accountcreation/emailWizard.js +++ b/mailnews/base/prefs/content/accountcreation/emailWizard.js @@ -6,7 +6,9 @@ Components.utils.import("resource:///modules/mailServices.js"); Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource:///modules/hostnameUtils.jsm"); +#ifdef MOZ_MAILNEWS_OAUTH2 Components.utils.import("resource://gre/modules/OAuth2Providers.jsm"); +#endif /** * This is the dialog opened by menu File | New account | Mail... . @@ -184,7 +186,9 @@ EmailConfigWizard.prototype = "authPasswordEncrypted"); setLabelFromStringBundle("in-authMethod-kerberos", "authKerberos"); setLabelFromStringBundle("in-authMethod-ntlm", "authNTLM"); +#ifdef MOZ_MAILNEWS_OAUTH2 setLabelFromStringBundle("in-authMethod-oauth2", "authOAuth2"); +#endif setLabelFromStringBundle("out-authMethod-no", "authNo"); setLabelFromStringBundle("out-authMethod-password-cleartext", "authPasswordCleartextViaSSL"); // will warn about insecure later @@ -1014,7 +1018,11 @@ EmailConfigWizard.prototype = e("incoming_ssl").value = sanitize.enum(config.incoming.socketType, [ 0, 1, 2, 3 ], 0); e("incoming_authMethod").value = sanitize.enum(config.incoming.auth, +#ifdef MOZ_MAILNEWS_OAUTH2 [ 0, 3, 4, 5, 6, 10 ], 0); +#else + [ 0, 3, 4, 5, 6 ], 0); +#endif e("incoming_username").value = config.incoming.username; if (config.incoming.port) { e("incoming_port").value = config.incoming.port; @@ -1023,6 +1031,7 @@ EmailConfigWizard.prototype = } this.fillPortDropdown(config.incoming.type); +#ifdef MOZ_MAILNEWS_OAUTH2 // If the hostname supports OAuth2 and imap is enabled, enable OAuth2. let iDetails = OAuth2Providers.getHostnameDetails(config.incoming.hostname); gEmailWizardLogger.info("OAuth2 details for incoming hostname " + @@ -1035,6 +1044,7 @@ EmailConfigWizard.prototype = // store them in the base configuration. this._currentConfig.oauthSettings = config.oauthSettings; } +#endif // outgoing server e("outgoing_hostname").value = config.outgoing.hostname; @@ -1052,6 +1062,7 @@ EmailConfigWizard.prototype = this.adjustOutgoingPortToSSLAndProtocol(config); } +#ifdef MOZ_MAILNEWS_OAUTH2 // If the hostname supports OAuth2 and imap is enabled, enable OAuth2. let oDetails = OAuth2Providers.getHostnameDetails(config.outgoing.hostname); gEmailWizardLogger.info("OAuth2 details for outgoing hostname " + @@ -1064,6 +1075,7 @@ EmailConfigWizard.prototype = // store them in the base configuration. this._currentConfig.oauthSettings = config.oauthSettings; } +#endif // populate fields even if existingServerKey, in case user changes back if (config.outgoing.existingServerKey) { @@ -1614,10 +1626,12 @@ EmailConfigWizard.prototype = self._currentConfig.incoming.username = successfulConfig.incoming.username; self._currentConfig.outgoing.username = successfulConfig.outgoing.username; +#ifdef MOZ_MAILNEWS_OAUTH2 // We loaded dynamic client registration, fill this data back in to the // config set. if (successfulConfig.oauthSettings) self._currentConfig.oauthSettings = successfulConfig.oauthSettings; +#endif self.finish(); }, diff --git a/mailnews/base/prefs/content/accountcreation/emailWizard.xul b/mailnews/base/prefs/content/accountcreation/emailWizard.xul index 0777d1651..261545671 100644 --- a/mailnews/base/prefs/content/accountcreation/emailWizard.xul +++ b/mailnews/base/prefs/content/accountcreation/emailWizard.xul @@ -309,7 +309,9 @@ +#ifdef MOZ_MAILNEWS_OAUTH2