33 Filter::Type filter_type ,
const Filter::Config & config ,
const std::string & ) :
36 m_domain(config.domain)
40GSmtp::Filter::Result GFilters::MessageIdFilter::run(
const GStore::MessageId & message_id ,
41 bool & , GStore::FileStore::State )
43 std::string e = process( m_store.contentPath(message_id) , m_domain ) ;
59 bool have_id = false ;
61 static constexpr std::size_t line_limit = 10000U ;
63 line.reserve( 2000U ) ;
64 while(
G::Str::readLine( in , line ,
"\n" ,
true , line_limit ) && line.size() > 1U && !have_id )
65 have_id = isId( line ) ;
67 return "format error" ;
72 G::Path path_out = path_in.
str().append(
".tmp") ;
79 return "create error" ;
81 out <<
"Message-ID: " << newId(domain) <<
"\r\n" ;
90 return "write error" ;
98 return "rename error" ;
103bool GFilters::MessageIdFilter::isId( std::string_view line )
noexcept
105 return line.find(
':') != std::string::npos && G::sv_imatch( G::sv_substr_noexcept(line,0U,line.find(
':')) ,
"message-id" ) ;
108std::string GFilters::MessageIdFilter::newId(
const std::string & domain )
110 std::ostringstream ss ;
112 static int generator = 0 ;
114 << now.
s() <<
"." << now.
us() <<
"."
116 <<
"@" << domain <<
">" ;
static std::string process(const G::Path &, const std::string &domain)
Edits a content file by adding a message-id if necessary.
MessageIdFilter(GNet::EventState, 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 concrete implementation of the MessageStore interface dealing in paired flat files.
A somewhat opaque identifer for a GStore::MessageStore message id.
static void open(std::ofstream &, const Path &)
Calls open() on the given output file stream.
static bool renameOnto(const Path &from, const Path &to, std::nothrow_t) noexcept
Renames the file, deleting 'to' first if necessary.
static bool copy(const Path &from, const Path &to, std::nothrow_t)
Copies a file. Returns false on error.
A Path object represents a file system path.
std::string str() const
Returns the path string.
A class which acquires the process's special privileges on construction and releases them on destruct...
static std::istream & readLine(std::istream &stream, std::string &result, std::string_view eol={}, bool pre_erase_result=true, std::size_t limit=0U)
Reads a line from the stream using the given line terminator, which may be multi-character.
Represents a unix-epoch time with microsecond resolution.
static SystemTime now()
Factory function for the current time.
std::time_t s() const noexcept
Returns the number of seconds since the start of the epoch.
unsigned int us() const
Returns the microsecond fraction.