19 |
|
} |
20 |
|
} |
21 |
|
|
22 |
< |
void Poller::poll(bool nodelete, const string& file) |
22 |
> |
Poller::~Poller() |
23 |
> |
{ |
24 |
> |
if (!nodelete) |
25 |
> |
{ |
26 |
> |
session->expunge(); |
27 |
> |
} |
28 |
> |
} |
29 |
> |
|
30 |
> |
void Poller::poll(bool nodelete, const string& file, bool approve) |
31 |
|
{ |
32 |
|
this->nodelete = nodelete; |
33 |
|
this->file = file; |
34 |
|
|
35 |
|
load(); |
36 |
|
|
37 |
< |
ballots(); |
38 |
< |
approvals(); |
37 |
> |
session->select('\"' + account.getMailbox() + '\"'); |
38 |
> |
|
39 |
> |
if (!approve) |
40 |
> |
{ |
41 |
> |
ballots(); |
42 |
> |
} |
43 |
> |
else |
44 |
> |
{ |
45 |
> |
approvals(); |
46 |
> |
} |
47 |
|
|
48 |
|
save(); |
49 |
|
} |
53 |
|
ifstream fin(file.c_str()); |
54 |
|
if (!fin.is_open()) |
55 |
|
{ |
56 |
+ |
fin.clear(); |
57 |
+ |
|
58 |
|
ofstream fout(file.c_str()); |
59 |
|
|
60 |
|
fout << "_find_\n" |
81 |
|
fin.open(file.c_str()); |
82 |
|
} |
83 |
|
|
84 |
< |
do |
84 |
> |
while (fin.good()) |
85 |
|
{ |
86 |
|
enum { FIND, HELP, IMPROVE } type; |
87 |
|
string vote; |
88 |
|
unsigned count; |
89 |
|
string text; |
90 |
|
|
91 |
< |
getline(fin, vote, '='); |
91 |
> |
fin.peek() != '_' ? getline(fin, vote, '=') : getline(fin, vote); |
92 |
|
if (debug) cerr << "vote = " << vote << "\n"; |
93 |
|
|
94 |
|
if (vote == "_find_") |
116 |
|
fin.get(); |
117 |
|
} |
118 |
|
|
119 |
+ |
if (fin.peek() == EOF) fin.get(); |
120 |
+ |
|
121 |
|
switch (type) |
122 |
|
{ |
123 |
|
case FIND: |
204 |
|
break; |
205 |
|
} |
206 |
|
} |
187 |
– |
while (fin.good()); |
207 |
|
|
208 |
|
fin.close(); |
209 |
|
} |
258 |
|
|
259 |
|
void Poller::ballots() |
260 |
|
{ |
242 |
– |
session->select('\"' + account.getMailbox() + '\"'); |
243 |
– |
|
261 |
|
stringstream search; |
262 |
|
search << session->search(string("ALL HEADER X-Mailer \"WinXPFAQPoll 1.0 ") |
263 |
< |
+ "(Perl)\" SUBJECT \"Windows XP FAQ | Poll Ballot\" UNDELETED FROM \"" |
264 |
< |
+ "Windows XP FAQ | Poll\" HEADER \"X-WinXPFAQPoll-Post-Host\" * HEADE" |
248 |
< |
+ "R \"X-WinXPFAQPoll-Post-Agent\" *"); |
263 |
> |
+ "(Perl)\" SUBJECT \"Windows XP FAQ | Poll Ballot\" FROM \"Windows XP" |
264 |
> |
+ " FAQ | Poll\""); |
265 |
|
|
266 |
< |
string junk; |
267 |
< |
|
252 |
< |
getline(search, junk, ' '); |
253 |
< |
getline(search, junk, ' '); |
266 |
> |
search.ignore(9); |
267 |
> |
search.peek(); |
268 |
|
|
269 |
|
while (search.good()) |
270 |
|
{ |
271 |
|
unsigned message; |
272 |
|
search >> message; |
259 |
– |
search.get(); |
273 |
|
|
274 |
|
if (debug) cerr << "message = " << message << "\n"; |
275 |
|
messages.push(message); |
276 |
+ |
|
277 |
+ |
search.get(); |
278 |
+ |
search.peek(); |
279 |
|
} |
280 |
|
|
281 |
|
if (!messages.empty()) |
286 |
|
ballot(message); |
287 |
|
} |
288 |
|
|
289 |
< |
if (!nodelete) |
289 |
> |
if (submits.size() > 0) |
290 |
|
{ |
291 |
< |
session->expunge(); |
291 |
> |
cout << "Sending submits..." << flush; |
292 |
> |
|
293 |
> |
for (unsigned index = 0; index < submits.size(); index++) |
294 |
> |
{ |
295 |
> |
submit(submits[index].first, submits[index].second); |
296 |
> |
} |
297 |
> |
|
298 |
> |
submits.clear(); |
299 |
> |
|
300 |
> |
cout << "done.\n"; |
301 |
|
} |
302 |
|
} |
303 |
|
|
305 |
|
{ |
306 |
|
cout << "Checking message: " << message << "..." << flush; |
307 |
|
|
308 |
< |
char number[32 + 1]; |
309 |
< |
sprintf(number, "%u", message); |
308 |
> |
ostringstream number; |
309 |
> |
number << message; |
310 |
|
|
311 |
|
stringstream buffer; |
312 |
|
|
313 |
< |
buffer << session->fetch(string(number) + " BODY.PEEK[2]"); |
313 |
> |
buffer << session->fetch(number.str() + " BODY.PEEK[2]"); |
314 |
|
|
315 |
< |
if (session->successful()) |
315 |
> |
if (session->successful() && session->fetch(number.str() + " FLAGS").find( |
316 |
> |
"\\Deleted") == string::npos) |
317 |
|
{ |
318 |
< |
bool approved = session->fetch(string(number) + " FLAGS").find("\\Flag" |
293 |
< |
+ string("ged")) != string::npos; |
318 |
> |
buffer.ignore(string::npos, '\n'); |
319 |
|
|
320 |
< |
do |
320 |
> |
bool approved = session->fetch(number.str() + " FLAGS").find("\\Flagge" |
321 |
> |
+ string("d")) != string::npos; |
322 |
> |
|
323 |
> |
while (buffer.peek() != '\n' && buffer.good()) |
324 |
|
{ |
325 |
|
enum { FIND, HELP, IMPROVE } type; |
326 |
|
string vote; |
344 |
|
continue; |
345 |
|
} |
346 |
|
|
347 |
+ |
buffer.peek(); |
348 |
+ |
|
349 |
|
switch (type) |
350 |
|
{ |
351 |
|
case FIND: |
377 |
|
{ |
378 |
|
find.other++; |
379 |
|
|
380 |
< |
// |
380 |
> |
string text; |
381 |
> |
getline(buffer, text); |
382 |
> |
|
383 |
> |
if (approved) |
384 |
> |
{ |
385 |
> |
find.approved.push_back(text); |
386 |
> |
} |
387 |
> |
else |
388 |
> |
{ |
389 |
> |
find.approve.push_back(text); |
390 |
> |
|
391 |
> |
submits.push_back(pair<string, string>("find", text)); |
392 |
> |
} |
393 |
|
} |
394 |
|
break; |
395 |
|
case HELP: |
427 |
|
{ |
428 |
|
improve.suggest++; |
429 |
|
|
430 |
< |
// |
430 |
> |
string text; |
431 |
> |
getline(buffer, text); |
432 |
> |
|
433 |
> |
if (approved) |
434 |
> |
{ |
435 |
> |
improve.approved.push_back(text); |
436 |
> |
} |
437 |
> |
else |
438 |
> |
{ |
439 |
> |
improve.approve.push_back(text); |
440 |
> |
|
441 |
> |
submits.push_back(pair<string, string>("improve", |
442 |
> |
text)); |
443 |
> |
} |
444 |
|
} |
445 |
|
break; |
446 |
|
} |
447 |
|
} |
448 |
< |
while (buffer.good()); |
448 |
> |
|
449 |
> |
session->store(number.str() + " +FLAGS (\\Deleted)"); |
450 |
|
|
451 |
|
cout << "done.\n"; |
452 |
|
} |
464 |
|
} |
465 |
|
} |
466 |
|
|
467 |
+ |
void Poller::submit(const string& type, const string& text) |
468 |
+ |
{ |
469 |
+ |
ostringstream message; |
470 |
+ |
|
471 |
+ |
message << "From: \"Windows XP FAQ | Poll\" <" << account.getEmail() |
472 |
+ |
<< ">\n" |
473 |
+ |
<< "To: \"" << account.getName() << "\" <" << account.getEmail() |
474 |
+ |
<< ">\n" |
475 |
+ |
<< "Subject: Windows XP FAQ | Poll Submit\n" |
476 |
+ |
<< "Content-Type: text/plain charset=\"us-ascii\"\n" |
477 |
+ |
<< "Content-Transfer-Encoding: 7bit\n" |
478 |
+ |
<< "X-Mailer: WinXPFAQPoll 1.0\n" |
479 |
+ |
<< "X-WinXPFAQPoll-Submit-Type: " << type << "\n" |
480 |
+ |
<< "X-WinXPFAQPoll-Submit-Text: " << text << "\n\n"; |
481 |
+ |
|
482 |
+ |
if (type == "find") |
483 |
+ |
{ |
484 |
+ |
message << "How did you find this page?\n" |
485 |
+ |
<< " I arrived here by entirely different means:\n"; |
486 |
+ |
} |
487 |
+ |
else if (type == "improve") |
488 |
+ |
{ |
489 |
+ |
message << "How could I improve this site?\n" |
490 |
+ |
<< " I have my own completely insane suggestion:\n"; |
491 |
+ |
} |
492 |
+ |
|
493 |
+ |
message << " " << text << "\n\n" |
494 |
+ |
<< "Flag this message to approve the voter\'s possibly objectionable\n" |
495 |
+ |
<< "input or delete it to disapprove.\n\n" |
496 |
+ |
<< "This message will be marked deleted when it is processed.\n"; |
497 |
+ |
|
498 |
+ |
ostringstream length; |
499 |
+ |
length << (message.str().length() + 16); |
500 |
+ |
|
501 |
+ |
session->append('\"' + account.getMailbox() + "\" {" + length.str() + '}', |
502 |
+ |
message.str()); |
503 |
+ |
|
504 |
+ |
session->noop(); |
505 |
+ |
} |
506 |
+ |
|
507 |
|
void Poller::approvals() |
508 |
|
{ |
509 |
< |
// |
509 |
> |
session->check(); |
510 |
|
|
511 |
< |
if (!nodelete) |
511 |
> |
unsigned index; |
512 |
> |
|
513 |
> |
for (index = find.approve.size(); index > 0; index--) |
514 |
|
{ |
515 |
< |
session->expunge(); |
515 |
> |
cout << "Checking find: " << index << "..." << flush; |
516 |
> |
|
517 |
> |
switch (approval("find", find.approve[index - 1])) |
518 |
> |
{ |
519 |
> |
case true: |
520 |
> |
find.approved.push_back(find.approve[index - 1]); |
521 |
> |
case false: |
522 |
> |
find.approve.erase(find.approve.begin() + (index - 1)); |
523 |
> |
break; |
524 |
> |
default: |
525 |
> |
break; |
526 |
> |
} |
527 |
> |
} |
528 |
> |
|
529 |
> |
for (index = improve.approve.size(); index > 0; index--) |
530 |
> |
{ |
531 |
> |
cout << "Checking improve: " << index << "..." << flush; |
532 |
> |
|
533 |
> |
switch (approval("improve", improve.approve[index - 1])) |
534 |
> |
{ |
535 |
> |
case true: |
536 |
> |
improve.approved.push_back(improve.approve[index - 1]); |
537 |
> |
case false: |
538 |
> |
improve.approve.erase(improve.approve.begin() + (index - 1)); |
539 |
> |
break; |
540 |
> |
default: |
541 |
> |
break; |
542 |
> |
} |
543 |
> |
} |
544 |
> |
|
545 |
> |
if (find.disapprove.size() > 0 || improve.disapprove.size() > 0) |
546 |
> |
{ |
547 |
> |
cout << "Sending disapprovals..." << flush; |
548 |
> |
|
549 |
> |
ostringstream message; |
550 |
> |
|
551 |
> |
message << "From: \"Windows XP FAQ | Poll\" <" << account.getEmail() |
552 |
> |
<< ">\n" |
553 |
> |
<< "To: \"" << account.getName() << "\" <" << account.getEmail() |
554 |
> |
<< ">\n" |
555 |
> |
<< "Subject: Windows XP FAQ | Poll Disapprovals\n" |
556 |
> |
<< "Content-Type: multipart/mixed;\n" |
557 |
> |
<< " boundary=\"----=_NextPart_WinXPFAQPoll_0\"\n" |
558 |
> |
<< "Content-Transfer-Encoding: 7bit\n" |
559 |
> |
<< "X-Mailer: WinXPFAQPoll 1.0\n\n" |
560 |
> |
<< "This is a multi-part message in MIME format.\n\n" |
561 |
> |
<< "------=_NextPart_WinXPFAQPoll_0\n" |
562 |
> |
<< "Content-Type: text/plain charset=\"us-ascii\"\n" |
563 |
> |
<< "Content-Transfer-Encoding: 7bit\n\n" |
564 |
> |
<< "Apparently these answers where disapproved:\n\n"; |
565 |
> |
|
566 |
> |
unsigned extra = 0; |
567 |
> |
|
568 |
> |
for (index = 0; index < find.disapprove.size(); index++, extra += 4) |
569 |
> |
{ |
570 |
> |
message << "How did you find this page?\n" |
571 |
> |
<< " I arrived here by entirely different means:\n" |
572 |
> |
<< " " << find.disapprove[index] << "\n\n"; |
573 |
> |
} |
574 |
> |
|
575 |
> |
for (index = 0; index < improve.disapprove.size(); index++, extra += 4) |
576 |
> |
{ |
577 |
> |
message << "How could I improve this site?\n" |
578 |
> |
<< " I have my own completely insane suggestion:\n" |
579 |
> |
<< " " << improve.disapprove[index] << "\n\n"; |
580 |
> |
} |
581 |
> |
|
582 |
> |
message << "Make sure there were no errors.\n\n" |
583 |
> |
<< "------=_NextPart_WinXPFAQPoll_0\n" |
584 |
> |
<< "Content-Type: text/plain;\n" |
585 |
> |
<< " name=\"disapprove.dat\"\n" |
586 |
> |
<< "Content-Transfer-Encoding: 7bit\n" |
587 |
> |
<< "Content-Disposition: attachment;\n" |
588 |
> |
<< " filename=\"disapprove.dat\"\n\n"; |
589 |
> |
|
590 |
> |
if (find.disapprove.size() > 0) |
591 |
> |
{ |
592 |
> |
message << "_find_\n"; |
593 |
> |
extra++; |
594 |
> |
} |
595 |
> |
|
596 |
> |
for (index = 0; index < find.disapprove.size(); index++, extra += 1) |
597 |
> |
{ |
598 |
> |
message << find.disapprove[index] << "\n"; |
599 |
> |
} |
600 |
> |
|
601 |
> |
if (improve.disapprove.size() > 0) |
602 |
> |
{ |
603 |
> |
message << "_improve_\n"; |
604 |
> |
extra++; |
605 |
> |
} |
606 |
> |
|
607 |
> |
for (index = 0; index < improve.disapprove.size(); index++, extra += 1) |
608 |
> |
{ |
609 |
> |
message << improve.disapprove[index] << "\n"; |
610 |
> |
} |
611 |
> |
|
612 |
> |
message << "\n------=_NextPart_WinXPFAQPoll_0--\n"; |
613 |
> |
|
614 |
> |
ostringstream length; |
615 |
> |
length << (message.str().length() + 26 + extra); |
616 |
> |
|
617 |
> |
session->append('\"' + account.getMailbox() + "\" {" + length.str() + |
618 |
> |
'}', message.str()); |
619 |
> |
|
620 |
> |
session->noop(); |
621 |
> |
|
622 |
> |
cout << "done.\n"; |
623 |
|
} |
624 |
|
} |
625 |
+ |
|
626 |
+ |
short Poller::approval(const string& type, const string& text) |
627 |
+ |
{ |
628 |
+ |
short answer = -1; |
629 |
+ |
|
630 |
+ |
stringstream search; |
631 |
+ |
search << session->search(string("ALL HEADER X-Mailer \"WinXPFAQPoll 1.0") |
632 |
+ |
+ "\" SUBJECT \"Windows XP FAQ | Poll Submit\" FROM \"Windows XP FAQ |" |
633 |
+ |
+ " Poll\" HEADER X-WinXPFAQPoll-Submit-Type \"" + type + "\" HEADER X" |
634 |
+ |
+ "-WinXPFAQPoll-Submit-Text \"" + text + '\"'); |
635 |
+ |
|
636 |
+ |
search.ignore(9); |
637 |
+ |
search.peek(); |
638 |
+ |
|
639 |
+ |
if (search.good()) |
640 |
+ |
{ |
641 |
+ |
unsigned message; |
642 |
+ |
search >> message; |
643 |
+ |
|
644 |
+ |
if (debug) cerr << "message = " << message << "\n"; |
645 |
+ |
|
646 |
+ |
ostringstream number; |
647 |
+ |
number << message; |
648 |
+ |
|
649 |
+ |
if (session->fetch(number.str() + " FLAGS").find("\\Deleted") != |
650 |
+ |
string::npos) |
651 |
+ |
{ |
652 |
+ |
answer = false; |
653 |
+ |
} |
654 |
+ |
else if (session->fetch(number.str() + " FLAGS").find("\\Flagged") != |
655 |
+ |
string::npos) |
656 |
+ |
{ |
657 |
+ |
answer = true; |
658 |
+ |
|
659 |
+ |
session->store(number.str() + " +FLAGS (\\Deleted)"); |
660 |
+ |
} |
661 |
+ |
} |
662 |
+ |
else |
663 |
+ |
{ |
664 |
+ |
answer = false; |
665 |
+ |
} |
666 |
+ |
|
667 |
+ |
switch (answer) |
668 |
+ |
{ |
669 |
+ |
case true: |
670 |
+ |
cout << "approved.\n"; |
671 |
+ |
break; |
672 |
+ |
case false: |
673 |
+ |
if (type == "find") |
674 |
+ |
{ |
675 |
+ |
find.disapprove.push_back(text); |
676 |
+ |
} |
677 |
+ |
else if (type == "improve") |
678 |
+ |
{ |
679 |
+ |
improve.disapprove.push_back(text); |
680 |
+ |
} |
681 |
+ |
cout << "disapproved.\n"; |
682 |
+ |
break; |
683 |
+ |
default: |
684 |
+ |
cout << "cancelled.\n"; |
685 |
+ |
break; |
686 |
+ |
} |
687 |
+ |
|
688 |
+ |
return answer; |
689 |
+ |
} |