29 const std::string & server ) :
31 m_file_store(file_store) ,
35 m_connection_timeout(config.timeout) ,
36 m_response_timeout(config.timeout)
43 m_client_ptr.eventSignal().disconnect() ;
46std::string GFilters::NetworkFilter::id()
const
48 return m_location.displayString() ;
51bool GFilters::NetworkFilter::quiet()
const
59 m_timer.cancelTimer() ;
60 m_done_signal.reset() ;
61 if( m_client_ptr.get() ==
nullptr || m_client_ptr->busy() )
63 unsigned int idle_timeout = 0U ;
64 m_client_ptr.reset( std::make_unique<GSmtp::RequestClient>(
67 m_location , m_connection_timeout , m_response_timeout ,
70 m_client_ptr->request( m_file_store.contentPath(message_id).str() ) ;
75 if( m_client_ptr.get() )
76 m_client_ptr->doOnDelete( e.what() , done ) ;
77 m_client_ptr.reset() ;
79 sendResult( std::string(
"failed\t").append(e.what()) ) ;
82void GFilters::NetworkFilter::clientEvent(
const std::string & s1 ,
const std::string & s2 ,
const std::string & )
90void GFilters::NetworkFilter::sendResult(
const std::string & reason )
92 if( !m_text.has_value() )
95 m_timer.startTimer( 0 ) ;
96 m_result = m_text.value().empty() ? Result::ok : Result::fail ;
100void GFilters::NetworkFilter::onTimeout()
102 if( m_text.has_value() )
103 m_done_signal.emit(
static_cast<int>(m_result) ) ;
106GSmtp::Filter::Result GFilters::NetworkFilter::result()
const
111bool GFilters::NetworkFilter::special()
const
116std::pair<std::string,int> GFilters::NetworkFilter::responsePair()
const
121 if( s.size() >= 3U &&
122 ( s[0] ==
'4' || s[0] ==
'5' ) &&
123 ( s[1] >=
'0' && s[1] <=
'9' ) &&
124 ( s[2] >=
'0' && s[2] <=
'9' ) &&
125 ( s.size() == 3U || s[3] ==
' ' ) )
128 s.erase( 0U , s.size() == 3U ? 3U : 4U ) ;
133std::string GFilters::NetworkFilter::response()
const
135 return responsePair().first ;
138int GFilters::NetworkFilter::responseCode()
const
140 return responsePair().second ;
143std::string GFilters::NetworkFilter::reason()
const
150 return m_done_signal ;
153void GFilters::NetworkFilter::cancel()
156 m_timer.cancelTimer() ;
157 m_done_signal.emitted(
true ) ;
158 m_client_ptr.reset() ;
A Filter class that passes the name of a message file to a remote network server.
NetworkFilter(GNet::EventState, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &server_location)
Constructor.
~NetworkFilter() override
Destructor.
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 mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
A concrete implementation of the MessageStore interface dealing in paired flat files.
A somewhat opaque identifer for a GStore::MessageStore message id.
static int toInt(std::string_view s)
Converts string 's' to an int.
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 ...
static std::string tail(std::string_view in, std::size_t pos, std::string_view default_={})
Returns the last part of the string after the given position.
static std::string head(std::string_view in, std::size_t pos, std::string_view default_={})
Returns the first part of the string up to just before the given position.
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.