42 m_file_store(file_store)
53 result =
Spec(
"exit" ,
"0" ) ;
55 else if( spec_in.find(
',') != std::string::npos )
57 result =
Spec(
"chain" ,
"" ) ;
59 result += parse( t() , base_dir , app_dir , warnings_p ) ;
63 result =
Spec(
"exit" , tail ) ;
64 checkNumber( result ) ;
68 result =
Spec(
"sleep" , tail ) ;
69 checkNumber( result ) ;
73 result =
Spec(
"net" , tail ) ;
78 result =
Spec(
"spam" , tail ) ;
83 result =
Spec(
"spam-edit" , tail ) ;
88 result =
Spec(
"deliver" , tail ) ;
89 checkRange( result ) ;
93 result =
Spec(
"copy" , tail ) ;
97 result =
Spec(
"split" , tail ) ;
101 result =
Spec(
"mx" , tail ) ;
105 result =
Spec(
"msgid" , tail ) ;
109 result =
Spec(
"file" , tail ) ;
110 fixFile( result , base_dir , app_dir ) ;
111 checkFile( result , warnings_p ) ;
115 result =
Spec(
"file" , spec_in ) ;
116 fixFile( result , base_dir , app_dir ) ;
117 checkFile( result , warnings_p ) ;
126 if( spec.first ==
"chain" )
129 return std::make_unique<FilterChain>( es , *
this , filter_type , filter_config , spec ) ;
131 else if( spec.first ==
"spam" )
134 return std::make_unique<SpamFilter>( es , m_file_store , filter_type , filter_config , spec.second ,
true ,
false ) ;
136 else if( spec.first ==
"spam-edit" )
139 return std::make_unique<SpamFilter>( es , m_file_store , filter_type , filter_config , spec.second ,
false ,
true ) ;
141 else if( spec.first ==
"net" )
143 return std::make_unique<NetworkFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
145 else if( spec.first ==
"exit" )
147 return std::make_unique<NullFilter>( es , m_file_store , filter_type , filter_config ,
G::Str::toUInt(spec.second) ) ;
149 else if( spec.first ==
"sleep" )
153 else if( spec.first ==
"file" )
155 return std::make_unique<ExecutableFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
157 else if( spec.first ==
"deliver" )
159 return std::make_unique<DeliveryFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
161 else if( spec.first ==
"copy" )
163 return std::make_unique<CopyFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
165 else if( spec.first ==
"split" )
167 return std::make_unique<SplitFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
169 else if( spec.first ==
"mx" )
171 return std::make_unique<MxFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
173 else if( spec.first ==
"msgid" )
175 return std::make_unique<MessageIdFilter>( es , m_file_store , filter_type , filter_config , spec.second ) ;
183void GFilters::FilterFactory::checkNumber( Spec & result )
185 if( result.second.empty() )
187 result.first.clear() ;
188 result.second =
"numeric value missing" ;
192 result.first.clear() ;
195 else if(
G::Str::toUInt(result.second) >= (std::numeric_limits<unsigned>::max()/1000U) )
197 result.first.clear() ;
202void GFilters::FilterFactory::checkNet( Spec & result )
208 catch( std::exception & e )
210 result.first.clear() ;
211 result.second = e.what() ;
215void GFilters::FilterFactory::checkRange( Spec & result )
219 G::Range::check( result.second ) ;
221 catch( std::exception & e )
223 result.first.clear() ;
224 result.second = e.what() ;
228void GFilters::FilterFactory::fixFile( Spec & result ,
231 if( result.second.find(
"@app") == 0U && !app_dir.
empty() )
237 result.second = (base_dir/result.second).str() ;
241void GFilters::FilterFactory::checkFile( Spec & result ,
G::StringArray * warnings_p )
243 if( result.second.empty() )
245 result.first.clear() ;
246 result.second =
"empty file path" ;
250 warnings_p->push_back( std::string(
"filter program does not exist: ").append(result.second) ) ;
254 warnings_p->push_back( std::string(
"invalid program: ").append(result.second) ) ;
std::unique_ptr< GSmtp::Filter > newFilter(GNet::EventState, GSmtp::Filter::Type, const GSmtp::Filter::Config &, const Spec &) override
Returns a Filter on the heap.
static Spec parse(std::string_view spec, const G::Path &base_dir={}, const G::Path &app_dir={}, G::StringArray *warnings_p=nullptr)
Parses and validates the filter specification string returning the type and value in a Spec tuple,...
FilterFactory(GStore::FileStore &)
Constructor.
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
static Location nosocks(const std::string &spec, int family=AF_UNSPEC)
Factory function for a remote location but not allowing the extended syntax for socks.
A concrete implementation of the MessageStore interface dealing in paired flat files.
A general-purpose exception class derived from std::exception and containing an error message.
static bool isDirectory(const Path &path, std::nothrow_t)
Returns true if the path exists() and is a directory.
static bool exists(const Path &file)
Returns true if the file (directory, device etc.) exists.
A Path object represents a file system path.
bool isRelative() const noexcept
Returns true if the path is a relative path or empty().
std::string str() const
Returns the path string.
bool empty() const noexcept
Returns true if the path is empty.
static bool isUInt(std::string_view s) noexcept
Returns true if the string can be converted into an unsigned integer without throwing an exception.
static bool headMatch(std::string_view in, std::string_view head) noexcept
Returns true if the string has the given start (or head is empty).
static std::string printable(const std::string &in, char escape='\\')
Returns a printable representation of the given input string, using chacter code ranges 0x20 to 0x7e ...
static std::string_view tailView(std::string_view in, std::size_t pos, std::string_view default_={}) noexcept
Like tail() but returning a view into the input string.
static unsigned int toUInt(std::string_view s)
Converts string 's' to an unsigned int.
static bool replace(std::string &s, std::string_view from, std::string_view to, std::size_t *pos_p=nullptr)
A std::string_view overload.
A zero-copy string token iterator where the token separators are runs of whitespace characters,...
An interval between two G::SystemTime values or two G::TimerTime values.
std::vector< std::string > StringArray
A std::vector of std::strings.
Filter specification tuple for GSmtp::FilterFactoryBase::newFilter().
Configuration passed to filter constructors.