E-MailRelay
gmxfilter.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 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 "gstringview.h"
30#include "gtimer.h"
31#include "geventstate.h"
32#include <utility>
33#include <memory>
34
35namespace GFilters
36{
37 class MxFilter ;
38}
39
40//| \class GFilters::MxFilter
41/// A concrete GSmtp::Filter class for message routing: if the
42/// message's 'forward-to' envelope field is set then the
43/// 'forward-to-address' field is populated with the result of
44/// a MX lookup. Does nothing if run as a client filter because
45/// by then it will have already run as a routing filter.
46///
48{
49public:
51 Filter::Type , const Filter::Config & , const std::string & spec ) ;
52 ///< Constructor.
53
54 ~MxFilter() override ;
55 ///< Destructor.
56
57public:
58 MxFilter( const MxFilter & ) = delete ;
59 MxFilter & operator=( const MxFilter & ) = delete ;
60 MxFilter( MxFilter && ) = delete ;
61 MxFilter & operator=( MxFilter && ) = delete ;
62
63private: // overrides
64 std::string id() const override ; // GSmtp::Filter
65 bool quiet() const override ; // GSmtp::Filter
66 G::Slot::Signal<int> & doneSignal() noexcept override ; // GSmtp::Filter
67 void start( const GStore::MessageId & ) override ; // GSmtp::Filter
68 void cancel() override ; // GSmtp::Filter
69 Result result() const override ; // GSmtp::Filter
70 std::string response() const override ; // GSmtp::Filter
71 int responseCode() const override ; // GSmtp::Filter
72 std::string reason() const override ; // GSmtp::Filter
73 bool special() const override ; // GSmtp::Filter
74
75private:
76 void onTimeout() ;
77 void lookupDone( GStore::MessageId , std::string , std::string ) ;
78 GStore::FileStore::State storestate() const ;
79 std::string prefix() const ;
80 static MxLookup::Config parseSpec( std::string_view , std::vector<GNet::Address> & ) ;
81 struct ParserResult
82 {
83 std::string domain ;
84 unsigned int port ;
85 std::string address ;
86 } ;
87 static ParserResult parseForwardTo( const std::string & ) ;
88 static std::string addressLiteral( std::string_view s , unsigned int port = 0U ) ;
89
90private:
92 GNet::EventState m_es ;
93 GStore::FileStore & m_store ;
94 Filter::Type m_filter_type ;
95 Filter::Config m_filter_config ;
96 std::string m_spec ;
97 MxLookup::Config m_mxlookup_config ;
98 std::vector<GNet::Address> m_mxlookup_nameservers ;
99 std::string m_id ;
100 Result m_result {Result::fail} ;
101 bool m_special {false} ;
102 GNet::Timer<MxFilter> m_timer ;
103 G::Slot::Signal<int> m_done_signal ;
104 std::unique_ptr<MxLookup> m_lookup ;
105} ;
106
107#endif
A concrete GSmtp::Filter class for message routing: if the message's 'forward-to' envelope field is s...
Definition: gmxfilter.h:48
~MxFilter() override
Destructor.
Definition: gmxfilter.cpp:50
MxFilter(GNet::EventState es, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &spec)
Constructor.
Definition: gmxfilter.cpp:34
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
Definition: geventstate.h:131
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:53
Low-level file-system operations for GStore::FileStore.
Definition: gfilestore.h:76