27 Filter::Type ,
const Filter::Config & config ,
const std::string & server ,
28 bool read_only ,
bool always_pass ) :
30 m_done_timer(*this,&
SpamFilter::onDoneTimeout,m_es) ,
32 m_file_store(file_store) ,
34 m_read_only(read_only) ,
35 m_always_pass(always_pass) ,
36 m_connection_timeout(config.timeout) ,
37 m_response_timeout(config.timeout) ,
38 m_result(Result::fail)
46 m_client_ptr.eventSignal().disconnect() ;
47 m_client_ptr.deletedSignal().disconnect() ;
50std::string GFilters::SpamFilter::id()
const
52 return m_location.displayString() ;
55bool GFilters::SpamFilter::quiet()
const
63 m_client_ptr.reset( std::make_unique<GSmtp::SpamClient>(
GNet::ExceptionSink(m_client_ptr,m_es.esrc()) ,
64 m_location , m_read_only , m_connection_timeout , m_response_timeout ) ) ;
66 m_done_signal.emitted(
false ) ;
68 m_client_ptr->request( m_file_store.contentPath(message_id).str() ) ;
71void GFilters::SpamFilter::clientDeleted(
const std::string & reason )
73 if( !reason.empty() && !m_done_signal.emitted() )
75 G_WARNING(
"GFilters::SpamFilter::clientDeleted: spamd interaction failed: " << reason ) ;
81void GFilters::SpamFilter::clientEvent(
const std::string & s1 ,
const std::string & s2 ,
const std::string & )
83 G_DEBUG(
"GFilters::SpamFilter::clientEvent: [" << s1 <<
"] [" << s2 <<
"]" ) ;
86 m_text = ( s2.empty() || m_always_pass ) ? std::string() : std::string(
"spam: ").append(
G::Str::printable(s2)) ;
89 else if( s1 ==
"failed" )
96bool GFilters::SpamFilter::special()
const
101void GFilters::SpamFilter::done()
103 m_done_timer.startTimer( 0U ) ;
106void GFilters::SpamFilter::onDoneTimeout()
108 m_result = m_text.empty() ? Result::ok : Result::fail ;
109 m_done_signal.emit(
static_cast<int>(m_result) ) ;
112GSmtp::Filter::Result GFilters::SpamFilter::result()
const
117std::string GFilters::SpamFilter::response()
const
119 return m_text.empty() ? std::string() :
std::string(
"rejected") ;
122int GFilters::SpamFilter::responseCode()
const
127std::string GFilters::SpamFilter::reason()
const
134 return m_done_signal ;
137void GFilters::SpamFilter::cancel()
139 G_DEBUG(
"GFilters::SpamFilter::cancel: cancelled" ) ;
140 m_done_timer.cancelTimer() ;
142 if( m_client_ptr.get() !=
nullptr && m_client_ptr->busy() )
143 m_client_ptr.reset() ;
A Filter class that passes the body of a message file to a remote process over the network and option...
~SpamFilter() override
Destructor.
SpamFilter(GNet::ExceptionSink, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &server_location, bool read_only, bool always_pass)
Constructor.
G::Slot::Signal< const std::string & > & deletedSignal() noexcept
A signal that is triggered after deleteSignal() once the client has been deleted and the ClientPtr is...
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & eventSignal() noexcept
A signal that is linked to the contained client's eventSignal().
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A concrete implementation of the MessageStore interface dealing in paired flat files.
A somewhat opaque identifer for a GStore::MessageStore message id.
static std::string printable(const std::string &in, char escape='\\')
Returns a printable representation of the given input string, using chacter code ranges 0x20 to 0x7e ...
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.