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
31 namespace 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///
42 class GSmtp::StoredMessage
43{
44 public:
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///
109 class GSmtp::StoredMessageStub : public StoredMessage
110{
111 public:
112 StoredMessageStub() ;
113 ///< Constructor.
114
115 ~StoredMessageStub() override ;
116 ///< Destructor.
117
118 private: // 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
136 public:
137 StoredMessageStub( const StoredMessageStub & ) = delete ;
138 StoredMessageStub( StoredMessageStub && ) = delete ;
139 void operator=( const StoredMessageStub & ) = delete ;
140 void operator=( StoredMessageStub && ) = delete ;
141
142 private:
143 G::StringArray m_to_list ;
144 std::ifstream m_content_stream ;
145} ;
146
147 inline GSmtp::MessageId GSmtp::StoredMessageStub::id() const { return MessageId::none() ; }
148 inline std::string GSmtp::StoredMessageStub::location() const { return std::string() ; }
149 inline std::string GSmtp::StoredMessageStub::from() const { return std::string() ; }
150 inline std::string GSmtp::StoredMessageStub::to( std::size_t ) const { return std::string() ; }
151 inline std::size_t GSmtp::StoredMessageStub::toCount() const { return 0U ; }
152 inline std::istream & GSmtp::StoredMessageStub::contentStream() { return m_content_stream ; }
153 inline void GSmtp::StoredMessageStub::close() {}
154 inline std::string GSmtp::StoredMessageStub::reopen() { return std::string() ; }
155 inline void GSmtp::StoredMessageStub::destroy() {}
156 inline void GSmtp::StoredMessageStub::edit( const G::StringArray & ) {}
157 inline void GSmtp::StoredMessageStub::fail( const std::string & , int ) {}
158 inline void GSmtp::StoredMessageStub::unfail() {}
159 inline int GSmtp::StoredMessageStub::eightBit() const { return false ; }
160 inline std::string GSmtp::StoredMessageStub::authentication() const { return std::string() ; }
161 inline std::string GSmtp::StoredMessageStub::fromAuthIn() const { return std::string() ; }
162 inline std::string GSmtp::StoredMessageStub::fromAuthOut() const { return std::string() ; }
163
164#endif
GSmtp::MessageId
A somewhat opaque identifer for a MessageStore message.
Definition: gmessagestore.h:43
GSmtp::MessageId::none
static MessageId none()
Returns an in-valid() id.
Definition: gmessagestore.h:152
GSmtp::StoredMessageStub
A StoredMessage class that does nothing and can be used as a placeholder.
Definition: gstoredmessage.h:110
GSmtp::StoredMessageStub::StoredMessageStub
StoredMessageStub()
Constructor.
GSmtp::StoredMessageStub::~StoredMessageStub
~StoredMessageStub() override
Destructor.
GSmtp::StoredMessage
An abstract interface for messages which have come from the store.
Definition: gstoredmessage.h:43
GSmtp::StoredMessage::eightBit
virtual int eightBit() const =0
Returns 1 if the message content (header+body) contains a character with the most significant bit set...
GSmtp::StoredMessage::id
virtual MessageId id() const =0
Returns the message identifier.
GSmtp::StoredMessage::destroy
virtual void destroy()=0
Deletes the message within the store.
GSmtp::StoredMessage::~StoredMessage
virtual ~StoredMessage()=default
Destructor.
GSmtp::StoredMessage::contentStream
virtual std::istream & contentStream()=0
Returns a reference to the content stream.
GSmtp::StoredMessage::edit
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.
GSmtp::StoredMessage::reopen
virtual std::string reopen()=0
Reverses a close(), returning the empty string on success or an error reason.
GSmtp::StoredMessage::fail
virtual void fail(const std::string &reason, int reason_code)=0
Marks the message as failed within the store.
GSmtp::StoredMessage::from
virtual std::string from() const =0
Returns the envelope 'from' field.
GSmtp::StoredMessage::to
virtual std::string to(std::size_t) const =0
Returns the requested envelope non-local recipient or the empty string if out of range.
GSmtp::StoredMessage::fromAuthIn
virtual std::string fromAuthIn() const =0
Returns the incoming "mail from" auth parameter, either empty, xtext-encoded or "<>".
GSmtp::StoredMessage::location
virtual std::string location() const =0
Returns the message location.
GSmtp::StoredMessage::toCount
virtual std::size_t toCount() const =0
Returns the number of non-local recipients.
GSmtp::StoredMessage::fromAuthOut
virtual std::string fromAuthOut() const =0
Returns the outgoing "mail from" auth parameter, either empty, xtext-encoded or "<>".
GSmtp::StoredMessage::authentication
virtual std::string authentication() const =0
Returns the original session authentication id.
GSmtp::StoredMessage::unfail
virtual void unfail()=0
Marks the message as unfailed within the store.
GSmtp::StoredMessage::close
virtual void close()=0
Releases the message to allow external editing.
gmessagestore.h
gpath.h
gstrings.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31