21 #ifndef G_SMTP_CLIENT_PROTOCOL_H
22 #define G_SMTP_CLIENT_PROTOCOL_H
38 class ClientProtocol ;
39 class ClientProtocolReply ;
51 PositivePreliminary = 1 ,
52 PositiveCompletion = 2 ,
53 PositiveIntermediate = 3 ,
54 TransientNegative = 4 ,
67 Internal_filter_ok = 222 ,
68 Internal_filter_abandon = 223 ,
69 Internal_secure = 224 ,
70 ServiceReady_220 = 220 ,
72 Authenticated_235 = 235 ,
75 SyntaxError_500 = 500 ,
76 SyntaxError_501 = 501 ,
77 NotImplemented_502 = 502 ,
78 BadSequence_503 = 503 ,
79 Internal_filter_error = 590 ,
80 NotAuthenticated_535 = 535 ,
81 NotAvailable_454 = 454 ,
111 bool is( Value v )
const ;
117 std::string
text()
const ;
132 std::string
textLine(
const std::string & prefix )
const ;
143 static bool is_digit(
char ) ;
150 std::string m_reason ;
159 G_EXCEPTION( NotReady ,
"not ready" ) ;
160 G_EXCEPTION( SmtpError ,
"smtp error" ) ;
161 G_EXCEPTION( TlsError ,
"tls/ssl error" ) ;
166 public:
virtual bool protocolSend(
const std::string & ,
size_t offset ,
bool go_secure ) = 0 ;
179 private:
void operator=(
const Sender & ) ;
180 public:
virtual ~
Sender() ;
185 std::string thishost_name ;
186 unsigned int response_timeout ;
187 unsigned int ready_timeout ;
188 unsigned int filter_timeout ;
189 bool use_starttls_if_possible ;
191 bool must_authenticate ;
193 bool must_accept_all_recipients ;
194 bool eight_bit_strict ;
195 Config(
const std::string & name ,
unsigned int response_timeout ,
196 unsigned int ready_timeout ,
unsigned int filter_timeout ,
197 bool use_starttls_if_possible ,
bool must_use_tls ,
198 bool must_authenticate ,
bool anonymous ,
199 bool must_accept_all_recipients ,
bool eight_bit_strict ) ;
221 std::string mail_from_auth , unique_ptr<std::istream> content ) ;
235 void filterDone(
bool ok ,
const std::string & response ,
const std::string & reason ) ;
245 bool apply(
const std::string & rx ) ;
255 struct AuthError :
public SmtpError
258 std::string str()
const ;
262 void send(
const char * ) ;
263 void send(
const char * ,
const std::string & ) ;
264 void send(
const char * ,
const std::string & ,
const char * ) ;
265 bool send(
const std::string & ,
bool eot ,
bool sensitive =
false ) ;
266 bool sendLine( std::string & ) ;
271 void sendMailCore() ;
272 bool endOfContent()
const ;
273 bool applyEvent(
const Reply & event ,
bool is_start_event =
false ) ;
274 static bool parseReply( Reply & ,
const std::string & , std::string & ) ;
275 void raiseDoneSignal(
int ,
const std::string & ,
const std::string & = std::string() ) ;
278 void startFiltering() ;
305 std::string m_thishost ;
310 size_t m_to_accepted ;
311 unique_ptr<std::istream> m_content ;
312 bool m_server_has_starttls ;
313 bool m_server_has_auth ;
315 bool m_server_secure ;
316 bool m_server_has_8bitmime ;
317 bool m_message_is_8bit ;
318 std::string m_message_mail_from_auth ;
320 bool m_authenticated_with_server ;
321 std::string m_auth_mechanism ;
322 unique_ptr<GAuth::SaslClient> m_sasl ;
323 bool m_must_authenticate ;
325 bool m_must_accept_all_recipients ;
326 bool m_use_starttls_if_possible ;
327 bool m_must_use_tls ;
328 bool m_in_secure_tunnel ;
331 unsigned int m_response_timeout ;
332 unsigned int m_ready_timeout ;
333 unsigned int m_filter_timeout ;
void secure()
To be called when the secure socket protocol has been successfully established.
SMTP and message-store classes.
Type type() const
Returns the reply type (category).
static ClientProtocolReply error(Value, const std::string &response, const std::string &error_reason)
Factory function for an error reply with a specific 5xx value.
bool incomplete() const
Returns true if the reply is incomplete.
std::string errorText() const
Returns the text() string, plus any error reason, but with the guarantee that the returned string is ...
ClientProtocol(GNet::ExceptionHandler &, Sender &sender, const GAuth::Secrets &secrets, Config config, bool in_secure_tunnel)
Constructor.
G::Slot::Signal0 & filterSignal()
Returns a signal that is raised when the protocol needs to do message filtering.
bool validFormat() const
Returns true if a valid format.
std::vector< std::string > StringArray
A std::vector of std::strings.
G::Slot::Signal3< int, std::string, std::string > & doneSignal()
Returns a signal that is raised once the protocol has finished with a given message.
virtual void onTimeout() override
Override from GNet::TimerBase.
A structure containing GSmtp::ClientProtocol configuration parameters.
An interface used by ClientProtocol to send protocol messages.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
bool is(Value v) const
Returns true if the reply value is 'v'.
Implements the client-side SMTP protocol.
void filterDone(bool ok, const std::string &response, const std::string &reason)
To be called when the Filter interface has done its thing.
void finish()
Called after the last message has been sent.
ClientProtocolReply(const std::string &line=std::string())
Constructor for one line of text.
A simple interface for a store of secrets 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.
std::string errorReason() const
Returns an error reason string, as passed to error().
int value() const
Returns the numeric value of the reply.
A signal class for zero-parameter callbacks.
SubType subType() const
Returns the reply sub-type.
void start(const std::string &from, const G::StringArray &to, bool eight_bit, std::string mail_from_auth, unique_ptr< std::istream > content)
Starts transmission of the given message.
bool apply(const std::string &rx)
Called on receipt of a line of text from the server.
A class that implements the client-side SASL challenge/response concept.
An interface used by GNet::TimerList to keep track of pending timeouts and to deliver timeout events...
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.
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.
A private implementation class used by ClientProtocol.
std::string text() const
Returns the text of the reply, excluding the numeric part, and with embedded newlines.