1 #include "updateitem.h"
2 #include "genericcommand.h"
3 #include "exchangeitadaptor.h"
7 #include "wvtnefconv.h"
8 #include "wvloopback.h"
9 #include "wvencoderstream.h"
11 UpdateItem::UpdateItem(WvStream
&_stream
,
12 ExchangeItAdaptor
*_adaptor
,
14 log("UpdateItem", WvLog::Debug1
),
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)
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);
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();
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);
58 log("Could not open %s for writing: %s\n",
59 tnef_path
, file
.errstr());
64 WvTnef
tnef(&b64_stream
, out_stream
);
67 adaptor
->update_item(tnef
, uid
);