E-MailRelay
gnewmessage.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 gnewmessage.h
19///
20
21#ifndef G_SMTP_NEW_MESSAGE_H
22#define G_SMTP_NEW_MESSAGE_H
23
24#include "gdef.h"
25#include "gmessagestore.h"
26
27namespace GStore
28{
29 class NewMessage ;
30}
31
32//| \class GStore::NewMessage
33/// An abstract class to allow the creation of a new message in
34/// the message store.
35///
36/// \code
37/// auto new_msg = make_unique<NewMessageImp>( envelope_from ) ;
38/// new_msg->addTo( envelope_to_1 ) ;
39/// new_msg->addTo( envelope_to_2 ) ;
40/// for( auto line : content )
41/// new_msg->addContent( line ) ;
42/// new_msg->prepare(...) ;
43/// startFiltering( new_msg ) ;
44/// \endcode
45///
46/// \see GStore::MessageStore
47///
49{
50public:
51 enum class Status
52 {
53 Ok ,
54 TooBig ,
55 Error
56 } ;
57
58 virtual void addTo( const std::string & to , bool local , MessageStore::AddressStyle ) = 0 ;
59 ///< Adds a 'to' address.
60
61 virtual Status addContent( const char * , std::size_t ) = 0 ;
62 ///< Adds a line of content, typically ending with CR-LF.
63 ///< Returns an error enum, but errors accumulate internally
64 ///< and thrown by prepare(). Adding zero bytes in order
65 ///< to test the current status is allowed.
66
67 virtual void prepare( const std::string & session_auth_id ,
68 const std::string & peer_socket_address , const std::string & peer_certificate ) = 0 ;
69 ///< Prepares to store the message in the message store.
70 ///< Throws on error, including any errors that accumulated
71 ///< while adding content.
72
73 virtual void commit( bool throw_on_error ) = 0 ;
74 ///< Commits the prepare()d message to the store and disables
75 ///< the cleanup otherwise performed by the destructor.
76 ///< Either throws or ignores commit errors.
77
78 virtual MessageId id() const = 0 ;
79 ///< Returns the message's unique identifier.
80
81 virtual std::string location() const = 0 ;
82 ///< Returns the message's unique location.
83
84 virtual std::size_t contentSize() const = 0 ;
85 ///< Returns the content size. Returns the maximum size_t value
86 ///< on overflow.
87
88 void addContentLine( const std::string & ) ;
89 ///< A convenience function that calls addContent() taking
90 ///< a string parameter and adding CR-LF.
91
92 virtual ~NewMessage() = default ;
93 ///< Destructor. Rolls back any prepare()d storage
94 ///< if un-commit()ed.
95} ;
96
97#endif
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
An abstract class to allow the creation of a new message in the message store.
Definition: gnewmessage.h:49
virtual void commit(bool throw_on_error)=0
Commits the prepare()d message to the store and disables the cleanup otherwise performed by the destr...
virtual std::string location() const =0
Returns the message's unique location.
virtual ~NewMessage()=default
Destructor.
virtual Status addContent(const char *, std::size_t)=0
Adds a line of content, typically ending with CR-LF.
virtual MessageId id() const =0
Returns the message's unique identifier.
virtual std::size_t contentSize() const =0
Returns the content size.
void addContentLine(const std::string &)
A convenience function that calls addContent() taking a string parameter and adding CR-LF.
Definition: gnewmessage.cpp:26
virtual void prepare(const std::string &session_auth_id, const std::string &peer_socket_address, const std::string &peer_certificate)=0
Prepares to store the message in the message store.
virtual void addTo(const std::string &to, bool local, MessageStore::AddressStyle)=0
Adds a 'to' address.
Message store classes.
Definition: genvelope.cpp:30