54 virtual std::auto_ptr<GSmtp::StoredMessage>
next() ;
68 m_iter.
readType( dir , std::string(failures?
".envelope.bad":
".envelope") ) ;
73 while( m_iter.more() )
75 std::auto_ptr<StoredFile> m(
new StoredFile(m_store,m_iter.filePath()) ) ;
76 if( m_lock && !m->lock() )
78 G_WARNING(
"GSmtp::MessageStore: cannot lock file: \"" << m_iter.filePath() <<
"\"" ) ;
83 const bool check = m_lock ;
84 bool ok = m->readEnvelope(reason,check) && m->openContent(reason) ;
86 return std::auto_ptr<StoredMessage>( m.release() ) ;
89 m->fail( reason , 0 ) ;
91 G_WARNING(
"GSmtp::MessageStore: ignoring \"" << m_iter.filePath() <<
"\": " << reason ) ;
93 return std::auto_ptr<StoredMessage>(NULL) ;
101 m_optimise(optimise) ,
106 m_pid_modifier =
static_cast<unsigned long>(
G::DateTime::now()) % 1000000UL ;
112 return "X-MailRelay-" ;
122 return format ==
"#2821.3" || format ==
"#2821.4" ;
125 void GSmtp::FileStore::checkPath(
const G::Path & directory_path )
133 ok = dir_test.valid() ;
137 throw InvalidDirectory( directory_path.
str() ) ;
143 FileWriter claim_writer ;
144 ok = dir_test.writeable(tmp) ;
148 G_WARNING(
"GSmtp::MessageStore: directory not writable: \"" << directory_path <<
"\"" ) ;
155 std::auto_ptr<std::ostream> ptr(
156 new std::ofstream( path.
str().c_str() ,
157 std::ios_base::binary | std::ios_base::out | std::ios_base::trunc ) ) ;
163 return fullPath( filePrefix(seq) +
".content" ) ;
168 return fullPath( filePrefix(seq) +
".envelope" ) ;
173 return fullPath( filePrefix(seq) +
".envelope.new" ) ;
176 std::string GSmtp::FileStore::filePrefix(
unsigned long seq )
const
178 std::ostringstream ss ;
180 ss <<
"emailrelay." << pid.
str() <<
"." << m_pid_modifier <<
"." << seq ;
184 G::Path GSmtp::FileStore::fullPath(
const std::string & filename )
const
187 p.pathAppend( filename ) ;
204 const_cast<FileStore*
>(
this)->m_empty = emptyCore() ;
213 bool GSmtp::FileStore::emptyCore()
const
217 list.
readType( m_dir ,
".envelope" , 1U ) ;
218 const bool no_more = !list.
more() ;
234 G::Path path = envelopePath(
id ) ;
236 std::auto_ptr<StoredFile> message(
new StoredFile(*
this,path) ) ;
238 if( ! message->lock() )
239 throw GetError( path.
str() +
": cannot lock the file" ) ;
242 const bool check = false ;
243 if( ! message->readEnvelope(reason,check) )
244 throw GetError( path.
str() +
": cannot read the envelope: " + reason ) ;
246 if( ! message->openContent(reason) )
247 throw GetError( path.
str() +
": cannot read the content: " + reason ) ;
249 G_LOG(
"GSmtp::FileStore::get: processing message \"" << message->name() <<
"\"" ) ;
251 std::auto_ptr<StoredMessage> message_base_ptr( message.release() ) ;
252 return message_base_ptr ;
258 return std::auto_ptr<NewMessage>(
new NewFile(from,*
this,m_max_size) ) ;
263 G_DEBUG(
"GSmtp::FileStore::updated" ) ;
264 bool repoll = m_repoll ;
266 m_signal.emit( repoll ) ;
284 std::auto_ptr<StoredMessage> message = iter.
next() ;
285 if( message.get() == NULL )
287 G_DEBUG(
"GSmtp::FileStore::unfailAll: " << message->name() ) ;
316 G::Process::Umask(
G::Process::Umask::Tighter)
static std::string format()
Returns an identifier for the storage format implemented by this class.
std::string str() const
Returns the path string.
static EpochTime now()
Returns the current epoch time.
A noncopyable base class (a la boost).
G::Path contentPath(unsigned long seq) const
Returns the path for a content file.
SMTP and message-store classes.
static std::string x()
Returns the prefix for envelope header lines.
FileWriter()
Default constructor.
virtual void unfailAll()
Final override from GSmtp::MessageStore.
virtual G::Signal1< bool > & signal()
Final override from GSmtp::MessageStore.
virtual std::auto_ptr< NewMessage > newMessage(const std::string &from)
Final override from GSmtp::MessageStore.
virtual MessageStore::Iterator iterator(bool lock)
Final override from GSmtp::MessageStore.
bool more()
Returns true if more and advances by one.
Used by GSmtp::FileStore, GSmtp::NewFile and GSmtp::StoredFile to claim read permissions for reading ...
Used by GSmtp::FileStore, GSmtp::NewFile and GSmtp::StoredFile to claim write permissions.
std::auto_ptr< std::ostream > stream(const G::Path &path)
Returns a stream to the given content.
~DirectoryReader()
Destructor. Switches identity back.
A base class for MessageStore::Iterator implementations.
std::auto_ptr< StoredMessage > next()
void readType(const Path &dir, const std::string &suffix, unsigned int limit=0U)
An initialiser that is to be used after default construction.
An encapsulation of a file system directory which allows for iterating through the set of contained f...
virtual std::auto_ptr< GSmtp::StoredMessage > next()
FileStore(const G::Path &dir, bool optimise=false, unsigned long max_size=0UL)
Constructor.
A 'body' class for the MessageStore::Iterator 'handle'.
virtual MessageStore::Iterator failures()
Final override from GSmtp::MessageStore.
virtual bool empty() const
Final override from GSmtp::MessageStore.
virtual std::auto_ptr< StoredMessage > get(unsigned long id)
Final override from GSmtp::MessageStore.
A concrete derived class implementing the NewMessage interface.
A concete derived class implementing the StoredMessage interface.
A Directory iterator that does all file i/o in one go.
~FileReader()
Destructor. Switches identity back.
static std::string tmp()
A convenience function for constructing a filename for writeable().
~FileWriter()
Destructor. Switches identity back.
A concrete implementation of the MessageStore interface dealing in paired flat files and with an opti...
G::Path envelopePath(unsigned long seq) const
Returns the path for an envelope file.
virtual void updated()
Final override from GSmtp::MessageStore.
DirectoryReader()
Default constructor.
static bool knownFormat(const std::string &format)
Returns true if the storage format string is recognised and supported for reading.
FileIterator(FileStore &store, const G::Path &dir, bool lock, bool failures)
unsigned long newSeq()
Hands out a new non-zero sequence number.
virtual void repoll()
Final override from GSmtp::MessageStore.
A Path object represents a file system path.
FileReader()
Default constructor.
G::Path envelopeWorkingPath(unsigned long seq) const
Returns the path for an envelope file which is in the process of being written.
An iterator class for GSmtp::MessageStore.