31 Filter::Type filter_type ,
const Filter::Config & filter_config ,
const std::string & spec ) :
34 m_filter_config(filter_config) ,
37 std::string_view spec_sv = spec ;
40 if( t() ==
"p" || t() ==
"pop" ) m_pop_by_name = true ;
41 if( t() ==
"h" || t() ==
"hardlink" ) m_hardlink = true ;
42 if( t() ==
"n" || t() ==
"nodelete" || t() ==
"no_delete" ) m_no_delete = true ;
46GSmtp::Filter::Result GFilters::CopyFilter::run(
const GStore::MessageId & message_id ,
47 bool & , GStore::FileStore::State e_state )
49 G::Path content_path = m_store.contentPath( message_id ) ;
50 G::Path envelope_path = m_store.envelopePath( message_id , e_state ) ;
64 std::string name = subdir.
basename() ;
65 if( name.empty() || name.at(0U) ==
'.' || name ==
"postmaster" )
67 ignore_names.push_back( name ) ;
71 copy_names.push_back( name ) ;
73 subdir , envelope_path , content_path ,
74 m_hardlink , m_pop_by_name ) ;
78 if( copy_names.empty() )
80 G_WARNING_ONCE(
"GFilters::CopyFilter::start: copy filter: "
81 "no sub-directories of [" << m_store.directory() <<
"] to copy in to" ) ;
86 G_LOG(
"GFilters::CopyFilter::start: " << prefix() <<
": "
87 << message_id.
str() <<
" copied to [" <<
G::Str::join(
",",copy_names) <<
"]"
88 << (ignore_names.empty()?
"":
" not [") <<
G::Str::join(
",",ignore_names)
89 << (ignore_names.empty()?
"":
"]") ) ;
101 return Result::abandon ;
CopyFilter(GNet::EventState es, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &spec)
Constructor.
A GSmtp::Filter base class for filters that run synchronously.
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
A structure containing the contents of an envelope file, with support for file reading,...
static void deliverTo(FileStore &, std::string_view prefix, const G::Path &dst_dir, const G::Path &envelope_path, const G::Path &content_path, bool hardlink=false, bool pop_by_name=false)
Low-level function to copy a single message into a mailbox sub-directory or a pop-by-name sub-directo...
A concrete implementation of the MessageStore interface dealing in paired flat files.
static Envelope readEnvelope(const G::Path &, std::ifstream *=nullptr)
Used by FileStore sibling classes to read an envelope file.
A somewhat opaque identifer for a GStore::MessageStore message id.
std::string str() const
Returns the id string.
A iterator similar to G::DirectoryIterator but doing all file i/o in one go and providing a sorted re...
Path filePath() const
Returns the current path.
bool more()
Returns true if more and advances by one.
std::size_t readDirectories(const Path &dir, unsigned int limit=0U)
An initialiser that reads all sub-directories.
static bool remove(const Path &path, std::nothrow_t) noexcept
Deletes the file or directory. Returns false on error.
A Path object represents a file system path.
std::string basename() const
Returns the rightmost part of the path, ignoring "." parts.
A class which acquires the process's special privileges on construction and releases them on destruct...
static std::string join(std::string_view sep, const StringArray &strings)
Concatenates an array of strings with separators.
A zero-copy string token iterator where the token separators are runs of whitespace characters,...
std::vector< std::string > StringArray
A std::vector of std::strings.