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 230 by douglas, 2003-08-05T19:01:05-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();
267 >
268 >        while (!isdigit(search.peek()) && search.good())
269 >        {
270 >                search.get();
271 >        }
272  
273          while (search.good())
274          {
# Line 269 | Line 279 | void Poller::ballots()
279                  messages.push(message);
280  
281                  search.get();
282 <                search.peek();
282 >
283 >                while (!isdigit(search.peek()) && search.good())
284 >                {
285 >                        search.get();
286 >                }
287          }
288  
289          if (!messages.empty())
# Line 279 | Line 293 | void Poller::ballots()
293  
294                  ballot(message);
295          }
296 +
297 +        if (submits.size() > 0)
298 +        {
299 +                cout << "Sending submits..." << flush;
300 +
301 +                for (unsigned index = 0; index < submits.size(); index++)
302 +                {
303 +                        submit(submits[index].first, submits[index].second);
304 +                }
305 +
306 +                submits.clear();
307 +
308 +                cout << "done.\n";
309 +        }
310   }
311  
312   void Poller::ballot(unsigned message)
# Line 289 | Line 317 | void Poller::ballot(unsigned message)
317          number << message;
318  
319          stringstream buffer;
320 +        string junk;
321  
322          buffer << session->fetch(number.str() + " BODY.PEEK[2]");
323  
324 <        if (session->successful())
324 >        if (session->successful() && buffer.str() == "* " + number.str() + " FETCH"
325 >                + " (BODY[2] \"\")\n")
326 >        {
327 >                do
328 >                {
329 >                        getline(buffer, junk);
330 >                }
331 >                while (buffer.good());
332 >
333 >                buffer.clear();
334 >
335 >                buffer << session->fetch(number.str() + " BODY.PEEK[TEXT]");
336 >
337 >                for (unsigned index = 0; index < 25; index++)
338 >                {
339 >                        getline(buffer, junk);
340 >                }
341 >        }
342 >
343 >        if (session->successful() && session->fetch(number.str() + " FLAGS").find(
344 >                "\\Deleted") == string::npos)
345          {
346 <                buffer.ignore(string::npos, '\n');
346 >                getline(buffer, junk);
347  
348                  bool approved = session->fetch(number.str() + " FLAGS").find("\\Flagge"
349                          + string("d")) != string::npos;
# Line 367 | Line 416 | void Poller::ballot(unsigned message)
416                                          {
417                                                  find.approve.push_back(text);
418  
419 <                                                submit("find", text);
419 >                                                submits.push_back(pair<string, string>("find", text));
420                                          }
421                                  }
422                                  break;
# Line 417 | Line 466 | void Poller::ballot(unsigned message)
466                                          {
467                                                  improve.approve.push_back(text);
468  
469 <                                                submit("improve", text);
469 >                                                submits.push_back(pair<string, string>("improve",
470 >                                                        text));
471                                          }
472                                  }
473                                  break;
# Line 444 | Line 494 | void Poller::ballot(unsigned message)
494  
495   void Poller::submit(const string& type, const string& text)
496   {
497 <        //
497 >        ostringstream message;
498 >
499 >        message << "From: \"Windows XP FAQ | Poll\" <" << account.getEmail()
500 >                << ">\n"
501 >                << "To: \"" << account.getName() << "\" <" << account.getEmail()
502 >                << ">\n"
503 >                << "Subject: Windows XP FAQ | Poll Submit\n"
504 >                << "Content-Type: text/plain charset=\"us-ascii\"\n"
505 >                << "Content-Transfer-Encoding: 7bit\n"
506 >                << "X-Mailer: WinXPFAQPoll 1.0\n"
507 >                << "X-WinXPFAQPoll-Submit-Type: " << type << "\n"
508 >                << "X-WinXPFAQPoll-Submit-Text: " << text << "\n\n";
509 >
510 >        if (type == "find")
511 >        {
512 >                message << "How did you find this page?\n"
513 >                        << "    I arrived here by entirely different means:\n";
514 >        }
515 >        else if (type == "improve")
516 >        {
517 >                message << "How could I improve this site?\n"
518 >                        << "    I have my own completely insane suggestion:\n";
519 >        }
520 >
521 >        message << "    " << text << "\n\n"
522 >                << "Flag this message to approve the voter\'s possibly objectionable\n"
523 >                << "input or delete it to disapprove.\n\n"
524 >                << "This message will be marked deleted when it is processed.\n";
525 >
526 >        ostringstream length;
527 >        length << (message.str().length() + 16);
528 >
529 >        session->append('\"' + account.getMailbox() + "\" {" + length.str() + '}',
530 >                message.str());
531 >
532 >        session->noop();
533   }
534  
535   void Poller::approvals()
536   {
537 <        //
537 >        session->check();
538 >
539 >        unsigned index;
540 >
541 >        for (index = find.approve.size(); index > 0; index--)
542 >        {
543 >                cout << "Checking find: " << index << "..." << flush;
544 >
545 >                switch (approval("find", find.approve[index - 1]))
546 >                {
547 >                case true:
548 >                        find.approved.push_back(find.approve[index - 1]);
549 >                case false:
550 >                        find.approve.erase(find.approve.begin() + (index - 1));
551 >                        break;
552 >                default:
553 >                        break;
554 >                }
555 >        }
556 >
557 >        for (index = improve.approve.size(); index > 0; index--)
558 >        {
559 >                cout << "Checking improve: " << index << "..." << flush;
560 >
561 >                switch (approval("improve", improve.approve[index - 1]))
562 >                {
563 >                case true:
564 >                        improve.approved.push_back(improve.approve[index - 1]);
565 >                case false:
566 >                        improve.approve.erase(improve.approve.begin() + (index - 1));
567 >                        break;
568 >                default:
569 >                        break;
570 >                }
571 >        }
572 >
573 >        if (find.disapprove.size() > 0 || improve.disapprove.size() > 0)
574 >        {
575 >                cout << "Sending disapprovals..." << flush;
576 >
577 >                ostringstream message;
578 >
579 >                message << "From: \"Windows XP FAQ | Poll\" <" << account.getEmail()
580 >                        << ">\n"
581 >                        << "To: \"" << account.getName() << "\" <" << account.getEmail()
582 >                        << ">\n"
583 >                        << "Subject: Windows XP FAQ | Poll Disapprovals\n"
584 >                        << "Content-Type: multipart/mixed;\n"
585 >                        << "    boundary=\"----=_NextPart_WinXPFAQPoll_0\"\n"
586 >                        << "Content-Transfer-Encoding: 7bit\n"
587 >                        << "X-Mailer: WinXPFAQPoll 1.0\n\n"
588 >                        << "This is a multi-part message in MIME format.\n\n"
589 >                        << "------=_NextPart_WinXPFAQPoll_0\n"
590 >                        << "Content-Type: text/plain charset=\"us-ascii\"\n"
591 >                        << "Content-Transfer-Encoding: 7bit\n\n"
592 >                        << "Apparently these answers where disapproved:\n\n";
593 >
594 >                unsigned extra = 0;
595 >
596 >                for (index = 0; index < find.disapprove.size(); index++, extra += 4)
597 >                {
598 >                        message << "How did you find this page?\n"
599 >                                << "    I arrived here by entirely different means:\n"
600 >                                << "    " << find.disapprove[index] << "\n\n";
601 >                }
602 >
603 >                for (index = 0; index < improve.disapprove.size(); index++, extra += 4)
604 >                {
605 >                        message << "How could I improve this site?\n"
606 >                                << "    I have my own completely insane suggestion:\n"
607 >                                << "    " << improve.disapprove[index] << "\n\n";
608 >                }
609 >
610 >                message << "Make sure there were no errors.\n\n"
611 >                        << "------=_NextPart_WinXPFAQPoll_0\n"
612 >                        << "Content-Type: text/plain;\n"
613 >                        << "    name=\"disapprove.dat\"\n"
614 >                        << "Content-Transfer-Encoding: 7bit\n"
615 >                        << "Content-Disposition: attachment;\n"
616 >                        << "    filename=\"disapprove.dat\"\n\n";
617 >
618 >                if (find.disapprove.size() > 0)
619 >                {
620 >                        message << "_find_\n";
621 >                        extra++;
622 >                }
623 >
624 >                for (index = 0; index < find.disapprove.size(); index++, extra += 1)
625 >                {
626 >                        message << find.disapprove[index] << "\n";
627 >                }
628 >
629 >                if (improve.disapprove.size() > 0)
630 >                {
631 >                        message << "_improve_\n";
632 >                        extra++;
633 >                }
634 >
635 >                for (index = 0; index < improve.disapprove.size(); index++, extra += 1)
636 >                {
637 >                        message << improve.disapprove[index] << "\n";
638 >                }
639 >
640 >                message << "\n------=_NextPart_WinXPFAQPoll_0--\n";
641 >
642 >                ostringstream length;
643 >                length << (message.str().length() + 26 + extra);
644 >
645 >                session->append('\"' + account.getMailbox() + "\" {" + length.str() +
646 >                        '}', message.str());
647 >                
648 >                session->noop();
649 >
650 >                cout << "done.\n";
651 >        }
652 > }
653 >
654 > short Poller::approval(const string& type, const string& text)
655 > {
656 >        short answer = -1;
657 >
658 >        stringstream search;
659 >        search << session->search(string("ALL HEADER X-Mailer \"WinXPFAQPoll 1.0")
660 >                + "\" SUBJECT \"Windows XP FAQ | Poll Submit\" FROM \"Windows XP FAQ |"
661 >                + " Poll\" HEADER X-WinXPFAQPoll-Submit-Type \"" + type + "\" HEADER X"
662 >                + "-WinXPFAQPoll-Submit-Text \"" + text + '\"');
663 >
664 >        search.ignore(9);
665 >        search.peek();
666 >
667 >        if (search.good())
668 >        {
669 >                unsigned message;
670 >                search >> message;
671 >
672 >                if (debug) cerr << "message = " << message << "\n";
673 >
674 >                ostringstream number;
675 >                number << message;
676 >
677 >                if (session->fetch(number.str() + " FLAGS").find("\\Deleted") !=
678 >                        string::npos)
679 >                {
680 >                        answer = false;
681 >                }
682 >                else if (session->fetch(number.str() + " FLAGS").find("\\Flagged") !=
683 >                        string::npos)
684 >                {
685 >                        answer = true;
686 >
687 >                        session->store(number.str() + " +FLAGS (\\Deleted)");
688 >                }
689 >        }
690 >        else
691 >        {
692 >                answer = false;
693 >        }
694 >
695 >        switch (answer)
696 >        {
697 >        case true:
698 >                cout << "approved.\n";
699 >                break;
700 >        case false:
701 >                if (type == "find")
702 >                {
703 >                        find.disapprove.push_back(text);
704 >                }
705 >                else if (type == "improve")
706 >                {
707 >                        improve.disapprove.push_back(text);
708 >                }
709 >                cout << "disapproved.\n";
710 >                break;
711 >        default:
712 >                cout << "cancelled.\n";
713 >                break;
714 >        }
715 >
716 >        return answer;
717   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines