29 const std::string & server ,
unsigned int connection_timeout ,
unsigned int response_timeout ,
31 m_exception_handler(exception_handler) ,
33 m_connection_timeout(connection_timeout) ,
34 m_response_timeout(response_timeout) ,
36 m_compatible(compatible)
38 G_DEBUG(
"GSmtp::NetworkVerifier::ctor: " << server ) ;
39 m_client.eventSignal().connect(
G::Slot::slot(*
this,&GSmtp::NetworkVerifier::clientEvent) ) ;
44 m_client.eventSignal().disconnect() ;
48 const std::string & mail_from_address ,
const GNet::Address & client_ip ,
49 const std::string & auth_mechanism ,
const std::string & auth_extra )
51 if( !m_lazy || m_client.get() == nullptr )
53 m_client.reset(
new RequestClient(
"verify",
"",m_location,m_connection_timeout,m_response_timeout) ) ;
59 std::string user =
G::Str::head( mail_to_address ,
"@" ,
false ) ;
60 std::string host =
G::Str::tail( mail_to_address ,
"@" ,
true ) ;
61 args.push_back( mail_to_address ) ;
65 args.push_back( mail_from_address ) ;
67 args.push_back( auth_mechanism ) ;
68 args.push_back( auth_extra ) ;
72 args.push_back( mail_to_address ) ;
73 args.push_back( mail_from_address ) ;
77 args.push_back( auth_extra ) ;
80 m_to_address = mail_to_address ;
84 void GSmtp::NetworkVerifier::clientEvent( std::string s1 , std::string s2 )
86 G_DEBUG(
"GSmtp::NetworkVerifier::clientEvent: [" << s1 <<
"] [" << s2 <<
"]" ) ;
96 if( part.size() >= 1U && part[0U] ==
"100" )
98 status.is_valid = false ;
101 else if( part.size() >= 2U && part[0U] ==
"1" )
103 status.is_valid = true ;
104 status.is_local = false ;
105 status.address = part[1U] ;
107 else if( part.size() >= 3U && part[0U] ==
"0" )
109 status.is_valid = true ;
110 status.is_local = true ;
111 status.address = part[1U] ;
112 status.full_name = part[2U] ;
114 else if( part.size() >= 2U && ( part[0U] ==
"2" || part[0U] ==
"3" ) )
116 status.is_valid = false ;
117 status.response = part[1U] ;
118 status.temporary = part[0U] ==
"3" ;
122 status.is_valid = false ;
123 status.temporary = false ;
130 catch( std::exception & e )
132 m_exception_handler.onException( e ) ;
139 return m_done_signal ;
145 m_to_address.erase() ;
virtual void verify(const std::string &rcpt_to_parameter, const std::string &mail_from_parameter, const GNet::Address &client_ip, const std::string &auth_mechanism, const std::string &auth_extra) override
Override from GSmtp::Verifier.
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
static std::string canonicalName()
Returns the canonical network name assiciated with hostname().
static std::string tail(const std::string &in, size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
static std::string head(const std::string &in, size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
virtual G::Slot::Signal2< std::string, VerifierStatus > & doneSignal() override
Override from GSmtp::Verifier.
The GNet::Address class encapsulates a TCP/UDP transport address.
std::vector< std::string > StringArray
A std::vector of std::strings.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
virtual ~NetworkVerifier()
Destructor.
virtual void cancel() override
Override from GSmtp::Verifier.
static std::string lower(const std::string &s)
Returns a copy of 's' in which all Latin-1 uppercase characters have been replaced by lowercase chara...
NetworkVerifier(GNet::ExceptionHandler &, const std::string &server, unsigned int connection_timeout, unsigned int response_timeout, bool compatible)
Constructor.
std::string hostPartString() const
Returns a string which represents the network address for debugging and diagnostics purposes...
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
static std::string upper(const std::string &s)
Returns a copy of 's' in which all Latin-1 lowercase characters have been replaced by uppercase chara...
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' recipient.
static std::string join(const std::string &sep, const StringArray &strings)
Concatenates an array of strings with separators.
static void splitIntoFields(const std::string &in, StringArray &out, const std::string &separators, char escape= '\0', bool remove_escapes=true)
Splits the string into fields.
std::string displayString() const
Returns a string which represents the transport address for debugging and diagnostics purposes...
A network client class that interacts with a remote server using a stateless line-based request/respo...