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; |
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" |
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_") |
108 |
|
fin.get(); |
109 |
|
} |
110 |
|
|
111 |
+ |
fin.peek(); |
112 |
+ |
|
113 |
|
switch (type) |
114 |
|
{ |
115 |
|
case FIND: |
196 |
|
break; |
197 |
|
} |
198 |
|
} |
187 |
– |
while (fin.good()); |
199 |
|
|
200 |
|
fin.close(); |
201 |
|
} |
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\" HEADER \"X-WinXPFAQPoll-Post-Host\" * HEADE" |
248 |
< |
+ "R \"X-WinXPFAQPoll-Post-Agent\" *"); |
258 |
> |
+ "Windows XP FAQ | Poll\""); |
259 |
|
|
260 |
< |
string junk; |
261 |
< |
|
252 |
< |
getline(search, junk, ' '); |
253 |
< |
getline(search, junk, ' '); |
260 |
> |
search.ignore(9); |
261 |
> |
search.peek(); |
262 |
|
|
263 |
|
while (search.good()) |
264 |
|
{ |
265 |
|
unsigned message; |
266 |
|
search >> message; |
259 |
– |
search.get(); |
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()) |
279 |
|
|
280 |
|
ballot(message); |
281 |
|
} |
272 |
– |
|
273 |
– |
if (!nodelete) |
274 |
– |
{ |
275 |
– |
session->expunge(); |
276 |
– |
} |
282 |
|
} |
283 |
|
|
284 |
|
void Poller::ballot(unsigned message) |
285 |
|
{ |
286 |
|
cout << "Checking message: " << message << "..." << flush; |
287 |
|
|
288 |
< |
char number[32 + 1]; |
289 |
< |
sprintf(number, "%u", message); |
288 |
> |
ostringstream number; |
289 |
> |
number << message; |
290 |
|
|
291 |
|
stringstream buffer; |
292 |
|
|
293 |
< |
buffer << session->fetch(string(number) + " BODY.PEEK[2]"); |
293 |
> |
buffer << session->fetch(number.str() + " BODY.PEEK[2]"); |
294 |
|
|
295 |
|
if (session->successful()) |
296 |
|
{ |
297 |
< |
bool approved = session->fetch(string(number) + " FLAGS").find("\\Flag" |
293 |
< |
+ string("ged")) != string::npos; |
297 |
> |
buffer.ignore(string::npos, '\n'); |
298 |
|
|
299 |
< |
do |
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; |
323 |
|
continue; |
324 |
|
} |
325 |
|
|
326 |
+ |
buffer.peek(); |
327 |
+ |
|
328 |
|
switch (type) |
329 |
|
{ |
330 |
|
case FIND: |
356 |
|
{ |
357 |
|
find.other++; |
358 |
|
|
359 |
< |
// |
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: |
406 |
|
{ |
407 |
|
improve.suggest++; |
408 |
|
|
409 |
< |
// |
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 |
< |
while (buffer.good()); |
426 |
> |
|
427 |
> |
session->store(number.str() + " +FLAGS (\\Deleted)"); |
428 |
|
|
429 |
|
cout << "done.\n"; |
430 |
|
} |
442 |
|
} |
443 |
|
} |
444 |
|
|
445 |
< |
void Poller::approvals() |
445 |
> |
void Poller::submit(const string& type, const string& text) |
446 |
|
{ |
447 |
< |
// |
447 |
> |
ostringstream message; |
448 |
|
|
449 |
< |
if (!nodelete) |
449 |
> |
message << "From: \"Windows XP FAQ | Poll\" <" << account.getEmail() |
450 |
> |
<< ">\n" |
451 |
> |
<< "To: \"" << account.getName() << "\" <" << account.getEmail() |
452 |
> |
<< ">\n" |
453 |
> |
<< "Subject: Windows XP FAQ | Poll Submit\n" |
454 |
> |
<< "Content-Type: text/plain charset=\"us-ascii\"\n" |
455 |
> |
<< "Content-Transfer-Encoding: 7bit\n" |
456 |
> |
<< "X-Mailer: WinXPFAQPoll 1.0\n" |
457 |
> |
<< "X-WinXPFAQPoll-Submit-Type: " << type << "\n" |
458 |
> |
<< "X-WinXPFAQPoll-Submit-Text: " << text << "\n\n"; |
459 |
> |
|
460 |
> |
if (type == "find") |
461 |
|
{ |
462 |
< |
session->expunge(); |
462 |
> |
message << "How did you find this page?\n" |
463 |
> |
<< " I arrived here by entirely different means:\n"; |
464 |
> |
} |
465 |
> |
else if (type == "improve") |
466 |
> |
{ |
467 |
> |
message << "How could I improve this site?\n" |
468 |
> |
<< " I have my own completely insane suggestion:\n"; |
469 |
|
} |
470 |
+ |
|
471 |
+ |
message << " " << text << "\n\n" |
472 |
+ |
<< "Flag this message to approve the voter\'s possibly objectionable\n" |
473 |
+ |
<< "input or delete it to disapprove.\n\n" |
474 |
+ |
<< "This message will be marked deleted when it is processed.\n"; |
475 |
+ |
|
476 |
+ |
ostringstream length; |
477 |
+ |
length << (message.str().length() + 16); |
478 |
+ |
|
479 |
+ |
session->append('\"' + account.getMailbox() + "\" {" + length.str() + '}', |
480 |
+ |
message.str()); |
481 |
+ |
|
482 |
+ |
session->noop(); |
483 |
+ |
} |
484 |
+ |
|
485 |
+ |
void Poller::approvals() |
486 |
+ |
{ |
487 |
+ |
// |
488 |
+ |
} |
489 |
+ |
|
490 |
+ |
void Poller::approval(unsigned message) |
491 |
+ |
{ |
492 |
+ |
// |
493 |
|
} |