Corrected the yellowness for bugs between the MagicDay and the bounce date.
[wvapps.git] / retchmail / wvsendmail.cc
blobfc5da87994a0ea7def7de5fd579bc4f8f29ecba0
1 #include "wvsendmail.h"
3 int WvSendmailProc::num_sendmails = 0;
5 WvSendmailProc::WvSendmailProc(const char **argv, int _count,
6 const WvSendmailCallback &_cb)
7 : WvPipe(argv[0], argv, true, false, false), count(_count), cb(_cb)
9 is_done = exited = false;
10 num_sendmails++;
14 WvSendmailProc::~WvSendmailProc()
16 close();
18 int ret = finish();
20 // be certain the callback gets called
21 if (!exited && cb)
22 cb(count, (ret == 0));
24 num_sendmails--;
28 bool WvSendmailProc::pre_select(SelectInfo &si)
30 bool must = false;
32 if (is_done && !exited && si.msec_timeout > 20)
33 si.msec_timeout = 20;
35 if (child_exited() && !exited && is_done)
37 exited = true;
39 // call the callback
40 if (cb)
41 cb(count, !exit_status());
43 si.msec_timeout = 0;
44 must = true;
47 // another hack because isok() returns true when it shouldn't really
48 if ((exited || is_done) && si.wants.writable)
49 must = true;
51 return must || WvPipe::pre_select(si);
55 bool WvSendmailProc::isok() const
57 // note: this means people will try to write to us even if the pipe
58 // says it's invalid!
59 return WvPipe::isok() || !exited;
63 size_t WvSendmailProc::uwrite(const void *buf, size_t count)
65 if (child_exited())
66 return count; // fake it, because isok() is also faking it
67 return WvPipe::uwrite(buf, count);
71 void WvSendmailProc::execute()
73 WvPipe::execute();
75 if (is_done && select(0, false, true, false))
76 close();
80 void WvSendmailProc::done()
82 is_done = true;
83 force_select(false, true);