E-MailRelay
gmessagestore.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 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 "gsmtp.h"
26 #include "gnewmessage.h"
27 #include "gstoredmessage.h"
28 #include "gexception.h"
29 #include "gslot.h"
30 #include "gstrings.h"
31 #include "gpath.h"
32 
33 namespace GSmtp
34 {
35  class MessageStore ;
36 }
37 
38 /// \class GSmtp::MessageStore
39 /// A class which allows SMTP messages to be stored and retrieved.
40 ///
41 /// \see GSmtp::NewMessage, GSmtp::StoredMessage, GSmtp::ProtocolMessage
42 ///
44 {
45 public:
46  class IteratorImp /// A base class for MessageStore::Iterator implementations.
47  {
48  public: unsigned long m_ref_count ;
49  public: virtual unique_ptr<StoredMessage> next() = 0 ;
50  public: IteratorImp() ;
51  public: virtual ~IteratorImp() ;
52  private: IteratorImp( const IteratorImp & ) ;
53  private: void operator=( const IteratorImp & ) ;
54  } ;
55  class Iterator /// An iterator class for GSmtp::MessageStore.
56  {
57  public: Iterator() ;
58  public: explicit Iterator( IteratorImp * ) ;
59  public: ~Iterator() ;
60  public: Iterator( const Iterator & ) ;
61  public: Iterator & operator=( const Iterator & ) ;
62  public: unique_ptr<StoredMessage> next() ;
63  public: void last() ;
64  private: IteratorImp * m_imp ;
65  } ;
66 
67  static G::Path defaultDirectory() ;
68  ///< Returns a default spool directory, such as "/var/spool/emailrelay".
69  ///< (Typically with an os-specific implementation.)
70 
71  virtual ~MessageStore() ;
72  ///< Destructor.
73 
74  virtual unique_ptr<NewMessage> newMessage( const std::string & from ,
75  const std::string & from_auth_in , const std::string & from_auth_out ) = 0 ;
76  ///< Creates a new message.
77 
78  virtual bool empty() const = 0 ;
79  ///< Returns true if the message store is empty.
80 
81  virtual unique_ptr<StoredMessage> get( unsigned long id ) = 0 ;
82  ///< Pulls the specified message out of the store.
83  ///< Throws execptions on error.
84  ///<
85  ///< See also NewMessage::id().
86  ///<
87  ///< As a side effect some stored messages may be marked as bad,
88  ///< or deleted (if they have no recipients).
89 
90  virtual Iterator iterator( bool lock ) = 0 ;
91  ///< Returns an iterator for stored messages. (Note that copies
92  ///< of iterators share state. For independent iterators call
93  ///< iterator() for each.)
94  ///<
95  ///< If 'lock' is true then stored messages returned by the
96  ///< iterator are locked. Normally they are then processed
97  ///< (using StoredMessage::extractContentStream()) and then
98  ///< deleted (by StoredMessage::destroy()).
99  ///<
100  ///< As a side effect of iteration when 'lock' is true some
101  ///< stored messages may be marked as bad, or get deleted
102  ///< (if they have no recipients).
103 
104  virtual Iterator failures() = 0 ;
105  ///< Returns an iterator for failed messages.
106 
107  virtual void unfailAll() = 0 ;
108  ///< Causes messages marked as failed to be unmarked.
109 
110  virtual void rescan() = 0 ;
111  ///< Requests that a messageStoreRescanSignal() is emitted.
112 
113  virtual void updated() = 0 ;
114  ///< Called by associated classes to indicate that the
115  ///< store has changed. Implementations must cause the
116  ///< messageStoreUpdateSignal() signal to be emitted.
117 
119  ///< Provides a signal which is when something might
120  ///< have changed in the store.
121 
123  ///< Provides a signal which is emitted when iteration
124  ///< finishes and rescan() has been called.
125 
126 private:
127  void operator=( const MessageStore & ) ;
128 } ;
129 
130 #endif
131 
virtual unique_ptr< NewMessage > newMessage(const std::string &from, const std::string &from_auth_in, const std::string &from_auth_out)=0
Creates a new message.
SMTP and message-store classes.
Definition: gadminserver.h:39
virtual G::Slot::Signal0 & messageStoreRescanSignal()=0
Provides a signal which is emitted when iteration finishes and rescan() has been called.
virtual void updated()=0
Called by associated classes to indicate that the store has changed.
virtual bool empty() const =0
Returns true if the message store is empty.
virtual Iterator failures()=0
Returns an iterator for failed messages.
virtual void unfailAll()=0
Causes messages marked as failed to be unmarked.
virtual G::Slot::Signal0 & messageStoreUpdateSignal()=0
Provides a signal which is when something might have changed in the store.
A base class for MessageStore::Iterator implementations.
Definition: gmessagestore.h:46
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:43
static G::Path defaultDirectory()
Returns a default spool directory, such as "/var/spool/emailrelay".
virtual ~MessageStore()
Destructor.
A signal class for zero-parameter callbacks.
Definition: gslot.h:193
virtual void rescan()=0
Requests that a messageStoreRescanSignal() is emitted.
A Path object represents a file system path.
Definition: gpath.h:72
virtual Iterator iterator(bool lock)=0
Returns an iterator for stored messages.
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:55