E-MailRelay
gsimplefilterbase.cpp
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 gsimplefilterbase.cpp
19///
20
21#include "gdef.h"
22#include "gsimplefilterbase.h"
23#include "gfilestore.h"
24
26 Filter::Type filter_type , G::string_view id ) :
27 m_filter_type(filter_type) ,
28 m_id(G::sv_to_string(id)) ,
29 m_timer(*this,&SimpleFilterBase::onTimeout,es) ,
30 m_result(Result::fail) ,
31 m_special(false)
32{
33}
34
35std::string GFilters::SimpleFilterBase::id() const
36{
37 return m_id ;
38}
39
40bool GFilters::SimpleFilterBase::quiet() const
41{
42 return false ;
43}
44
45void GFilters::SimpleFilterBase::start( const GStore::MessageId & message_id )
46{
47 GStore::FileStore::State e_state =
48 m_filter_type == GSmtp::Filter::Type::server ?
49 GStore::FileStore::State::New :
50 GStore::FileStore::State::Locked ;
51
52 m_special = false ;
53 m_result = run( message_id , m_special , e_state ) ;
54 m_timer.startTimer( 0U ) ;
55}
56
57G::Slot::Signal<int> & GFilters::SimpleFilterBase::doneSignal() noexcept
58{
59 return m_done_signal ;
60}
61
62void GFilters::SimpleFilterBase::cancel()
63{
64 m_timer.cancelTimer() ;
65}
66
67GSmtp::Filter::Result GFilters::SimpleFilterBase::result() const
68{
69 return m_result ;
70}
71
72std::string GFilters::SimpleFilterBase::response() const
73{
74 return std::string( m_result == Result::fail ? "failed" : "" ) ;
75}
76
77int GFilters::SimpleFilterBase::responseCode() const
78{
79 return 0 ;
80}
81
82std::string GFilters::SimpleFilterBase::reason() const
83{
84 return response() ;
85}
86
87bool GFilters::SimpleFilterBase::special() const
88{
89 return m_special ;
90}
91
92void GFilters::SimpleFilterBase::onTimeout()
93{
94 m_done_signal.emit( static_cast<int>(m_result) ) ;
95}
96
98{
99 return G::sv_to_string(strtype(m_filter_type)).append(" [").append(id()).append(1U,']') ;
100}
101
A GSmtp::Filter base class for filters that run synchronously.
SimpleFilterBase(GNet::ExceptionSink, Filter::Type, G::string_view id)
Constructor.
std::string prefix() const
Returns a logging prefix derived from Filter::Type and filter id.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
A class like c++17's std::string_view.
Definition: gstringview.h:51
Low-level classes.
Definition: garg.h:30