21#ifndef G_SMTP_SERVER_H
22#define G_SMTP_SERVER_H
57 using AddressList = std::vector<GNet::Address> ;
61 bool allow_remote {
false} ;
63 unsigned int port {0U} ;
65 bool anonymous_smtp {
false} ;
66 bool anonymous_content {
false} ;
74 std::string dnsbl_config ;
78 Config & set_allow_remote(
bool =
true ) noexcept ;
80 Config & set_port(
unsigned int ) noexcept ;
81 Config & set_ident(
const std::string & ) ;
82 Config & set_anonymous(
bool =
true ) noexcept ;
83 Config & set_anonymous_smtp(
bool =
true ) noexcept ;
84 Config & set_anonymous_content(
bool =
true ) noexcept ;
92 Config & set_dnsbl_config(
const std::string & ) ;
94 Config & set_domain(
const std::string & ) ;
100 const std::string & forward_to ,
int forward_to_family ,
117 void report(
const std::string & group = {} )
const ;
129 void nodnsbl(
unsigned int seconds ) ;
148 std::unique_ptr<
Filter> newFilter(
GNet::EventState ) const ;
151 std::unique_ptr<
ServerProtocol::Text> newProtocolText(
bool ,
bool , const
GNet::Address & , const
std::
string & domain ) const ;
152 Config serverConfig() const ;
155 GStore::MessageStore & m_store ;
158 Config m_server_config ;
159 Client::Config m_client_config ;
160 const
GAuth::SaslServerSecrets & m_server_secrets ;
161 std::
string m_sasl_server_config ;
162 std::
string m_forward_to ;
163 int m_forward_to_family ;
164 const
GAuth::SaslClientSecrets & m_client_secrets ;
165 std::
string m_sasl_client_config ;
166 G::Slot::Signal<const
std::
string&,const
std::
string&> m_event_signal ;
167 G::TimerTime m_dnsbl_suspend_time ;
168 bool m_enabled {
true} ;
178 G_EXCEPTION( Error ,
tx(
"smtp server error") )
179 G_EXCEPTION( SendError ,
tx(
"failed to send smtp response") )
183 const Server::Config & server_config , std::unique_ptr<ServerProtocol::Text> ptext ) ;
190 void onSendComplete()
override ;
191 void onDelete(
const std::string & reason )
override ;
192 bool onReceive(
const char * , std::size_t , std::size_t , std::size_t ,
char )
override ;
193 void onSecure(
const std::string & ,
const std::string & ,
const std::string & )
override ;
194 void protocolSecure()
override ;
195 void protocolSend(
const std::string & line ,
bool )
override ;
196 void protocolShutdown(
int how )
override ;
197 void protocolExpect( std::size_t )
override ;
198 void onData(
const char * , std::size_t )
override ;
207 void onDnsBlockResult(
bool ) ;
208 void onCheckTimeout() ;
209 void onFlow(
bool ) ;
216 std::unique_ptr<Verifier> m_verifier ;
217 std::unique_ptr<ProtocolMessage> m_pmessage ;
218 std::unique_ptr<ServerProtocol::Text> m_ptext ;
221 std::string m_output_buffer ;
222 bool m_output_blocked {
false} ;
225inline GSmtp::Server::Config & GSmtp::Server::Config::set_allow_remote(
bool b )
noexcept { allow_remote = b ;
return *this ; }
227inline GSmtp::Server::Config & GSmtp::Server::Config::set_port(
unsigned int n )
noexcept { port = n ;
return *this ; }
228inline GSmtp::Server::Config & GSmtp::Server::Config::set_ident(
const std::string & s ) { ident = s ;
return *this ; }
229inline GSmtp::Server::Config & GSmtp::Server::Config::set_anonymous(
bool b )
noexcept { anonymous_smtp = anonymous_content = b ;
return *this ; }
230inline GSmtp::Server::Config & GSmtp::Server::Config::set_anonymous_smtp(
bool b )
noexcept { anonymous_smtp = b ;
return *this ; }
231inline GSmtp::Server::Config & GSmtp::Server::Config::set_anonymous_content(
bool b )
noexcept { anonymous_content = b ;
return *this ; }
232inline GSmtp::Server::Config & GSmtp::Server::Config::set_filter_config(
const Filter::Config & c ) { filter_config = c ;
return *this ; }
233inline GSmtp::Server::Config & GSmtp::Server::Config::set_filter_spec(
const FilterFactoryBase::Spec & r ) { filter_spec = r ;
return *this ; }
234inline GSmtp::Server::Config & GSmtp::Server::Config::set_verifier_config(
const Verifier::Config & c ) { verifier_config = c ;
return *this ; }
235inline GSmtp::Server::Config & GSmtp::Server::Config::set_verifier_spec(
const VerifierFactoryBase::Spec & r ) { verifier_spec = r ;
return *this ; }
238inline GSmtp::Server::Config & GSmtp::Server::Config::set_protocol_config(
const ServerProtocol::Config & c ) { protocol_config = c ;
return *this ; }
239inline GSmtp::Server::Config & GSmtp::Server::Config::set_dnsbl_config(
const std::string & s ) { dnsbl_config = s ;
return *this ; }
240inline GSmtp::Server::Config & GSmtp::Server::Config::set_buffer_config(
const ServerBufferIn::Config & c ) { buffer_config = c ;
return *this ; }
241inline GSmtp::Server::Config & GSmtp::Server::Config::set_domain(
const std::string & s ) { domain = s ;
return *this ; }
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
An interface used by GAuth::SaslServer to obtain authentication secrets.
A minimal bridge to GNet::DnsBlock.
The EventStateUnbound class is used as a device to force factory methods to plumb-in an ExceptionSour...
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
MultiServer(EventState es_listener, const G::StringArray &listen_list, unsigned int port, const std::string &server_type, ServerPeer::Config server_peer_config, Server::Config server_config)
Constructor.
A move-only structure used in GNet::Server::newPeer() and containing the new socket.
An abstract base class for the GNet::Server's connection to a remote client.
A timer class template in which the timeout is delivered to the specified method.
A class which acts as an SMTP client, sending messages to a remote SMTP server.
A factory interface for making GSmtp::Filter message processors.
An interface for processing a message file through a filter.
An interface used by the ServerProtocol class to assemble and process an incoming message.
A helper class for GSmtp::ServerProtocol that does buffering of data received from the remote peer an...
Handles a connection from a remote SMTP client.
~ServerPeer() override
Destructor.
ServerPeer(GNet::EventStateUnbound, GNet::ServerPeerInfo &&peer_info, Server &server, bool enabled, VerifierFactoryBase &vf, const GAuth::SaslServerSecrets &server_secrets, const Server::Config &server_config, std::unique_ptr< ServerProtocol::Text > ptext)
Constructor.
Implements the SMTP server-side protocol.
An interface used by ServerProtocol to send protocol responses.
void enable(bool)
Disables or re-enables new SMTP sessions.
void report(const std::string &group={}) const
Generates helpful diagnostics after construction.
Config & config()
Exposes the configuration sub-object.
Server(GNet::EventState es, GStore::MessageStore &, FilterFactoryBase &, VerifierFactoryBase &, const GAuth::SaslClientSecrets &, const GAuth::SaslServerSecrets &, const Config &server_config, const std::string &forward_to, int forward_to_family, const GSmtp::Client::Config &client_config)
Constructor.
std::unique_ptr< ProtocolMessage > newProtocolMessage(GNet::EventState)
Called by GSmtp::ServerPeer to construct a ProtocolMessage.
void nodnsbl(unsigned int seconds)
Clears the DNSBL configuration string for a period of time.
~Server() override
Destructor.
G::Slot::Signal< const std::string &, const std::string & > & eventSignal() noexcept
Returns a signal that indicates that something has happened.
A factory interface for addresss verifiers.
A class which allows SMTP messages to be stored and retrieved.
SASL authentication classes.
bool enabled() noexcept
Returns true if pop code is built in.
std::vector< std::string > StringArray
A std::vector of std::strings.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
A configuration structure for GNet::ServerPeer.
A configuration structure for GNet::Server.
A structure containing GSmtp::Client configuration parameters.
Filter specification tuple for GSmtp::FilterFactoryBase::newFilter().
Configuration passed to filter constructors.
A configuration structure for GSmtp::ServerBufferIn.
A configuration structure for GSmtp::ServerProtocol.
A configuration structure for GSmtp::Server.
Verifier specification tuple for GSmtp::VerifierFactoryBase::newVerifier().
Configuration passed to address verifier constructors.