E-MailRelay

gnewfile.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 gnewfile.h
19///
20
21#ifndef G_SMTP_NEW_FILE_H
22#define G_SMTP_NEW_FILE_H
23
24#include "gdef.h"
25#include "gfilestore.h"
26#include "genvelope.h"
27#include "gstrings.h"
28#include "gnewmessage.h"
29#include "gexception.h"
30#include <fstream>
31
32 namespace GSmtp
33{
34 class NewFile ;
35}
36
37//| \class GSmtp::NewFile
38/// A concrete derived class implementing the GSmtp::NewMessage
39/// interface. Writes itself to the i/o streams supplied by
40/// GSmtp::FileStore.
41///
42 class GSmtp::NewFile : public NewMessage
43{
44 public:
45 G_EXCEPTION( InvalidPath , "invalid path: must be absolute" ) ;
46 G_EXCEPTION( FileError , "message store error" ) ;
47 G_EXCEPTION( TooBig , "message too big" ) ;
48
49 NewFile( FileStore & store , const std::string & from , const std::string & from_auth_in ,
50 const std::string & from_auth_out , std::size_t max_size , bool test_for_eight_bit ) ;
51 ///< Constructor. The FileStore reference is kept.
52
53 ~NewFile() override ;
54 ///< Destructor. If the new message has not been
55 ///< commit()ed then the files are deleted.
56
57 G::Path contentPath() const ;
58 ///< Returns the path of the content file.
59
60 public:
61 NewFile( const NewFile & ) = delete ;
62 NewFile( NewFile && ) = delete ;
63 void operator=( const NewFile & ) = delete ;
64 void operator=( NewFile && ) = delete ;
65
66 private: // overrides
67 void commit( bool strict ) override ; // Override from GSmtp::NewMessage.
68 std::string location() const override ; // Override from GSmtp::NewMessage.
69 MessageId id() const override ; // Override from GSmtp::NewMessage.
70 void addTo( const std::string & to , bool local ) override ; // Override from GSmtp::NewMessage.
71 bool addText( const char * , std::size_t ) override ; // Override from GSmtp::NewMessage.
72 bool prepare( const std::string & auth_id , const std::string & peer_socket_address ,
73 const std::string & peer_certificate ) override ; // Override from GSmtp::NewMessage.
74
75 private:
76 enum class State { New , Normal } ;
77 G::Path cpath() const ;
78 G::Path epath( State ) const ;
79 void cleanup() ;
80 void discardContent() ;
81 bool commitEnvelope() ;
82 void deleteContent() ;
83 void deleteEnvelope() ;
84 static bool isEightBit( const char * , std::size_t ) ;
85 bool saveEnvelope() ;
86 void moveToLocal( const G::Path & , const G::Path & , const G::Path & ) ;
87 void copyToLocal( const G::Path & , const G::Path & , const G::Path & ) ;
88
89 private:
90 FileStore & m_store ;
91 MessageId m_id ;
92 std::unique_ptr<std::ofstream> m_content ;
93 bool m_committed ;
94 bool m_test_for_eight_bit ;
95 bool m_saved ;
96 std::size_t m_size ;
97 std::size_t m_max_size ;
98 Envelope m_env ;
99} ;
100
101#endif
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::NewFile
A concrete derived class implementing the GSmtp::NewMessage interface.
Definition: gnewfile.h:43
GSmtp::NewFile::contentPath
G::Path contentPath() const
Returns the path of the content file.
GSmtp::NewFile::~NewFile
~NewFile() override
Destructor.
Definition: gnewfile.cpp:57
GSmtp::NewFile::NewFile
NewFile(FileStore &store, const std::string &from, const std::string &from_auth_in, const std::string &from_auth_out, std::size_t max_size, bool test_for_eight_bit)
Constructor. The FileStore reference is kept.
Definition: gnewfile.cpp:37
GSmtp::NewMessage
An abstract class to allow the creation of a new message in the message store.
Definition: gnewmessage.h:38
G::Path
A Path object represents a file system path.
Definition: gpath.h:72
genvelope.h
gexception.h
gfilestore.h
gnewmessage.h
gstrings.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39