// Windows XP FAQ Poll // // Douglas Thrift // // Poller.cpp #include "Poller.h" Poller::Poller() { string mailbox = session->list("\"\" \"" + account.getMailbox() + "\""); if (mailbox.find(account.getMailbox()) == string::npos) { cerr << program << ": Mailbox does not exist: " << account.getMailbox() << "\n"; exit(1); } } void Poller::poll(bool nodelete, const string& file) { this->nodelete = nodelete; this->file = file; load(); // // save(); } void Poller::load() { ifstream fin(file.c_str()); if (!fin.is_open()) { ofstream fout(file.c_str()); fout << "_find_\n" << "reply=0\n" << "news=0\n" << "sig=0\n" << "search=0\n" << "link=0\n" << "browse=0\n" << "other=0\n" << "_help_\n" << "solved=0\n" << "note=0\n" << "link=0\n" << "news=0\n" << "lazy=0\n" << "_improve_\n" << "nothing=0\n" << "links=0\n" << "suggest=0\n"; fout.close(); fin.open(file.c_str()); } do { enum { FIND, HELP, IMPROVE } type; string vote; unsigned count; string text; getline(fin, vote, '='); if (debug) cerr << "vote = " << vote << "\n"; if (vote == "_find_") { type = FIND; continue; } else if (vote == "_help_") { type = HELP; continue; } else if (vote == "_improve_") { type = IMPROVE; continue; } else if (vote == "approved" || vote == "approve") { getline(fin, text); } else { fin >> count; fin.get(); } switch (type) { case FIND: if (vote == "reply") { find.reply = count; } else if (vote == "news") { find.news = count; } else if (vote == "sig") { find.sig = count; } else if (vote == "search") { find.search = count; } else if (vote == "link") { find.link = count; } else if (vote == "browse") { find.browse = count; } else if (vote == "other") { find.other = count; } else if (vote == "approved") { find.approved.push_back(text); } else if (vote == "approve") { find.approve.push_back(text); } break; case HELP: if (vote == "solved") { help.solved = count; } else if (vote == "note") { help.note = count; } else if (vote == "link") { help.link = count; } else if (vote == "news") { help.news = count; } else if (vote == "lazy") { help.lazy = count; } break; case IMPROVE: if (vote == "nothing") { improve.nothing = count; } else if (vote == "links") { improve.links = count; } else if (vote == "suggest") { improve.suggest = count; } else if (vote == "approved") { improve.approved.push_back(text); } else if (vote == "approve") { improve.approve.push_back(text); } break; } } while (fin.good()); fin.close(); } void Poller::save() { unsigned index; ofstream fout(file.c_str()); fout << "_find_\n" << "reply=" << find.reply << "\n" << "news=" << find.news << "\n" << "sig=" << find.sig << "\n" << "search=" << find.search << "\n" << "link=" << find.link << "\n" << "browse=" << find.browse << "\n" << "other=" << find.other << "\n"; for (index = 0; index < find.approved.size(); index++) { fout << "approved=" << find.approved[index] << "\n"; } for (index = 0; index < find.approve.size(); index++) { fout << "approve=" << find.approve[index] << "\n"; } fout << "_help_\n" << "solved=" << help.solved << "\n" << "note=" << help.note << "\n" << "link=" << help.link << "\n" << "news=" << help.news << "\n" << "lazy=" << help.lazy << "\n" << "_improve_\n" << "nothing=" << improve.nothing << "\n" << "links=" << improve.links << "\n" << "suggest=" << improve.suggest << "\n"; for (index = 0; index < improve.approved.size(); index++) { fout << "approved=" << improve.approved[index] << "\n"; } for (index = 0; index < improve.approve.size(); index++) { fout << "approve=" << improve.approve[index] << "\n"; } fout.close(); }