E-MailRelay

gnewfile.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 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 "gstringarray.h"
28#include "gnewmessage.h"
29#include "gexception.h"
30#include <memory>
31#include <fstream>
32
33 namespace GStore
34{
35 class NewFile ;
36}
37
38//| \class GStore::NewFile
39/// A concrete class implementing the GStore::NewMessage interface using
40/// files.
41///
42/// The prepare() override creates one ".envelope.new" file and one
43/// ".content" file.
44///
45/// The commit() override renames the envelope file to remove the ".new"
46/// filename extension. This makes it visible to FileStore::iterator().
47///
48 class GStore::NewFile : public NewMessage
49{
50 public:
51 G_EXCEPTION( FileError , tx("message store error") )
52
53 NewFile( FileStore & store , const std::string & from , const MessageStore::SmtpInfo & ,
54 const std::string & from_auth_out , std::size_t max_size ) ;
55 ///< Constructor. The max-size is the size limit, as also
56 ///< reported by the EHLO response, and is not the size
57 ///< estimate from MAIL-FROM.
58
59 ~NewFile() override ;
60 ///< Destructor. If the new message has not been
61 ///< commit()ed then the files are deleted.
62
63 G::Path contentPath() const ;
64 ///< Returns the path of the content file.
65
66 public:
67 NewFile( const NewFile & ) = delete ;
68 NewFile( NewFile && ) = delete ;
69 NewFile & operator=( const NewFile & ) = delete ;
70 NewFile & operator=( NewFile && ) = delete ;
71
72 private: // overrides
73 void commit( bool strict ) override ; // GStore::NewMessage
74 MessageId id() const override ; // GStore::NewMessage
75 std::string location() const override ; // GStore::NewMessage
76 void addTo( const std::string & to , bool local , MessageStore::AddressStyle ) override ; // GStore::NewMessage
77 NewMessage::Status addContent( const char * , std::size_t ) override ; // GStore::NewMessage
78 std::size_t contentSize() const override ; // GStore::NewMessage
79 void prepare( const std::string & auth_id , const std::string & peer_socket_address ,
80 const std::string & peer_certificate ) override ; // GStore::NewMessage
81
82 private:
83 using FileOp = FileStore::FileOp ;
84 enum class State { New , Normal } ;
85 G::Path cpath() const ;
86 G::Path epath( State ) const ;
87 void cleanup() ;
88 void saveEnvelope( Envelope & , const G::Path & ) ;
89
90 private:
91 FileStore & m_store ;
92 MessageId m_id ;
93 std::unique_ptr<std::ofstream> m_content ;
94 bool m_committed {false} ;
95 bool m_saved {false} ;
96 std::size_t m_size {0U} ;
97 std::size_t m_max_size ;
98 Envelope m_env ;
99} ;
100
101#endif
GStore::Envelope
A structure containing the contents of an envelope file, with support for file reading,...
Definition: genvelope.h:41
GStore::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:56
GStore::MessageId
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
GStore::NewFile
A concrete class implementing the GStore::NewMessage interface using files.
Definition: gnewfile.h:49
GStore::NewFile::contentPath
G::Path contentPath() const
Returns the path of the content file.
GStore::NewFile::NewFile
NewFile(FileStore &store, const std::string &from, const MessageStore::SmtpInfo &, const std::string &from_auth_out, std::size_t max_size)
Constructor.
Definition: gnewfile.cpp:37
GStore::NewFile::~NewFile
~NewFile() override
Destructor.
Definition: gnewfile.cpp:57
GStore::NewMessage
An abstract class to allow the creation of a new message in the message store.
Definition: gnewmessage.h:49
G::Path
A Path object represents a file system path.
Definition: gpath.h:82
genvelope.h
gexception.h
gfilestore.h
gnewmessage.h
gstringarray.h
GStore
Message store classes.
Definition: genvelope.cpp:30
G::tx
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
Definition: ggettext.h:84
GStore::FileStore::FileOp
Low-level file-system operations for GStore::FileStore.
Definition: gfilestore.h:76
GStore::MessageStore::SmtpInfo
Information on the SMTP options used when submitted.
Definition: gmessagestore.h:84