19 |
|
} |
20 |
|
} |
21 |
|
|
22 |
+ |
Poller::~Poller() |
23 |
+ |
{ |
24 |
+ |
if (!nodelete) |
25 |
+ |
{ |
26 |
+ |
session->expunge(); |
27 |
+ |
} |
28 |
+ |
} |
29 |
+ |
|
30 |
|
void Poller::poll(bool nodelete, const string& file) |
31 |
|
{ |
32 |
|
this->nodelete = nodelete; |
34 |
|
|
35 |
|
load(); |
36 |
|
|
37 |
< |
// |
37 |
> |
ballots(); |
38 |
> |
approvals(); |
39 |
|
|
40 |
< |
// save(); |
40 |
> |
save(); |
41 |
|
} |
42 |
|
|
43 |
|
void Poller::load() |
45 |
|
ifstream fin(file.c_str()); |
46 |
|
if (!fin.is_open()) |
47 |
|
{ |
48 |
+ |
fin.clear(); |
49 |
+ |
|
50 |
|
ofstream fout(file.c_str()); |
51 |
|
|
52 |
|
fout << "_find_\n" |
73 |
|
fin.open(file.c_str()); |
74 |
|
} |
75 |
|
|
76 |
< |
do |
76 |
> |
while (fin.good()) |
77 |
|
{ |
78 |
|
enum { FIND, HELP, IMPROVE } type; |
79 |
|
string vote; |
80 |
|
unsigned count; |
81 |
|
string text; |
82 |
|
|
83 |
< |
getline(fin, vote, '='); |
83 |
> |
fin.peek() != '_' ? getline(fin, vote, '=') : getline(fin, vote); |
84 |
|
if (debug) cerr << "vote = " << vote << "\n"; |
85 |
|
|
86 |
|
if (vote == "_find_") |
108 |
|
fin.get(); |
109 |
|
} |
110 |
|
|
111 |
+ |
fin.peek(); |
112 |
+ |
|
113 |
|
switch (type) |
114 |
|
{ |
115 |
|
case FIND: |
196 |
|
break; |
197 |
|
} |
198 |
|
} |
186 |
– |
while (fin.good()); |
199 |
|
|
200 |
|
fin.close(); |
201 |
|
} |
247 |
|
|
248 |
|
fout.close(); |
249 |
|
} |
250 |
+ |
|
251 |
+ |
void Poller::ballots() |
252 |
+ |
{ |
253 |
+ |
session->select('\"' + account.getMailbox() + '\"'); |
254 |
+ |
|
255 |
+ |
stringstream search; |
256 |
+ |
search << session->search(string("ALL HEADER X-Mailer \"WinXPFAQPoll 1.0 ") |
257 |
+ |
+ "(Perl)\" SUBJECT \"Windows XP FAQ | Poll Ballot\" UNDELETED FROM \"" |
258 |
+ |
+ "Windows XP FAQ | Poll\""); |
259 |
+ |
|
260 |
+ |
search.ignore(9); |
261 |
+ |
search.peek(); |
262 |
+ |
|
263 |
+ |
while (search.good()) |
264 |
+ |
{ |
265 |
+ |
unsigned message; |
266 |
+ |
search >> message; |
267 |
+ |
|
268 |
+ |
if (debug) cerr << "message = " << message << "\n"; |
269 |
+ |
messages.push(message); |
270 |
+ |
|
271 |
+ |
search.get(); |
272 |
+ |
search.peek(); |
273 |
+ |
} |
274 |
+ |
|
275 |
+ |
if (!messages.empty()) |
276 |
+ |
{ |
277 |
+ |
unsigned message = messages.front(); |
278 |
+ |
messages.pop(); |
279 |
+ |
|
280 |
+ |
ballot(message); |
281 |
+ |
} |
282 |
+ |
} |
283 |
+ |
|
284 |
+ |
void Poller::ballot(unsigned message) |
285 |
+ |
{ |
286 |
+ |
cout << "Checking message: " << message << "..." << flush; |
287 |
+ |
|
288 |
+ |
ostringstream number; |
289 |
+ |
number << message; |
290 |
+ |
|
291 |
+ |
stringstream buffer; |
292 |
+ |
|
293 |
+ |
buffer << session->fetch(number.str() + " BODY.PEEK[2]"); |
294 |
+ |
|
295 |
+ |
if (session->successful()) |
296 |
+ |
{ |
297 |
+ |
buffer.ignore(string::npos, '\n'); |
298 |
+ |
|
299 |
+ |
bool approved = session->fetch(number.str() + " FLAGS").find("\\Flagge" |
300 |
+ |
+ string("d")) != string::npos; |
301 |
+ |
|
302 |
+ |
while (buffer.peek() != '\n' && buffer.good()) |
303 |
+ |
{ |
304 |
+ |
enum { FIND, HELP, IMPROVE } type; |
305 |
+ |
string vote; |
306 |
+ |
|
307 |
+ |
getline(buffer, vote); |
308 |
+ |
if (debug) cerr << "vote = " << vote << "\n"; |
309 |
+ |
|
310 |
+ |
if (vote == "_find_") |
311 |
+ |
{ |
312 |
+ |
type = FIND; |
313 |
+ |
continue; |
314 |
+ |
} |
315 |
+ |
else if (vote == "_help_") |
316 |
+ |
{ |
317 |
+ |
type = HELP; |
318 |
+ |
continue; |
319 |
+ |
} |
320 |
+ |
else if (vote == "_improve_") |
321 |
+ |
{ |
322 |
+ |
type = IMPROVE; |
323 |
+ |
continue; |
324 |
+ |
} |
325 |
+ |
|
326 |
+ |
buffer.peek(); |
327 |
+ |
|
328 |
+ |
switch (type) |
329 |
+ |
{ |
330 |
+ |
case FIND: |
331 |
+ |
if (vote == "reply") |
332 |
+ |
{ |
333 |
+ |
find.reply++; |
334 |
+ |
} |
335 |
+ |
else if (vote == "news") |
336 |
+ |
{ |
337 |
+ |
find.news++; |
338 |
+ |
} |
339 |
+ |
else if (vote == "sig") |
340 |
+ |
{ |
341 |
+ |
find.sig++; |
342 |
+ |
} |
343 |
+ |
else if (vote == "search") |
344 |
+ |
{ |
345 |
+ |
find.search++; |
346 |
+ |
} |
347 |
+ |
else if (vote == "link") |
348 |
+ |
{ |
349 |
+ |
find.link++; |
350 |
+ |
} |
351 |
+ |
else if (vote == "browse") |
352 |
+ |
{ |
353 |
+ |
find.browse++; |
354 |
+ |
} |
355 |
+ |
else if (vote == "other") |
356 |
+ |
{ |
357 |
+ |
find.other++; |
358 |
+ |
|
359 |
+ |
string text; |
360 |
+ |
getline(buffer, text); |
361 |
+ |
|
362 |
+ |
if (approved) |
363 |
+ |
{ |
364 |
+ |
find.approved.push_back(text); |
365 |
+ |
} |
366 |
+ |
else |
367 |
+ |
{ |
368 |
+ |
find.approve.push_back(text); |
369 |
+ |
|
370 |
+ |
submit("find", text); |
371 |
+ |
} |
372 |
+ |
} |
373 |
+ |
break; |
374 |
+ |
case HELP: |
375 |
+ |
if (vote == "solved") |
376 |
+ |
{ |
377 |
+ |
help.solved++; |
378 |
+ |
} |
379 |
+ |
else if (vote == "note") |
380 |
+ |
{ |
381 |
+ |
help.note++; |
382 |
+ |
} |
383 |
+ |
else if (vote == "link") |
384 |
+ |
{ |
385 |
+ |
help.link++; |
386 |
+ |
} |
387 |
+ |
else if (vote == "news") |
388 |
+ |
{ |
389 |
+ |
help.news++; |
390 |
+ |
} |
391 |
+ |
else if (vote == "lazy") |
392 |
+ |
{ |
393 |
+ |
help.lazy++; |
394 |
+ |
} |
395 |
+ |
break; |
396 |
+ |
case IMPROVE: |
397 |
+ |
if (vote == "nothing") |
398 |
+ |
{ |
399 |
+ |
improve.nothing++; |
400 |
+ |
} |
401 |
+ |
else if (vote == "links") |
402 |
+ |
{ |
403 |
+ |
improve.links++; |
404 |
+ |
} |
405 |
+ |
else if (vote == "suggest") |
406 |
+ |
{ |
407 |
+ |
improve.suggest++; |
408 |
+ |
|
409 |
+ |
string text; |
410 |
+ |
getline(buffer, text); |
411 |
+ |
|
412 |
+ |
if (approved) |
413 |
+ |
{ |
414 |
+ |
improve.approved.push_back(text); |
415 |
+ |
} |
416 |
+ |
else |
417 |
+ |
{ |
418 |
+ |
improve.approve.push_back(text); |
419 |
+ |
|
420 |
+ |
submit("improve", text); |
421 |
+ |
} |
422 |
+ |
} |
423 |
+ |
break; |
424 |
+ |
} |
425 |
+ |
} |
426 |
+ |
|
427 |
+ |
session->store(number.str() + " +FLAGS (\\Deleted)"); |
428 |
+ |
|
429 |
+ |
cout << "done.\n"; |
430 |
+ |
} |
431 |
+ |
else |
432 |
+ |
{ |
433 |
+ |
cout << "cancelled.\n"; |
434 |
+ |
} |
435 |
+ |
|
436 |
+ |
if (!messages.empty()) |
437 |
+ |
{ |
438 |
+ |
unsigned message = messages.front(); |
439 |
+ |
messages.pop(); |
440 |
+ |
|
441 |
+ |
ballot(message); |
442 |
+ |
} |
443 |
+ |
} |
444 |
+ |
|
445 |
+ |
void Poller::submit(const string& type, const string& text) |
446 |
+ |
{ |
447 |
+ |
// |
448 |
+ |
} |
449 |
+ |
|
450 |
+ |
void Poller::approvals() |
451 |
+ |
{ |
452 |
+ |
// |
453 |
+ |
} |