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