21 #ifndef G_SMTP_CLIENT_PROTOCOL_H
22 #define G_SMTP_CLIENT_PROTOCOL_H
40 class ClientProtocol ;
41 class ClientProtocolReply ;
118 std::string
text()
const ;
132 std::string
textLine(
const std::string & prefix )
const ;
143 static bool is_digit(
char ) ;
164 G_EXCEPTION( ResponseError ,
"protocol error: unexpected response" ) ;
165 G_EXCEPTION( NoMechanism ,
"cannot do authentication mandated by remote server" ) ;
166 G_EXCEPTION( AuthenticationRequired ,
"authentication required by the remote smtp server" ) ;
167 G_EXCEPTION( AuthenticationNotSupported ,
"authentication not supported by the remote smtp server" ) ;
168 G_EXCEPTION( AuthenticationError ,
"authentication error" ) ;
175 public:
virtual bool protocolSend(
const std::string & ,
size_t offset ,
bool go_secure ) = 0 ;
188 private:
void operator=(
const Sender & ) ;
202 Config(
const std::string & ,
unsigned int ,
unsigned int ,
unsigned int ,
bool ,
bool ,
bool ) ;
229 void start(
const std::string & from ,
const G::Strings & to ,
bool eight_bit ,
230 std::string authentication , std::string server_name ,
231 std::auto_ptr<std::istream> content ) ;
256 bool apply(
const std::string & rx ) ;
269 void send(
const char * ) ;
270 void send(
const char * ,
const std::string & ) ;
271 void send(
const char * ,
const std::string & ,
const char * ) ;
272 bool send(
const std::string & ,
bool eot ,
bool sensitive =
false ) ;
273 bool sendLine( std::string & ) ;
278 void sendMailCore() ;
279 bool endOfContent()
const ;
280 static const std::string & crlf() ;
281 bool applyEvent(
const Reply & event ,
bool is_start_event =
false ) ;
282 static bool parseReply( Reply & ,
const std::string & , std::string & ) ;
283 void raiseDoneSignal(
const std::string & ,
int = 0 ,
bool =
false ) ;
286 void startPreprocessing() ;
289 enum State { sInit , sStarted , sServiceReady , sSentEhlo , sSentHelo , sAuth1 , sAuth2 , sSentMail ,
290 sPreprocessing , sSentRcpt , sSentData , sSentDataStub , sData , sSentDot , sStartTls , sSentTlsEhlo , sDone } ;
293 std::string m_thishost ;
298 size_t m_to_accepted ;
299 std::auto_ptr<std::istream> m_content ;
300 bool m_server_has_auth ;
301 bool m_server_has_8bitmime ;
302 bool m_server_has_tls ;
303 bool m_message_is_8bit ;
304 std::string m_message_authentication ;
306 bool m_authenticated_with_server ;
307 std::string m_auth_mechanism ;
308 std::auto_ptr<GAuth::SaslClient> m_sasl ;
309 bool m_must_authenticate ;
310 bool m_must_accept_all_recipients ;
313 unsigned int m_response_timeout ;
314 unsigned int m_ready_timeout ;
315 unsigned int m_preprocessor_timeout ;
void secure()
To be called when the secure socket protocol has been successfully established.
SMTP and message-store classes.
ClientProtocol(Sender &sender, const GAuth::Secrets &secrets, Config config)
Constructor.
Type type() const
Returns the reply type (category).
unsigned int ready_timeout
bool incomplete() const
Returns true if the reply is incomplete.
std::string errorText() const
Returns the text() string but with the guarantee that the returned string is empty if and only if the...
std::list< std::string > Strings
A std::list of std::strings.
virtual void onTimeoutException(std::exception &)
Final override from GNet::AbstractTimer.
bool validFormat() const
Returns true if a valid format.
A structure containing GSmtp::ClientProtocol configuration parameters.
An interface used by ClientProtocol to send protocol messages.
bool is(Value v) const
Returns true if the reply value is 'v'.
G::Signal2< std::string, int > & doneSignal()
Returns a signal that is raised once the protocol has finished with a given message.
Implements the client-side SMTP protocol.
virtual void onTimeout()
Final override from GNet::AbstractTimer.
ClientProtocolReply(const std::string &line=std::string())
Constructor for one line of text.
A simple interface to a store of secrets as used in authentication.
static ClientProtocolReply ok()
Factory function for an ok reply.
std::string textLine(const std::string &prefix) const
Returns a line of text() which starts with prefix.
void sendDone()
To be called when a blocked connection becomes unblocked.
ClientProtocolReply Reply
void start(const std::string &from, const G::Strings &to, bool eight_bit, std::string authentication, std::string server_name, std::auto_ptr< std::istream > content)
Starts transmission of the given message.
unsigned int preprocessor_timeout
int value() const
Returns the numeric value of the reply.
Part of the slot/signal system.
unsigned int response_timeout
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
SubType subType() const
Returns the reply sub-type.
std::string thishost_name
bool apply(const std::string &rx)
Called on receipt of a line of text from the server.
Config(const std::string &, unsigned int, unsigned int, unsigned int, bool, bool, bool)
bool must_accept_all_recipients
bool textContains(std::string s) const
Returns true if the text() contains the given substring.
bool add(const ClientProtocolReply &other)
Adds more lines to this reply.
static ClientProtocolReply error(const std::string &reason)
Factory function for a generalised error reply.
virtual bool protocolSend(const std::string &, size_t offset, bool go_secure)=0
Called by the Protocol class to send network data to the peer.
bool positive() const
Returns true if the numeric value of the reply is less that four hundred.
G::Signal0 & preprocessorSignal()
Returns a signal that is raised when the protocol needs to do message preprocessing.
void preprocessorDone(bool ok, const std::string &reason)
To be called when the Preprocessor interface has done its thing.
A private implementation class used by ClientProtocol.
std::string text() const
Returns the complete text of the reply, excluding the numeric part, and with embedded newlines...
A timer base class that calls a pure virtual method on expiry.