31 m_filter(filter.release())
33 m_filter->doneSignal().connect(
G::Slot::slot(*
this,&ProtocolMessageStore::filterDone) ) ;
38 m_filter->doneSignal().disconnect() ;
43 G_DEBUG(
"GSmtp::ProtocolMessageStore::reset" ) ;
49 G_DEBUG(
"GSmtp::ProtocolMessageStore::clear" ) ;
57 G_DEBUG(
"GSmtp::ProtocolMessageStore::setFrom: " << from ) ;
59 if( from.length() == 0U )
60 G_WARNING(
"GSmtp::ProtocolMessageStore: empty MAIL-FROM return path" ) ;
62 G_ASSERT( m_new_msg.get() == nullptr ) ;
65 m_new_msg.reset( m_store.newMessage(from,from_auth,
"").release() ) ;
73 G_DEBUG(
"GSmtp::ProtocolMessageStore::addTo: " << to ) ;
75 G_ASSERT( m_new_msg.get() != nullptr ) ;
76 if( to.length() > 0U && m_new_msg.get() != nullptr )
78 if( !to_status.is_valid )
80 G_WARNING(
"GSmtp::ProtocolMessage: rejecting recipient \"" << to <<
"\": "
81 << to_status.response << (to_status.reason.empty()?
"":
": ") << to_status.reason ) ;
86 m_new_msg->addTo( to_status.address , to_status.is_local ) ;
98 G_DEBUG(
"GSmtp::ProtocolMessageStore::addReceived" ) ;
99 if( m_new_msg.get() != nullptr )
100 m_new_msg->addTextLine( received_line ) ;
105 G_ASSERT( m_new_msg.get() != nullptr ) ;
106 if( m_new_msg.get() == nullptr )
108 return m_new_msg->addText( line_data , line_size ) ;
113 return m_new_msg.get() ? m_from : std::string() ;
117 const std::string & peer_certificate )
121 G_DEBUG(
"GSmtp::ProtocolMessageStore::process: \"" << session_auth_id <<
"\", \"" << peer_socket_address <<
"\"" ) ;
122 G_ASSERT( m_new_msg.get() != nullptr ) ;
123 if( m_new_msg.get() == nullptr )
127 std::string message_location = m_new_msg->prepare( session_auth_id , peer_socket_address , peer_certificate ) ;
130 if( !m_filter->simple() )
131 G_LOG(
"GSmtp::ProtocolMessageStore::process: filter start: [" << m_filter->id() <<
"] [" << message_location <<
"]" ) ;
132 m_filter->start( message_location ) ;
134 catch( std::exception & e )
136 G_WARNING(
"GSmtp::ProtocolMessageStore::process: message processing exception: " << e.what() ) ;
138 m_done_signal.emit(
false , 0UL ,
"failed" , e.what() ) ;
142 void GSmtp::ProtocolMessageStore::filterDone(
int filter_result )
146 G_DEBUG(
"GSmtp::ProtocolMessageStore::filterDone: " << filter_result ) ;
147 G_ASSERT( m_new_msg.get() != nullptr ) ;
148 if( m_new_msg.get() == nullptr )
151 const bool ok = filter_result == 0 ;
152 const bool abandon = filter_result == 1 ;
153 const bool rescan = m_filter->special() ;
154 G_ASSERT( m_filter->reason().empty() == (ok || abandon) ) ;
156 if( !m_filter->simple() )
157 G_LOG(
"GSmtp::ProtocolMessageStore::filterDone: filter done: " << m_filter->str(
true) ) ;
159 unsigned long id = 0UL ;
163 m_new_msg->commit(
true ) ;
164 id = m_new_msg->id() ;
170 m_new_msg->commit(
false ) ;
174 G_LOG_S(
"GSmtp::ProtocolMessageStore::filterDone: rejected by filter: [" << m_filter->reason() <<
"]" ) ;
183 std::string filter_response = m_filter->response() ;
184 std::string filter_reason = m_filter->reason() ;
186 G_DEBUG(
"GSmtp::ProtocolMessageStore::filterDone: emiting done signal" ) ;
187 m_done_signal.emit( ok || abandon ,
id , filter_response , filter_reason ) ;
189 catch( std::exception & e )
191 G_WARNING(
"GSmtp::ProtocolMessageStore::filterDone: filter exception: " << e.what() ) ;
193 m_done_signal.emit(
false , 0UL ,
"rejected" , e.what() ) ;
199 return m_done_signal ;
virtual void reset() override
Override from GSmtp::ProtocolMessage.
virtual G::Slot::Signal4< bool, unsigned long, std::string, std::string > & doneSignal() override
Override from GSmtp::ProtocolMessage.
virtual bool addTo(const std::string &to_user, VerifierStatus to_status) override
Override from GSmtp::ProtocolMessage.
virtual std::string from() const override
Override from GSmtp::ProtocolMessage.
A class which allows SMTP messages to be stored and retrieved.
virtual bool setFrom(const std::string &from_user, const std::string &) override
Override from GSmtp::ProtocolMessage.
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
ProtocolMessageStore(MessageStore &store, unique_ptr< Filter >)
Constructor.
virtual ~ProtocolMessageStore()
Destructor.
virtual void clear() 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.
virtual void addReceived(const std::string &) override
Override from GSmtp::ProtocolMessage.
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' recipient.
A general-purpose exception class derived from std::exception and containing a std::string.
virtual bool addText(const char *, size_t) override
Override from GSmtp::ProtocolMessage.