- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gstoredfile.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // ===
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 "gexecutable.h"
28 #include "gstoredmessage.h"
29 #include "gexception.h"
30 #include "gpath.h"
31 #include "gstrings.h"
32 #include <iostream>
33 #include <memory>
34
36 namespace GSmtp
37 {
38 class StoredFile ;
39 }
40
45 class GSmtp::StoredFile : public GSmtp::StoredMessage
46 {
47 public:
48 G_EXCEPTION( InvalidFormat , "invalid format field in envelope" ) ;
49 G_EXCEPTION( NoEnd , "invalid envelope file: misplaced end marker" ) ;
50 G_EXCEPTION( InvalidTo , "invalid 'to' line in envelope file" ) ;
51 G_EXCEPTION( NoRecipients , "no remote recipients" ) ;
52 G_EXCEPTION( OpenError , "cannot open the envelope" ) ;
53 G_EXCEPTION( StreamError , "envelope reading/parsing error" ) ;
54 G_EXCEPTION( InvalidFilename , "invalid filename" ) ;
55
56 StoredFile( FileStore & store , const G::Path & envelope_path ) ;
58
59 virtual ~StoredFile() ;
62
63 bool lock() ;
66
67 bool readEnvelope( std::string & reason , bool check_for_no_remote_recipients ) ;
70
71 bool openContent( std::string & reason ) ;
74
75 virtual std::string name() const ;
77
78 virtual std::string location() const ;
80
81 virtual bool eightBit() const ;
83
84 virtual const std::string & from() const ;
86
87 virtual const G::Strings & to() const ;
89
90 virtual std::string authentication() const ;
92
93 virtual void destroy() ;
95
96 virtual void fail( const std::string & reason , int reason_code ) ;
98
99 virtual void unfail() ;
101
102 virtual std::auto_ptr<std::istream> extractContentStream() ;
104
105 virtual size_t remoteRecipientCount() const ;
107
108 virtual size_t errorCount() const ;
110
111 virtual void sync() ;
113
114 private:
115 StoredFile( const StoredFile & ) ; // not implemented
116 void operator=( const StoredFile & ) ; // not implemented
117 static const std::string & crlf() ;
118 std::string getline( std::istream & stream ) const ;
119 std::string value( const std::string & s , const std::string & k = std::string() ) const ;
120 G::Path contentPath() const ;
121 void readFormat( std::istream & stream ) ;
122 void readFlag( std::istream & stream ) ;
123 void readFrom( std::istream & stream ) ;
124 void readToList( std::istream & stream ) ;
125 void readEnd( std::istream & stream ) ;
126 void readReasons( std::istream & stream ) ;
127 void readAuthentication( std::istream & stream ) ;
128 void readClientSocketAddress( std::istream & stream ) ;
129 void readClientSocketName( std::istream & stream ) ;
130 void readClientCertificate( std::istream & stream ) ;
131 void readEnvelopeCore( bool ) ;
132 static void addReason( const G::Path & path , const std::string & , int ) ;
133 static G::Path badPath( G::Path ) ;
134 void unlock() ;
135
136 private:
137 FileStore & m_store ;
138 G::Strings m_to_local ;
139 G::Strings m_to_remote ;
140 std::string m_from ;
141 G::Path m_envelope_path ;
142 G::Path m_old_envelope_path ;
143 std::string m_name ;
144 std::auto_ptr<std::istream> m_content ;
145 bool m_eight_bit ;
146 std::string m_authentication ;
147 std::string m_format ;
148 std::string m_client_socket_address ;
149 std::string m_client_socket_name ;
150 std::string m_client_certificate ;
151 size_t m_errors ;
152 bool m_locked ;
153 } ;
154
155 #endif
156
GSmtp::StoredFile::readEnvelope
bool readEnvelope(std::string &reason, bool check_for_no_remote_recipients)
Reads the envelope.
Definition: gstoredfile.cpp:77
GSmtp::StoredFile::destroy
virtual void destroy()
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:354
GSmtp::StoredFile::errorCount
virtual size_t errorCount() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:403
gstrings.h
GSmtp
SMTP and message-store classes.
G::Strings
std::list< std::string > Strings
A std::list of std::strings.
Definition: gstrings.h:39
GSmtp::StoredMessage
An abstract class for messages which have come from the store.
Definition: gstoredmessage.h:40
GSmtp::StoredFile::name
virtual std::string name() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:57
gexecutable.h
GSmtp::StoredFile::eightBit
virtual bool eightBit() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:67
GSmtp::StoredFile::sync
virtual void sync()
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:72
GSmtp::StoredFile::~StoredFile
virtual ~StoredFile()
Destructor.
Definition: gstoredfile.cpp:46
GSmtp::StoredFile::extractContentStream
virtual std::auto_ptr< std::istream > extractContentStream()
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:381
GSmtp::StoredFile::to
virtual const G::Strings & to() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:376
GSmtp::StoredFile::openContent
bool openContent(std::string &reason)
Opens the content file.
Definition: gstoredfile.cpp:206
gmessagestore.h
GSmtp::StoredFile
A concete derived class implementing the StoredMessage interface.
Definition: gstoredfile.h:45
GSmtp::StoredFile::StoredFile
StoredFile(FileStore &store, const G::Path &envelope_path)
Constructor.
Definition: gstoredfile.cpp:33
GSmtp::StoredFile::from
virtual const std::string & from() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:371
GSmtp::StoredFile::fail
virtual void fail(const std::string &reason, int reason_code)
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:297
GSmtp::StoredFile::authentication
virtual std::string authentication() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:408
GSmtp::StoredFile::location
virtual std::string location() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:62
GSmtp::StoredFile::unfail
virtual void unfail()
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:313
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
GSmtp::StoredFile::remoteRecipientCount
virtual size_t remoteRecipientCount() const
Final override from GSmtp::StoredMessage.
Definition: gstoredfile.cpp:398
gpath.h
GSmtp::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files and with an opti...
Definition: gfilestore.h:62
gstoredmessage.h
gsmtp.h
GSmtp::StoredFile::lock
bool lock()
Locks the file by renaming the envelope file.
Definition: gstoredfile.cpp:262
G::Path
A Path object represents a file system path.
Definition: gpath.h:44