E-MailRelay
gmessagestore.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2023 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 gmessagestore.h
19///
20
21#ifndef G_SMTP_MESSAGE_STORE_H
22#define G_SMTP_MESSAGE_STORE_H
23
24#include "gdef.h"
25#include "gexception.h"
26#include "gslot.h"
27#include "gstringarray.h"
28#include "gpath.h"
29#include <memory>
30
31namespace GStore
32{
33 class NewMessage ;
34 class StoredMessage ;
35 class MessageId ;
36 class MessageStore ;
37}
38
39//| \class GStore::MessageId
40/// A somewhat opaque identifer for a GStore::MessageStore message id.
41///
43{
44public:
45 explicit MessageId( const std::string & ) ;
46 ///< Constructor.
47
48 static MessageId none() ;
49 ///< Returns an in-valid() id.
50
51 bool valid() const ;
52 ///< Returns true if valid.
53
54 std::string str() const ;
55 ///< Returns the id string.
56
57public:
58 explicit MessageId( int ) = delete ;
59
60private:
61 MessageId() = default ;
62
63private:
64 std::string m_s ;
65} ;
66
67//| \class GStore::MessageStore
68/// A class which allows SMTP messages to be stored and retrieved.
69///
70/// \see GStore::NewMessage, GStore::StoredMessage, GStore::ProtocolMessage
71///
73{
74public:
75 struct SmtpInfo /// Information on the SMTP options used when submitted.
76 {
77 std::string auth ; // AUTH=
78 std::string body ; // BODY=
79 bool utf8address {false} ; // beyond ascii
80 } ;
81 enum class BodyType
82 {
83 Unknown = -1 ,
84 SevenBit ,
85 EightBitMime , // RFC-1652
86 BinaryMime // RFC-3030
87 } ;
88 struct Iterator /// A base class for GStore::MessageStore iterators.
89 {
90 virtual std::unique_ptr<StoredMessage> next() = 0 ;
91 ///< Returns the next stored message or a null pointer.
92
93 virtual ~Iterator() = default ;
94 ///< Destructor.
95 } ;
96
97 virtual ~MessageStore() = default ;
98 ///< Destructor.
99
100 virtual std::unique_ptr<NewMessage> newMessage( const std::string & from ,
101 const SmtpInfo & smtp_info , const std::string & from_auth_out ) = 0 ;
102 ///< Creates a new message.
103
104 virtual bool empty() const = 0 ;
105 ///< Returns true if the message store is empty.
106
107 virtual std::string location( const MessageId & ) const = 0 ;
108 ///< Returns the location of the given message.
109
110 virtual std::unique_ptr<StoredMessage> get( const MessageId & id ) = 0 ;
111 ///< Pulls the specified message out of the store. Throws
112 ///< execptions on error.
113
114 virtual std::unique_ptr<Iterator> iterator( bool lock ) = 0 ;
115 ///< Returns an iterator for stored messages.
116 ///<
117 ///< If 'lock' is true then stored messages returned by the
118 ///< iterator are locked. They can then be deleted by
119 ///< StoredMessage::destroy() once they have been fully
120 ///< processed.
121
122 virtual std::vector<MessageId> ids() = 0 ;
123 ///< Returns a list of spooled message ids (excluding new or
124 ///< locked messages).
125
126 virtual std::vector<MessageId> failures() = 0 ;
127 ///< Returns a list of failed message ids.
128
129 virtual void unfailAll() = 0 ;
130 ///< Unfails all failed messages.
131
132 virtual void rescan() = 0 ;
133 ///< Requests that a messageStoreRescanSignal() is emitted.
134
135 virtual void updated() = 0 ;
136 ///< Called by associated classes to indicate that the
137 ///< store has changed. Implementations must cause the
138 ///< messageStoreUpdateSignal() signal to be emitted.
139
141 ///< Provides a signal which is emitted when something might
142 ///< have changed in the store.
143
144 virtual G::Slot::Signal<> & messageStoreRescanSignal() noexcept = 0 ;
145 ///< Provides a signal which is emitted when rescan()
146 ///< is called.
147} ;
148
149namespace GStore
150{
151 std::unique_ptr<StoredMessage> operator++( std::shared_ptr<MessageStore::Iterator> & iter ) ;
152}
153
154inline GStore::MessageId::MessageId( const std::string & s ) : m_s(s) {}
156inline std::string GStore::MessageId::str() const { return m_s ; }
157inline bool GStore::MessageId::valid() const { return !m_s.empty() ; }
158
159#endif
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
static MessageId none()
Returns an in-valid() id.
bool valid() const
Returns true if valid.
std::string str() const
Returns the id string.
MessageId(const std::string &)
Constructor.
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:73
virtual std::unique_ptr< Iterator > iterator(bool lock)=0
Returns an iterator for stored messages.
virtual void unfailAll()=0
Unfails all failed messages.
virtual void rescan()=0
Requests that a messageStoreRescanSignal() is emitted.
virtual std::unique_ptr< NewMessage > newMessage(const std::string &from, const SmtpInfo &smtp_info, const std::string &from_auth_out)=0
Creates a new message.
virtual std::vector< MessageId > ids()=0
Returns a list of spooled message ids (excluding new or locked messages).
virtual ~MessageStore()=default
Destructor.
virtual std::vector< MessageId > failures()=0
Returns a list of failed message ids.
virtual G::Slot::Signal & messageStoreRescanSignal() noexcept=0
Provides a signal which is emitted when rescan() is called.
virtual G::Slot::Signal & messageStoreUpdateSignal() noexcept=0
Provides a signal which is emitted when something might have changed in the store.
virtual std::unique_ptr< StoredMessage > get(const MessageId &id)=0
Pulls the specified message out of the store.
virtual bool empty() const =0
Returns true if the message store is empty.
virtual void updated()=0
Called by associated classes to indicate that the store has changed.
virtual std::string location(const MessageId &) const =0
Returns the location of the given message.
Message store classes.
Definition: genvelope.cpp:30
Low-level classes.
Definition: garg.h:30
A base class for GStore::MessageStore iterators.
Definition: gmessagestore.h:89
virtual ~Iterator()=default
Destructor.
virtual std::unique_ptr< StoredMessage > next()=0
Returns the next stored message or a null pointer.
Information on the SMTP options used when submitted.
Definition: gmessagestore.h:76
A slot holder, with connect() and emit() methods.
Definition: gslot.h:184