28 bool server_side ,
const std::string & server ,
bool read_only ,
bool always_pass ,
29 unsigned int connection_timeout ,
unsigned int response_timeout ) :
30 m_exception_handler(exception_handler) ,
31 m_server_side(server_side) ,
33 m_read_only(read_only) ,
34 m_always_pass(always_pass) ,
35 m_connection_timeout(connection_timeout) ,
36 m_response_timeout(response_timeout)
38 m_client.eventSignal().connect(
G::Slot::slot(*
this,&GSmtp::SpamFilter::clientEvent) ) ;
43 m_client.eventSignal().disconnect() ;
48 return m_location.displayString() ;
59 m_client.reset(
new SpamClient(m_location,m_read_only,m_connection_timeout,m_response_timeout) ) ;
62 m_client->request( path ) ;
65 void GSmtp::SpamFilter::clientEvent( std::string s1 , std::string s2 )
67 G_DEBUG(
"GSmtp::SpamFilter::clientEvent: [" << s1 <<
"] [" << s2 <<
"]" ) ;
70 m_text = ( s2.empty() || m_always_pass ) ? std::string() : (
"spam: "+
G::Str::printable(s2)) ;
71 emit( m_text.empty() ) ;
73 else if( s1 ==
"failed" )
76 emit( m_text.empty() ) ;
80 void GSmtp::SpamFilter::emit(
bool ok )
84 m_done_signal.emit( ok ? 0 : 2 ) ;
86 catch( std::exception & e )
88 m_exception_handler.onException( e ) ;
99 return m_text.empty() ? std::string() : std::string(
"rejected") ;
109 return m_done_signal ;
114 G_DEBUG(
"GSmtp::SpamFilter::cancel: cancelled" ) ;
116 if( m_client.get() !=
nullptr && m_client->busy() )
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
virtual ~SpamFilter()
Destructor.
virtual void start(const std::string &path) override
Override from from GSmtp::Filter.
virtual std::string response() const override
Override from from GSmtp::Filter.
virtual std::string reason() const override
Override from from GSmtp::Filter.
virtual bool abandoned() const override
Override from from GSmtp::Filter.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
A client class that interacts with a remote process using a protocol somewhat similar to the spamassa...
virtual bool special() const override
Override from from GSmtp::Filter.
virtual bool simple() const override
Override from from GSmtp::Filter.
SpamFilter(GNet::ExceptionHandler &, bool server_side, const std::string &server_location, bool read_only, bool always_pass, unsigned int connection_timeout, unsigned int response_timeout)
Constructor.
virtual G::Slot::Signal1< int > & doneSignal() override
Override from from GSmtp::Filter.
virtual void cancel() override
Override from from GSmtp::Filter.
virtual std::string id() const override
Override from from GSmtp::Filter.