E-MailRelay
gprotocolmessageforward.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 gprotocolmessageforward.h
19 ///
20 
21 #ifndef G_SMTP_PROTOCOL_MESSAGE_FORWARD_H
22 #define G_SMTP_PROTOCOL_MESSAGE_FORWARD_H
23 
24 #include "gdef.h"
25 #include "gsmtp.h"
26 #include "glocation.h"
27 #include "gclientptr.h"
28 #include "gprotocolmessage.h"
29 #include "gprotocolmessagestore.h"
30 #include "gsecrets.h"
31 #include "gsmtpclient.h"
32 #include "gmessagestore.h"
33 #include "gnewmessage.h"
34 #include "gverifierstatus.h"
35 #include <string>
36 #include <memory>
37 
38 namespace GSmtp
39 {
40  class ProtocolMessageForward ;
41 }
42 
43 /// \class GSmtp::ProtocolMessageForward
44 /// A concrete implementation of the ProtocolMessage interface that stores
45 /// incoming messages in the message store and then immediately forwards
46 /// them on to the downstream server.
47 ///
48 /// The implementation delegates to an instance of the ProtocolMessageStore
49 /// class (ie. its sibling class) to do the storage, and to an instance
50 /// of the GSmtp::Client class to do the forwarding.
51 ///
52 /// \see GSmtp::ProtocolMessageStore
53 ///
55 {
56 public:
58  unique_ptr<ProtocolMessage> pm ,
59  const GSmtp::Client::Config & client_config ,
60  const GAuth::Secrets & client_secrets ,
61  const std::string & remote_server_address ) ;
62  ///< Constructor. The 'store' and 'client-secrets' references
63  ///< are kept.
64 
65  virtual ~ProtocolMessageForward() ;
66  ///< Destructor.
67 
69  ///< Override from GSmtp::ProtocolMessage.
70 
71  virtual void reset() override ;
72  ///< Override from GSmtp::ProtocolMessage.
73 
74  virtual void clear() override ;
75  ///< Override from GSmtp::ProtocolMessage.
76 
77  virtual bool setFrom( const std::string & from_user , const std::string & ) override ;
78  ///< Override from GSmtp::ProtocolMessage.
79 
80  virtual bool addTo( const std::string & to_user , VerifierStatus to_status ) override ;
81  ///< Override from GSmtp::ProtocolMessage.
82 
83  virtual void addReceived( const std::string & ) override ;
84  ///< Override from GSmtp::ProtocolMessage.
85 
86  virtual bool addText( const char * , size_t ) override ;
87  ///< Override from GSmtp::ProtocolMessage.
88 
89  virtual std::string from() const override ;
90  ///< Override from GSmtp::ProtocolMessage.
91 
92  virtual void process( const std::string & auth_id, const std::string & peer_socket_address ,
93  const std::string & peer_certificate ) override ;
94  ///< Override from GSmtp::ProtocolMessage.
95 
96 protected:
98  ///< Returns the signal which is used to signal that the storage
99  ///< is complete. Derived classes can use this to
100  ///< intercept the storage-done signal emit()ed by
101  ///< the ProtocolMessageStore object.
102 
103  void processDone( bool , unsigned long , std::string , std::string ) ;
104  ///< Called by derived classes that have intercepted
105  ///< the storageDoneSignal() when their own post-storage
106  ///< processing is complete.
107 
108 private:
109  void operator=( const ProtocolMessageForward & ) ; // not implemented
110  void clientDone( std::string ) ; // GNet::Client::doneSignal()
111  void messageDone( std::string ) ; // GSmtp::Client::messageDoneSignal()
112  std::string forward( unsigned long , bool & ) ;
113 
114 private:
115  MessageStore & m_store ;
116  GNet::Location m_client_location ;
117  Client::Config m_client_config ;
118  const GAuth::Secrets & m_client_secrets ;
119  unique_ptr<ProtocolMessage> m_pm ;
121  unsigned long m_id ;
123 } ;
124 
125 #endif
ProtocolMessageForward(MessageStore &store, unique_ptr< ProtocolMessage > pm, const GSmtp::Client::Config &client_config, const GAuth::Secrets &client_secrets, const std::string &remote_server_address)
Constructor.
SMTP and message-store classes.
Definition: gadminserver.h:39
A concrete implementation of the ProtocolMessage interface that stores incoming messages in the messa...
G::Slot::Signal4< bool, unsigned long, std::string, std::string > & storageDoneSignal()
Returns the signal which is used to signal that the storage is complete.
void processDone(bool, unsigned long, std::string, std::string)
Called by derived classes that have intercepted the storageDoneSignal() when their own post-storage p...
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
virtual bool addTo(const std::string &to_user, VerifierStatus to_status) override
Override from GSmtp::ProtocolMessage.
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:43
A simple interface for a store of secrets used in authentication.
Definition: gsecrets.h:40
virtual std::string from() const override
Override from GSmtp::ProtocolMessage.
virtual void process(const std::string &auth_id, const std::string &peer_socket_address, const std::string &peer_certificate) override
Override from GSmtp::ProtocolMessage.
virtual bool setFrom(const std::string &from_user, const std::string &) override
Override from GSmtp::ProtocolMessage.
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:55
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' recipient.
An interface used by the ServerProtocol class to assemble and process an incoming message...
virtual void reset() override
Override from GSmtp::ProtocolMessage.
A smart pointer class for GNet::HeapClient that keeps track of when the contained instance deletes it...
Definition: gclientptr.h:33
virtual bool addText(const char *, size_t) override
Override from GSmtp::ProtocolMessage.
virtual void addReceived(const std::string &) override
Override from GSmtp::ProtocolMessage.
virtual G::Slot::Signal4< bool, unsigned long, std::string, std::string > & doneSignal() override
Override from GSmtp::ProtocolMessage.
virtual void clear() override
Override from GSmtp::ProtocolMessage.
virtual ~ProtocolMessageForward()
Destructor.