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 119 by douglas, 2003-04-01T14:49:17-08:00 vs.
Revision 123 by douglas, 2003-04-02T18:10:51-08:00

# Line 19 | Line 19 | Poller::Poller()
19          }
20   }
21  
22 + Poller::~Poller()
23 + {
24 +        if (!nodelete)
25 +        {
26 +                session->expunge();
27 +        }
28 + }
29 +
30   void Poller::poll(bool nodelete, const string& file)
31   {
32          this->nodelete = nodelete;
# Line 26 | Line 34 | void Poller::poll(bool nodelete, const s
34  
35          load();
36  
37 <        //
37 >        ballots();
38 >        approvals();
39  
40 < //      save();
40 >        save();
41   }
42  
43   void Poller::load()
# Line 36 | Line 45 | void Poller::load()
45          ifstream fin(file.c_str());
46          if (!fin.is_open())
47          {
48 +                fin.clear();
49 +
50                  ofstream fout(file.c_str());
51  
52                  fout << "_find_\n"
# Line 62 | Line 73 | void Poller::load()
73                  fin.open(file.c_str());
74          }
75  
76 <        do
76 >        while (fin.good())
77          {
78                  enum { FIND, HELP, IMPROVE } type;
79                  string vote;
80                  unsigned count;
81                  string text;
82  
83 <                getline(fin, vote, '=');
83 >                fin.peek() != '_' ? getline(fin, vote, '=') : getline(fin, vote);
84                  if (debug) cerr << "vote = " << vote << "\n";
85  
86                  if (vote == "_find_")
# Line 97 | Line 108 | void Poller::load()
108                          fin.get();
109                  }
110  
111 +                fin.peek();
112 +
113                  switch (type)
114                  {
115                  case FIND:
# Line 183 | Line 196 | void Poller::load()
196                          break;
197                  }
198          }
186        while (fin.good());
199  
200          fin.close();
201   }
202  
203   void Poller::save()
204   {
205 +        unsigned index;
206          ofstream fout(file.c_str());
207  
208 <        //
208 >        fout << "_find_\n"
209 >                << "reply=" << find.reply << "\n"
210 >                << "news=" << find.news << "\n"
211 >                << "sig=" << find.sig << "\n"
212 >                << "search=" << find.search << "\n"
213 >                << "link=" << find.link << "\n"
214 >                << "browse=" << find.browse << "\n"
215 >                << "other=" << find.other << "\n";
216 >
217 >        for (index = 0; index < find.approved.size(); index++)
218 >        {
219 >                fout << "approved=" << find.approved[index] << "\n";
220 >        }
221 >
222 >        for (index = 0; index < find.approve.size(); index++)
223 >        {
224 >                fout << "approve=" << find.approve[index] << "\n";
225 >        }
226 >
227 >        fout << "_help_\n"
228 >                << "solved=" << help.solved << "\n"
229 >                << "note=" << help.note << "\n"
230 >                << "link=" << help.link << "\n"
231 >                << "news=" << help.news << "\n"
232 >                << "lazy=" << help.lazy << "\n"
233 >                << "_improve_\n"
234 >                << "nothing=" << improve.nothing << "\n"
235 >                << "links=" << improve.links << "\n"
236 >                << "suggest=" << improve.suggest << "\n";
237 >
238 >        for (index = 0; index < improve.approved.size(); index++)
239 >        {
240 >                fout << "approved=" << improve.approved[index] << "\n";
241 >        }
242 >
243 >        for (index = 0; index < improve.approve.size(); index++)
244 >        {
245 >                fout << "approve=" << improve.approve[index] << "\n";
246 >        }
247  
248          fout.close();
249   }
250 +
251 + void Poller::ballots()
252 + {
253 +        session->select('\"' + account.getMailbox() + '\"');
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\"");
259 +
260 +        search.ignore(9);
261 +        search.peek();
262 +
263 +        while (search.good())
264 +        {
265 +                unsigned message;
266 +                search >> message;
267 +
268 +                if (debug) cerr << "message = " << message << "\n";
269 +                messages.push(message);
270 +
271 +                search.get();
272 +                search.peek();
273 +        }
274 +
275 +        if (!messages.empty())
276 +        {
277 +                unsigned message = messages.front();
278 +                messages.pop();
279 +
280 +                ballot(message);
281 +        }
282 + }
283 +
284 + void Poller::ballot(unsigned message)
285 + {
286 +        cout << "Checking message: " << message << "..." << flush;
287 +
288 +        ostringstream number;
289 +        number << message;
290 +
291 +        stringstream buffer;
292 +
293 +        buffer << session->fetch(number.str() + " BODY.PEEK[2]");
294 +
295 +        if (session->successful())
296 +        {
297 +                buffer.ignore(string::npos, '\n');
298 +
299 +                bool approved = session->fetch(number.str() + " FLAGS").find("\\Flagge"
300 +                        + string("d")) != string::npos;
301 +
302 +                while (buffer.peek() != '\n' && buffer.good())
303 +                {
304 +                        enum { FIND, HELP, IMPROVE } type;
305 +                        string vote;
306 +
307 +                        getline(buffer, vote);
308 +                        if (debug) cerr << "vote = " << vote << "\n";
309 +
310 +                        if (vote == "_find_")
311 +                        {
312 +                                type = FIND;
313 +                                continue;
314 +                        }
315 +                        else if (vote == "_help_")
316 +                        {
317 +                                type = HELP;
318 +                                continue;
319 +                        }
320 +                        else if (vote == "_improve_")
321 +                        {
322 +                                type = IMPROVE;
323 +                                continue;
324 +                        }
325 +
326 +                        buffer.peek();
327 +
328 +                        switch (type)
329 +                        {
330 +                        case FIND:
331 +                                if (vote == "reply")
332 +                                {
333 +                                        find.reply++;
334 +                                }
335 +                                else if (vote == "news")
336 +                                {
337 +                                        find.news++;
338 +                                }
339 +                                else if (vote == "sig")
340 +                                {
341 +                                        find.sig++;
342 +                                }
343 +                                else if (vote == "search")
344 +                                {
345 +                                        find.search++;
346 +                                }
347 +                                else if (vote == "link")
348 +                                {
349 +                                        find.link++;
350 +                                }
351 +                                else if (vote == "browse")
352 +                                {
353 +                                        find.browse++;
354 +                                }
355 +                                else if (vote == "other")
356 +                                {
357 +                                        find.other++;
358 +
359 +                                        string text;
360 +                                        getline(buffer, text);
361 +
362 +                                        if (approved)
363 +                                        {
364 +                                                find.approved.push_back(text);
365 +                                        }
366 +                                        else
367 +                                        {
368 +                                                find.approve.push_back(text);
369 +
370 +                                                submit("find", text);
371 +                                        }
372 +                                }
373 +                                break;
374 +                        case HELP:
375 +                                if (vote == "solved")
376 +                                {
377 +                                        help.solved++;
378 +                                }
379 +                                else if (vote == "note")
380 +                                {
381 +                                        help.note++;
382 +                                }
383 +                                else if (vote == "link")
384 +                                {
385 +                                        help.link++;
386 +                                }
387 +                                else if (vote == "news")
388 +                                {
389 +                                        help.news++;
390 +                                }
391 +                                else if (vote == "lazy")
392 +                                {
393 +                                        help.lazy++;
394 +                                }
395 +                                break;
396 +                        case IMPROVE:
397 +                                if (vote == "nothing")
398 +                                {
399 +                                        improve.nothing++;
400 +                                }
401 +                                else if (vote == "links")
402 +                                {
403 +                                        improve.links++;
404 +                                }
405 +                                else if (vote == "suggest")
406 +                                {
407 +                                        improve.suggest++;
408 +
409 +                                        string text;
410 +                                        getline(buffer, text);
411 +
412 +                                        if (approved)
413 +                                        {
414 +                                                improve.approved.push_back(text);
415 +                                        }
416 +                                        else
417 +                                        {
418 +                                                improve.approve.push_back(text);
419 +
420 +                                                submit("improve", text);
421 +                                        }
422 +                                }
423 +                                break;
424 +                        }
425 +                }
426 +
427 +                session->store(number.str() + " +FLAGS (\\Deleted)");
428 +
429 +                cout << "done.\n";
430 +        }
431 +        else
432 +        {
433 +                cout << "cancelled.\n";
434 +        }
435 +
436 +        if (!messages.empty())
437 +        {
438 +                unsigned message = messages.front();
439 +                messages.pop();
440 +
441 +                ballot(message);
442 +        }
443 + }
444 +
445 + void Poller::submit(const string& type, const string& text)
446 + {
447 +        //
448 + }
449 +
450 + void Poller::approvals()
451 + {
452 +        //
453 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines