43 <<
"usage: " << prefix <<
" <emailrelay-content-file>" << std::endl
45 <<
"Copies the corresponding emailrelay envelope file into all " << std::endl
46 <<
"subdirectories of the spool directory. Exits with a " << std::endl
47 <<
"value of 100 if copied once or more. Intended for use " << std::endl
48 <<
"with \"emailrelay --pop-by-name\"." << std::endl
58 G::Path content_path( content ) ;
61 throw FilterError(
"no such file" ) ;
66 std::string envelope_name = content_path.
basename() ;
69 throw FilterError(
"invalid filename" ) ;
73 G::Path envelope_path =
G::Path( dir_path , envelope_name +
".new" ) ;
79 envelope_path = envelope_path_alt ;
81 throw FilterError( std::string() +
"no envelope file \"" + envelope_path.
str() +
"\"" ) ;
89 int directory_count = 0 ;
90 std::list<std::string> failures ;
107 bool envelope_deleted = false ;
108 if( directory_count > 0 && failures.empty() )
115 if( ! failures.empty() )
117 std::ostringstream ss ;
118 ss <<
"failed to copy envelope file " << envelope_path.
str() <<
" into " ;
119 if( failures.size() == 1U )
121 ss <<
"the \"" << failures.front() <<
"\" sub-directory" ;
125 ss << failures.size() <<
" sub-directories, including \"" << failures.front() <<
"\"" ;
127 throw FilterError( ss.str() ) ;
129 if( directory_count == 0 )
131 throw FilterError(
"no sub-directories to copy into: check permissions" ) ;
134 return envelope_deleted ;
141 G::Arg args( argc , argv ) ;
144 throw FilterError(
"usage error: must be run by emailrelay with the full path of a message content file" ) ;
146 if( args.
v(1U) ==
"--help" )
156 catch( std::exception & e )
158 std::cout <<
"<<" << e.what() <<
">>" << std::endl ;
162 std::cout <<
"<<" <<
"exception" <<
">>" << std::endl ;
std::string str() const
Returns the path string.
static std::string copyright()
Returns the copyright text.
static bool copy(const Path &from, const Path &to, const NoThrow &)
Copies a file. Returns false on error.
std::string prefix() const
Returns the basename of v(0) without any extension.
static std::string warranty(const std::string &prefix, const std::string &eol)
Returns the warranty text.
std::string basename() const
Returns the path, excluding drive/directory parts.
void filter_help(const std::string &prefix)
Path filePath() const
Returns the path of the current item.
int filter_main(int argc, char *argv[])
bool filter_run(const std::string &content)
bool filter_match(G::Path, std::string)
An encapsulation of a file system directory which allows for iterating through the set of contained f...
std::string filter_read_to(const std::string &)
Path fileName() const
Returns the name of the current item.
std::string v(size_type i) const
Returns the i'th argument.
static unsigned int replaceAll(std::string &s, const std::string &from, const std::string &to)
Does a global replace on string 's', replacing all occurences of sub-string 'from' with 'to'...
size_type c() const
Returns the number of tokens in the command line, including the program name.
static bool exists(const Path &file)
Returns true if the file (directory, link, device etc.) exists.
Path dirname() const
Returns the drive/directory parts of the path.
static bool remove(const Path &path, const NoThrow &)
Deletes the file or directory. Returns false on error.
An overload discriminator class for File methods.
bool more()
Returns true if more and advances by one.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
bool isDir() const
Returns true if the current item is a directory.
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
bool error() const
Returns true on error. The caller should stop the iteration.
A Path object represents a file system path.