E-MailRelay

gdeliveryfilter.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 gdeliveryfilter.cpp
19///
20
21#include "gdef.h"
22#include "gdeliveryfilter.h"
23#include "gfiledelivery.h"
24#include "gstringtoken.h"
25#include "glog.h"
26
27 GFilters::DeliveryFilter::DeliveryFilter( GNet::EventState es , GStore::FileStore & store ,
28 Filter::Type filter_type , const Filter::Config & filter_config , const std::string & spec ) :
29 SimpleFilterBase(es,filter_type,"deliver:") ,
30 m_store(store) ,
31 m_filter_type(filter_type) ,
32 m_filter_config(filter_config) ,
33 m_spec(spec)
34{
35}
36
37GSmtp::Filter::Result GFilters::DeliveryFilter::run( const GStore::MessageId & message_id ,
38 bool & , GStore::FileStore::State )
39{
40 GStore::FileDelivery::Config config ;
41 std::string_view spec = m_spec ;
42 for( G::StringTokenView t( spec , ";" , 1U ) ; t ; ++t )
43 {
44 if( t() == "h" || t() == "hardlink" ) config.hardlink = true ;
45 if( t() == "n" || t() == "no_delete" || t() == "nodelete" ) config.no_delete = true ;
46 if( t() == "p" || t() == "pop" ) config.pop_by_name = true ;
47 }
48
49 GStore::FileDelivery delivery_imp( m_store , config ) ;
50 GStore::MessageDelivery & delivery = delivery_imp ;
51 bool removed = delivery.deliver( message_id , m_filter_type == Filter::Type::server ) ;
52
53 return removed ? Result::abandon : Result::ok ;
54}
55
GFilters::DeliveryFilter::DeliveryFilter
DeliveryFilter(GNet::EventState es, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &spec)
Constructor.
Definition: gdeliveryfilter.cpp:27
GFilters::SimpleFilterBase
A GSmtp::Filter base class for filters that run synchronously.
Definition: gsimplefilterbase.h:43
GNet::EventState
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
Definition: geventstate.h:131
GStore::FileDelivery
An implementation of the MessageDelivery interface that delivers message files to mailboxes.
Definition: gfiledelivery.h:50
GStore::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:56
GStore::MessageDelivery
An interface to deliver a message to its local recipients' mailboxes.
Definition: gmessagedelivery.h:52
GStore::MessageDelivery::deliver
virtual bool deliver(const MessageId &, bool is_new)=0
Delivers a new or locked message to its local recipients' mailboxes.
GStore::MessageId
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
G::StringTokenT
A zero-copy string token iterator where the token separators are runs of whitespace characters,...
Definition: gstringtoken.h:54
gdeliveryfilter.h
gfiledelivery.h
glog.h
gstringtoken.h
GStore::FileDelivery::Config
A configuration structure for GStore::FileDelivery.
Definition: gfiledelivery.h:58