E-MailRelay
gmxfilter.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2023 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 gmxfilter.h
19///
20
21#ifndef G_MX_FILTER_H
22#define G_MX_FILTER_H
23
24#include "gdef.h"
25#include "gfilter.h"
26#include "gmxlookup.h"
27#include "gfilestore.h"
28#include "gstoredfile.h"
29#include "gtimer.h"
30#include "gexceptionsink.h"
31#include <utility>
32
33namespace GFilters
34{
35 class MxFilter ;
36}
37
38//| \class GFilters::MxFilter
39/// A concrete GSmtp::Filter class for message routing: if the
40/// message's 'forward-to' field is set then the 'forward-to-address'
41/// envelope field is populated with the result of a MX lookup.
42/// Does nothing if run as a client filter because by then it
43/// will have already run as a routing filter.
44///
46{
47public:
49 Filter::Type , const Filter::Config & , const std::string & spec ) ;
50 ///< Constructor.
51
52 ~MxFilter() override ;
53 ///< Destructor.
54
55public:
56 MxFilter( const MxFilter & ) = delete ;
57 MxFilter & operator=( const MxFilter & ) = delete ;
58 MxFilter( MxFilter && ) = delete ;
59 MxFilter & operator=( MxFilter && ) = delete ;
60
61private: // overrides
62 std::string id() const override ; // GSmtp::Filter
63 bool quiet() const override ; // GSmtp::Filter
64 G::Slot::Signal<int> & doneSignal() noexcept override ; // GSmtp::Filter
65 void start( const GStore::MessageId & ) override ; // GSmtp::Filter
66 void cancel() override ; // GSmtp::Filter
67 Result result() const override ; // GSmtp::Filter
68 std::string response() const override ; // GSmtp::Filter
69 int responseCode() const override ; // GSmtp::Filter
70 std::string reason() const override ; // GSmtp::Filter
71 bool special() const override ; // GSmtp::Filter
72
73private:
74 void onTimeout() ;
75 void lookupDone( GStore::MessageId , std::string , std::string ) ;
76 GStore::FileStore::State storestate() const ;
77 std::string prefix() const ;
78 static MxLookup::Config mxconfig( const std::string & spec ) ;
79 static std::vector<GNet::Address> mxnameservers( const std::string & spec ) ;
80 static std::string parseForwardToDomain( const std::string & ) ;
81 static unsigned int parseForwardToPort( const std::string & ) ;
82 static std::pair<std::string,unsigned int> parseForwardTo( const std::string & ) ;
83
84private:
87 GStore::FileStore & m_store ;
88 Filter::Type m_filter_type ;
89 Filter::Config m_filter_config ;
90 std::string m_spec ;
91 std::string m_id ;
92 Result m_result ;
93 bool m_special ;
94 GNet::Timer<MxFilter> m_timer ;
95 G::Slot::Signal<int> m_done_signal ;
96 std::unique_ptr<MxLookup> m_lookup ;
97} ;
98
99#endif
A concrete GSmtp::Filter class for message routing: if the message's 'forward-to' field is set then t...
Definition: gmxfilter.h:46
~MxFilter() override
Destructor.
Definition: gmxfilter.cpp:48
MxFilter(GNet::ExceptionSink es, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &spec)
Constructor.
Definition: gmxfilter.cpp:32
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A timer class template in which the timeout is delivered to the specified method.
Definition: gtimer.h:141
An interface for processing a message file through a filter.
Definition: gfilter.h:51
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:56
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
Message filter classes.
Definition: gcopyfilter.h:31
A configuration structure for GFilters::MxLookup.
Definition: gmxlookup.h:52
Low-level file-system operations for GStore::FileStore.
Definition: gfilestore.h:76