E-MailRelay

gstoredfile.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gstoredfile.h
19///
20
21#ifndef G_SMTP_STORED_FILE_H
22#define G_SMTP_STORED_FILE_H
23
24#include "gdef.h"
25#include "gfilestore.h"
26#include "gstoredmessage.h"
27#include "genvelope.h"
28#include "gexception.h"
29#include "gpath.h"
30#include "gstrings.h"
31#include <iostream>
32#include <memory>
33
34 namespace GSmtp
35{
36 class StoredFile ;
37}
38
39//| \class GSmtp::StoredFile
40/// A concete derived class implementing the
41/// StoredMessage interface.
42///
43 class GSmtp::StoredFile : public StoredMessage
44{
45 public:
46 G_EXCEPTION( FormatError , "invalid envelope file" ) ;
47 G_EXCEPTION( FilenameError , "invalid envelope filename" ) ;
48 G_EXCEPTION( ReadError , "cannot read envelope file" ) ;
49 G_EXCEPTION( EditError , "cannot update envelope file" ) ;
50
51 StoredFile( FileStore & store , const G::Path & envelope_path ) ;
52 ///< Constructor.
53
54 ~StoredFile() override ;
55 ///< Destructor. Unlocks the file if it has been lock()ed
56 ///< but not destroy()ed or fail()ed.
57
58 bool lock() ;
59 ///< Locks the file by renaming the envelope file.
60 ///< Used by FileStore and FileIterator.
61
62 bool readEnvelope( std::string & reason , bool check_for_no_remote_recipients ) ;
63 ///< Reads the envelope. Returns false on error.
64 ///< Used by FileStore and FileIterator.
65
66 bool openContent( std::string & reason ) ;
67 ///< Opens the content file. Returns false on error.
68 ///< Used by FileStore and FileIterator.
69
70 MessageId id() const override ;
71 ///< Override from GSmtp::StoredMessage.
72
73 void edit( const G::StringArray & ) override ;
74 ///< Override from GSmtp::StoredMessage.
75
76 void fail( const std::string & reason , int reason_code ) override ;
77 ///< Override from GSmtp::StoredMessage.
78
79 private: // overrides
80 std::string location() const override ; // Override from GSmtp::StoredMessage.
81 int eightBit() const override ; // Override from GSmtp::StoredMessage.
82 std::string from() const override ; // Override from GSmtp::StoredMessage.
83 std::string to( std::size_t ) const override ; // Override from GSmtp::StoredMessage.
84 std::size_t toCount() const override ; // Override from GSmtp::StoredMessage.
85 std::string authentication() const override ; // Override from GSmtp::StoredMessage.
86 std::string fromAuthIn() const override ; // Override from GSmtp::StoredMessage.
87 std::string fromAuthOut() const override ; // Override from GSmtp::StoredMessage.
88 void close() override ; // Override from GSmtp::StoredMessage.
89 std::string reopen() override ; // Override from GSmtp::StoredMessage.
90 void destroy() override ; // Override from GSmtp::StoredMessage.
91 void unfail() override ; // Override from GSmtp::StoredMessage.
92 std::istream & contentStream() override ; // Override from GSmtp::StoredMessage.
93
94 public:
95 StoredFile( const StoredFile & ) = delete ;
96 StoredFile( StoredFile && ) = delete ;
97 void operator=( const StoredFile & ) = delete ;
98 void operator=( StoredFile && ) = delete ;
99
100 private:
101 enum class State { Normal , Locked , Bad } ;
102 G::Path cpath() const ;
103 G::Path epath( State ) const ;
104 void readEnvelopeCore( bool check_recipients ) ;
105 const std::string & eol() const ;
106 G::Path contentPath() const ;
107 void addReason( const G::Path & path , const std::string & , int ) const ;
108
109 private:
110 FileStore & m_store ;
111 std::unique_ptr<std::istream> m_content ;
112 MessageId m_id ;
113 Envelope m_env ;
114 State m_state ;
115} ;
116
117#endif
118
GSmtp::Envelope
A structure containing the contents of an envelope file, with support for file reading,...
Definition: genvelope.h:39
GSmtp::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:58
GSmtp::MessageId
A somewhat opaque identifer for a MessageStore message.
Definition: gmessagestore.h:43
GSmtp::StoredFile
A concete derived class implementing the StoredMessage interface.
Definition: gstoredfile.h:44
GSmtp::StoredFile::StoredFile
StoredFile(FileStore &store, const G::Path &envelope_path)
Constructor.
Definition: gstoredfile.cpp:31
GSmtp::StoredFile::fail
void fail(const std::string &reason, int reason_code) override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:260
GSmtp::StoredFile::lock
bool lock()
Locks the file by renaming the envelope file.
Definition: gstoredfile.cpp:176
GSmtp::StoredFile::id
MessageId id() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:66
GSmtp::StoredFile::~StoredFile
~StoredFile() override
Destructor.
Definition: gstoredfile.cpp:50
GSmtp::StoredFile::edit
void edit(const G::StringArray &) override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:194
GSmtp::StoredFile::openContent
bool openContent(std::string &reason)
Opens the content file.
Definition: gstoredfile.cpp:142
GSmtp::StoredFile::readEnvelope
bool readEnvelope(std::string &reason, bool check_for_no_remote_recipients)
Reads the envelope.
Definition: gstoredfile.cpp:109
GSmtp::StoredMessage
An abstract interface for messages which have come from the store.
Definition: gstoredmessage.h:43
G::Path
A Path object represents a file system path.
Definition: gpath.h:72
genvelope.h
gexception.h
gfilestore.h
gpath.h
gstoredmessage.h
gstrings.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31