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 125 by douglas, 2003-04-02T23:25:29-08:00 vs.
Revision 126 by douglas, 2003-04-03T20:36:16-08:00

# Line 254 | Line 254 | void Poller::ballots()
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\"");
257 >                + "(Perl)\" SUBJECT \"Windows XP FAQ | Poll Ballot\" FROM \"Windows XP"
258 >                + " FAQ | Poll\"");
259  
260          search.ignore(9);
261          search.peek();
# Line 279 | Line 279 | void Poller::ballots()
279  
280                  ballot(message);
281          }
282 +
283 +        if (submits.size() > 0)
284 +        {
285 +                cout << "Sending submits..." << flush;
286 +
287 +                for (unsigned index = 0; index < submits.size(); index++)
288 +                {
289 +                        submit(submits[index].first, submits[index].second);
290 +                }
291 +
292 +                submits.clear();
293 +
294 +                cout << "done.\n";
295 +        }
296   }
297  
298   void Poller::ballot(unsigned message)
# Line 292 | Line 306 | void Poller::ballot(unsigned message)
306  
307          buffer << session->fetch(number.str() + " BODY.PEEK[2]");
308  
309 <        if (session->successful())
309 >        if (session->successful() && session->fetch(number.str() + " FLAGS").find(
310 >                "\\Deleted") == string::npos)
311          {
312                  buffer.ignore(string::npos, '\n');
313  
# Line 367 | Line 382 | void Poller::ballot(unsigned message)
382                                          {
383                                                  find.approve.push_back(text);
384  
385 <                                                submit("find", text);
385 >                                                submits.push_back(pair<string, string>("find", text));
386                                          }
387                                  }
388                                  break;
# Line 417 | Line 432 | void Poller::ballot(unsigned message)
432                                          {
433                                                  improve.approve.push_back(text);
434  
435 <                                                submit("improve", text);
435 >                                                submits.push_back(pair<string, string>("improve",
436 >                                                        text));
437                                          }
438                                  }
439                                  break;
# Line 484 | Line 500 | void Poller::submit(const string& type,
500  
501   void Poller::approvals()
502   {
503 <        //
503 >        unsigned index;
504 >
505 >        session->check();
506 >
507 >        for (index = find.approve.size(); index > 0; index--)
508 >        {
509 >                cout << "Checking find: " << index << "..." << flush;
510 >
511 >                switch (approval("find", find.approve[index - 1]))
512 >                {
513 >                case true:
514 >                        find.approved.push_back(find.approve[index - 1]);
515 >                case false:
516 >                        find.approve.erase(&find.approve[index - 1]);
517 >                        break;
518 >                default:
519 >                        break;
520 >                }
521 >        }
522 >
523 >        for (index = improve.approve.size(); index > 0; index--)
524 >        {
525 >                cout << "Checking improve: " << index << "..." << flush;
526 >
527 >                switch (approval("improve", improve.approve[index - 1]))
528 >                {
529 >                case true:
530 >                        improve.approved.push_back(improve.approve[index - 1]);
531 >                case false:
532 >                        improve.approve.erase(&improve.approve[index - 1]);
533 >                        break;
534 >                default:
535 >                        break;
536 >                }
537 >        }
538 >
539 >        if (find.disapprove.size() > 0 || improve.disapprove.size() > 0)
540 >        {
541 >                cout << "Sending disapprovals..." << flush;
542 >
543 >                ostringstream message;
544 >
545 >                message << "From: \"Windows XP FAQ | Poll\" <" << account.getEmail()
546 >                        << ">\n"
547 >                        << "To: \"" << account.getName() << "\" <" << account.getEmail()
548 >                        << ">\n"
549 >                        << "Subject: Windows XP FAQ | Poll Disapprovals\n"
550 >                        << "Content-Type: multipart/mixed;\n"
551 >                        << "    boundary=\"----=_NextPart_WinXPFAQPoll_0\"\n"
552 >                        << "Content-Transfer-Encoding: 7bit\n"
553 >                        << "X-Mailer: WinXPFAQPoll 1.0\n\n"
554 >                        << "This is a multi-part message in MIME format.\n\n"
555 >                        << "------=_NextPart_WinXPFAQPoll_0\n"
556 >                        << "Content-Type: text/plain charset=\"us-ascii\"\n"
557 >                        << "Content-Transfer-Encoding: 7bit\n\n"
558 >                        << "Apparently these answers where disapproved:\n\n";
559 >
560 >                unsigned extra = 0;
561 >
562 >                for (index = 0; index < find.disapprove.size(); index++, extra += 4)
563 >                {
564 >                        message << "How did you find this page?\n"
565 >                                << "    I arrived here by entirely different means:\n"
566 >                                << "    " << find.disapprove[index] << "\n\n";
567 >                }
568 >
569 >                for (index = 0; index < improve.disapprove.size(); index++, extra += 4)
570 >                {
571 >                        message << "How could I improve this site?\n"
572 >                                << "    I have my own completely insane suggestion:\n"
573 >                                << "    " << improve.disapprove[index] << "\n\n";
574 >                }
575 >
576 >                message << "Make sure there were no errors.\n\n"
577 >                        << "------=_NextPart_WinXPFAQPoll_0\n"
578 >                        << "Content-Type: text/plain;\n"
579 >                        << "    name=\"disapprove.dat\"\n"
580 >                        << "Content-Transfer-Encoding: 7bit\n"
581 >                        << "Content-Disposition: attachment;\n"
582 >                        << "    filename=\"disapprove.dat\"\n\n";
583 >
584 >                if (find.disapprove.size() > 0)
585 >                {
586 >                        message << "_find_\n";
587 >                        extra++;
588 >                }
589 >
590 >                for (index = 0; index < find.disapprove.size(); index++, extra += 1)
591 >                {
592 >                        message << find.disapprove[index] << "\n";
593 >                }
594 >
595 >                if (improve.disapprove.size() > 0)
596 >                {
597 >                        message << "_improve_\n";
598 >                        extra++;
599 >                }
600 >
601 >                for (index = 0; index < improve.disapprove.size(); index++, extra += 1)
602 >                {
603 >                        message << improve.disapprove[index] << "\n";
604 >                }
605 >
606 >                message << "\n------=_NextPart_WinXPFAQPoll_0--\n";
607 >
608 >                ostringstream length;
609 >                length << (message.str().length() + 26 + extra);
610 >
611 >                session->append('\"' + account.getMailbox() + "\" {" + length.str() +
612 >                        '}', message.str());
613 >                
614 >                session->noop();
615 >
616 >                cout << "done.\n";
617 >        }
618   }
619  
620 < void Poller::approval(unsigned message)
620 > short Poller::approval(const string& type, const string& text)
621   {
622 <        //
622 >        short answer = -1;
623 >
624 >        stringstream search;
625 >        search << session->search(string("ALL HEADER X-Mailer \"WinXPFAQPoll 1.0")
626 >                + "\" SUBJECT \"Windows XP FAQ | Poll Submit\" FROM \"Windows XP FAQ |"
627 >                + " Poll\" HEADER X-WinXPFAQPoll-Submit-Type \"" + type + "\" HEADER X"
628 >                + "-WinXPFAQPoll-Submit-Text \"" + text + '\"');
629 >
630 >        search.ignore(9);
631 >        search.peek();
632 >
633 >        if (search.good())
634 >        {
635 >                unsigned message;
636 >                search >> message;
637 >
638 >                if (debug) cerr << "message = " << message << "\n";
639 >
640 >                ostringstream number;
641 >                number << message;
642 >
643 >                if (session->fetch(number.str() + " FLAGS").find("\\Deleted") !=
644 >                        string::npos)
645 >                {
646 >                        answer = false;
647 >                }
648 >                else if (session->fetch(number.str() + " FLAGS").find("\\Flagged") !=
649 >                        string::npos)
650 >                {
651 >                        answer = true;
652 >
653 >                        session->store(number.str() + " +FLAGS (\\Deleted)");
654 >                }
655 >        }
656 >        else
657 >        {
658 >                answer = false;
659 >        }
660 >
661 >        switch (answer)
662 >        {
663 >        case true:
664 >                cout << "approved.\n";
665 >                break;
666 >        case false:
667 >                if (type == "find")
668 >                {
669 >                        find.disapprove.push_back(text);
670 >                }
671 >                else if (type == "improve")
672 >                {
673 >                        improve.disapprove.push_back(text);
674 >                }
675 >                cout << "disapproved.\n";
676 >                break;
677 >        default:
678 >                cout << "cancelled.\n";
679 >                break;
680 >        }
681 >
682 >        return answer;
683   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines