29 std::unique_ptr<Filter> filter ) :
31 m_filter(
std::move(filter))
33 m_filter->doneSignal().connect(
G::Slot::slot(*
this,&ProtocolMessageStore::filterDone) ) ;
38 m_filter->doneSignal().disconnect() ;
41void GSmtp::ProtocolMessageStore::reset()
43 G_DEBUG(
"GSmtp::ProtocolMessageStore::reset" ) ;
47void GSmtp::ProtocolMessageStore::clear()
49 G_DEBUG(
"GSmtp::ProtocolMessageStore::clear" ) ;
52 m_from_info = FromInfo() ;
57 const FromInfo & from_info )
59 G_DEBUG(
"GSmtp::ProtocolMessageStore::setFrom: " << from ) ;
62 G_WARNING(
"GSmtp::ProtocolMessageStore: empty MAIL-FROM return path" ) ;
64 G_ASSERT( m_new_msg ==
nullptr ) ;
68 smtp_info.auth = from_info.auth ;
69 smtp_info.body = from_info.body ;
70 smtp_info.address_style = from_info.address_style ;
71 const std::string & from_auth_out = std::string() ;
72 m_new_msg = m_store.newMessage( from , smtp_info , from_auth_out ) ;
75 m_from_info = from_info ;
76 return m_new_msg->id() ;
79bool GSmtp::ProtocolMessageStore::addTo(
const ToInfo & to_info )
81 G_DEBUG(
"GSmtp::ProtocolMessageStore::addTo: " << to_info.status.recipient ) ;
82 G_ASSERT( m_new_msg !=
nullptr ) ;
84 if( to_info.status.recipient.empty() )
88 else if( !to_info.status.is_valid )
90 G_WARNING(
"GSmtp::ProtocolMessage: rejecting recipient \"" << to_info.status.recipient <<
"\": "
91 << to_info.status.response << (to_info.status.reason.empty()?
"":
": ") << to_info.status.reason ) ;
96 m_new_msg->addTo( to_info.status.address , to_info.status.is_local , to_info.address_style ) ;
101void GSmtp::ProtocolMessageStore::addReceived(
const std::string & received_line )
103 G_DEBUG(
"GSmtp::ProtocolMessageStore::addReceived" ) ;
104 if( m_new_msg !=
nullptr )
105 m_new_msg->addContentLine( received_line ) ;
108GStore::NewMessage::Status GSmtp::ProtocolMessageStore::addContent(
const char * data , std::size_t data_size )
110 G_ASSERT( m_new_msg !=
nullptr ) ;
111 return m_new_msg->addContent( data , data_size ) ;
114std::size_t GSmtp::ProtocolMessageStore::contentSize()
const
116 return m_new_msg ? m_new_msg->contentSize() : 0U ;
119std::string GSmtp::ProtocolMessageStore::from()
const
129std::string GSmtp::ProtocolMessageStore::bodyType()
const
131 return m_from_info.body ;
134void GSmtp::ProtocolMessageStore::process(
const std::string & session_auth_id ,
135 const std::string & peer_socket_address ,
const std::string & peer_certificate )
139 G_DEBUG(
"GSmtp::ProtocolMessageStore::process: \""
140 << session_auth_id <<
"\", \"" << peer_socket_address <<
"\"" ) ;
141 G_ASSERT( m_new_msg !=
nullptr ) ;
144 m_new_msg->prepare( session_auth_id , peer_socket_address , peer_certificate ) ;
147 G_LOG_MORE(
"GSmtp::ProtocolMessageStore::process: filter [" << m_filter->id() <<
"]: [" << m_new_msg->id().str() <<
"]" ) ;
148 m_filter->start( m_new_msg->id() ) ;
150 catch( std::exception & e )
152 G_WARNING(
"GSmtp::ProtocolMessageStore::process: message processing exception: " << e.what() ) ;
158void GSmtp::ProtocolMessageStore::filterDone(
int filter_result )
162 G_DEBUG(
"GSmtp::ProtocolMessageStore::filterDone: " << filter_result ) ;
163 G_ASSERT(
static_cast<int>(m_filter->result()) == filter_result ) ;
164 G_ASSERT( m_new_msg !=
nullptr ) ;
166 const bool ok = filter_result == 0 ;
167 const bool abandon = filter_result == 1 ;
168 const bool rescan = m_filter->special() ;
170 std::string filter_response =
G::Str::replaced( (ok||abandon) ? std::string() : m_filter->response() ,
'\t' ,
' ' ) ;
171 int filter_response_code = (ok||abandon) ? 0 : m_filter->responseCode() ;
172 std::string filter_reason = (ok||abandon) ? std::string() : m_filter->reason() ;
174 G_LOG_IF( !m_filter->quiet() ,
"GSmtp::ProtocolMessageStore::filterDone: "
175 "filter [" << m_filter->id() <<
"]: [" << m_new_msg->id().str() <<
"]: "
176 << m_filter->str(Filter::Type::server) ) ;
182 m_new_msg->commit(
true ) ;
183 message_id = m_new_msg->id() ;
189 m_new_msg->commit(
false ) ;
193 G_LOG_S(
"GSmtp::ProtocolMessageStore::filterDone: rejected by filter: [" << filter_reason <<
"]" ) ;
203 m_processed_signal.emit( { ok || abandon , message_id , filter_response_code , filter_response , filter_reason } ) ;
205 catch( std::exception & e )
207 G_WARNING(
"GSmtp::ProtocolMessageStore::filterDone: filter exception: " << e.what() ) ;
215 return m_processed_signal ;
ProtocolMessageStore(GStore::MessageStore &store, std::unique_ptr< Filter >)
Constructor.
~ProtocolMessageStore() override
Destructor.
A somewhat opaque identifer for a GStore::MessageStore message id.
static MessageId none()
Returns an in-valid() id.
A class which allows SMTP messages to be stored and retrieved.
static std::string replaced(const std::string &s, char from, char to)
Returns the string 's' with all occurrences of 'from' replaced by 'to'.
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.
Extra information from the SMTP MAIL-FROM command passed to GSmtp::ProtocolMessage::setFrom().
Information on the SMTP options used when submitted.