E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gsmtpclient.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // ===
17 ///
18 /// \file gsmtpclient.h
19 ///
20
21 #ifndef G_SMTP_CLIENT_H
22 #define G_SMTP_CLIENT_H
23
24 #include "gdef.h"
25 #include "gsmtp.h"
26 #include "glocation.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 "gfilter.h"
34 #include "gsocket.h"
35 #include "gslot.h"
36 #include "gtimer.h"
37 #include "gstrings.h"
38 #include "gexception.h"
39 #include <memory>
40 #include <iostream>
41
42 namespace GSmtp
43 {
44 class Client ;
45 class ClientProtocol ;
46 }
47
48 /// \class GSmtp::Client
49 /// A class which acts as an SMTP client, extracting messages from a
50 /// message store and forwarding them to a remote SMTP server.
51 ///
52 class GSmtp::Client : public GNet::Client , private ClientProtocol::Sender
53 {
54 public:
55 struct Config /// A structure containing GSmtp::Client configuration parameters.
56 {
57 std::string filter_address ;
58 unsigned int filter_timeout ;
59 bool bind_local_address ;
60 GNet::Address local_address ;
61 ClientProtocol::Config client_protocol_config ;
62 unsigned int connection_timeout ;
63 unsigned int secure_connection_timeout ;
64 bool secure_tunnel ;
65 Config( std::string filter_address , unsigned int filter_timeout ,
66 bool bind_local_address , const GNet::Address & local_address ,
67 const ClientProtocol::Config & protocol_config ,
68 unsigned int connection_timeout , unsigned int secure_connection_timeout ,
69 bool secure_tunnel ) ;
70 } ;
71
72 Client( const GNet::Location & remote , const GAuth::Secrets & secrets , Config config ) ;
73 ///< Constructor. Starts connecting immediately.
74 ///<
75 ///< All Client instances must be on the heap since they
76 ///< delete themselves after raising the done signal.
77 ///<
78 ///< Use sendMessagesFrom() once, or use sendMessage()
79 ///< repeatedly. Wait for a messageDoneSignal() between
80 ///< each sendMessage().
81
82 virtual ~Client() ;
83 ///< Destructor.
84
85 void sendMessagesFrom( MessageStore & store ) ;
86 ///< Sends all messages from the given message store once
87 ///< connected. This must be used immediately after
88 ///< construction with a non-empty message store.
89 ///<
90 ///< Once all messages have been sent the client will delete
91 ///< itself (see GNet::HeapClient).
92 ///<
93 ///< The base class GNet::Client::doneSignal() can be used as
94 ///< an indication that all messages have been sent and the
95 ///< object is about to delete itself. The messageDoneSignal()
96 ///< is not used.
97
98 void sendMessage( unique_ptr<StoredMessage> message ) ;
99 ///< Starts sending the given message. Cannot be called
100 ///< if there is a message already in the pipeline.
101 ///<
102 ///< The messageDoneSignal() is used to indicate that the message
103 ///< filtering has finished or failed.
104 ///<
105 ///< The message is fail()ed if it cannot be sent. If this
106 ///< Client object is deleted before the message is sent
107 ///< the message is neither fail()ed or destroy()ed.
108
109 G::Slot::Signal1<std::string> & messageDoneSignal() ;
110 ///< Returns a signal that indicates that sendMessage()
111 ///< has completed or failed.
112
113 protected:
114 virtual void onConnect() override ;
115 ///< Override from GNet::SimpleClient.
116
117 virtual bool onReceive( const char * , size_t , size_t ) override ;
118 ///< Override from GNet::Client.
119
120 virtual void onDelete( const std::string & ) override ;
121 ///< Override from GNet::HeapClient.
122
123 virtual void onSendComplete() override ;
124 ///< Override from GNet::BufferedClient.
125
126 virtual void onSecure( const std::string & ) override ;
127 ///< Override from GNet::SocketProtocol.
128
129 private:
130 virtual bool protocolSend( const std::string & , size_t , bool ) override ; // override from private base class
131 void protocolDone( int , std::string , std::string ) ; // see ClientProtocol::doneSignal()
132 void filterStart() ;
133 void filterDone( int ) ;
134 bool sendNext() ;
135 void start( StoredMessage & ) ;
136 void messageFail( int = 0 , const std::string & = std::string() ) ;
137 void messageDestroy() ;
138 void doOnConnect() ;
139 void logCertificate( const std::string & ) ;
140
141 private:
142 MessageStore * m_store ;
143 unique_ptr<Filter> m_filter ;
144 unique_ptr<StoredMessage> m_message ;
145 MessageStore::Iterator m_iter ;
146 ClientProtocol m_protocol ;
147 bool m_secure_tunnel ;
148 G::Slot::Signal1<std::string> m_message_done_signal ;
149 unsigned int m_message_count ;
150 } ;
151
152 #endif
GSmtp::Client::onDelete
virtual void onDelete(const std::string &) override
Override from GNet::HeapClient.
Definition: gsmtpclient.cpp:309
gstrings.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
GSmtp::Client::onSecure
virtual void onSecure(const std::string &) override
Override from GNet::SocketProtocol.
Definition: gsmtpclient.cpp:139
GSmtp::Client::sendMessage
void sendMessage(unique_ptr< StoredMessage > message)
Starts sending the given message.
Definition: gsmtpclient.cpp:67
GNet::Address
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:54
gclient.h
GSmtp::Client::messageDoneSignal
G::Slot::Signal1< std::string > & messageDoneSignal()
Returns a signal that indicates that sendMessage() has completed or failed.
Definition: gsmtpclient.cpp:56
GSmtp::StoredMessage
An abstract interface for messages which have come from the store.
Definition: gstoredmessage.h:38
GSmtp::ClientProtocol::Config
A structure containing GSmtp::ClientProtocol configuration parameters.
Definition: gclientprotocol.h:183
gslot.h
GSmtp::Client::onConnect
virtual void onConnect() override
Override from GNet::SimpleClient.
Definition: gsmtpclient.cpp:171
glocation.h
GSmtp::ClientProtocol::Sender
An interface used by ClientProtocol to send protocol messages.
Definition: gclientprotocol.h:164
glinebuffer.h
GSmtp::Client::~Client
virtual ~Client()
Destructor.
Definition: gsmtpclient.cpp:49
GNet::Location
A class that holds a host/service name pair and the preferred address family (if any), and also the results of a name-to-address lookup, ie.
Definition: glocation.h:50
GSmtp::ClientProtocol
Implements the client-side SMTP protocol.
Definition: gclientprotocol.h:156
GSmtp::Client::Client
Client(const GNet::Location &remote, const GAuth::Secrets &secrets, Config config)
Constructor.
Definition: gsmtpclient.cpp:34
gsecrets.h
GSmtp::MessageStore
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:43
GAuth::Secrets
A simple interface for a store of secrets used in authentication.
Definition: gsecrets.h:40
gtimer.h
GSmtp::Client::onReceive
virtual bool onReceive(const char *, size_t, size_t) override
Override from GNet::Client.
Definition: gsmtpclient.cpp:299
GSmtp::Client::onSendComplete
virtual void onSendComplete() override
Override from GNet::BufferedClient.
Definition: gsmtpclient.cpp:320
gmessagestore.h
gsocket.h
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:55
GSmtp::Client
A class which acts as an SMTP client, extracting messages from a message store and forwarding them to...
Definition: gsmtpclient.h:52
gexception.h
GSmtp::Client::sendMessagesFrom
void sendMessagesFrom(MessageStore &store)
Sends all messages from the given message store once connected.
Definition: gsmtpclient.cpp:61
gstoredmessage.h
gfilter.h
gsmtp.h
gclientprotocol.h
G::Slot::Signal1< std::string >
GNet::Client
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
Definition: gclient.h:48
GSmtp::MessageStore::Iterator
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:55