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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
/*
** Copyright 2002-2011, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_search_H
#define libmail_search_H
#include "libmail_config.h"
#if TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#include "mail.H"
#include "structure.H"
#include "runlater.H"
#include "maildir/maildirsearch.h"
#include <vector>
#include <queue>
#include <time.h>
/////////////////////////////////////////////////////////////////////////
//
// Structure that describes the search criteria
#include <string>
LIBMAIL_START
class searchParams {
public:
searchParams();
~searchParams();
bool searchNot; // If set, the following criteria is negated
enum Criteria {
// Messages with the following flags set:
replied,
deleted,
draft,
unread,
// Header match
from,
to,
cc,
bcc,
subject,
header,
body,
text,
// Internal date:
before,
on,
since,
// Sent date,
sentbefore,
senton,
sentsince,
larger,
smaller
} criteria;
std::string param1; // Header name, or date, or byte size
std::string param2; // Header or content value
std::string charset; // Charset for param2
// All strings use UTF-8
enum Scope {
search_all, // Search all messages
search_marked, // Only those msgs already marked
search_unmarked, // Only those msgs not already marked
search_range // Only messages in the following range:
} scope;
size_t rangeLo, rangeHi; // Used for search_range only
// Serialize/deserialize:
searchParams(std::string);
operator std::string() const;
// INTERNAL USE:
static std::string decode(std::string, std::string &);
static std::string encode(std::string);
};
class searchCallback {
public:
searchCallback();
virtual ~searchCallback();
virtual void success(const std::vector<size_t> &found)=0;
virtual void fail(std::string)=0;
virtual void reportProgress(size_t bytesCompleted,
size_t bytesEstimatedTotal,
size_t messagesCompleted,
size_t messagesEstimatedTotal)=0;
};
class searchOneMessage {
searchCallback &callback;
//
// For searches, mail::callback::success is called with a non-empty string
// if the message matches, an empty string if it does not.
//
searchParams searchInfo;
time_t cmpDate;
mail::ptr<mail::account> ptr;
size_t messageNum;
size_t alreadyCompleted;
std::string uid;
std::string searchCharset;
class Callback : public mail::callback::message {
public:
searchOneMessage *me;
void (searchOneMessage::*nextFunc)();
Callback();
~Callback();
void success(std::string message);
void fail(std::string message);
void messageEnvelopeCallback(size_t messageNumber,
const class envelope
&envelope);
void messageArrivalDateCallback(size_t messageNumber,
time_t datetime);
void messageSizeCallback(size_t messageNumber,
unsigned long size);
void messageStructureCallback(size_t messageNumber,
const class mimestruct
&messageStructure);
void messageTextCallback(size_t n, std::string text);
void reportProgress(size_t bytesCompleted,
size_t bytesEstimatedTotal,
size_t messagesCompleted,
size_t messagesEstimatedTotal);
};
Callback my_callback;
bool searchFlag;
class Searcher : public mail::Search, public mail::iconvert {
int converted(const char *str, size_t n);
public:
using mail::Search::operator bool;
using mail::Search::operator !;
using mail::iconvert::operator();
};
Searcher searchEngine;
mimestruct structureBuffer;
std::queue<mimestruct *> mimeSearch;
std::string headerSearchBuffer;
void doDateCmp(time_t);
public:
searchOneMessage(searchCallback &callbackArg,
searchParams &searchInfoArg,
mail::account *ptrArg,
size_t messageNumArg,
size_t alreadyCompletedArg=0);
~searchOneMessage();
void go();
void search(const envelope &envelope);
void search(time_t internaldate);
void search(unsigned long messageSize);
void search(const mimestruct &structureInfo);
void search(std::string text);
void searchEnvelope(const envelope &envelope);
void searchFwdEnvelope(mimestruct &structureInfo);
private:
bool sanityCheck();
void checkSearch();
void checkNextHeader();
void checkFwdEnvelope();
void success(searchCallback &callback, size_t messageNum,
bool result);
};
class searchMessages : public runLater {
searchCallback &callback;
size_t nextMsgNum;
std::string uid;
std::vector<std::string> successArray;
class Callback : public searchCallback {
public:
searchMessages *me;
Callback();
~Callback();
void fail(std::string message);
void success(const std::vector<size_t> &found);
void reportProgress(size_t bytesCompleted,
size_t bytesEstimatedTotal,
size_t messagesCompleted,
size_t messagesEstimatedTotal);
} search_callback;
ptr<mail::account> server;
searchMessages(searchCallback &callbackArg,
const searchParams &searchInfoArg,
mail::account *ptrArg);
~searchMessages();
searchParams searchInfo, searchInfoCpy;
void nextSearch();
void RunningLater();
public:
friend class Callback;
static void search(searchCallback &callbackArg,
const searchParams &searchInfoArg,
mail::account *ptrArg);
};
LIBMAIL_END
#endif
|