37 m_client_location(server) ,
38 m_client_config(client_config) ,
39 m_client_secrets(client_secrets) ,
51 m_pm->doneSignal().disconnect() ;
52 m_client_ptr.deleteSignal().disconnect() ;
53 if( m_client_ptr.get() !=
nullptr )
54 m_client_ptr->messageDoneSignal().disconnect() ;
59 return m_pm->doneSignal() ;
64 return m_done_signal ;
67void GSmtp::ProtocolMessageForward::reset()
70 m_client_ptr.reset() ;
73void GSmtp::ProtocolMessageForward::clear()
78GSmtp::MessageId GSmtp::ProtocolMessageForward::setFrom(
const std::string & from ,
const std::string & from_auth )
80 return m_pm->setFrom( from , from_auth ) ;
83bool GSmtp::ProtocolMessageForward::addTo( VerifierStatus to_status )
85 return m_pm->addTo( to_status ) ;
88void GSmtp::ProtocolMessageForward::addReceived(
const std::string & line )
90 m_pm->addReceived( line ) ;
93bool GSmtp::ProtocolMessageForward::addText(
const char * line_data , std::size_t line_size )
95 return m_pm->addText( line_data , line_size ) ;
98std::string GSmtp::ProtocolMessageForward::from()
const
100 return m_pm->from() ;
103void GSmtp::ProtocolMessageForward::process(
const std::string & auth_id ,
const std::string & peer_socket_address ,
104 const std::string & peer_certificate )
106 m_done_signal.reset() ;
107 m_pm->process( auth_id , peer_socket_address , peer_certificate ) ;
111 const std::string & reason )
113 G_DEBUG(
"ProtocolMessageForward::processDone: " << (success?1:0) <<
" "
114 <<
id.str() <<
" [" << response <<
"] [" << reason <<
"]" ) ;
116 if( success &&
id.valid() )
121 bool nothing_to_do = false ;
122 std::string error = forward(
id , nothing_to_do ) ;
123 if( this_.deleted() ) return ;
124 if( !error.empty() || nothing_to_do )
127 m_done_signal.emit( success ,
id ,
"forwarding failed" , error ) ;
133 m_done_signal.emit( success ,
id , std::string(response) , std::string(reason) ) ;
137std::string GSmtp::ProtocolMessageForward::forward(
const MessageId &
id ,
bool & nothing_to_do )
141 nothing_to_do = false ;
142 G_DEBUG(
"GSmtp::ProtocolMessageForward::forward: forwarding message " <<
id.str() ) ;
144 std::unique_ptr<StoredMessage> message = m_store.get(
id ) ;
145 G_LOG(
"GSmtp::ProtocolMessageForward::forward: processing message \"" << message->location() <<
"\"" ) ;
147 if( message->toCount() == 0U )
150 nothing_to_do = true ;
155 if( m_client_ptr.get() ==
nullptr )
157 m_client_ptr.reset( std::make_unique<Client>(
GNet::ExceptionSink(m_client_ptr,m_es.esrc()),
158 m_ff , m_client_location , m_client_secrets , m_client_config ) ) ;
159 m_client_ptr->messageDoneSignal().connect(
G::Slot::slot( *
this ,
160 &GSmtp::ProtocolMessageForward::messageDone ) ) ;
162 m_client_ptr->sendMessage( std::unique_ptr<StoredMessage>(message.release()) ) ;
164 return std::string() ;
166 catch( std::exception & e )
168 G_WARNING(
"GSmtp::ProtocolMessageForward::forward: forwarding exception: " << e.what() ) ;
169 std::string e_what = e.what() ;
171 e_what =
"exception" ;
176void GSmtp::ProtocolMessageForward::messageDone(
const std::string & reason )
178 G_DEBUG(
"GSmtp::ProtocolMessageForward::messageDone: \"" << reason <<
"\"" ) ;
179 const bool ok = reason.empty() ;
180 m_done_signal.emit( ok , m_id , ok?
"":
"forwarding failed" , std::string(reason) ) ;
183void GSmtp::ProtocolMessageForward::clientDone(
const std::string & reason )
185 G_DEBUG(
"GSmtp::ProtocolMessageForward::clientDone: \"" << reason <<
"\"" ) ;
186 const bool ok = reason.empty() ;
187 m_done_signal.emit( ok , m_id , ok?
"":
"forwarding failed" , std::string(reason) ) ;
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
G::Slot::Signal< const std::string & > & deleteSignal()
A signal that is triggered as the client is deleted following an exception handled by this class.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A factory interface for GSmtp::Filter message processors.
A somewhat opaque identifer for a MessageStore message.
A class which allows SMTP messages to be stored and retrieved.
void processDone(bool, const MessageId &, const std::string &, const std::string &)
Called by derived classes that have intercepted the storageDoneSignal() when their own post-storage p...
ProtocolMessageForward(GNet::ExceptionSink, MessageStore &store, FilterFactory &, std::unique_ptr< ProtocolMessage > pm, const GSmtp::Client::Config &client_config, const GAuth::SaslClientSecrets &client_secrets, const std::string &remote_server_address)
Constructor.
~ProtocolMessageForward() override
Destructor.
ProtocolMessage::DoneSignal & storageDoneSignal()
Returns the signal which is used to signal that the storage is complete.
An object to represent a nested execution context.
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.
A structure containing GSmtp::Client configuration parameters.