TextMessage.cpp
changeset 15 b1c2c371379c
parent 13 d83d94f11e62
child 20 f77dd13806ff
     1.1 --- a/TextMessage.cpp	Wed Apr 29 09:49:18 2015 +0200
     1.2 +++ b/TextMessage.cpp	Fri May 01 00:24:12 2015 +0200
     1.3 @@ -153,3 +153,848 @@
     1.4  
     1.5      return S_OK;
     1.6  }
     1.7 +
     1.8 +STDMETHODIMP CTextMessage::get_recv_by(pEp_identity_s* pVal)
     1.9 +{
    1.10 +    assert(pVal);
    1.11 +
    1.12 +    try {
    1.13 +        copy_identity(pVal, msg->recv_by);
    1.14 +    }
    1.15 +    catch (bad_alloc& e) {
    1.16 +        return E_OUTOFMEMORY;
    1.17 +    }
    1.18 +    catch (exception& e) {
    1.19 +        return E_FAIL;
    1.20 +    }
    1.21 +
    1.22 +    return S_OK;
    1.23 +}
    1.24 +
    1.25 +
    1.26 +STDMETHODIMP CTextMessage::put_recv_by(pEp_identity_s* newVal)
    1.27 +{
    1.28 +    assert(newVal);
    1.29 +
    1.30 +    ::pEp_identity *_recv_by;
    1.31 +
    1.32 +    try {
    1.33 +        _recv_by = new_identity(newVal);
    1.34 +    }
    1.35 +    catch (bad_alloc& e) {
    1.36 +        return E_OUTOFMEMORY;
    1.37 +    }
    1.38 +    catch (exception& e) {
    1.39 +        return E_FAIL;
    1.40 +    }
    1.41 +
    1.42 +    ::free_identity(msg->recv_by);
    1.43 +    msg->recv_by = _recv_by;
    1.44 +    return S_OK;
    1.45 +}
    1.46 +
    1.47 +STDMETHODIMP CTextMessage::get_cc(LPSAFEARRAY * pVal)
    1.48 +{
    1.49 +    assert(pVal);
    1.50 +
    1.51 +    int len = identity_list_length(msg->cc);
    1.52 +
    1.53 +    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
    1.54 +    if (sa == NULL)
    1.55 +        return E_OUTOFMEMORY;
    1.56 +
    1.57 +    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);
    1.58 +
    1.59 +    identity_list *il = msg->cc;
    1.60 +    ULONG i;
    1.61 +    for (i = 0, il = msg->cc; il && il->ident; il = il->next, i++) {
    1.62 +        try {
    1.63 +            copy_identity(&cs[i], il->ident);
    1.64 +        }
    1.65 +        catch (bad_alloc& e) {
    1.66 +            SafeArrayUnaccessData(sa);
    1.67 +            SafeArrayDestroy(sa);
    1.68 +            return E_OUTOFMEMORY;
    1.69 +        }
    1.70 +        catch (exception& e) {
    1.71 +            SafeArrayUnaccessData(sa);
    1.72 +            SafeArrayDestroy(sa);
    1.73 +            return E_FAIL;
    1.74 +        }
    1.75 +    }
    1.76 +
    1.77 +    SafeArrayUnaccessData(sa);
    1.78 +
    1.79 +    *pVal = sa;
    1.80 +    return S_OK;
    1.81 +}
    1.82 +
    1.83 +STDMETHODIMP CTextMessage::put_cc(SAFEARRAY * newVal)
    1.84 +{
    1.85 +    assert(newVal);
    1.86 +
    1.87 +    if (newVal == NULL)
    1.88 +        return E_INVALIDARG;
    1.89 +
    1.90 +    identity_list *il = new_identity_list(NULL);
    1.91 +    if (il == NULL)
    1.92 +        return E_OUTOFMEMORY;
    1.93 +
    1.94 +    pEp_identity_s *cs;
    1.95 +    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
    1.96 +    assert(SUCCEEDED(hr) && cs);
    1.97 +    if (cs == NULL) {
    1.98 +        free_identity_list(il);
    1.99 +        return E_FAIL;
   1.100 +    }
   1.101 +
   1.102 +    identity_list *_il;
   1.103 +    LONG i, lbound, ubound;
   1.104 +    SafeArrayGetLBound(newVal, 1, &lbound);
   1.105 +    SafeArrayGetUBound(newVal, 1, &ubound);
   1.106 +
   1.107 +    for (i = lbound, _il = il; i <= ubound; i++) {
   1.108 +        pEp_identity * ident;
   1.109 +        try {
   1.110 +            ident = new_identity(&cs[i]);
   1.111 +        }
   1.112 +        catch (bad_alloc& e) {
   1.113 +            SafeArrayUnaccessData(newVal);
   1.114 +            free_identity_list(il);
   1.115 +            return E_OUTOFMEMORY;
   1.116 +        }
   1.117 +        catch (exception& e) {
   1.118 +            SafeArrayUnaccessData(newVal);
   1.119 +            free_identity_list(il);
   1.120 +            return E_FAIL;
   1.121 +        }
   1.122 +        _il = identity_list_add(_il, ident);
   1.123 +        if (_il == NULL) {
   1.124 +            SafeArrayUnaccessData(newVal);
   1.125 +            free_identity_list(il);
   1.126 +            return E_OUTOFMEMORY;
   1.127 +        }
   1.128 +    }
   1.129 +
   1.130 +    SafeArrayUnaccessData(newVal);
   1.131 +
   1.132 +    free_identity_list(msg->cc);
   1.133 +    msg->cc = il;
   1.134 +
   1.135 +    return S_OK;
   1.136 +}
   1.137 +
   1.138 +STDMETHODIMP CTextMessage::get_bcc(LPSAFEARRAY * pVal)
   1.139 +{
   1.140 +    assert(pVal);
   1.141 +
   1.142 +    int len = identity_list_length(msg->bcc);
   1.143 +
   1.144 +    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
   1.145 +    if (sa == NULL)
   1.146 +        return E_OUTOFMEMORY;
   1.147 +
   1.148 +    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);
   1.149 +
   1.150 +    identity_list *il = msg->bcc;
   1.151 +    ULONG i;
   1.152 +    for (i = 0, il = msg->bcc; il && il->ident; il = il->next, i++) {
   1.153 +        try {
   1.154 +            copy_identity(&cs[i], il->ident);
   1.155 +        }
   1.156 +        catch (bad_alloc& e) {
   1.157 +            SafeArrayUnaccessData(sa);
   1.158 +            SafeArrayDestroy(sa);
   1.159 +            return E_OUTOFMEMORY;
   1.160 +        }
   1.161 +        catch (exception& e) {
   1.162 +            SafeArrayUnaccessData(sa);
   1.163 +            SafeArrayDestroy(sa);
   1.164 +            return E_FAIL;
   1.165 +        }
   1.166 +    }
   1.167 +
   1.168 +    SafeArrayUnaccessData(sa);
   1.169 +
   1.170 +    *pVal = sa;
   1.171 +    return S_OK;
   1.172 +}
   1.173 +
   1.174 +STDMETHODIMP CTextMessage::put_bcc(SAFEARRAY * newVal)
   1.175 +{
   1.176 +    assert(newVal);
   1.177 +
   1.178 +    if (newVal == NULL)
   1.179 +        return E_INVALIDARG;
   1.180 +
   1.181 +    identity_list *il = new_identity_list(NULL);
   1.182 +    if (il == NULL)
   1.183 +        return E_OUTOFMEMORY;
   1.184 +
   1.185 +    pEp_identity_s *cs;
   1.186 +    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
   1.187 +    assert(SUCCEEDED(hr) && cs);
   1.188 +    if (cs == NULL) {
   1.189 +        free_identity_list(il);
   1.190 +        return E_FAIL;
   1.191 +    }
   1.192 +
   1.193 +    identity_list *_il;
   1.194 +    LONG i, lbound, ubound;
   1.195 +    SafeArrayGetLBound(newVal, 1, &lbound);
   1.196 +    SafeArrayGetUBound(newVal, 1, &ubound);
   1.197 +
   1.198 +    for (i = lbound, _il = il; i <= ubound; i++) {
   1.199 +        pEp_identity * ident;
   1.200 +        try {
   1.201 +            ident = new_identity(&cs[i]);
   1.202 +        }
   1.203 +        catch (bad_alloc& e) {
   1.204 +            SafeArrayUnaccessData(newVal);
   1.205 +            free_identity_list(il);
   1.206 +            return E_OUTOFMEMORY;
   1.207 +        }
   1.208 +        catch (exception& e) {
   1.209 +            SafeArrayUnaccessData(newVal);
   1.210 +            free_identity_list(il);
   1.211 +            return E_FAIL;
   1.212 +        }
   1.213 +        _il = identity_list_add(_il, ident);
   1.214 +        if (_il == NULL) {
   1.215 +            SafeArrayUnaccessData(newVal);
   1.216 +            free_identity_list(il);
   1.217 +            return E_OUTOFMEMORY;
   1.218 +        }
   1.219 +    }
   1.220 +
   1.221 +    SafeArrayUnaccessData(newVal);
   1.222 +
   1.223 +    free_identity_list(msg->bcc);
   1.224 +    msg->bcc = il;
   1.225 +
   1.226 +    return S_OK;
   1.227 +}
   1.228 +
   1.229 +STDMETHODIMP CTextMessage::get_reply_to(LPSAFEARRAY * pVal)
   1.230 +{
   1.231 +    assert(pVal);
   1.232 +
   1.233 +    int len = identity_list_length(msg->reply_to);
   1.234 +
   1.235 +    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
   1.236 +    if (sa == NULL)
   1.237 +        return E_OUTOFMEMORY;
   1.238 +
   1.239 +    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);
   1.240 +
   1.241 +    identity_list *il = msg->reply_to;
   1.242 +    ULONG i;
   1.243 +    for (i = 0, il = msg->reply_to; il && il->ident; il = il->next, i++) {
   1.244 +        try {
   1.245 +            copy_identity(&cs[i], il->ident);
   1.246 +        }
   1.247 +        catch (bad_alloc& e) {
   1.248 +            SafeArrayUnaccessData(sa);
   1.249 +            SafeArrayDestroy(sa);
   1.250 +            return E_OUTOFMEMORY;
   1.251 +        }
   1.252 +        catch (exception& e) {
   1.253 +            SafeArrayUnaccessData(sa);
   1.254 +            SafeArrayDestroy(sa);
   1.255 +            return E_FAIL;
   1.256 +        }
   1.257 +    }
   1.258 +
   1.259 +    SafeArrayUnaccessData(sa);
   1.260 +
   1.261 +    *pVal = sa;
   1.262 +    return S_OK;
   1.263 +}
   1.264 +
   1.265 +STDMETHODIMP CTextMessage::put_reply_to(SAFEARRAY * newVal)
   1.266 +{
   1.267 +    assert(newVal);
   1.268 +
   1.269 +    if (newVal == NULL)
   1.270 +        return E_INVALIDARG;
   1.271 +
   1.272 +    identity_list *il = new_identity_list(NULL);
   1.273 +    if (il == NULL)
   1.274 +        return E_OUTOFMEMORY;
   1.275 +
   1.276 +    pEp_identity_s *cs;
   1.277 +    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
   1.278 +    assert(SUCCEEDED(hr) && cs);
   1.279 +    if (cs == NULL) {
   1.280 +        free_identity_list(il);
   1.281 +        return E_FAIL;
   1.282 +    }
   1.283 +
   1.284 +    identity_list *_il;
   1.285 +    LONG i, lbound, ubound;
   1.286 +    SafeArrayGetLBound(newVal, 1, &lbound);
   1.287 +    SafeArrayGetUBound(newVal, 1, &ubound);
   1.288 +
   1.289 +    for (i = lbound, _il = il; i <= ubound; i++) {
   1.290 +        pEp_identity * ident;
   1.291 +        try {
   1.292 +            ident = new_identity(&cs[i]);
   1.293 +        }
   1.294 +        catch (bad_alloc& e) {
   1.295 +            SafeArrayUnaccessData(newVal);
   1.296 +            free_identity_list(il);
   1.297 +            return E_OUTOFMEMORY;
   1.298 +        }
   1.299 +        catch (exception& e) {
   1.300 +            SafeArrayUnaccessData(newVal);
   1.301 +            free_identity_list(il);
   1.302 +            return E_FAIL;
   1.303 +        }
   1.304 +        _il = identity_list_add(_il, ident);
   1.305 +        if (_il == NULL) {
   1.306 +            SafeArrayUnaccessData(newVal);
   1.307 +            free_identity_list(il);
   1.308 +            return E_OUTOFMEMORY;
   1.309 +        }
   1.310 +    }
   1.311 +
   1.312 +    SafeArrayUnaccessData(newVal);
   1.313 +
   1.314 +    free_identity_list(msg->reply_to);
   1.315 +    msg->reply_to = il;
   1.316 +
   1.317 +    return S_OK;
   1.318 +}
   1.319 +
   1.320 +STDMETHODIMP CTextMessage::get_dir(pEp_msg_direction *pVal)
   1.321 +{
   1.322 +    assert(pVal);
   1.323 +
   1.324 +    *pVal = (pEp_msg_direction) msg->dir;
   1.325 +
   1.326 +    return S_OK;
   1.327 +}
   1.328 +
   1.329 +STDMETHODIMP CTextMessage::put_dir(pEp_msg_direction newVal)
   1.330 +{
   1.331 +    msg->dir = (PEP_msg_direction) newVal;
   1.332 +
   1.333 +    return S_OK;
   1.334 +}
   1.335 +
   1.336 +STDMETHODIMP CTextMessage::get_id(BSTR * pVal)
   1.337 +{
   1.338 +    assert(pVal);
   1.339 +
   1.340 +    _bstr_t val;
   1.341 +
   1.342 +    if (msg->id) {
   1.343 +        try {
   1.344 +            val = utf16_bstr(msg->id);
   1.345 +        }
   1.346 +        catch (bad_alloc& e) {
   1.347 +            return E_OUTOFMEMORY;
   1.348 +        }
   1.349 +        catch (exception& e) {
   1.350 +            return E_FAIL;
   1.351 +        }
   1.352 +    }
   1.353 +
   1.354 +    *pVal = val.Detach();
   1.355 +
   1.356 +    return S_OK;
   1.357 +}
   1.358 +
   1.359 +STDMETHODIMP CTextMessage::put_id(BSTR newVal)
   1.360 +{
   1.361 +    assert(newVal);
   1.362 +
   1.363 +    string val;
   1.364 +
   1.365 +    try {
   1.366 +        val = utf8_string(newVal);
   1.367 +    }
   1.368 +    catch (bad_alloc& e) {
   1.369 +        return E_OUTOFMEMORY;
   1.370 +    }
   1.371 +    catch (exception& e) {
   1.372 +        return E_FAIL;
   1.373 +    }
   1.374 +
   1.375 +    if (msg->id)
   1.376 +        free(msg->id);
   1.377 +
   1.378 +    msg->id = _strdup(val.c_str());
   1.379 +    if (msg->id == NULL)
   1.380 +        return E_OUTOFMEMORY;
   1.381 +
   1.382 +    return S_OK;
   1.383 +}
   1.384 +
   1.385 +STDMETHODIMP CTextMessage::get_shortmsg(BSTR * pVal)
   1.386 +{
   1.387 +    assert(pVal);
   1.388 +
   1.389 +    _bstr_t val;
   1.390 +
   1.391 +    if (msg->shortmsg) {
   1.392 +        try {
   1.393 +            val = utf16_bstr(msg->shortmsg);
   1.394 +        }
   1.395 +        catch (bad_alloc& e) {
   1.396 +            return E_OUTOFMEMORY;
   1.397 +        }
   1.398 +        catch (exception& e) {
   1.399 +            return E_FAIL;
   1.400 +        }
   1.401 +    }
   1.402 +
   1.403 +    *pVal = val.Detach();
   1.404 +
   1.405 +    return S_OK;
   1.406 +}
   1.407 +
   1.408 +STDMETHODIMP CTextMessage::put_shortmsg(BSTR newVal)
   1.409 +{
   1.410 +    assert(newVal);
   1.411 +
   1.412 +    string val;
   1.413 +
   1.414 +    try {
   1.415 +        val = utf8_string(newVal);
   1.416 +    }
   1.417 +    catch (bad_alloc& e) {
   1.418 +        return E_OUTOFMEMORY;
   1.419 +    }
   1.420 +    catch (exception& e) {
   1.421 +        return E_FAIL;
   1.422 +    }
   1.423 +
   1.424 +    if (msg->shortmsg)
   1.425 +        free(msg->shortmsg);
   1.426 +
   1.427 +    msg->shortmsg = _strdup(val.c_str());
   1.428 +    if (msg->shortmsg == NULL)
   1.429 +        return E_OUTOFMEMORY;
   1.430 +
   1.431 +    return S_OK;
   1.432 +}
   1.433 +
   1.434 +STDMETHODIMP CTextMessage::get_longmsg(BSTR * pVal)
   1.435 +{
   1.436 +    assert(pVal);
   1.437 +
   1.438 +    _bstr_t val;
   1.439 +
   1.440 +    if (msg->longmsg) {
   1.441 +        try {
   1.442 +            val = utf16_bstr(msg->longmsg);
   1.443 +        }
   1.444 +        catch (bad_alloc& e) {
   1.445 +            return E_OUTOFMEMORY;
   1.446 +        }
   1.447 +        catch (exception& e) {
   1.448 +            return E_FAIL;
   1.449 +        }
   1.450 +    }
   1.451 +
   1.452 +    *pVal = val.Detach();
   1.453 +
   1.454 +    return S_OK;
   1.455 +}
   1.456 +
   1.457 +STDMETHODIMP CTextMessage::put_longmsg(BSTR newVal)
   1.458 +{
   1.459 +    assert(newVal);
   1.460 +
   1.461 +    string val;
   1.462 +
   1.463 +    try {
   1.464 +        val = utf8_string(newVal);
   1.465 +    }
   1.466 +    catch (bad_alloc& e) {
   1.467 +        return E_OUTOFMEMORY;
   1.468 +    }
   1.469 +    catch (exception& e) {
   1.470 +        return E_FAIL;
   1.471 +    }
   1.472 +
   1.473 +    if (msg->longmsg)
   1.474 +        free(msg->longmsg);
   1.475 +
   1.476 +    msg->longmsg = _strdup(val.c_str());
   1.477 +    if (msg->longmsg == NULL)
   1.478 +        return E_OUTOFMEMORY;
   1.479 +
   1.480 +    return S_OK;
   1.481 +}
   1.482 +
   1.483 +STDMETHODIMP CTextMessage::get_longmsg_formatted(BSTR * pVal)
   1.484 +{
   1.485 +    assert(pVal);
   1.486 +
   1.487 +    _bstr_t val;
   1.488 +
   1.489 +    if (msg->longmsg_formatted) {
   1.490 +        try {
   1.491 +            val = utf16_bstr(msg->longmsg_formatted);
   1.492 +        }
   1.493 +        catch (bad_alloc& e) {
   1.494 +            return E_OUTOFMEMORY;
   1.495 +        }
   1.496 +        catch (exception& e) {
   1.497 +            return E_FAIL;
   1.498 +        }
   1.499 +    }
   1.500 +
   1.501 +    *pVal = val.Detach();
   1.502 +
   1.503 +    return S_OK;
   1.504 +}
   1.505 +
   1.506 +STDMETHODIMP CTextMessage::put_longmsg_formatted(BSTR newVal)
   1.507 +{
   1.508 +    assert(newVal);
   1.509 +
   1.510 +    string val;
   1.511 +
   1.512 +    try {
   1.513 +        val = utf8_string(newVal);
   1.514 +    }
   1.515 +    catch (bad_alloc& e) {
   1.516 +        return E_OUTOFMEMORY;
   1.517 +    }
   1.518 +    catch (exception& e) {
   1.519 +        return E_FAIL;
   1.520 +    }
   1.521 +
   1.522 +    if (msg->longmsg_formatted)
   1.523 +        free(msg->longmsg_formatted);
   1.524 +
   1.525 +    msg->longmsg_formatted = _strdup(val.c_str());
   1.526 +    if (msg->longmsg_formatted == NULL)
   1.527 +        return E_OUTOFMEMORY;
   1.528 +
   1.529 +    return S_OK;
   1.530 +}
   1.531 +
   1.532 +STDMETHODIMP CTextMessage::add_attachment(SAFEARRAY * data, BSTR mime_type, BSTR filename)
   1.533 +{
   1.534 +    assert(data);
   1.535 +    if (data == NULL)
   1.536 +        return E_INVALIDARG;
   1.537 +
   1.538 +    CComSafeArray<BYTE> sa_data(data);
   1.539 +    size_t len = sa_data.GetCount();
   1.540 +
   1.541 +    char *_data = (char *) malloc(sa_data.GetCount());
   1.542 +    assert(_data);
   1.543 +    if (_data == NULL)
   1.544 +        return E_OUTOFMEMORY;
   1.545 +
   1.546 +    memcpy(_data, sa_data.m_psa->pvData, len);
   1.547 +    sa_data.Detach();
   1.548 +
   1.549 +    string _mime_type;
   1.550 +    if (mime_type) {
   1.551 +        try {
   1.552 +            _mime_type = utf8_string(mime_type);
   1.553 +        }
   1.554 +        catch (bad_alloc& e) {
   1.555 +            free(_data);
   1.556 +            return E_OUTOFMEMORY;
   1.557 +        }
   1.558 +        catch (exception& e) {
   1.559 +            free(_data);
   1.560 +            return E_FAIL;
   1.561 +        }
   1.562 +    }
   1.563 +
   1.564 +    string _filename;
   1.565 +    if (filename) {
   1.566 +        try {
   1.567 +            _filename = utf8_string(filename);
   1.568 +        }
   1.569 +        catch (bad_alloc& e) {
   1.570 +            free(_data);
   1.571 +            return E_OUTOFMEMORY;
   1.572 +        }
   1.573 +        catch (exception& e) {
   1.574 +            free(_data);
   1.575 +            return E_FAIL;
   1.576 +        }
   1.577 +    }
   1.578 +
   1.579 +    bloblist_t *blob = bloblist_add(msg->attachments, _data, len, _mime_type.c_str(), _filename.c_str());
   1.580 +    if (blob == NULL) {
   1.581 +        free(_data);
   1.582 +        return E_OUTOFMEMORY;
   1.583 +    }
   1.584 +
   1.585 +    return S_OK;
   1.586 +}
   1.587 +
   1.588 +STDMETHODIMP CTextMessage::has_attachments(boolean *result)
   1.589 +{
   1.590 +    assert(result);
   1.591 +
   1.592 +    if (msg->attachments == NULL || msg->attachments->data == NULL) {
   1.593 +        m_next_attachment = NULL;
   1.594 +        *result = false;
   1.595 +        return S_OK;
   1.596 +    }
   1.597 +
   1.598 +    m_next_attachment = msg->attachments;
   1.599 +    *result = true;
   1.600 +
   1.601 +    return S_OK;
   1.602 +}
   1.603 +
   1.604 +STDMETHODIMP CTextMessage::next_attachment(SAFEARRAY ** data, BSTR * mime_type, BSTR * filename, boolean *result)
   1.605 +{
   1.606 +    assert(data);
   1.607 +    assert(mime_type);
   1.608 +    assert(filename);
   1.609 +    assert(result);
   1.610 +
   1.611 +    if (m_next_attachment == NULL)
   1.612 +        return E_ILLEGAL_METHOD_CALL;
   1.613 +
   1.614 +    CComSafeArray<BYTE> sa;
   1.615 +    try {
   1.616 +        sa.Create(m_next_attachment->size);
   1.617 +    }
   1.618 +    catch (bad_alloc& e) {
   1.619 +        return E_OUTOFMEMORY;
   1.620 +    }
   1.621 +
   1.622 +    memcpy(sa.m_psa->pvData, m_next_attachment->data, m_next_attachment->size);
   1.623 +
   1.624 +    _bstr_t _mime_type;
   1.625 +    if (m_next_attachment->mime_type) {
   1.626 +        try {
   1.627 +            _mime_type = utf16_bstr(m_next_attachment->mime_type);
   1.628 +        }
   1.629 +        catch (bad_alloc& e) {
   1.630 +            return E_OUTOFMEMORY;
   1.631 +        }
   1.632 +        catch (exception& e) {
   1.633 +            return E_FAIL;
   1.634 +        }
   1.635 +    }
   1.636 +
   1.637 +    _bstr_t _filename;
   1.638 +    if (m_next_attachment->filename) {
   1.639 +        try {
   1.640 +            _filename = utf16_bstr(m_next_attachment->filename);
   1.641 +        }
   1.642 +        catch (bad_alloc& e) {
   1.643 +            return E_OUTOFMEMORY;
   1.644 +        }
   1.645 +        catch (exception& e) {
   1.646 +            return E_FAIL;
   1.647 +        }
   1.648 +    }
   1.649 +
   1.650 +    *data = sa.Detach();
   1.651 +    *mime_type = _mime_type.Detach();
   1.652 +    *filename = _filename.Detach();
   1.653 +
   1.654 +    m_next_attachment = m_next_attachment->next;
   1.655 +    *result = m_next_attachment != NULL;
   1.656 +
   1.657 +    return S_OK;
   1.658 +}
   1.659 +
   1.660 +STDMETHODIMP CTextMessage::get_sent(hyper * result)
   1.661 +{
   1.662 +    assert(result);
   1.663 +
   1.664 +    if (msg->sent == NULL)
   1.665 +        return E_NOT_SET;
   1.666 +
   1.667 +    *result = mktime(msg->sent);
   1.668 +    return S_OK;
   1.669 +}
   1.670 +
   1.671 +STDMETHODIMP CTextMessage::put_sent(hyper val)
   1.672 +{
   1.673 +    ::timestamp * ts = new_timestamp(val);
   1.674 +    if (ts == NULL)
   1.675 +        return E_OUTOFMEMORY;
   1.676 +
   1.677 +    if (msg->sent)
   1.678 +        free_timestamp(msg->sent);
   1.679 +    msg->sent = ts;
   1.680 +
   1.681 +    return S_OK;
   1.682 +}
   1.683 +
   1.684 +STDMETHODIMP CTextMessage::get_recv(hyper * result)
   1.685 +{
   1.686 +    assert(result);
   1.687 +
   1.688 +    if (msg->recv == NULL)
   1.689 +        return E_NOT_SET;
   1.690 +
   1.691 +    *result = mktime(msg->recv);
   1.692 +    return S_OK;
   1.693 +}
   1.694 +
   1.695 +STDMETHODIMP CTextMessage::put_recv(hyper val)
   1.696 +{
   1.697 +    ::timestamp * ts = new_timestamp(val);
   1.698 +    if (ts == NULL)
   1.699 +        return E_OUTOFMEMORY;
   1.700 +
   1.701 +    if (msg->recv)
   1.702 +        free_timestamp(msg->recv);
   1.703 +    msg->recv = ts;
   1.704 +
   1.705 +    return S_OK;
   1.706 +}
   1.707 +
   1.708 +STDMETHODIMP CTextMessage::get_references(SAFEARRAY ** pVal)
   1.709 +{
   1.710 +    assert(pVal);
   1.711 +
   1.712 +    CComSafeArray<BSTR> sa;
   1.713 +    try {
   1.714 +        if (msg->references) {
   1.715 +            sa = string_array(msg->references);
   1.716 +        }
   1.717 +        else {
   1.718 +            sa.Create(0UL);
   1.719 +        }
   1.720 +    }
   1.721 +    catch (bad_alloc& e) {
   1.722 +        return E_OUTOFMEMORY;
   1.723 +    }
   1.724 +    catch (exception& e) {
   1.725 +        return E_FAIL;
   1.726 +    }
   1.727 +    
   1.728 +    *pVal = sa.Detach();
   1.729 +    return S_OK;
   1.730 +}
   1.731 +
   1.732 +STDMETHODIMP CTextMessage::put_references(SAFEARRAY * newVal)
   1.733 +{
   1.734 +    assert(newVal);
   1.735 +
   1.736 +    stringlist_t *sl;
   1.737 +    
   1.738 +    try {
   1.739 +        sl = new_stringlist(newVal);
   1.740 +    }
   1.741 +    catch (bad_alloc& e) {
   1.742 +        return E_OUTOFMEMORY;
   1.743 +    }
   1.744 +    catch (exception& e) {
   1.745 +        return E_FAIL;
   1.746 +    }
   1.747 +
   1.748 +    if (msg->references)
   1.749 +        free_stringlist(msg->references);
   1.750 +
   1.751 +    msg->references = sl;
   1.752 +
   1.753 +    return S_OK;
   1.754 +}
   1.755 +
   1.756 +STDMETHODIMP CTextMessage::get_keywords(SAFEARRAY ** pVal)
   1.757 +{
   1.758 +    assert(pVal);
   1.759 +
   1.760 +    CComSafeArray<BSTR> sa;
   1.761 +    try {
   1.762 +        if (msg->keywords) {
   1.763 +            sa = string_array(msg->keywords);
   1.764 +        }
   1.765 +        else {
   1.766 +            sa.Create(0UL);
   1.767 +        }
   1.768 +    }
   1.769 +    catch (bad_alloc& e) {
   1.770 +        return E_OUTOFMEMORY;
   1.771 +    }
   1.772 +    catch (exception& e) {
   1.773 +        return E_FAIL;
   1.774 +    }
   1.775 +
   1.776 +    *pVal = sa.Detach();
   1.777 +    return S_OK;
   1.778 +}
   1.779 +
   1.780 +STDMETHODIMP CTextMessage::put_keywords(SAFEARRAY * newVal)
   1.781 +{
   1.782 +    assert(newVal);
   1.783 +
   1.784 +    stringlist_t *sl;
   1.785 +
   1.786 +    try {
   1.787 +        sl = new_stringlist(newVal);
   1.788 +    }
   1.789 +    catch (bad_alloc& e) {
   1.790 +        return E_OUTOFMEMORY;
   1.791 +    }
   1.792 +    catch (exception& e) {
   1.793 +        return E_FAIL;
   1.794 +    }
   1.795 +
   1.796 +    if (msg->keywords)
   1.797 +        free_stringlist(msg->keywords);
   1.798 +
   1.799 +    msg->keywords = sl;
   1.800 +
   1.801 +    return S_OK;
   1.802 +}
   1.803 +
   1.804 +STDMETHODIMP CTextMessage::get_comments(BSTR * pVal)
   1.805 +{
   1.806 +    assert(pVal);
   1.807 +
   1.808 +    _bstr_t val;
   1.809 +
   1.810 +    if (msg->comments) {
   1.811 +        try {
   1.812 +            val = utf16_bstr(msg->comments);
   1.813 +        }
   1.814 +        catch (bad_alloc& e) {
   1.815 +            return E_OUTOFMEMORY;
   1.816 +        }
   1.817 +        catch (exception& e) {
   1.818 +            return E_FAIL;
   1.819 +        }
   1.820 +    }
   1.821 +
   1.822 +    *pVal = val.Detach();
   1.823 +
   1.824 +    return S_OK;
   1.825 +}
   1.826 +
   1.827 +STDMETHODIMP CTextMessage::put_comments(BSTR newVal)
   1.828 +{
   1.829 +    assert(newVal);
   1.830 +
   1.831 +    string val;
   1.832 +
   1.833 +    try {
   1.834 +        val = utf8_string(newVal);
   1.835 +    }
   1.836 +    catch (bad_alloc& e) {
   1.837 +        return E_OUTOFMEMORY;
   1.838 +    }
   1.839 +    catch (exception& e) {
   1.840 +        return E_FAIL;
   1.841 +    }
   1.842 +
   1.843 +    if (msg->comments)
   1.844 +        free(msg->comments);
   1.845 +
   1.846 +    msg->comments = _strdup(val.c_str());
   1.847 +    if (msg->comments == NULL)
   1.848 +        return E_OUTOFMEMORY;
   1.849 +
   1.850 +    return S_OK;
   1.851 +}