33 unique_ptr<ProtocolMessage> pm ,
35 const GAuth::Secrets & client_secrets ,
const std::string & server ) :
37 m_client_location(server) ,
38 m_client_config(client_config) ,
39 m_client_secrets(client_secrets) ,
46 m_client.doneSignal().connect(
G::Slot::slot(*
this,&ProtocolMessageForward::clientDone) ) ;
51 m_pm->doneSignal().disconnect() ;
52 m_client.doneSignal().disconnect() ;
53 if( m_client.get() != nullptr )
54 m_client->messageDoneSignal().disconnect() ;
59 return m_pm->doneSignal() ;
64 return m_done_signal ;
80 return m_pm->setFrom( from , from_auth ) ;
85 return m_pm->addTo( to , to_status ) ;
90 m_pm->addReceived( line ) ;
95 return m_pm->addText( line_data , line_size ) ;
100 return m_pm->from() ;
104 const std::string & peer_certificate )
106 m_done_signal.reset() ;
107 m_pm->process( auth_id , peer_socket_address , peer_certificate ) ;
112 G_DEBUG(
"ProtocolMessageForward::processDone: " << (success?1:0) <<
" " <<
id <<
" [" << response <<
"] [" << reason <<
"]" ) ;
113 if( success &&
id != 0UL )
118 bool nothing_to_do = false ;
119 std::string error = forward(
id , nothing_to_do ) ;
120 if( !error.empty() || nothing_to_do )
123 m_done_signal.emit( success ,
id ,
"forwarding failed" , error ) ;
129 m_done_signal.emit( success ,
id , response , reason ) ;
133 std::string GSmtp::ProtocolMessageForward::forward(
unsigned long id ,
bool & nothing_to_do )
137 nothing_to_do = false ;
138 G_DEBUG(
"GSmtp::ProtocolMessageForward::forward: forwarding message " <<
id ) ;
140 unique_ptr<StoredMessage> message = m_store.get(
id ) ;
145 nothing_to_do = true ;
150 if( m_client.get() == nullptr )
152 m_client.reset(
new Client(m_client_location,m_client_secrets,m_client_config) ) ;
153 m_client->messageDoneSignal().connect(
G::Slot::slot(*
this,&GSmtp::ProtocolMessageForward::messageDone) ) ;
155 m_client->sendMessage( unique_ptr<StoredMessage>(message.release()) ) ;
157 return std::string() ;
159 catch( std::exception & e )
161 G_WARNING(
"GSmtp::ProtocolMessageForward::forward: forwarding exception: " << e.what() ) ;
162 std::string e_what = e.what() ;
if( e_what.empty() ) e_what =
"exception" ;
167 void GSmtp::ProtocolMessageForward::messageDone( std::string reason )
169 G_DEBUG(
"GSmtp::ProtocolMessageForward::messageDone: \"" << reason <<
"\"" ) ;
170 const bool ok = reason.empty() ;
171 m_done_signal.emit( ok , m_id , ok?
"":
"forwarding failed" , reason ) ;
174 void GSmtp::ProtocolMessageForward::clientDone( std::string reason )
176 G_DEBUG(
"GSmtp::ProtocolMessageForward::clientDone: \"" << reason <<
"\"" ) ;
177 const bool ok = reason.empty() ;
178 m_done_signal.emit( ok , m_id , ok?
"":
"forwarding failed" , reason ) ;
ProtocolMessageForward(MessageStore &store, unique_ptr< ProtocolMessage > pm, const GSmtp::Client::Config &client_config, const GAuth::Secrets &client_secrets, const std::string &remote_server_address)
Constructor.
G::Slot::Signal4< bool, unsigned long, std::string, std::string > & storageDoneSignal()
Returns the signal which is used to signal that the storage is complete.
virtual void destroy()=0
Deletes the message within the store.
void processDone(bool, unsigned long, std::string, std::string)
Called by derived classes that have intercepted the storageDoneSignal() when their own post-storage p...
virtual bool addTo(const std::string &to_user, VerifierStatus to_status) override
Override from GSmtp::ProtocolMessage.
A class which allows SMTP messages to be stored and retrieved.
A simple interface for a store of secrets used in authentication.
virtual std::string from() const override
Override from GSmtp::ProtocolMessage.
virtual void process(const std::string &auth_id, const std::string &peer_socket_address, const std::string &peer_certificate) override
Override from GSmtp::ProtocolMessage.
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
virtual bool setFrom(const std::string &from_user, const std::string &) override
Override from GSmtp::ProtocolMessage.
A structure containing GSmtp::Client configuration parameters.
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' recipient.
virtual void reset() override
Override from GSmtp::ProtocolMessage.
virtual size_t remoteRecipientCount() const =0
Returns the number of non-local recipients.
virtual bool addText(const char *, size_t) override
Override from GSmtp::ProtocolMessage.
virtual void addReceived(const std::string &) override
Override from GSmtp::ProtocolMessage.
virtual G::Slot::Signal4< bool, unsigned long, std::string, std::string > & doneSignal() override
Override from GSmtp::ProtocolMessage.
virtual void clear() override
Override from GSmtp::ProtocolMessage.
virtual ~ProtocolMessageForward()
Destructor.