E-MailRelay
gnewfile.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 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 "gsmtp.h"
26 #include "gfilestore.h"
27 #include "gstrings.h"
28 #include "gnewmessage.h"
29 #include "gexception.h"
30 #include <iostream>
31 
32 namespace GSmtp
33 {
34  class NewFile ;
35 }
36 
37 /// \class GSmtp::NewFile
38 /// A concrete derived class implementing the
39 /// NewMessage interface. Writes itself to the i/o streams
40 /// supplied by MessageStoreImp.
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 
48  NewFile( FileStore & store , const std::string & from , const std::string & from_auth_in ,
49  const std::string & from_auth_out = std::string() , size_t max_size = 0UL ) ;
50  ///< Constructor. The FileStore reference is kept.
51 
52  virtual ~NewFile() ;
53  ///< Destructor. If the new message has not been
54  ///< commit()ed then the files are deleted.
55 
56  virtual void addTo( const std::string & to , bool local ) override ;
57  ///< Override from GSmtp::NewMessage.
58 
59  virtual bool addText( const char * , size_t ) override ;
60  ///< Override from GSmtp::NewMessage.
61 
62  virtual std::string prepare( const std::string & auth_id , const std::string & peer_socket_address ,
63  const std::string & peer_certificate ) override ;
64  ///< Override from GSmtp::NewMessage.
65  ///<
66  ///< The implementation flushes and closes the
67  ///< content stream, creates a new envelope
68  ///< file (".new"), and does any local 'delivery'
69  ///< by creating ".local" copies. The path
70  ///< to the content file is returned.
71 
72  virtual void commit( bool strict ) override ;
73  ///< Override from GSmtp::NewMessage.
74  ///<
75  ///< The implementation renames the ".new"
76  ///< envelope file, removing the extension.
77 
78  virtual unsigned long id() const override ;
79  ///< Override from GSmtp::NewMessage.
80 
81  G::Path contentPath() const ;
82  ///< Returns the path of the content file.
83 
84 private:
85  FileStore & m_store ;
86  unsigned long m_seq ;
87  std::string m_from ;
88  std::string m_from_auth_in ;
89  std::string m_from_auth_out ;
90  G::StringArray m_to_local ;
91  G::StringArray m_to_remote ;
92  unique_ptr<std::ostream> m_content ;
93  G::Path m_content_path ;
94  G::Path m_envelope_path_0 ;
95  G::Path m_envelope_path_1 ;
96  bool m_committed ;
97  bool m_eight_bit ;
98  bool m_saved ;
99  size_t m_size ;
100  size_t m_max_size ;
101 
102 private:
103  void cleanup() ;
104  void flushContent() ;
105  void discardContent() ;
106  bool commitEnvelope() ;
107  void deleteContent() ;
108  void deleteEnvelope() ;
109  static bool isEightBit( const char * , size_t ) ;
110  static const char * crlf() ;
111  static std::string xnormalise( const std::string & ) ;
112  bool saveEnvelope( const std::string & auth_id , const std::string & peer_socket_address ,
113  const std::string & peer_certificate ) const ;
114  void writeEnvelope( std::ostream & , const std::string & where ,
115  const std::string & auth_id , const std::string & peer_socket_address ,
116  const std::string & peer_certificate ) const ;
117  void deliver( const G::StringArray & , const G::Path & , const G::Path & , const G::Path & ) ;
118 } ;
119 
120 #endif
virtual void commit(bool strict) override
Override from GSmtp::NewMessage.
Definition: gnewfile.cpp:110
G::Path contentPath() const
Returns the path of the content file.
Definition: gnewfile.cpp:276
SMTP and message-store classes.
Definition: gadminserver.h:39
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
virtual ~NewFile()
Destructor.
Definition: gnewfile.cpp:63
NewFile(FileStore &store, const std::string &from, const std::string &from_auth_in, const std::string &from_auth_out=std::string(), size_t max_size=0UL)
Constructor. The FileStore reference is kept.
Definition: gnewfile.cpp:38
virtual unsigned long id() const override
Override from GSmtp::NewMessage.
Definition: gnewfile.cpp:271
virtual void addTo(const std::string &to, bool local) override
Override from GSmtp::NewMessage.
Definition: gnewfile.cpp:118
A concrete derived class implementing the NewMessage interface.
Definition: gnewfile.h:42
virtual bool addText(const char *, size_t) override
Override from GSmtp::NewMessage.
Definition: gnewfile.cpp:126
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:58
virtual std::string prepare(const std::string &auth_id, const std::string &peer_socket_address, const std::string &peer_certificate) override
Override from GSmtp::NewMessage.
Definition: gnewfile.cpp:86
An abstract class to allow the creation of a new message in the message store.
Definition: gnewmessage.h:38
A Path object represents a file system path.
Definition: gpath.h:72