1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/** --------------------------------------------------------------------
* @file maildir.h
* @brief Declaration of the Maildir class.
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
#ifndef maildir_h_included
#define maildir_h_included
#include <string>
#include <vector>
#include <map>
#include "mailbox.h"
#include "maildirmessage.h"
namespace Binc {
static const std::string CACHEFILEVERSION = "1.0.5";
static const std::string UIDVALFILEVERSION = "1.0.5";
//----------------------------------------------------------------------
class Lock {
public:
Lock(const std::string &path);
~Lock();
private:
std::string lock;
};
//------------------------------------------------------------------------
class MaildirIndexItem {
public:
unsigned int uid;
std::string fileName;
};
//------------------------------------------------------------------------
class MaildirIndex
{
private:
std::map<std::string, MaildirIndexItem> idx;
public:
void insert(const std::string &unique, unsigned int uid,
const std::string &fileName = "");
void remove(const std::string &unique);
void clear(void);
void clearFileNames(void);
void clearUids(void);
unsigned int getSize(void) const;
MaildirIndexItem *find(const std::string &unique);
};
//------------------------------------------------------------------------
class Maildir : public Mailbox {
public:
typedef std::map<unsigned int, MaildirMessage> MessageMap;
class iterator : public BaseIterator {
public:
iterator(void);
iterator(Maildir *home, MessageMap::iterator i,
const SequenceSet &bset,
unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE);
iterator(const iterator ©);
~iterator(void);
Message &operator *(void);
void operator ++(void);
bool operator ==(const BaseIterator &) const;
bool operator !=(const BaseIterator &) const;
iterator &operator =(const iterator ©);
void erase(void);
friend class Maildir;
protected:
void reposition(void);
MaildirMessage &curMessage(void);
private:
Maildir *mailbox;
SequenceSet bset;
int mod;
MessageMap::iterator i;
unsigned int uidmax;
unsigned int sqnrmax;
iterator(iterator &external);
};
const std::string getTypeName(void) const;
Mailbox::iterator begin(const SequenceSet &bset, unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const;
Mailbox::iterator end(void) const;
unsigned int getMaxUid(void) const;
unsigned int getMaxSqnr(void) const;
unsigned int getUidValidity(void) const;
unsigned int getUidNext(void) const;
bool getUpdates(bool doscan, unsigned int type,
PendingUpdates &updates, bool forceScan);
const std::string &getPath(void) const;
void setPath(const std::string &path_in);
void bumpUidValidity(const std::string &) const;
unsigned int getStatusID(const std::string &) const;
bool getStatus(const std::string &, Status &) const;
void updateFlags(void);
bool isMailbox(const std::string &) const;
bool isMarked(const std::string &) const;
bool selectMailbox(const std::string &name, const std::string &s_in);
void closeMailbox(void);
void expungeMailbox(void);
bool createMailbox(const std::string &s, mode_t mode, uid_t owner = 0, gid_t group = 0, bool root = false);
bool deleteMailbox(const std::string &s);
Message *createMessage(const std::string &mbox, time_t idate = 0);
bool commitNewMessages(const std::string &mbox);
bool rollBackNewMessages(void);
bool fastCopy(Message &source, Mailbox &desttype, const std::string &destname);
//--
Maildir(void);
~Maildir(void);
friend class Maildir::iterator;
friend class MaildirMessage;
protected:
enum ReadCacheResult {
Ok,
NoCache,
Error
};
ReadCacheResult readCache(void);
bool writeCache(void);
bool scanFileNames(void) const;
enum ScanResult {
Success = 0,
TemporaryError = 1,
PermanentError = 2
};
ScanResult scan(bool forceScan = false);
MaildirMessage *get(const std::string &id);
void add(MaildirMessage &m);
private:
std::vector<MaildirMessage> newMessages;
unsigned int uidvalidity;
unsigned int uidnext;
bool selected;
std::string path;
mutable iterator beginIterator;
mutable iterator endIterator;
mutable bool firstscan;
mutable bool cacheRead;
mutable MaildirIndex index;
mutable MessageMap messages;
mutable unsigned int oldrecent;
mutable unsigned int oldexists;
mutable time_t old_bincimap_cache_st_mtime;
mutable time_t old_bincimap_cache_st_ctime;
mutable time_t old_cur_st_mtime;
mutable time_t old_cur_st_ctime;
mutable time_t old_new_st_mtime;
mutable time_t old_new_st_ctime;
mutable bool mailboxchanged;
};
}
#endif
|