diff options
Diffstat (limited to 'examples/example6.cpp')
-rw-r--r-- | examples/example6.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/examples/example6.cpp b/examples/example6.cpp index 6d8fe92f..344a4d87 100644 --- a/examples/example6.cpp +++ b/examples/example6.cpp @@ -35,7 +35,9 @@ static vmime::ref <vmime::net::session> g_session = vmime::create <vmime::net::session>(); -// Authentification handler +#if VMIME_HAVE_SASL_SUPPORT + +// SASL authentication handler class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator { const std::vector <vmime::ref <vmime::security::sasl::SASLMechanism> > getAcceptableMechanisms @@ -97,6 +99,46 @@ private: mutable vmime::string m_password; }; +#else // !VMIME_HAVE_SASL_SUPPORT + +// Simple authentication handler +class interactiveAuthenticator : public vmime::security::defaultAuthenticator +{ + const vmime::string getUsername() const + { + if (m_username.empty()) + m_username = getUserInput("Username"); + + return m_username; + } + + const vmime::string getPassword() const + { + if (m_password.empty()) + m_password = getUserInput("Password"); + + return m_password; + } + + static const vmime::string getUserInput(const std::string& prompt) + { + std::cout << prompt << ": "; + std::cout.flush(); + + vmime::string res; + std::getline(std::cin, res); + + return res; + } + +private: + + mutable vmime::string m_username; + mutable vmime::string m_password; +}; + +#endif // VMIME_HAVE_SASL_SUPPORT + #if VMIME_HAVE_TLS_SUPPORT |