29 const std::string & server ) :
31 m_file_store(file_store) ,
35 m_connection_timeout(config.timeout) ,
36 m_response_timeout(config.timeout) ,
37 m_result(Result::fail)
44 m_client_ptr.eventSignal().disconnect() ;
47std::string GFilters::NetworkFilter::id()
const
49 return m_location.displayString() ;
52bool GFilters::NetworkFilter::quiet()
const
60 m_timer.cancelTimer() ;
61 m_done_signal.reset() ;
62 if( m_client_ptr.get() ==
nullptr || m_client_ptr->busy() )
64 unsigned int idle_timeout = 0U ;
65 m_client_ptr.reset( std::make_unique<GSmtp::RequestClient>(
68 m_location , m_connection_timeout , m_response_timeout ,
71 m_client_ptr->request( m_file_store.contentPath(message_id).str() ) ;
76 if( m_client_ptr.get() )
77 m_client_ptr->doOnDelete( e.what() , done ) ;
78 m_client_ptr.reset() ;
80 sendResult( std::string(
"failed\t").append(e.what()) ) ;
83void GFilters::NetworkFilter::clientEvent(
const std::string & s1 ,
const std::string & s2 ,
const std::string & )
91void GFilters::NetworkFilter::sendResult(
const std::string & reason )
93 if( !m_text.has_value() )
96 m_timer.startTimer( 0 ) ;
97 m_result = m_text.value().empty() ? Result::ok : Result::fail ;
101void GFilters::NetworkFilter::onTimeout()
103 if( m_text.has_value() )
104 m_done_signal.emit(
static_cast<int>(m_result) ) ;
107GSmtp::Filter::Result GFilters::NetworkFilter::result()
const
112bool GFilters::NetworkFilter::special()
const
117std::pair<std::string,int> GFilters::NetworkFilter::responsePair()
const
122 if( s.size() >= 3U &&
123 ( s[0] ==
'4' || s[0] ==
'5' ) &&
124 ( s[1] >=
'0' && s[1] <=
'9' ) &&
125 ( s[2] >=
'0' && s[2] <=
'9' ) &&
126 ( s.size() == 3U || s[3] ==
' ' ) )
129 s.erase( 0U , s.size() == 3U ? 3U : 4U ) ;
134std::string GFilters::NetworkFilter::response()
const
136 return responsePair().first ;
139int GFilters::NetworkFilter::responseCode()
const
141 return responsePair().second ;
144std::string GFilters::NetworkFilter::reason()
const
151 return m_done_signal ;
154void GFilters::NetworkFilter::cancel()
157 m_timer.cancelTimer() ;
158 m_done_signal.emitted(
true ) ;
159 m_client_ptr.reset() ;
A Filter class that passes the name of a message file to a remote network server.
~NetworkFilter() override
Destructor.
NetworkFilter(GNet::ExceptionSink, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &server_location)
Constructor.
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 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(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(string_view in, std::size_t pos, string_view default_={})
Returns the last part of the string after the given position.
static std::string head(string_view in, std::size_t pos, 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.