diff options
Diffstat (limited to 'mailnews')
25 files changed, 176 insertions, 23 deletions
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 @@ <menuitem id="in-authMethod-password-encrypted" value="4"/> <menuitem id="in-authMethod-kerberos" value="5"/> <menuitem id="in-authMethod-ntlm" value="6"/> +#ifdef MOZ_MAILNEWS_OAUTH2 <menuitem id="in-authMethod-oauth2" value="10" hidden="true"/> +#endif </menupopup> </menulist> </row> @@ -359,7 +361,9 @@ <menuitem id="out-authMethod-password-encrypted" value="4"/> <menuitem id="out-authMethod-kerberos" value="5"/> <menuitem id="out-authMethod-ntlm" value="6"/> +#ifdef MOZ_MAILNEWS_OAUTH2 <menuitem id="out-authMethod-oauth2" value="10" hidden="true"/> +#endif </menupopup> </menulist> </row> diff --git a/mailnews/base/prefs/content/accountcreation/guessConfig.js b/mailnews/base/prefs/content/accountcreation/guessConfig.js index 755c499cd..9a44f7904 100644 --- a/mailnews/base/prefs/content/accountcreation/guessConfig.js +++ b/mailnews/base/prefs/content/accountcreation/guessConfig.js @@ -60,11 +60,13 @@ function guessConfig(domain, progressCallback, successCallback, errorCallback, assert(typeof(successCallback) == "function", "need successCallback"); assert(typeof(errorCallback) == "function", "need errorCallback"); +#ifdef MOZ_MAILNEWS_OAUTH2 // Servers that we know enough that they support OAuth2 do not need guessing. if (resultConfig.incoming.auth == Ci.nsMsgAuthMethod.OAuth2) { successCallback(resultConfig); return null; } +#endif if (!resultConfig) resultConfig = new AccountConfig(); diff --git a/mailnews/base/prefs/content/accountcreation/readFromXML.js b/mailnews/base/prefs/content/accountcreation/readFromXML.js index c7e796f5f..4ef13ec1d 100644 --- a/mailnews/base/prefs/content/accountcreation/readFromXML.js +++ b/mailnews/base/prefs/content/accountcreation/readFromXML.js @@ -95,7 +95,10 @@ function readFromXML(clientConfigXML) "secure" : Ci.nsMsgAuthMethod.passwordEncrypted, "GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI, "NTLM" : Ci.nsMsgAuthMethod.NTLM, - "OAuth2" : Ci.nsMsgAuthMethod.OAuth2 }); +#ifdef MOZ_MAILNEWS_OAUTH2 + "OAuth2" : Ci.nsMsgAuthMethod.OAuth2 +#endif + }); break; // take first that we support } catch (e) { exception = e; } } @@ -176,7 +179,9 @@ function readFromXML(clientConfigXML) "secure" : Ci.nsMsgAuthMethod.passwordEncrypted, "GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI, "NTLM" : Ci.nsMsgAuthMethod.NTLM, +#ifdef MOZ_MAILNEWS_OAUTH2 "OAuth2" : Ci.nsMsgAuthMethod.OAuth2, +#endif }); break; // take first that we support diff --git a/mailnews/base/prefs/content/accountcreation/verifyConfig.js b/mailnews/base/prefs/content/accountcreation/verifyConfig.js index a2afbdad8..26fa7967e 100644 --- a/mailnews/base/prefs/content/accountcreation/verifyConfig.js +++ b/mailnews/base/prefs/content/accountcreation/verifyConfig.js @@ -30,7 +30,9 @@ */ Components.utils.import("resource:///modules/mailServices.js"); +#ifdef MOZ_MAILNEWS_OAUTH2 Components.utils.import("resource://gre/modules/OAuth2Providers.jsm"); +#endif if (typeof gEmailWizardLogger == "undefined") { Cu.import("resource:///modules/gloda/log4moz.js"); @@ -74,6 +76,7 @@ function verifyConfig(config, alter, msgWindow, successCallback, errorCallback) config.incoming.auth); inServer.authMethod = config.incoming.auth; +#ifdef MOZ_MAILNEWS_OAUTH2 try { // Lookup issuer if needed. if (config.incoming.auth == Ci.nsMsgAuthMethod.OAuth2 || @@ -100,6 +103,9 @@ function verifyConfig(config, alter, msgWindow, successCallback, errorCallback) if (inServer.password || inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) +#else + if (inServer.password) +#endif verifyLogon(config, inServer, alter, msgWindow, successCallback, errorCallback); else { diff --git a/mailnews/base/prefs/content/am-server.js b/mailnews/base/prefs/content/am-server.js index e3c2d2b09..01b22e4ae 100644 --- a/mailnews/base/prefs/content/am-server.js +++ b/mailnews/base/prefs/content/am-server.js @@ -31,7 +31,9 @@ function onInit(aPageId, aServerId) setupImapDeleteUI(aServerId); // TLS Cert (External) and OAuth2 are only supported on IMAP. +#ifdef MOZ_MAILNEWS_OAUTH2 document.getElementById("authMethod-oauth2").hidden = (serverType != "imap"); +#endif document.getElementById("authMethod-external").hidden = (serverType != "imap"); // "STARTTLS, if available" is vulnerable to MITM attacks so we shouldn't @@ -83,7 +85,9 @@ function initServerType() setLabelFromStringBundle("authMethod-kerberos", "authKerberos"); setLabelFromStringBundle("authMethod-external", "authExternal"); setLabelFromStringBundle("authMethod-ntlm", "authNTLM"); +#ifdef MOZ_MAILNEWS_OAUTH2 setLabelFromStringBundle("authMethod-oauth2", "authOAuth2"); +#endif setLabelFromStringBundle("authMethod-anysecure", "authAnySecure"); setLabelFromStringBundle("authMethod-any", "authAny"); setLabelFromStringBundle("authMethod-password-encrypted", diff --git a/mailnews/base/prefs/content/am-server.xul b/mailnews/base/prefs/content/am-server.xul index f52aef1cc..7828e4cf4 100644 --- a/mailnews/base/prefs/content/am-server.xul +++ b/mailnews/base/prefs/content/am-server.xul @@ -139,7 +139,9 @@ <menuitem id="authMethod-kerberos" value="5"/> <menuitem id="authMethod-ntlm" value="6"/> <menuitem id="authMethod-external" value="7"/> +#ifdef MOZ_MAILNEWS_OAUTH2 <menuitem id="authMethod-oauth2" value="10"/> +#endif <menuitem id="authMethod-anysecure" value="8"/> <menuitem id="authMethod-any" value="9"/> </menupopup> diff --git a/mailnews/base/prefs/content/am-smtp.js b/mailnews/base/prefs/content/am-smtp.js index f5e9ab38c..f107a32ae 100644 --- a/mailnews/base/prefs/content/am-smtp.js +++ b/mailnews/base/prefs/content/am-smtp.js @@ -140,9 +140,11 @@ var gSmtpServerListWindow = ? "authPasswordCleartextViaSSL" : "authPasswordCleartextInsecurely"; break; +#ifdef MOZ_MAILNEWS_OAUTH2 case AuthMethod.OAuth2: authStr = "authOAuth2"; break; +#endif default: // leave empty Components.utils.reportError("Warning: unknown value for smtpserver... authMethod: " + diff --git a/mailnews/base/prefs/content/smtpEditOverlay.js b/mailnews/base/prefs/content/smtpEditOverlay.js index 54590e1b2..d8d216065 100644 --- a/mailnews/base/prefs/content/smtpEditOverlay.js +++ b/mailnews/base/prefs/content/smtpEditOverlay.js @@ -53,7 +53,9 @@ function initSmtpSettings(server) { "authPasswordCleartextInsecurely"); setLabelFromStringBundle("authMethod-kerberos", "authKerberos"); setLabelFromStringBundle("authMethod-ntlm", "authNTLM"); +#ifdef MOZ_MAILNEWS_OAUTH2 setLabelFromStringBundle("authMethod-oauth2", "authOAuth2"); +#endif setLabelFromStringBundle("authMethod-anysecure", "authAnySecure"); setLabelFromStringBundle("authMethod-any", "authAny"); diff --git a/mailnews/base/prefs/content/smtpEditOverlay.xul b/mailnews/base/prefs/content/smtpEditOverlay.xul index f78916d2a..0bc900a3d 100644 --- a/mailnews/base/prefs/content/smtpEditOverlay.xul +++ b/mailnews/base/prefs/content/smtpEditOverlay.xul @@ -103,7 +103,9 @@ <menuitem id="authMethod-password-encrypted" value="4"/> <menuitem id="authMethod-kerberos" value="5"/> <menuitem id="authMethod-ntlm" value="6"/> +#ifdef MOZ_MAILNEWS_OAUTH2 <menuitem id="authMethod-oauth2" value="10"/> +#endif <menuitem id="authMethod-anysecure" value="8"/> <menuitem id="authMethod-any" value="9"/> </menupopup> diff --git a/mailnews/base/public/moz.build b/mailnews/base/public/moz.build index aaedcd2bb..e38c223e4 100644 --- a/mailnews/base/public/moz.build +++ b/mailnews/base/public/moz.build @@ -3,11 +3,13 @@ # 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/. +if CONFIG['MOZ_MAILNEWS_OAUTH2']: + XPIDL_SOURCES += ['msgIOAuth2Module.idl'] + XPIDL_SOURCES += [ 'MailNewsTypes2.idl', 'mozINewMailListener.idl', 'mozINewMailNotificationService.idl', - 'msgIOAuth2Module.idl', 'nsICopyMessageListener.idl', 'nsICopyMsgStreamListener.idl', 'nsIFolderListener.idl', diff --git a/mailnews/base/src/moz.build b/mailnews/base/src/moz.build index b84839e9e..55dbab154 100644 --- a/mailnews/base/src/moz.build +++ b/mailnews/base/src/moz.build @@ -68,12 +68,15 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': EXTRA_COMPONENTS += [ 'folderLookupService.js', 'msgAsyncPrompter.js', - 'msgBase.manifest', - 'msgOAuth2Module.js', 'newMailNotificationService.js', 'nsMailNewsCommandLineHandler.js', ] +if CONFIG['MOZ_MAILNEWS_OAUTH2']: + EXTRA_COMPONENTS += ['msgOAuth2Module.js'] + +EXTRA_PP_COMPONENTS += ['msgBase.manifest'] + EXTRA_JS_MODULES += [ 'virtualFolderWrapper.js', ] diff --git a/mailnews/base/src/msgBase.manifest b/mailnews/base/src/msgBase.manifest index e7af18bdf..1753939b8 100644 --- a/mailnews/base/src/msgBase.manifest +++ b/mailnews/base/src/msgBase.manifest @@ -8,5 +8,7 @@ contract @mozilla.org/newMailNotificationService;1 {740880E6-E299-4165-B82F-DF1D category profile-after-change NewMailNotificationService @mozilla.org/newMailNotificationService;1 component {a30be08c-afc8-4fed-9af7-79778a23db23} folderLookupService.js contract @mozilla.org/mail/folder-lookup;1 {a30be08c-afc8-4fed-9af7-79778a23db23} +#ifdef MOZ_MAILNEWS_OAUTH2 component {b63d8e4c-bf60-439b-be0e-7c9f67291042} msgOAuth2Module.js contract @mozilla.org/mail/oauth2-module;1 {b63d8e4c-bf60-439b-be0e-7c9f67291042} +#endif
\ No newline at end of file diff --git a/mailnews/base/util/moz.build b/mailnews/base/util/moz.build index 134a46ae1..0f1295ffe 100644 --- a/mailnews/base/util/moz.build +++ b/mailnews/base/util/moz.build @@ -60,13 +60,17 @@ EXTRA_JS_MODULES += [ 'mailnewsMigrator.js', 'mailServices.js', 'msgDBCacheManager.js', - 'OAuth2.jsm', - 'OAuth2Providers.jsm', 'StringBundle.js', 'templateUtils.js', 'traceHelper.js', ] +if CONFIG['MOZ_MAILNEWS_OAUTH2']: + EXTRA_JS_MODULES += [ + 'OAuth2.jsm', + 'OAuth2Providers.jsm', + ] + LOCAL_INCLUDES += [ '/netwerk/base' ] diff --git a/mailnews/compose/src/nsSmtpProtocol.cpp b/mailnews/compose/src/nsSmtpProtocol.cpp index d525d3f7f..54d1e6f64 100644 --- a/mailnews/compose/src/nsSmtpProtocol.cpp +++ b/mailnews/compose/src/nsSmtpProtocol.cpp @@ -216,9 +216,17 @@ esmtp_value_encode(const char *addr) // END OF TEMPORARY HARD CODED FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////////// +#ifdef MOZ_MAILNEWS_OAUTH2 NS_IMPL_ISUPPORTS_INHERITED(nsSmtpProtocol, nsMsgAsyncWriteProtocol, 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) : nsMsgAsyncWriteProtocol(aURL) { @@ -291,6 +299,7 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL) smtpServer->GetSocketType(&m_prefSocketType); smtpServer->GetHelloArgument(getter_Copies(m_helloArgument)); +#ifdef MOZ_MAILNEWS_OAUTH2 // Query for OAuth2 support. If the SMTP server preferences don't allow // for OAuth2, then don't carry around the OAuth2 module any longer // since we won't need it. @@ -302,6 +311,7 @@ void nsSmtpProtocol::Initialize(nsIURI * aURL) if (!supportsOAuth) mOAuth2Support = nullptr; } +#endif } InitPrefAuthMethods(authMethod); @@ -794,9 +804,11 @@ nsresult nsSmtpProtocol::SendEhloResponse(nsIInputStream * inputStream, uint32_t CaseInsensitiveCompare) >= 0) SetFlag(SMTP_AUTH_EXTERNAL_ENABLED); +#ifdef MOZ_MAILNEWS_OAUTH2 if (responseLine.Find(NS_LITERAL_CSTRING("XOAUTH2"), CaseInsensitiveCompare) >= 0) SetFlag(SMTP_AUTH_OAUTH2_ENABLED); +#endif } else if (StringBeginsWith(responseLine, NS_LITERAL_CSTRING("SIZE"), nsCaseInsensitiveCStringComparator())) { @@ -891,9 +903,11 @@ void nsSmtpProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue) case nsMsgAuthMethod::GSSAPI: m_prefAuthMethods = SMTP_AUTH_GSSAPI_ENABLED; break; +#ifdef MOZ_MAILNEWS_OAUTH2 case nsMsgAuthMethod::OAuth2: m_prefAuthMethods = SMTP_AUTH_OAUTH2_ENABLED; break; +#endif case nsMsgAuthMethod::secure: m_prefAuthMethods = SMTP_AUTH_CRAM_MD5_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_CRAM_MD5_ENABLED | SMTP_AUTH_GSSAPI_ENABLED | SMTP_AUTH_NTLM_ENABLED | SMTP_AUTH_MSN_ENABLED | +#ifdef MOZ_MAILNEWS_OAUTH2 SMTP_AUTH_OAUTH2_ENABLED | +#endif SMTP_AUTH_EXTERNAL_ENABLED; break; } +#ifdef MOZ_MAILNEWS_OAUTH2 // Only enable OAuth2 support if we can do the lookup. if ((m_prefAuthMethods & SMTP_AUTH_OAUTH2_ENABLED) && !mOAuth2Support) m_prefAuthMethods &= ~SMTP_AUTH_OAUTH2_ENABLED; +#endif NS_ASSERTION(m_prefAuthMethods != 0, "SMTP:InitPrefAuthMethods() failed"); } @@ -952,8 +970,10 @@ nsresult nsSmtpProtocol::ChooseAuthMethod() m_currentAuthMethod = SMTP_AUTH_NTLM_ENABLED; else if (SMTP_AUTH_MSN_ENABLED & availCaps) m_currentAuthMethod = SMTP_AUTH_MSN_ENABLED; +#ifdef MOZ_MAILNEWS_OAUTH2 else if (SMTP_AUTH_OAUTH2_ENABLED & availCaps) m_currentAuthMethod = SMTP_AUTH_OAUTH2_ENABLED; +#endif else if (SMTP_AUTH_PLAIN_ENABLED & availCaps) m_currentAuthMethod = SMTP_AUTH_PLAIN_ENABLED; else if (SMTP_AUTH_LOGIN_ENABLED & availCaps) @@ -1060,10 +1080,12 @@ nsresult nsSmtpProtocol::ProcessAuth() { m_nextState = SMTP_SEND_AUTH_LOGIN_STEP0; } +#ifdef MOZ_MAILNEWS_OAUTH2 else if (m_currentAuthMethod == SMTP_AUTH_OAUTH2_ENABLED) { m_nextState = SMTP_AUTH_OAUTH2_STEP; } +#endif else // All auth methods failed { // show an appropriate error msg @@ -1487,6 +1509,7 @@ nsresult nsSmtpProtocol::AuthLoginStep2() return static_cast<nsresult>(-1); } +#ifdef MOZ_MAILNEWS_OAUTH2 nsresult nsSmtpProtocol::AuthOAuth2Step1() { MOZ_ASSERT(mOAuth2Support, "Can't do anything without OAuth2 support"); @@ -1536,7 +1559,7 @@ nsresult nsSmtpProtocol::OnFailure(nsresult aError) m_nextState = SMTP_ERROR_DONE; return ProcessProtocolState(nullptr, nullptr, 0, 0); } - +#endif nsresult nsSmtpProtocol::SendMailResponse() { @@ -2025,10 +2048,11 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp status = AuthLoginStep2(); break; +#ifdef MOZ_MAILNEWS_OAUTH2 case SMTP_AUTH_OAUTH2_STEP: status = AuthOAuth2Step1(); break; - +#endif case SMTP_SEND_MAIL_RESPONSE: if (inputStream == nullptr) @@ -2086,11 +2110,13 @@ nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp nsMsgAsyncWriteProtocol::CloseSocket(); return NS_OK; /* final end */ +#ifdef MOZ_MAILNEWS_OAUTH2 // This state means we're going into an async loop and waiting for // something (say auth) to happen. ProcessProtocolState will be // retriggered when necessary. case SMTP_SUSPENDED: return NS_OK; +#endif default: /* should never happen !!! */ m_nextState = SMTP_ERROR_DONE; diff --git a/mailnews/compose/src/nsSmtpProtocol.h b/mailnews/compose/src/nsSmtpProtocol.h index c23b35dda..c5dba76e3 100644 --- a/mailnews/compose/src/nsSmtpProtocol.h +++ b/mailnews/compose/src/nsSmtpProtocol.h @@ -7,7 +7,9 @@ #define nsSmtpProtocol_h___ #include "mozilla/Attributes.h" +#ifdef MOZ_MAILNEWS_OAUTH2 #include "msgIOAuth2Module.h" +#endif #include "nsMsgProtocol.h" #include "nsIStreamListener.h" #include "nsISmtpUrl.h" @@ -19,8 +21,10 @@ #include "nsCOMPtr.h" #include "nsTArray.h" +#ifdef MOZ_MAILNEWS_OAUTH2 class nsIVariant; class nsIWritableVariant; +#endif /* states of the machine */ @@ -50,9 +54,11 @@ SMTP_AUTH_PROCESS_STATE, // 21 SMTP_AUTH_CRAM_MD5_CHALLENGE_RESPONSE, // 22 SMTP_SEND_AUTH_GSSAPI_FIRST, // 23 SMTP_SEND_AUTH_GSSAPI_STEP, // 24 +#ifdef MOZ_MAILNEWS_OAUTH2 SMTP_SUSPENDED, // 25 SMTP_AUTH_OAUTH2_STEP, // 26 SMTP_AUTH_OAUTH2_RESPONSE, // 27 +#endif } SmtpState; // 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_NTLM_ENABLED 0x00004000 #define SMTP_AUTH_MSN_ENABLED 0x00008000 +#ifdef MOZ_MAILNEWS_OAUTH2 #define SMTP_AUTH_OAUTH2_ENABLED 0x00010000 // sum of all above auth mechanisms #define SMTP_AUTH_ANY 0x0001FF00 @@ -82,13 +89,24 @@ SMTP_AUTH_OAUTH2_RESPONSE, // 27 #define SMTP_AUTH 0x00020000 // No login necessary (pref) #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, public msgIOAuth2ModuleListener +#else +class nsSmtpProtocol : public nsMsgAsyncWriteProtocol +#endif { public: NS_DECL_ISUPPORTS_INHERITED +#ifdef MOZ_MAILNEWS_OAUTH2 NS_DECL_MSGIOAUTH2MODULELISTENER +#endif // Creating a protocol instance requires the URL which needs to be run. nsSmtpProtocol(nsIURI * aURL); @@ -182,7 +200,9 @@ private: nsresult AuthLoginStep1(); nsresult AuthLoginStep2(); nsresult AuthLoginResponse(nsIInputStream * stream, uint32_t length); +#ifdef MOZ_MAILNEWS_OAUTH2 nsresult AuthOAuth2Step1(); +#endif nsresult SendTLSResponse(); nsresult SendMailResponse(); @@ -217,9 +237,11 @@ private: int32_t m_failedAuthMethods; // ditto 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 // and working. nsCOMPtr<msgIOAuth2Module> mOAuth2Support; +#endif }; #endif // nsSmtpProtocol_h___ diff --git a/mailnews/imap/src/nsImapCore.h b/mailnews/imap/src/nsImapCore.h index 5fd0e1c1f..0eac33663 100644 --- a/mailnews/imap/src/nsImapCore.h +++ b/mailnews/imap/src/nsImapCore.h @@ -147,7 +147,9 @@ const eIMAPCapabilityFlag kHasHighestModSeqCapability = 0x80000000; /* Subset o const eIMAPCapabilityFlag kHasListExtendedCapability = 0x100000000LL; /* RFC 5258 */ const eIMAPCapabilityFlag kHasSpecialUseCapability = 0x200000000LL; /* RFC 6154: Sent, Draft etc. folders */ const eIMAPCapabilityFlag kGmailImapCapability = 0x400000000LL; /* X-GM-EXT-1 capability extension for gmail */ +#ifdef MOZ_MAILNEWS_OAUTH2 const eIMAPCapabilityFlag kHasXOAuth2Capability = 0x800000000LL; /* AUTH XOAUTH2 extension */ +#endif // this used to be part of the connection object class - maybe we should move it into diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index 2a3d1e9ff..73484b2aa 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -797,7 +797,11 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer) server->GetRealHostName(m_realHostName); int32_t authMethod; (void) server->GetAuthMethod(&authMethod); +#ifdef MOZ_MAILNEWS_OAUTH2 InitPrefAuthMethods(authMethod, server); +#else + InitPrefAuthMethods(authMethod); +#endif (void) server->GetSocketType(&m_socketType); bool 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, nsIMsgIncomingServer *aServer) +#else +void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue) +#endif { // for m_prefAuthMethods, using the same flags as server capablities. switch (authMethodPrefValue) @@ -5608,11 +5616,16 @@ void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue, kHasAuthLoginCapability | kHasAuthPlainCapability | kHasCRAMCapability | kHasAuthGssApiCapability | kHasAuthNTLMCapability | kHasAuthMSNCapability | +#ifdef MOZ_MAILNEWS_OAUTH2 kHasAuthExternalCapability | kHasXOAuth2Capability; break; case nsMsgAuthMethod::OAuth2: m_prefAuthMethods = kHasXOAuth2Capability; +#else + kHasAuthExternalCapability; +#endif break; + } 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", serverCaps, m_prefAuthMethods, m_failedAuthMethods, availCaps)); +#ifdef MOZ_MAILNEWS_OAUTH2 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, OAUTH2 = 0x%llx)", kHasAuthGssApiCapability, kHasCRAMCapability, kHasAuthNTLMCapability, kHasAuthMSNCapability, kHasAuthPlainCapability, kHasAuthLoginCapability, 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) m_currentAuthMethod = kHasAuthExternalCapability; @@ -5656,8 +5678,10 @@ nsresult nsImapProtocol::ChooseAuthMethod() m_currentAuthMethod = kHasAuthNTLMCapability; else if (kHasAuthMSNCapability & availCaps) m_currentAuthMethod = kHasAuthMSNCapability; +#ifdef MOZ_MAILNEWS_OAUTH2 else if (kHasXOAuth2Capability & availCaps) m_currentAuthMethod = kHasXOAuth2Capability; +#endif else if (kHasAuthPlainCapability & availCaps) m_currentAuthMethod = kHasAuthPlainCapability; else if (kHasAuthLoginCapability & availCaps) @@ -5933,6 +5957,7 @@ nsresult nsImapProtocol::AuthLogin(const char *userName, const nsCString &passwo NS_ENSURE_SUCCESS(rv, rv); ParseIMAPandCheckForNewMail(); } +#ifdef MOZ_MAILNEWS_OAUTH2 else if (flag & kHasXOAuth2Capability) { 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); ParseIMAPandCheckForNewMail(); } +#endif else if (flag & kHasAuthNoneCapability) { // TODO What to do? "login <username>" like POP? @@ -8617,7 +8643,9 @@ bool nsImapProtocol::TryToLogon() // Get password if (m_currentAuthMethod != kHasAuthGssApiCapability && // GSSAPI uses no pw in apps m_currentAuthMethod != kHasAuthExternalCapability && +#ifdef MOZ_MAILNEWS_OAUTH2 m_currentAuthMethod != kHasXOAuth2Capability && +#endif m_currentAuthMethod != kHasAuthNoneCapability) { rv = GetPassword(password, newPasswordRequested); @@ -8654,6 +8682,7 @@ bool nsImapProtocol::TryToLogon() break; } +#ifdef MOZ_MAILNEWS_OAUTH2 if (m_prefAuthMethods & kHasXOAuth2Capability) { // OAuth2 failed. We don't have an error message for this, and we @@ -8662,6 +8691,7 @@ bool nsImapProtocol::TryToLogon() AlertUserEventUsingName("imapUnknownHostError"); break; } +#endif // The reason that we failed might be a wrong password, so // ask user what to do diff --git a/mailnews/imap/src/nsImapProtocol.h b/mailnews/imap/src/nsImapProtocol.h index 0341d87bb..5c4f43abd 100644 --- a/mailnews/imap/src/nsImapProtocol.h +++ b/mailnews/imap/src/nsImapProtocol.h @@ -463,8 +463,11 @@ private: // login related methods. nsresult GetPassword(nsCString &password, bool aNewPasswordRequested); - void InitPrefAuthMethods(int32_t authMethodPrefValue, - nsIMsgIncomingServer *aServer); +#ifdef MOZ_MAILNEWS_OAUTH2 + void InitPrefAuthMethods(int32_t authMethodPrefValue, nsIMsgIncomingServer *aServer); +#else + void InitPrefAuthMethods(int32_t authMethodPrefValue); +#endif nsresult ChooseAuthMethod(); void MarkAuthMethodAsFailed(eIMAPCapabilityFlags failedAuthMethod); void ResetAuthMethods(); @@ -675,7 +678,9 @@ private: nsString m_emptyMimePartString; +#ifdef MOZ_MAILNEWS_OAUTH2 RefPtr<mozilla::mailnews::OAuth2ThreadHelper> mOAuth2Support; +#endif }; // This small class is a "mock" channel because it is a mockery of the imap channel's implementation... diff --git a/mailnews/imap/src/nsImapServerResponseParser.cpp b/mailnews/imap/src/nsImapServerResponseParser.cpp index faa37cc45..c5cc49c12 100644 --- a/mailnews/imap/src/nsImapServerResponseParser.cpp +++ b/mailnews/imap/src/nsImapServerResponseParser.cpp @@ -2250,8 +2250,10 @@ void nsImapServerResponseParser::capability_data() fCapabilityFlag |= kHasAuthMSNCapability; else if (token.Equals("AUTH=EXTERNAL", nsCaseInsensitiveCStringComparator())) fCapabilityFlag |= kHasAuthExternalCapability; +#ifdef MOZ_MAILNEWS_OAUTH2 else if (token.Equals("AUTH=XOAUTH2", nsCaseInsensitiveCStringComparator())) fCapabilityFlag |= kHasXOAuth2Capability; +#endif else if (token.Equals("STARTTLS", nsCaseInsensitiveCStringComparator())) fCapabilityFlag |= kHasStartTLSCapability; else if (token.Equals("LOGINDISABLED", nsCaseInsensitiveCStringComparator())) diff --git a/mailnews/imap/src/nsSyncRunnableHelpers.cpp b/mailnews/imap/src/nsSyncRunnableHelpers.cpp index ec547eb91..2928df8eb 100644 --- a/mailnews/imap/src/nsSyncRunnableHelpers.cpp +++ b/mailnews/imap/src/nsSyncRunnableHelpers.cpp @@ -457,7 +457,7 @@ NS_SYNCRUNNABLEMETHOD1(ImapServerSink, ResetServerConnection, const nsACString & NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerDoingLsub, bool) NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerForceSelect, const nsACString &) - +#ifdef MOZ_MAILNEWS_OAUTH2 namespace mozilla { namespace mailnews { @@ -598,3 +598,4 @@ nsresult OAuth2ThreadHelper::OnFailure(nsresult aError) } // namespace mailnews } // namespace mozilla +#endif
\ No newline at end of file diff --git a/mailnews/imap/src/nsSyncRunnableHelpers.h b/mailnews/imap/src/nsSyncRunnableHelpers.h index 4fcadf465..4740fab10 100644 --- a/mailnews/imap/src/nsSyncRunnableHelpers.h +++ b/mailnews/imap/src/nsSyncRunnableHelpers.h @@ -8,8 +8,11 @@ #include "nsThreadUtils.h" #include "nsProxyRelease.h" +#ifdef MOZ_MAILNEWS_OAUTH2 #include "mozilla/Monitor.h" #include "msgIOAuth2Module.h" +#endif + #include "nsIStreamListener.h" #include "nsIInterfaceRequestor.h" #include "nsIImapMailFolderSink.h" @@ -110,6 +113,7 @@ private: nsCOMPtr<nsIImapProtocolSink> mReceiver; }; +#ifdef MOZ_MAILNEWS_OAUTH2 class msgIOAuth2Module; class nsIMsgIncomingServer; class nsIVariant; @@ -142,5 +146,6 @@ private: } // namespace mailnews } // namespace mozilla +#endif #endif // nsSyncRunnableHelpers_h diff --git a/mailnews/jar.mn b/mailnews/jar.mn index e2b851197..71539e9aa 100644 --- a/mailnews/jar.mn +++ b/mailnews/jar.mn @@ -22,10 +22,10 @@ messenger.jar: 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-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.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-copies.xul (base/prefs/content/am-copies.xul) 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.js (base/prefs/content/am-server-advanced.js) 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-identities-list.js (base/prefs/content/am-identities-list.js) 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/SmtpServerEdit.xul (base/prefs/content/SmtpServerEdit.xul) content/messenger/SmtpServerEdit.js (base/prefs/content/SmtpServerEdit.js) - content/messenger/smtpEditOverlay.xul (base/prefs/content/smtpEditOverlay.xul) - content/messenger/smtpEditOverlay.js (base/prefs/content/smtpEditOverlay.js) +* content/messenger/smtpEditOverlay.xul (base/prefs/content/smtpEditOverlay.xul) +* content/messenger/smtpEditOverlay.js (base/prefs/content/smtpEditOverlay.js) content/messenger/removeAccount.xul (base/prefs/content/removeAccount.xul) content/messenger/removeAccount.js (base/prefs/content/removeAccount.js) #if defined(MOZ_THUNDERBIRD) && defined(HYPE_ICEDOVE) - 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/emailWizard.js (base/prefs/content/accountcreation/emailWizard.js) - content/messenger/accountcreation/emailWizard.xul (base/prefs/content/accountcreation/emailWizard.xul) +* 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/emailWizard.js (base/prefs/content/accountcreation/emailWizard.js) +* 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/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/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/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 content/messenger/msgSynchronize.xul (base/content/msgSynchronize.xul) content/messenger/msgSynchronize.js (base/content/msgSynchronize.js) |