32 const std::string & forward_to ,
int forward_to_family ) :
36 m_client_location(forward_to,forward_to_family) ,
37 m_client_config(client_config) ,
38 m_client_secrets(client_secrets) ,
40 m_id(
GStore::MessageId::none()) ,
41 m_processed_signal(true)
44 m_pm->processedSignal().connect(
G::Slot::slot(*
this,&ProtocolMessageForward::protocolMessageProcessed) ) ;
50 m_pm->processedSignal().disconnect() ;
51 m_client_ptr.deleteSignal().disconnect() ;
52 if( m_client_ptr.get() !=
nullptr )
53 m_client_ptr->messageDoneSignal().disconnect() ;
58 return m_processed_signal ;
61void GSmtp::ProtocolMessageForward::reset()
64 m_client_ptr.reset() ;
67void GSmtp::ProtocolMessageForward::clear()
72GStore::MessageId GSmtp::ProtocolMessageForward::setFrom(
const std::string & from ,
const FromInfo & from_info )
74 return m_pm->setFrom( from , from_info ) ;
79 return m_pm->fromInfo() ;
82std::string GSmtp::ProtocolMessageForward::bodyType()
const
84 return m_pm->bodyType() ;
87bool GSmtp::ProtocolMessageForward::addTo(
const ToInfo & to_info )
89 return m_pm->addTo( to_info ) ;
92void GSmtp::ProtocolMessageForward::addReceived(
const std::string & line )
94 m_pm->addReceived( line ) ;
97GStore::NewMessage::Status GSmtp::ProtocolMessageForward::addContent(
const char * line_data , std::size_t line_size )
99 return m_pm->addContent( line_data , line_size ) ;
102std::size_t GSmtp::ProtocolMessageForward::contentSize()
const
104 return m_pm->contentSize() ;
107std::string GSmtp::ProtocolMessageForward::from()
const
109 return m_pm->from() ;
112void GSmtp::ProtocolMessageForward::process(
const std::string & auth_id ,
const std::string & peer_socket_address ,
113 const std::string & peer_certificate )
116 m_processed_signal.reset() ;
117 m_pm->process( auth_id , peer_socket_address , peer_certificate ) ;
120void GSmtp::ProtocolMessageForward::protocolMessageProcessed(
const ProtocolMessage::ProcessedInfo & info )
122 G_ASSERT( info.response.find(
'\t') == std::string::npos ) ;
123 G_DEBUG(
"ProtocolMessageForward::protocolMessageProcessed: " << (info.success?1:0) <<
" "
124 << info.id.str() <<
" [" << info.response <<
"] [" << info.reason <<
"]" ) ;
127 if( info.success && info.id.valid() )
132 bool nothing_to_do = false ;
133 std::string error = forward( info.id , nothing_to_do ) ;
135 if( this_.deleted() ) return ;
139 m_processed_signal.emit( { true , info.id , 0 , std::string() , std::string() } ) ;
141 else if( !error.empty() )
144 m_processed_signal.emit( { false , info.id , 0 ,
"forwarding failed" , error } ) ;
150 m_processed_signal.emit( info ) ;
154std::string GSmtp::ProtocolMessageForward::forward(
const GStore::MessageId &
id ,
bool & nothing_to_do )
158 nothing_to_do = false ;
159 G_DEBUG(
"GSmtp::ProtocolMessageForward::forward: forwarding message " <<
id.str() ) ;
161 std::unique_ptr<GStore::StoredMessage> message = m_store.get(
id ) ;
162 if( message->toCount() == 0U )
164 nothing_to_do = true ;
168 if( m_client_ptr.get() ==
nullptr )
170 m_client_ptr.reset( std::make_unique<Forward>( m_es.eh(m_client_ptr) ,
171 m_ff , m_client_location , m_client_secrets , m_client_config ) ) ;
173 m_client_ptr->messageDoneSignal().connect(
G::Slot::slot( *
this ,
174 &GSmtp::ProtocolMessageForward::messageDone ) ) ;
176 m_client_ptr->sendMessage( std::unique_ptr<GStore::StoredMessage>(message.release()) ) ;
180 catch( std::exception & e )
182 G_WARNING(
"GSmtp::ProtocolMessageForward::forward: forwarding exception: " << e.what() ) ;
183 std::string e_what = e.what() ;
185 e_what =
"exception" ;
190void GSmtp::ProtocolMessageForward::messageDone(
const Client::MessageDoneInfo & info )
192 G_DEBUG(
"GSmtp::ProtocolMessageForward::messageDone: \"" << info.response <<
"\"" ) ;
193 const bool ok = info.response.empty() ;
194 m_processed_signal.emit( { ok , m_id , ok?0:info.response_code , info.response , std::string() } ) ;
197void GSmtp::ProtocolMessageForward::clientDone(
const std::string & reason )
199 G_DEBUG(
"GSmtp::ProtocolMessageForward::clientDone: \"" << reason <<
"\"" ) ;
200 const bool ok = reason.empty() ;
201 m_processed_signal.emit( { ok , m_id , 0 , ok?
"":
"forwarding failed" , reason } ) ;
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
G::Slot::Signal< const std::string & > & deleteSignal() noexcept
A signal that is triggered as the client is deleted following an exception handled by this class.
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
A factory interface for making GSmtp::Filter message processors.
ProtocolMessageForward(GNet::EventState, GStore::MessageStore &store, FilterFactoryBase &, std::unique_ptr< ProtocolMessage > pm, const GSmtp::Client::Config &client_config, const GAuth::SaslClientSecrets &client_secrets, const std::string &forward_to, int forward_to_family)
Constructor.
~ProtocolMessageForward() override
Destructor.
A somewhat opaque identifer for a GStore::MessageStore message id.
A class which allows SMTP messages to be stored and retrieved.
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.
Extra information from the SMTP MAIL-FROM command passed to GSmtp::ProtocolMessage::setFrom().