ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/WinXPFAQPoll/Poller.cpp
(Generate patch)

Comparing trunk/WinXPFAQPoll/Poller.cpp (file contents):
Revision 123 by douglas, 2003-04-02T18:10:51-08:00 vs.
Revision 219 by douglas, 2003-07-23T19:09:16-07:00

# Line 27 | Line 27 | Poller::~Poller()
27          }
28   }
29  
30 < void Poller::poll(bool nodelete, const string& file)
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   }
# Line 108 | Line 116 | void Poller::load()
116                          fin.get();
117                  }
118  
119 <                fin.peek();
119 >                if (fin.peek() == EOF) fin.get();
120  
121                  switch (type)
122                  {
# Line 250 | Line 258 | void Poller::save()
258  
259   void Poller::ballots()
260   {
253        session->select('\"' + account.getMailbox() + '\"');
254
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\"");
263 >                + "(Perl)\" SUBJECT \"Windows XP FAQ | Poll Ballot\" FROM \"Windows XP"
264 >                + " FAQ | Poll\"");
265  
266          search.ignore(9);
267          search.peek();
# Line 279 | Line 285 | void Poller::ballots()
285  
286                  ballot(message);
287          }
288 +
289 +        if (submits.size() > 0)
290 +        {
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  
304   void Poller::ballot(unsigned message)
# Line 292 | Line 312 | void Poller::ballot(unsigned message)
312  
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                  buffer.ignore(string::npos, '\n');
319  
# Line 367 | Line 388 | void Poller::ballot(unsigned message)
388                                          {
389                                                  find.approve.push_back(text);
390  
391 <                                                submit("find", text);
391 >                                                submits.push_back(pair<string, string>("find", text));
392                                          }
393                                  }
394                                  break;
# Line 417 | Line 438 | void Poller::ballot(unsigned message)
438                                          {
439                                                  improve.approve.push_back(text);
440  
441 <                                                submit("improve", text);
441 >                                                submits.push_back(pair<string, string>("improve",
442 >                                                        text));
443                                          }
444                                  }
445                                  break;
# Line 444 | Line 466 | void Poller::ballot(unsigned message)
466  
467   void Poller::submit(const string& type, const string& text)
468   {
469 <        //
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 >        unsigned index;
512 >
513 >        for (index = find.approve.size(); index > 0; index--)
514 >        {
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines