37 m_task(*this,eh,
"<<verifier exec error: __strerror__>>",
G::Root::nobody()) ,
38 m_compatible(compatible)
44 const std::string & auth_mechanism ,
const std::string & auth_extra )
46 G_DEBUG(
"GSmtp::ExecutableVerifier::verify: to \"" << to_address <<
"\": from \"" << from_address <<
"\": "
47 <<
"ip \"" << ip.
hostPartString() <<
"\": auth-mechanism \"" << auth_mechanism <<
"\": "
48 <<
"auth-extra \"" << auth_extra <<
"\"" ) ;
53 std::string user =
G::Str::head( to_address ,
"@" ,
false ) ;
54 std::string host =
G::Str::tail( to_address ,
"@" ,
true ) ;
55 commandline.add( to_address ) ;
59 commandline.add( from_address ) ;
61 commandline.add( auth_mechanism ) ;
62 commandline.add( auth_extra ) ;
66 commandline.add( to_address ) ;
67 commandline.add( from_address ) ;
71 commandline.add( auth_extra ) ;
74 G_LOG(
"GSmtp::ExecutableVerifier: address verifier: executing " << commandline.displayString() ) ;
75 m_to_address = to_address ;
76 m_task.start( commandline ) ;
79 void GSmtp::ExecutableVerifier::onTaskDone(
int exit_code ,
const std::string & response_in )
81 std::string response( response_in ) ;
87 response_parts.reserve( 2U ) ;
89 size_t parts = response_parts.size() ;
90 response_parts.resize( 2U ) ;
92 G_LOG(
"GSmtp::ExecutableVerifier: address verifier: exit code " << exit_code <<
" "
96 if( ( exit_code == 0 || exit_code == 1 ) && parts >= 2 )
98 status.is_valid = true ;
99 status.is_local = exit_code == 0 ;
103 else if( exit_code == 100 )
105 status.is_valid = false ;
106 status.abort = true ;
110 status.is_valid = false ;
111 status.temporary = exit_code == 3 ;
116 status.response =
"no such mailbox: " +
117 ( response.empty() ?
G::Str::fromInt(exit_code) :
G::Str::printable(response) ) ;
118 status.reason =
"rejected by verifier" ;
122 status.response = parts > 0U ?
124 std::string(
"mailbox unavailable") ;
126 status.reason = parts > 1U ?
132 doneSignal().emit( m_to_address , status ) ;
137 return m_done_signal ;
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.
The GNet::Address class encapsulates a TCP/UDP transport address.
std::vector< std::string > StringArray
A std::vector of std::strings.
virtual void cancel() override
Override from GSmtp::Verifier.
static std::string fromInt(int i)
Converts int 'i' to a string.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
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...
static unsigned int replaceAll(std::string &s, const std::string &from, const std::string &to)
Does a global replace on string 's', replacing all occurances of sub-string 'from' with 'to'...
static void trimRight(std::string &s, const std::string &ws, size_type limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
std::string hostPartString() const
Returns a string which represents the network address for debugging and diagnostics purposes...
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 upper(const std::string &s)
Returns a copy of 's' in which all Latin-1 lowercase characters have been replaced by uppercase chara...
virtual G::Slot::Signal2< std::string, VerifierStatus > & doneSignal() override
Override from GSmtp::Verifier.
A structure representing an external program, holding a path and a set of arguments.
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' recipient.
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.
ExecutableVerifier(GNet::ExceptionHandler &, const G::Path &, bool compatible)
Constructor.
A Path object represents a file system path.
std::string displayString() const
Returns a string which represents the transport address for debugging and diagnostics purposes...