summaryrefslogtreecommitdiff
path: root/mailnews/compose
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-05 18:27:14 -0500
committerMatt A. Tobin <email@mattatobin.com>2019-11-05 18:27:14 -0500
commit03590a6711d601ef3ddb48787e9f3f556705b5db (patch)
treeb5985c23741cd03fd0ed32537773e07db2d7d21d /mailnews/compose
parent714afc76f690ba11e77330e067e5bce486292831 (diff)
downloaduxp-03590a6711d601ef3ddb48787e9f3f556705b5db.tar.gz
Issue #1258 - Part 8: Ifdef MailNews OAuth2 Support
Use --disable-mailnews-oauth2 to exclude it. Confvars won't be respected.
Diffstat (limited to 'mailnews/compose')
-rw-r--r--mailnews/compose/src/nsSmtpProtocol.cpp30
-rw-r--r--mailnews/compose/src/nsSmtpProtocol.h22
2 files changed, 50 insertions, 2 deletions
diff --git a/mailnews/compose/src/nsSmtpProtocol.cpp b/mailnews/compose/src/nsSmtpProtocol.cpp
index d525d3f7f1..54d1e6f64e 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 c23b35dda8..c5dba76e33 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___