28 const std::string & server ,
unsigned int connection_timeout ,
29 unsigned int response_timeout ) :
32 m_connection_timeout(connection_timeout) ,
33 m_response_timeout(response_timeout)
35 G_DEBUG(
"GSmtp::NetworkVerifier::ctor: " << server ) ;
36 m_client_ptr.eventSignal().connect(
G::Slot::slot(*
this,&GSmtp::NetworkVerifier::clientEvent) ) ;
37 m_client_ptr.deletedSignal().connect(
G::Slot::slot(*
this,&GSmtp::NetworkVerifier::clientDeleted) ) ;
42 m_client_ptr.eventSignal().disconnect() ;
43 m_client_ptr.deletedSignal().disconnect() ;
46void GSmtp::NetworkVerifier::verify(
const std::string & mail_to_address ,
47 const std::string & mail_from_address ,
const GNet::Address & client_ip ,
48 const std::string & auth_mechanism ,
const std::string & auth_extra )
50 if( m_client_ptr.get() ==
nullptr )
52 m_client_ptr.reset( std::make_unique<RequestClient>(
55 m_location , m_connection_timeout , m_response_timeout ) ) ;
59 args.push_back( mail_to_address ) ;
60 args.push_back( mail_from_address ) ;
64 args.push_back( auth_extra ) ;
66 m_to_address = mail_to_address ;
70void GSmtp::NetworkVerifier::clientDeleted(
const std::string & reason )
72 G_DEBUG(
"GSmtp::NetworkVerifier::clientDeleted: reason=[" << reason <<
"]" ) ;
75 std::string to_address = m_to_address ;
76 m_to_address.erase() ;
79 true ,
"cannot verify" , reason ) ;
81 doneSignal().emit( status ) ;
85void GSmtp::NetworkVerifier::clientEvent(
const std::string & s1 ,
const std::string & s2 ,
const std::string & )
87 G_DEBUG(
"GSmtp::NetworkVerifier::clientEvent: [" << s1 <<
"] [" << s2 <<
"]" ) ;
96 if( !parts.empty() && parts[0U] ==
"100" )
98 status.is_valid = false ;
101 else if( parts.size() >= 2U && parts[0U] ==
"1" )
103 const std::string & address = parts[1U] ;
106 else if( parts.size() >= 3U && parts[0U] ==
"0" )
108 const std::string & mbox = parts[1U] ;
109 const std::string & full_name = parts[2U] ;
112 else if( parts.size() >= 2U && ( parts[0U] ==
"2" || parts[0U] ==
"3" ) )
114 bool temporary = parts[0U] ==
"3" ;
115 const std::string & response = parts[1U] ;
116 std::string reason = parts.size() >= 3 ? parts[2U] : std::string() ;
118 temporary , response , reason ) ;
121 doneSignal().emit( status ) ;
127 return m_done_signal ;
130void GSmtp::NetworkVerifier::cancel()
132 m_to_address.erase() ;
133 m_client_ptr.reset() ;
The GNet::Address class encapsulates a TCP/UDP transport address.
std::string displayString(bool with_scope_id=false) const
Returns a string which represents the transport address.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
static std::string canonicalName()
Returns the canonical network name assiciated with hostname().
NetworkVerifier(GNet::ExceptionSink, const std::string &server, unsigned int connection_timeout, unsigned int response_timeout)
Constructor.
~NetworkVerifier() override
Destructor.
static VerifierStatus local(const std::string &recipient, const std::string &full_name, const std::string &mbox)
Constructor for a valid local mailbox.
static VerifierStatus invalid(const std::string &recipient, bool temporary=false, const std::string &response={}, const std::string &reason={})
Factory for an invalid address.
static VerifierStatus remote(const std::string &recipient, const std::string &address={})
Constructor for a valid remote mailbox.
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, string_view ws, char escape='\0', bool remove_escapes=true)
Splits the string into fields.
static std::string lower(const std::string &s)
Returns a copy of 's' in which all Latin-1 upper-case characters have been replaced by lower-case cha...
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.
std::vector< std::string > StringArray
A std::vector of std::strings.