gsmtpclient.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20 
21 #ifndef G_SMTP_CLIENT_H
22 #define G_SMTP_CLIENT_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gsmtp.h"
27 #include "gsecrets.h"
28 #include "glinebuffer.h"
29 #include "gclient.h"
30 #include "gclientprotocol.h"
31 #include "gmessagestore.h"
32 #include "gstoredmessage.h"
33 #include "gprocessor.h"
34 #include "gsocket.h"
35 #include "gslot.h"
36 #include "gtimer.h"
37 #include "gstrings.h"
38 #include "gexecutable.h"
39 #include "gexception.h"
40 #include <memory>
41 #include <iostream>
42 
44 namespace GSmtp
45 {
46  class Client ;
47  class ClientProtocol ;
48 }
49 
56 {
57 public:
58  G_EXCEPTION( NotConnected , "not connected" ) ;
59 
61  struct Config
62  {
63  std::string processor_address ;
64  unsigned int processor_timeout ;
67  unsigned int connection_timeout ;
70  Config( std::string , unsigned int , GNet::Address , ClientProtocol::Config , unsigned int , unsigned int , bool ) ;
71  } ;
72 
73  Client( const GNet::ResolverInfo & remote , const GAuth::Secrets & secrets , Config config ) ;
78 
79  void sendMessagesFrom( MessageStore & store ) ;
90 
91  void sendMessage( std::auto_ptr<StoredMessage> message ) ;
101 
105 
106 protected:
107  virtual ~Client() ;
109 
110  virtual void onConnect() ;
112 
113  virtual bool onReceive( const std::string & ) ;
115 
116  virtual void onDelete( const std::string & , bool ) ;
118 
119  virtual void onSendComplete() ;
121 
122  virtual void onSecure( const std::string & ) ;
124 
125 private:
126  virtual bool protocolSend( const std::string & , size_t , bool ) ; // override from private base class
127  void protocolDone( std::string , int ) ; // see ClientProtocol::doneSignal()
128  void preprocessorStart() ;
129  void preprocessorDone( bool ) ;
130  static const std::string & crlf() ;
131  bool sendNext() ;
132  void start( StoredMessage & ) ;
133  void messageFail( const std::string & , int = 0 ) ;
134  void messageDestroy() ;
135  void doOnConnect() ;
136  void logCertificate( const std::string & ) ;
137 
138 private:
139  MessageStore * m_store ;
140  std::auto_ptr<Processor> m_processor ;
141  std::auto_ptr<StoredMessage> m_message ;
142  MessageStore::Iterator m_iter ;
143  ClientProtocol m_protocol ;
144  bool m_secure_tunnel ;
145  G::Signal1<std::string> m_message_done_signal ;
146 } ;
147 
148 #endif
void sendMessage(std::auto_ptr< StoredMessage > message)
Starts sending the given message.
Definition: gsmtpclient.cpp:74
SMTP and message-store classes.
virtual void onConnect()
Final override from GNet::SimpleClient.
virtual bool onReceive(const std::string &)
Final override from GNet::Client.
std::string processor_address
Definition: gsmtpclient.h:63
ClientProtocol::Config client_protocol_config
Definition: gsmtpclient.h:66
G::Signal1< std::string > & messageDoneSignal()
Returns a signal that indicates that sendMessage() has completed or failed.
Definition: gsmtpclient.cpp:62
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
An abstract class for messages which have come from the store.
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
A structure containing GSmtp::ClientProtocol configuration parameters.
Config(std::string, unsigned int, GNet::Address, ClientProtocol::Config, unsigned int, unsigned int, bool)
An interface used by ClientProtocol to send protocol messages.
unsigned int secure_connection_timeout
Definition: gsmtpclient.h:68
virtual ~Client()
Destructor.
Definition: gsmtpclient.cpp:55
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocol.
Implements the client-side SMTP protocol.
Client(const GNet::ResolverInfo &remote, const GAuth::Secrets &secrets, Config config)
Constructor.
Definition: gsmtpclient.cpp:42
unsigned int processor_timeout
Definition: gsmtpclient.h:64
A class which allows SMTP messages (envelope+content) to be stored and retrieved. ...
Definition: gmessagestore.h:45
A simple interface to a store of secrets as used in authentication.
Definition: gsecrets.h:44
unsigned int connection_timeout
Definition: gsmtpclient.h:67
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
A class which acts as an SMTP client, extracting messages from a message store and forwarding them to...
Definition: gsmtpclient.h:55
virtual void onDelete(const std::string &, bool)
Final override from GNet::HeapClient.
virtual void onSendComplete()
Final override from GNet::BufferedClient.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
void sendMessagesFrom(MessageStore &store)
Sends all messages from the given message store once connected.
Definition: gsmtpclient.cpp:67
GNet::Address local_address
Definition: gsmtpclient.h:65
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
Definition: gclient.h:51
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:62