E-MailRelay
Classes | Public Member Functions | Static Public Member Functions | List of all members
GSmtp::SpamClient Class Reference

A client class that interacts with a remote process using a protocol somewhat similar to the spamassassin spamc/spamd protocol. More...

#include <gspamclient.h>

+ Inheritance diagram for GSmtp::SpamClient:
+ Collaboration diagram for GSmtp::SpamClient:

Public Member Functions

 SpamClient (GNet::EventState, const GNet::Location &host_and_service, bool read_only, unsigned int connection_timeout, unsigned int response_timeout)
 Constructor. More...
 
void request (const std::string &file_path)
 Starts sending a request that comprises a few http-like header lines followed by the contents of the given file. More...
 
bool busy () const
 Returns true after request() and before the subsequent event signal. More...
 
 SpamClient (const SpamClient &)=delete
 
 SpamClient (SpamClient &&)=delete
 
SpamClientoperator= (const SpamClient &)=delete
 
SpamClientoperator= (SpamClient &&)=delete
 
- Public Member Functions inherited from GNet::Client
 Client (EventState, const Location &remote_location, const Config &)
 Constructor. More...
 
 ~Client () override
 Destructor. More...
 
void connect ()
 Initiates a connection to the remote server. More...
 
bool connected () const
 Returns true if connected to the peer. More...
 
bool hasConnected () const
 Returns true if ever connected(). More...
 
std::string peerAddressString (bool with_port=true) const
 Returns the peer address display string or the empty string if not connected(). More...
 
void disconnect ()
 Aborts the connection and destroys the object's internal state, resulting in a zombie object. More...
 
Address localAddress () const override
 Returns the local address. More...
 
Address peerAddress () const override
 Returns the peer address. More...
 
std::string connectionState () const override
 Returns the connection state display string. More...
 
std::string peerCertificate () const override
 Returns the peer's TLS certificate. More...
 
Location remoteLocation () const
 Returns a Location structure, including the result of name lookup if available. More...
 
bool send (const std::string &data)
 Sends data to the peer and starts the response timer (if configured). More...
 
bool send (std::string_view data)
 Overload for string_view. More...
 
bool send (const std::vector< std::string_view > &data, std::size_t offset=0)
 Overload for scatter/gather segments. More...
 
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & eventSignal () noexcept
 Returns a signal that indicates that something interesting has happened. More...
 
void doOnDelete (const std::string &reason, bool done)
 This should be called by the Client owner (typically ClientPtr) just before this Client object is deleted as the result of an exception. More...
 
bool finished () const
 Returns true if finish() has been called. More...
 
LineBufferState lineBuffer () const
 Returns information about the state of the internal line-buffer. More...
 
bool secureConnectCapable () const
 Returns true if currently connected and secureConnect() can be used. More...
 
 Client (const Client &)=delete
 
 Client (Client &&)=delete
 
Clientoperator= (const Client &)=delete
 
Clientoperator= (Client &&)=delete
 
bool send (const char *, std::size_t)=delete
 
bool send (const char *)=delete
 
bool send (const std::string &, std::size_t)=delete
 
- Public Member Functions inherited from GNet::Connection
virtual ~Connection ()=default
 Destructor.
 
virtual Address localAddress () const =0
 Returns the connection's local address. More...
 
virtual Address peerAddress () const =0
 Returns the connection's peer address. More...
 
virtual std::string connectionState () const =0
 Returns the connection state as a display string. More...
 
virtual std::string peerCertificate () const =0
 Returns the peer's TLS certificate. More...
 
- Public Member Functions inherited from GNet::ExceptionSource
virtual ~ExceptionSource ()
 Destructor.
 
 ExceptionSource (const ExceptionSource &)=delete
 
 ExceptionSource (ExceptionSource &&)=delete
 
ExceptionSourceoperator= (const ExceptionSource &)=delete
 
ExceptionSourceoperator= (ExceptionSource &&)=delete
 

Static Public Member Functions

static void username (const std::string &)
 Sets the username used in the network protocol. More...
 

Additional Inherited Members

- Protected Member Functions inherited from GNet::Client
StreamSocketsocket ()
 Returns a reference to the socket. Throws if not connected. More...
 
const StreamSocketsocket () const
 Returns a const reference to the socket. Throws if not connected. More...
 
void finish ()
 Indicates that the last data has been sent and the client is expecting a peer disconnect. More...
 
void clearInput ()
 Clears the input LineBuffer and cancels the response timer if running. More...
 
virtual bool onReceive (const char *data, std::size_t size, std::size_t eolsize, std::size_t linesize, char c0)=0
 Called with received data. More...
 
virtual void onConnect ()=0
 Called once connected.
 
virtual void onSendComplete ()=0
 Called when all residual data from send() has been sent.
 
virtual void onDelete (const std::string &reason)=0
 Called from doOnDelete(), typically just before a ClientPtr destroys the Client as the result of handling an exception. More...
 
void secureConnect ()
 Starts TLS/SSL client-side negotiation. More...
 

Detailed Description

A client class that interacts with a remote process using a protocol somewhat similar to the spamassassin spamc/spamd protocol.

The interface is similar to GSmtp::RequestClient but it is single-use: only one request() can be made per object.

Definition at line 46 of file gspamclient.h.

Constructor & Destructor Documentation

◆ SpamClient()

GSmtp::SpamClient::SpamClient ( GNet::EventState  es,
const GNet::Location host_and_service,
bool  read_only,
unsigned int  connection_timeout,
unsigned int  response_timeout 
)

Constructor.

Definition at line 32 of file gspamclient.cpp.

Member Function Documentation

◆ busy()

bool GSmtp::SpamClient::busy ( ) const

Returns true after request() and before the subsequent event signal.

Definition at line 56 of file gspamclient.cpp.

◆ request()

void GSmtp::SpamClient::request ( const std::string &  file_path)

Starts sending a request that comprises a few http-like header lines followed by the contents of the given file.

The response is spooled into a temporary file and then committed back to the same file.

The base class's "event" signal will be emitted when processing is complete. In this case the first signal parameter will "spam" and the second will be the parsed response.

See also GNet::Client::eventSignal().

Definition at line 61 of file gspamclient.cpp.

◆ username()

void GSmtp::SpamClient::username ( const std::string &  username)
static

Sets the username used in the network protocol.

Definition at line 50 of file gspamclient.cpp.


The documentation for this class was generated from the following files: