Handle the EINTR error when doing a waitpid() in wvmagicloopback.
[wvapps.git] / evolution / updateitem.cc
blobbdd90c19336afd9dd0a2429309feb5a7120cd436
1 #include "updateitem.h"
2 #include "genericcommand.h"
3 #include "exchangeitadaptor.h"
4 #include "wvfile.h"
5 #include "wvbase64.h"
6 #include "wvstream.h"
7 #include "wvtnefconv.h"
8 #include "wvloopback.h"
9 #include "wvencoderstream.h"
11 UpdateItem::UpdateItem(WvStream &_stream,
12 ExchangeItAdaptor *_adaptor,
13 WvStringParm _uid) :
14 log("UpdateItem", WvLog::Debug1),
15 stream(_stream),
16 adaptor(_adaptor),
17 uid(_uid)
19 assert(adaptor);
22 bool UpdateItem::update(bool careful)
24 // FIXME (22/12/03): this code is inefficient, shouldn't be
25 // allocating all the time. probably not worth the effort
26 // until we fix the scalability problem on the server though
27 // It also tickles a bug in WvTnef, namely that it expects good
28 // data right away; with larger items, the Base64Decoder can't
29 // "keep up" (pcolijn)
31 WvString line;
32 WvStream *out_stream = NULL;
34 WvEncoderStream b64_stream(new WvLoopback());
35 b64_stream.writechain.append(new WvBase64Decoder(), true);
36 b64_stream.auto_flush(false);
38 log("Reading tnef");
40 while (!!(line = stream.blocking_getline(TIMEOUT)))
42 log(WvLog::Debug5, "Read:\n'%s'\nfrom stream\n", line);
43 b64_stream.write(line);
46 b64_stream.finish_write();
47 bool success = true;
49 // In some situations we may not receive a TNEF, and that's ok
50 if (b64_stream.isreadable())
52 WvString tnef_path("%s/%s", adaptor->get_storage_path(), uid);
53 WvFile file(tnef_path, (O_WRONLY|O_CREAT), 0600);
54 if (file.isok())
55 out_stream = &file;
56 else if (!careful)
58 log("Could not open %s for writing: %s\n",
59 tnef_path, file.errstr());
60 file.close();
61 return false;
64 WvTnef tnef(&b64_stream, out_stream);
66 if (tnef.isok())
67 adaptor->update_item(tnef, uid);
68 else
69 success = false;
71 file.close();
74 return success;