- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
55 class GSmtp::Client : public GNet::Client , private GSmtp::ClientProtocol::Sender
56 {
57 public:
58 G_EXCEPTION( NotConnected , "not connected" ) ;
59
61 struct Config
62 {
63 std::string processor_address ;
64 unsigned int processor_timeout ;
65 GNet::Address local_address ;
66 ClientProtocol::Config client_protocol_config ;
67 unsigned int connection_timeout ;
68 unsigned int secure_connection_timeout ;
69 bool secure_tunnel ;
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
102 G::Signal1<std::string> & messageDoneSignal() ;
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
GSmtp::Client::sendMessage
void sendMessage(std::auto_ptr< StoredMessage > message)
Starts sending the given message.
Definition: gsmtpclient.cpp:74
gstrings.h
GSmtp
SMTP and message-store classes.
GSmtp::Client::onConnect
virtual void onConnect()
Final override from GNet::SimpleClient.
Definition: gsmtpclient.cpp:152
GSmtp::Client::onReceive
virtual bool onReceive(const std::string &)
Final override from GNet::Client.
Definition: gsmtpclient.cpp:264
GSmtp::Client::Config::processor_address
std::string processor_address
Definition: gsmtpclient.h:63
GSmtp::Client::Config::client_protocol_config
ClientProtocol::Config client_protocol_config
Definition: gsmtpclient.h:66
GSmtp::Client::messageDoneSignal
G::Signal1< std::string > & messageDoneSignal()
Returns a signal that indicates that sendMessage() has completed or failed.
Definition: gsmtpclient.cpp:62
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
gclient.h
GSmtp::StoredMessage
An abstract class for messages which have come from the store.
Definition: gstoredmessage.h:40
GNet::ResolverInfo
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
GSmtp::ClientProtocol::Config
A structure containing GSmtp::ClientProtocol configuration parameters.
Definition: gclientprotocol.h:193
G::Signal1< std::string >
GSmtp::Client::Config::Config
Config(std::string, unsigned int, GNet::Address, ClientProtocol::Config, unsigned int, unsigned int, bool)
Definition: gsmtpclient.cpp:289
gslot.h
gexecutable.h
GSmtp::ClientProtocol::Sender
An interface used by ClientProtocol to send protocol messages.
Definition: gclientprotocol.h:173
glinebuffer.h
GSmtp::Client::Config::secure_connection_timeout
unsigned int secure_connection_timeout
Definition: gsmtpclient.h:68
GSmtp::Client::~Client
virtual ~Client()
Destructor.
Definition: gsmtpclient.cpp:55
GSmtp::Client::onSecure
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocol.
Definition: gsmtpclient.cpp:121
GSmtp::ClientProtocol
Implements the client-side SMTP protocol.
Definition: gclientprotocol.h:160
GSmtp::Client::Client
Client(const GNet::ResolverInfo &remote, const GAuth::Secrets &secrets, Config config)
Constructor.
Definition: gsmtpclient.cpp:42
GSmtp::Client::Config::processor_timeout
unsigned int processor_timeout
Definition: gsmtpclient.h:64
gsecrets.h
GSmtp::MessageStore
A class which allows SMTP messages (envelope+content) to be stored and retrieved. ...
Definition: gmessagestore.h:45
GAuth::Secrets
A simple interface to a store of secrets as used in authentication.
Definition: gsecrets.h:44
GSmtp::Client::Config::connection_timeout
unsigned int connection_timeout
Definition: gsmtpclient.h:67
gtimer.h
gmessagestore.h
gsocket.h
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
GSmtp::Client
A class which acts as an SMTP client, extracting messages from a message store and forwarding them to...
Definition: gsmtpclient.h:55
GSmtp::Client::onDelete
virtual void onDelete(const std::string &, bool)
Final override from GNet::HeapClient.
Definition: gsmtpclient.cpp:271
gexception.h
GSmtp::Client::Config::secure_tunnel
bool secure_tunnel
Definition: gsmtpclient.h:69
GSmtp::Client::onSendComplete
virtual void onSendComplete()
Final override from GNet::BufferedClient.
Definition: gsmtpclient.cpp:282
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
GSmtp::Client::sendMessagesFrom
void sendMessagesFrom(MessageStore &store)
Sends all messages from the given message store once connected.
Definition: gsmtpclient.cpp:67
gstoredmessage.h
gprocessor.h
gsmtp.h
gclientprotocol.h
GSmtp::Client::Config::local_address
GNet::Address local_address
Definition: gsmtpclient.h:65
GNet::Client
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
Definition: gclient.h:51
GSmtp::MessageStore::Iterator
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:62