E-MailRelay
gstoredmessage.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 gstoredmessage.h
19///
20
21#ifndef G_SMTP_STORED_MESSAGE_H
22#define G_SMTP_STORED_MESSAGE_H
23
24#include "gdef.h"
25#include "gmessagestore.h"
26#include "gstrings.h"
27#include "gpath.h"
28#include <iostream>
29#include <fstream>
30
31namespace GSmtp
32{
33 class MessageId ;
34 class StoredMessage ;
35 class StoredMessageStub ;
36}
37
38//| \class GSmtp::StoredMessage
39/// An abstract interface for messages which have come from the store.
40/// \see GSmtp::MessageStore, GSmtp::MessageStore::get()
41///
43{
44public:
45 virtual MessageId id() const = 0 ;
46 ///< Returns the message identifier.
47
48 virtual std::string location() const = 0 ;
49 ///< Returns the message location.
50
51 virtual std::string from() const = 0 ;
52 ///< Returns the envelope 'from' field.
53
54 virtual std::string to( std::size_t ) const = 0 ;
55 ///< Returns the requested envelope non-local recipient
56 ///< or the empty string if out of range.
57
58 virtual std::size_t toCount() const = 0 ;
59 ///< Returns the number of non-local recipients.
60
61 virtual std::istream & contentStream() = 0 ;
62 ///< Returns a reference to the content stream.
63
64 virtual void close() = 0 ;
65 ///< Releases the message to allow external editing.
66
67 virtual std::string reopen() = 0 ;
68 ///< Reverses a close(), returning the empty string
69 ///< on success or an error reason.
70
71 virtual void destroy() = 0 ;
72 ///< Deletes the message within the store.
73
74 virtual void edit( const G::StringArray & new_to_list ) = 0 ;
75 ///< Edits the message by updating the list of
76 ///< non-local recipients to the given non-empty list.
77
78 virtual void fail( const std::string & reason , int reason_code ) = 0 ;
79 ///< Marks the message as failed within the store.
80
81 virtual void unfail() = 0 ;
82 ///< Marks the message as unfailed within the store.
83
84 virtual int eightBit() const = 0 ;
85 ///< Returns 1 if the message content (header+body)
86 ///< contains a character with the most significant
87 ///< bit set, or 0 if no such characters, or -1
88 ///< if unknown.
89
90 virtual std::string authentication() const = 0 ;
91 ///< Returns the original session authentication id.
92
93 virtual std::string fromAuthIn() const = 0 ;
94 ///< Returns the incoming "mail from" auth parameter,
95 ///< either empty, xtext-encoded or "<>".
96
97 virtual std::string fromAuthOut() const = 0 ;
98 ///< Returns the outgoing "mail from" auth parameter,
99 ///< either empty, xtext-encoded or "<>".
100
101 virtual ~StoredMessage() = default ;
102 ///< Destructor.
103} ;
104
105//| \class GSmtp::StoredMessageStub
106/// A StoredMessage class that does nothing and can be used as
107/// a placeholder.
108///
110{
111public:
113 ///< Constructor.
114
116 ///< Destructor.
117
118private: // overrides
119 MessageId id() const override ;
120 std::string location() const override ;
121 std::string from() const override ;
122 std::string to( std::size_t ) const override ;
123 std::size_t toCount() const override ;
124 std::istream & contentStream() override ;
125 void close() override ;
126 std::string reopen() override ;
127 void destroy() override ;
128 void edit( const G::StringArray & ) override ;
129 void fail( const std::string & reason , int reason_code ) override ;
130 void unfail() override ;
131 int eightBit() const override ;
132 std::string authentication() const override ;
133 std::string fromAuthIn() const override ;
134 std::string fromAuthOut() const override ;
135
136public:
137 StoredMessageStub( const StoredMessageStub & ) = delete ;
138 StoredMessageStub( StoredMessageStub && ) = delete ;
139 void operator=( const StoredMessageStub & ) = delete ;
140 void operator=( StoredMessageStub && ) = delete ;
141
142private:
143 G::StringArray m_to_list ;
144 std::ifstream m_content_stream ;
145} ;
146
147inline GSmtp::MessageId GSmtp::StoredMessageStub::id() const { return MessageId::none() ; }
148inline std::string GSmtp::StoredMessageStub::location() const { return std::string() ; }
149inline std::string GSmtp::StoredMessageStub::from() const { return std::string() ; }
150inline std::string GSmtp::StoredMessageStub::to( std::size_t ) const { return std::string() ; }
151inline std::size_t GSmtp::StoredMessageStub::toCount() const { return 0U ; }
152inline std::istream & GSmtp::StoredMessageStub::contentStream() { return m_content_stream ; }
153inline void GSmtp::StoredMessageStub::close() {}
154inline std::string GSmtp::StoredMessageStub::reopen() { return std::string() ; }
155inline void GSmtp::StoredMessageStub::destroy() {}
156inline void GSmtp::StoredMessageStub::edit( const G::StringArray & ) {}
157inline void GSmtp::StoredMessageStub::fail( const std::string & , int ) {}
158inline void GSmtp::StoredMessageStub::unfail() {}
159inline int GSmtp::StoredMessageStub::eightBit() const { return false ; }
160inline std::string GSmtp::StoredMessageStub::authentication() const { return std::string() ; }
161inline std::string GSmtp::StoredMessageStub::fromAuthIn() const { return std::string() ; }
162inline std::string GSmtp::StoredMessageStub::fromAuthOut() const { return std::string() ; }
163
164#endif
A somewhat opaque identifer for a MessageStore message.
Definition: gmessagestore.h:43
static MessageId none()
Returns an in-valid() id.
A StoredMessage class that does nothing and can be used as a placeholder.
StoredMessageStub()
Constructor.
~StoredMessageStub() override
Destructor.
An abstract interface for messages which have come from the store.
virtual int eightBit() const =0
Returns 1 if the message content (header+body) contains a character with the most significant bit set...
virtual MessageId id() const =0
Returns the message identifier.
virtual void destroy()=0
Deletes the message within the store.
virtual ~StoredMessage()=default
Destructor.
virtual std::istream & contentStream()=0
Returns a reference to the content stream.
virtual void edit(const G::StringArray &new_to_list)=0
Edits the message by updating the list of non-local recipients to the given non-empty list.
virtual std::string reopen()=0
Reverses a close(), returning the empty string on success or an error reason.
virtual void fail(const std::string &reason, int reason_code)=0
Marks the message as failed within the store.
virtual std::string from() const =0
Returns the envelope 'from' field.
virtual std::string to(std::size_t) const =0
Returns the requested envelope non-local recipient or the empty string if out of range.
virtual std::string fromAuthIn() const =0
Returns the incoming "mail from" auth parameter, either empty, xtext-encoded or "<>".
virtual std::string location() const =0
Returns the message location.
virtual std::size_t toCount() const =0
Returns the number of non-local recipients.
virtual std::string fromAuthOut() const =0
Returns the outgoing "mail from" auth parameter, either empty, xtext-encoded or "<>".
virtual std::string authentication() const =0
Returns the original session authentication id.
virtual void unfail()=0
Marks the message as unfailed within the store.
virtual void close()=0
Releases the message to allow external editing.
SMTP and message-store classes.
Definition: gadminserver.h:39
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31