E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gstoredfile.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 "gsmtp.h"
26 #include "gmessagestore.h"
27 #include "gstoredmessage.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
50 StoredFile( FileStore & store , const G::Path & envelope_path ) ;
51 ///< Constructor.
52
53 virtual ~StoredFile() ;
54 ///< Destructor. Unlocks the file if it has been lock()ed
55 ///< but not destroy()ed or fail()ed.
56
57 bool lock() ;
58 ///< Locks the file by renaming the envelope file.
59 ///< Used by FileStore and FileIterator.
60
61 bool readEnvelope( std::string & reason , bool check_for_no_remote_recipients ) ;
62 ///< Reads the envelope. Returns false on error.
63 ///< Used by FileStore and FileIterator.
64
65 bool openContent( std::string & reason ) ;
66 ///< Opens the content file. Returns false on error.
67 ///< Used by FileStore and FileIterator.
68
69 virtual std::string name() const override ;
70 ///< Override from GSmtp::StoredMessage.
71
72 virtual std::string location() const override ;
73 ///< Override from GSmtp::StoredMessage.
74
75 virtual bool eightBit() const override ;
76 ///< Override from GSmtp::StoredMessage.
77
78 virtual const std::string & from() const override ;
79 ///< Override from GSmtp::StoredMessage.
80
81 virtual const G::StringArray & to() const override ;
82 ///< Override from GSmtp::StoredMessage.
83
84 virtual std::string authentication() const override ;
85 ///< Override from GSmtp::StoredMessage.
86
87 virtual std::string fromAuthIn() const override ;
88 ///< Override from GSmtp::StoredMessage.
89
90 virtual std::string fromAuthOut() const override ;
91 ///< Override from GSmtp::StoredMessage.
92
93 virtual void destroy() override ;
94 ///< Override from GSmtp::StoredMessage.
95
96 virtual void fail( const std::string & reason , int reason_code ) override ;
97 ///< Override from GSmtp::StoredMessage.
98
99 virtual void unfail() override ;
100 ///< Override from GSmtp::StoredMessage.
101
102 virtual unique_ptr<std::istream> extractContentStream() override ;
103 ///< Override from GSmtp::StoredMessage.
104
105 virtual size_t remoteRecipientCount() const override ;
106 ///< Override from GSmtp::StoredMessage.
107
108 virtual size_t errorCount() const override ;
109 ///< Override from GSmtp::StoredMessage.
110
111 virtual void sync( bool ) override ;
112 ///< Override from GSmtp::StoredMessage.
113
114 private:
115 StoredFile( const StoredFile & ) ; // not implemented
116 void operator=( const StoredFile & ) ; // not implemented
117 const std::string & eol() const ;
118 G::Path contentPath() const ;
119 std::string readLine( std::istream & ) ;
120 std::string readValue( std::istream & , const std::string & key ) ;
121 std::string value( const std::string & ) const ;
122 void readFormat( std::istream & stream ) ;
123 void readFlag( std::istream & stream ) ;
124 void readFrom( std::istream & stream ) ;
125 void readFromAuthIn( std::istream & stream ) ;
126 void readFromAuthOut( std::istream & stream ) ;
127 void readToList( std::istream & stream ) ;
128 void readEnd( std::istream & stream ) ;
129 void readReasons( std::istream & stream ) ;
130 void readAuthentication( std::istream & stream ) ;
131 void readClientSocketAddress( std::istream & stream ) ;
132 void readClientSocketName( std::istream & stream ) ;
133 void readClientCertificate( std::istream & stream ) ;
134 void readEnvelopeCore( bool ) ;
135 void addReason( const G::Path & path , const std::string & , int ) const ;
136 static G::Path badPath( G::Path ) ;
137 void unlock() ;
138
139 private:
140 FileStore & m_store ;
141 G::StringArray m_to_local ;
142 G::StringArray m_to_remote ;
143 std::string m_from ;
144 std::string m_from_auth_in ;
145 std::string m_from_auth_out ;
146 G::Path m_envelope_path ;
147 G::Path m_old_envelope_path ;
148 std::string m_name ;
149 unique_ptr<std::istream> m_content ;
150 bool m_eight_bit ;
151 std::string m_authentication ;
152 std::string m_format ;
153 std::string m_client_socket_address ;
154 std::string m_client_socket_name ;
155 std::string m_client_certificate ;
156 size_t m_errors ;
157 bool m_locked ;
158 bool m_crlf ;
159 } ;
160
161 #endif
162
GSmtp::StoredFile::readEnvelope
bool readEnvelope(std::string &reason, bool check_for_no_remote_recipients)
Reads the envelope.
Definition: gstoredfile.cpp:81
GSmtp::StoredFile::unfail
virtual void unfail() override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:353
gstrings.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
GSmtp::StoredFile::from
virtual const std::string & from() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:409
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
GSmtp::StoredMessage
An abstract interface for messages which have come from the store.
Definition: gstoredmessage.h:38
GSmtp::StoredFile::extractContentStream
virtual unique_ptr< std::istream > extractContentStream() override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:419
GSmtp::StoredFile::fromAuthIn
virtual std::string fromAuthIn() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:451
GSmtp::StoredFile::destroy
virtual void destroy() override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:392
GSmtp::StoredFile::fail
virtual void fail(const std::string &reason, int reason_code) override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:337
GSmtp::StoredFile::location
virtual std::string location() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:66
GSmtp::StoredFile::authentication
virtual std::string authentication() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:446
GSmtp::StoredFile::errorCount
virtual size_t errorCount() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:441
GSmtp::StoredFile::~StoredFile
virtual ~StoredFile()
Destructor.
Definition: gstoredfile.cpp:46
GSmtp::StoredFile::openContent
bool openContent(std::string &reason)
Opens the content file.
Definition: gstoredfile.cpp:223
GSmtp::StoredFile::fromAuthOut
virtual std::string fromAuthOut() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:456
gmessagestore.h
GSmtp::StoredFile
A concete derived class implementing the StoredMessage interface.
Definition: gstoredfile.h:43
GSmtp::StoredFile::StoredFile
StoredFile(FileStore &store, const G::Path &envelope_path)
Constructor.
Definition: gstoredfile.cpp:32
GSmtp::StoredFile::remoteRecipientCount
virtual size_t remoteRecipientCount() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:436
gexception.h
gpath.h
GSmtp::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:58
gstoredmessage.h
gsmtp.h
GSmtp::StoredFile::lock
bool lock()
Locks the file by renaming the envelope file.
Definition: gstoredfile.cpp:302
GSmtp::StoredFile::to
virtual const G::StringArray & to() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:414
GSmtp::StoredFile::name
virtual std::string name() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:61
G::Path
A Path object represents a file system path.
Definition: gpath.h:72
GSmtp::StoredFile::sync
virtual void sync(bool) override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:76
GSmtp::StoredFile::eightBit
virtual bool eightBit() const override
Override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:71