E-MailRelay
gprotocolmessageforward.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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 "glocation.h"
26#include "gclientptr.h"
27#include "gprotocolmessage.h"
29#include "gsecrets.h"
30#include "gsmtpclient.h"
31#include "gmessagestore.h"
32#include "gnewmessage.h"
33#include "gverifierstatus.h"
34#include "gfilterfactory.h"
35#include "gcall.h"
36#include <string>
37#include <memory>
38
39namespace GSmtp
40{
41 class ProtocolMessageForward ;
42}
43
44//| \class GSmtp::ProtocolMessageForward
45/// A concrete implementation of the ProtocolMessage interface that stores
46/// incoming messages in the message store and then immediately forwards
47/// them on to the downstream server.
48///
49/// The implementation delegates to an instance of the ProtocolMessageStore
50/// class (ie. its sibling class) to do the storage, and to an instance
51/// of the GSmtp::Client class to do the forwarding.
52///
53/// \see GSmtp::ProtocolMessageStore
54///
56{
57public:
59 std::unique_ptr<ProtocolMessage> pm ,
60 const GSmtp::Client::Config & client_config ,
61 const GAuth::SaslClientSecrets & client_secrets ,
62 const std::string & remote_server_address ) ;
63 ///< Constructor. The 'store' and 'client-secrets' references
64 ///< are kept.
65
66 ~ProtocolMessageForward() override ;
67 ///< Destructor.
68
69protected:
71 ///< Returns the signal which is used to signal that the storage
72 ///< is complete. Derived classes can use this to
73 ///< intercept the storage-done signal emit()ed by
74 ///< the ProtocolMessageStore object.
75
76 void processDone( bool , const MessageId & , const std::string & , const std::string & ) ;
77 ///< Called by derived classes that have intercepted
78 ///< the storageDoneSignal() when their own post-storage
79 ///< processing is complete.
80
81private: // overrides
82 ProtocolMessage::DoneSignal & doneSignal() override ; // Override from GSmtp::ProtocolMessage.
83 void reset() override ; // Override from GSmtp::ProtocolMessage.
84 void clear() override ; // Override from GSmtp::ProtocolMessage.
85 MessageId setFrom( const std::string & from_user , const std::string & ) override ; // Override from GSmtp::ProtocolMessage.
86 bool addTo( VerifierStatus to_status ) override ; // Override from GSmtp::ProtocolMessage.
87 void addReceived( const std::string & ) override ; // Override from GSmtp::ProtocolMessage.
88 bool addText( const char * , std::size_t ) override ; // Override from GSmtp::ProtocolMessage.
89 std::string from() const override ; // Override from GSmtp::ProtocolMessage.
90 void process( const std::string & auth_id, const std::string & peer_socket_address ,
91 const std::string & peer_certificate ) override ; // Override from GSmtp::ProtocolMessage.
92
93public:
96 void operator=( const ProtocolMessageForward & ) = delete ;
97 void operator=( ProtocolMessageForward && ) = delete ;
98
99private:
100 void clientDone( const std::string & ) ; // GNet::Client::doneSignal()
101 void messageDone( const std::string & ) ; // GSmtp::Client::messageDoneSignal()
102 std::string forward( const MessageId & , bool & ) ;
103
104private:
106 MessageStore & m_store ;
107 FilterFactory & m_ff ;
108 G::CallStack m_call_stack ;
109 GNet::Location m_client_location ;
110 Client::Config m_client_config ;
111 const GAuth::SaslClientSecrets & m_client_secrets ;
112 std::unique_ptr<ProtocolMessage> m_pm ;
113 GNet::ClientPtr<GSmtp::Client> m_client_ptr ;
114 MessageId m_id ;
115 ProtocolMessage::DoneSignal m_done_signal ;
116} ;
117
118#endif
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A class that represents the remote target for out-going client connections.
Definition: glocation.h:71
A factory interface for GSmtp::Filter message processors.
A somewhat opaque identifer for a MessageStore message.
Definition: gmessagestore.h:43
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:73
A concrete implementation of the ProtocolMessage interface that stores incoming messages in the messa...
void processDone(bool, const MessageId &, const std::string &, const std::string &)
Called by derived classes that have intercepted the storageDoneSignal() when their own post-storage p...
ProtocolMessageForward(GNet::ExceptionSink, MessageStore &store, FilterFactory &, std::unique_ptr< ProtocolMessage > pm, const GSmtp::Client::Config &client_config, const GAuth::SaslClientSecrets &client_secrets, const std::string &remote_server_address)
Constructor.
~ProtocolMessageForward() override
Destructor.
ProtocolMessage::DoneSignal & storageDoneSignal()
Returns the signal which is used to signal that the storage is complete.
An interface used by the ServerProtocol class to assemble and process an incoming message.
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' or 'vrfy' recipient.
A linked list of CallFrame pointers.
Definition: gcall.h:58
SMTP and message-store classes.
Definition: gadminserver.h:39
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:57