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)
45 m_client_ptr.eventSignal().disconnect() ;
46 m_client_ptr.deletedSignal().disconnect() ;
49std::string GFilters::SpamFilter::id()
const
51 return m_location.displayString() ;
54bool GFilters::SpamFilter::quiet()
const
62 m_client_ptr.reset( std::make_unique<GSmtp::SpamClient>( m_es.eh(m_client_ptr) ,
63 m_location , m_read_only , m_connection_timeout , m_response_timeout ) ) ;
65 m_done_signal.emitted(
false ) ;
67 m_client_ptr->request( m_file_store.contentPath(message_id).str() ) ;
70void GFilters::SpamFilter::clientDeleted(
const std::string & reason )
72 if( !reason.empty() && !m_done_signal.emitted() )
74 G_WARNING(
"GFilters::SpamFilter::clientDeleted: spamd interaction failed: " << reason ) ;
80void GFilters::SpamFilter::clientEvent(
const std::string & s1 ,
const std::string & s2 ,
const std::string & )
82 G_DEBUG(
"GFilters::SpamFilter::clientEvent: [" << s1 <<
"] [" << s2 <<
"]" ) ;
85 m_text = ( s2.empty() || m_always_pass ) ? std::string() : std::string(
"spam: ").append(
G::Str::printable(s2)) ;
88 else if( s1 ==
"failed" )
95bool GFilters::SpamFilter::special()
const
100void GFilters::SpamFilter::done()
102 m_done_timer.startTimer( 0U ) ;
105void GFilters::SpamFilter::onDoneTimeout()
107 m_result = m_text.empty() ? Result::ok : Result::fail ;
108 m_done_signal.emit(
static_cast<int>(m_result) ) ;
111GSmtp::Filter::Result GFilters::SpamFilter::result()
const
116std::string GFilters::SpamFilter::response()
const
118 return m_text.empty() ? std::string() :
std::string(
"rejected") ;
121int GFilters::SpamFilter::responseCode()
const
126std::string GFilters::SpamFilter::reason()
const
133 return m_done_signal ;
136void GFilters::SpamFilter::cancel()
138 G_DEBUG(
"GFilters::SpamFilter::cancel: cancelled" ) ;
139 m_done_timer.cancelTimer() ;
141 if( m_client_ptr.get() !=
nullptr && m_client_ptr->busy() )
142 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(GNet::EventState, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &server_location, bool read_only, bool always_pass)
Constructor.
~SpamFilter() override
Destructor.
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 lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
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.