diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-05 18:27:14 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-05 18:27:14 -0500 |
commit | 03590a6711d601ef3ddb48787e9f3f556705b5db (patch) | |
tree | b5985c23741cd03fd0ed32537773e07db2d7d21d /mailnews/imap/src | |
parent | 714afc76f690ba11e77330e067e5bce486292831 (diff) | |
download | UXP-03590a6711d601ef3ddb48787e9f3f556705b5db.tar UXP-03590a6711d601ef3ddb48787e9f3f556705b5db.tar.gz UXP-03590a6711d601ef3ddb48787e9f3f556705b5db.tar.lz UXP-03590a6711d601ef3ddb48787e9f3f556705b5db.tar.xz UXP-03590a6711d601ef3ddb48787e9f3f556705b5db.zip |
Issue #1258 - Part 8: Ifdef MailNews OAuth2 Support
Use --disable-mailnews-oauth2 to exclude it. Confvars won't be respected.
Diffstat (limited to 'mailnews/imap/src')
-rw-r--r-- | mailnews/imap/src/nsImapCore.h | 2 | ||||
-rw-r--r-- | mailnews/imap/src/nsImapProtocol.cpp | 30 | ||||
-rw-r--r-- | mailnews/imap/src/nsImapProtocol.h | 9 | ||||
-rw-r--r-- | mailnews/imap/src/nsImapServerResponseParser.cpp | 2 | ||||
-rw-r--r-- | mailnews/imap/src/nsSyncRunnableHelpers.cpp | 3 | ||||
-rw-r--r-- | mailnews/imap/src/nsSyncRunnableHelpers.h | 5 |
6 files changed, 48 insertions, 3 deletions
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 |